aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/H02ProtocolDecoder.java
diff options
context:
space:
mode:
authorIvan Muratov <binakot@gmail.com>2017-10-24 14:52:48 +0300
committerGitHub <noreply@github.com>2017-10-24 14:52:48 +0300
commitdb02157dbb29539dda4b51a5e8b317293cfc536c (patch)
treeb974f082172406e16a92cb9da8136ef856f571a5 /src/org/traccar/protocol/H02ProtocolDecoder.java
parent09d3cf2b5416327700ad22b652cf4a0dca09aaf2 (diff)
parent96e15853b9c28bd31295ca2c014e226e4a50aaa1 (diff)
downloadtrackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.tar.gz
trackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.tar.bz2
trackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.zip
Merge branch 'master' into master
Diffstat (limited to 'src/org/traccar/protocol/H02ProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java120
1 files changed, 104 insertions, 16 deletions
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index aa3d47650..4414870d2 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -150,10 +150,22 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
.text("*")
.expression("..,") // manufacturer
.number("(d+),") // imei
- .expression("[^,]+,")
- .any()
+ .groupBegin()
+ .text("VP1,")
+ .or()
+ .groupBegin()
+ .text("V4,")
+ .expression("(.*),") // response
+ .or()
+ .expression("V[^,]*,")
+ .groupEnd()
.number("(?:(dd)(dd)(dd))?,") // time (hhmmss)
- .expression("([AV])?,") // validity
+ .groupEnd()
+ .groupBegin()
+ .expression("([ABV])?,") // validity
+ .or()
+ .number("(d+),") // coding scheme
+ .groupEnd()
.groupBegin()
.number("-(d+)-(d+.d+),") // latitude
.or()
@@ -169,25 +181,28 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
.number("(d+.?d*),") // speed
.number("(d+.?d*)?,") // course
.number("(?:(dd)(dd)(dd))?") // date (ddmmyy)
- .any()
- .number(",(x{8})") // status
+ .groupBegin()
+ .expression(",[^,]*,")
+ .expression("[^,]*,")
+ .expression("[^,]*") // sim info
+ .groupEnd("?")
+ .groupBegin()
+ .number(",(x{8})")
.groupBegin()
.number(",(d+),") // odometer
.number("(-?d+),") // temperature
.number("(d+.d+),") // fuel
.number("(-?d+),") // altitude
.number("(x+),") // lac
- .number("(x+)#") // cid
+ .number("(x+)") // cid
.or()
- .number(",(d+),")
- .number("(d+),")
- .number("(d+),")
- .number("(d+)#")
+ .text(",")
+ .expression("(.*)") // data
.or()
- .expression(",.*")
+ .groupEnd()
.or()
- .text("#")
.groupEnd()
+ .text("#")
.compile();
private static final Pattern PATTERN_NBR = new PatternBuilder()
@@ -222,6 +237,24 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
+ private static final Pattern PATTERN_V3 = new PatternBuilder()
+ .text("*")
+ .expression("..,") // manufacturer
+ .number("(d+),") // imei
+ .text("V3,")
+ .number("(dd)(dd)(dd),") // time (hhmmss)
+ .number("(ddd)") // mcc
+ .number("(d+),") // mnc
+ .number("(d+),") // count
+ .expression("(.*),") // cell info
+ .number("(x{4}),") // battery
+ .number("d+,") // reboot info
+ .text("X,")
+ .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .number("(x{8})") // status
+ .text("#").optional()
+ .compile();
+
private Position decodeText(String sentence, Channel channel, SocketAddress remoteAddress) {
Parser parser = new Parser(PATTERN, sentence);
@@ -238,6 +271,10 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
+ if (parser.hasNext()) {
+ position.set(Position.KEY_RESULT, parser.next());
+ }
+
DateBuilder dateBuilder = new DateBuilder();
if (parser.hasNext(3)) {
dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
@@ -246,6 +283,10 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
if (parser.hasNext()) {
position.setValid(parser.next().equals("A"));
}
+ if (parser.hasNext()) {
+ parser.nextInt(); // coding scheme
+ position.setValid(true);
+ }
if (parser.hasNext(2)) {
position.setLatitude(-parser.nextCoordinate());
@@ -271,7 +312,9 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
position.setTime(new Date());
}
- processStatus(position, parser.nextLong(16, 0));
+ if (parser.hasNext()) {
+ processStatus(position, parser.nextLong(16, 0));
+ }
if (parser.hasNext(6)) {
position.set(Position.KEY_ODOMETER, parser.nextInt(0));
@@ -284,8 +327,9 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
}
if (parser.hasNext(4)) {
- for (int i = 1; i <= 4; i++) {
- position.set(Position.PREFIX_IO + i, parser.nextInt(0));
+ String[] values = parser.next().split(",");
+ for (int i = 0; i < values.length; i++) {
+ position.set(Position.PREFIX_IO + (i + 1), values[i].trim());
}
}
@@ -354,7 +398,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_RSSI, parser.nextInt());
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
- position.set("steps", parser.nextInt());
+ position.set(Position.KEY_STEPS, parser.nextInt());
position.set("turnovers", parser.nextInt());
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
@@ -366,6 +410,48 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Position decodeV3(String sentence, Channel channel, SocketAddress remoteAddress) {
+
+ Parser parser = new Parser(PATTERN_V3, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
+
+ int mcc = parser.nextInt();
+ int mnc = parser.nextInt();
+
+ int count = parser.nextInt();
+ Network network = new Network();
+ String[] values = parser.next().split(",");
+ for (int i = 0; i < count; i++) {
+ network.addCellTower(CellTower.from(
+ mcc, mnc, Integer.parseInt(values[i * 4]), Integer.parseInt(values[i * 4 + 1])));
+ }
+ position.setNetwork(network);
+
+ position.set(Position.KEY_BATTERY, parser.nextHexInt());
+
+ dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
+
+ getLastLocation(position, dateBuilder.getDate());
+
+ processStatus(position, parser.nextLong(16, 0));
+
+ return position;
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -385,6 +471,8 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
return decodeLbs(sentence, channel, remoteAddress);
case "LINK":
return decodeLink(sentence, channel, remoteAddress);
+ case "V3":
+ return decodeV3(sentence, channel, remoteAddress);
default:
return decodeText(sentence, channel, remoteAddress);
}