aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-01-04 21:18:22 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2021-01-04 21:18:22 -0800
commiteaca872f70921c63030d4758d52cf4fe2df2bfac (patch)
treeda5a05c9374d2b8dd162a15d418a6eda8b419f71 /src/main/java
parent3ecc99e19384ea3d1174a5dff3703081ae1a2a0c (diff)
downloadtraccar-server-eaca872f70921c63030d4758d52cf4fe2df2bfac.tar.gz
traccar-server-eaca872f70921c63030d4758d52cf4fe2df2bfac.tar.bz2
traccar-server-eaca872f70921c63030d4758d52cf4fe2df2bfac.zip
Support network location
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/protocol/EasyTrackProtocolDecoder.java61
1 files changed, 55 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/protocol/EasyTrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/EasyTrackProtocolDecoder.java
index 9be6442a5..4fcc48944 100644
--- a/src/main/java/org/traccar/protocol/EasyTrackProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/EasyTrackProtocolDecoder.java
@@ -25,6 +25,8 @@ import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
+import org.traccar.model.CellTower;
+import org.traccar.model.Network;
import org.traccar.model.Position;
import java.net.SocketAddress;
@@ -65,6 +67,18 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
+ private static final Pattern PATTERN_CELL = new PatternBuilder()
+ .text("*").expression("..,") // manufacturer
+ .number("(d+),") // imei
+ .text("JZ,") // command
+ .number("([01]),") // result
+ .number("(d+),") // cid
+ .number("(d+),") // lac
+ .number("(d+),") // mcc
+ .number("(d+)") // mnc
+ .any()
+ .compile();
+
private String decodeAlarm(long status) {
if ((status & 0x02000000) != 0) {
return Position.ALARM_GEOFENCE_ENTER;
@@ -97,27 +111,30 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder {
String sentence = (String) msg;
String type = sentence.substring(20, 22);
- if ((type.equals("TX") || type.equals("MQ")) && channel != null) {
+ if (channel != null && (type.equals("TX") || type.equals("MQ"))) {
channel.writeAndFlush(new NetworkMessage(sentence + "#", remoteAddress));
}
- return decodeLocation(channel, remoteAddress, sentence);
+ if (type.equals("JZ")) {
+ return decodeCell(channel, remoteAddress, sentence);
+ } else {
+ return decodeLocation(channel, remoteAddress, sentence);
+ }
}
- protected Object decodeLocation(
- Channel channel, SocketAddress remoteAddress, String sentence) {
+ private Position decodeLocation(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
- Position position = new Position(getProtocolName());
-
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
+
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_COMMAND, parser.next());
@@ -170,4 +187,36 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Position decodeCell(Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN_CELL, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ String imei = parser.next();
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ if (channel != null && parser.nextInt() > 0) {
+ String response = String.format("*ET,%s,JZ,undefined#", imei);
+ channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
+ }
+
+ int cid = parser.nextInt();
+ int lac = parser.nextInt();
+ int mcc = parser.nextInt();
+ int mnc = parser.nextInt();
+ position.setNetwork(new Network(CellTower.from(mcc, mnc, lac, cid)));
+
+ return position;
+ }
+
}