aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/Gps056FrameDecoder.java6
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java63
-rw-r--r--test/org/traccar/protocol/Gps056FrameDecoderTest.java4
-rw-r--r--test/org/traccar/protocol/H02ProtocolDecoderTest.java5
4 files changed, 72 insertions, 6 deletions
diff --git a/src/org/traccar/protocol/Gps056FrameDecoder.java b/src/org/traccar/protocol/Gps056FrameDecoder.java
index 7adfddd07..4ce83dc0a 100644
--- a/src/org/traccar/protocol/Gps056FrameDecoder.java
+++ b/src/org/traccar/protocol/Gps056FrameDecoder.java
@@ -33,7 +33,11 @@ public class Gps056FrameDecoder extends FrameDecoder {
if (buf.readableBytes() >= MESSAGE_HEADER) {
int length = Integer.parseInt(buf.toString(2, 2, StandardCharsets.US_ASCII)) + 5;
if (buf.readableBytes() >= length) {
- return buf.readBytes(length);
+ ChannelBuffer frame = buf.readBytes(length);
+ while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != '$') {
+ buf.readByte();
+ }
+ return frame;
}
}
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index 800ad0953..b9b979c7d 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -206,6 +206,22 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
+ private static final Pattern PATTERN_LINK = new PatternBuilder()
+ .text("*")
+ .expression("..,") // manufacturer
+ .number("(d+),") // imei
+ .text("LINK,")
+ .number("(dd)(dd)(dd),") // time (hhmmss)
+ .number("(d+),") // rssi
+ .number("(d+),") // satellites
+ .number("(d+),") // battery
+ .number("(d+),") // steps
+ .number("(d+),") // turnovers
+ .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .number("(x{8})") // status
+ .any()
+ .compile();
+
private Position decodeText(String sentence, Channel channel, SocketAddress remoteAddress) {
Parser parser = new Parser(PATTERN, sentence);
@@ -316,6 +332,40 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Position decodeLink(String sentence, Channel channel, SocketAddress remoteAddress) {
+
+ Parser parser = new Parser(PATTERN_LINK, 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));
+
+ 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("turnovers", parser.nextInt());
+
+ 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 {
@@ -326,10 +376,15 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
switch (marker) {
case "*":
String sentence = buf.toString(StandardCharsets.US_ASCII);
- if (sentence.contains(",NBR,")) {
- return decodeLbs(sentence, channel, remoteAddress);
- } else {
- return decodeText(sentence, channel, remoteAddress);
+ int typeStart = sentence.indexOf(',', sentence.indexOf(',') + 1) + 1;
+ String type = sentence.substring(typeStart, sentence.indexOf(',', typeStart));
+ switch (type) {
+ case "NBR":
+ return decodeLbs(sentence, channel, remoteAddress);
+ case "LINK":
+ return decodeLink(sentence, channel, remoteAddress);
+ default:
+ return decodeText(sentence, channel, remoteAddress);
}
case "$":
return decodeBinary(buf, channel, remoteAddress);
diff --git a/test/org/traccar/protocol/Gps056FrameDecoderTest.java b/test/org/traccar/protocol/Gps056FrameDecoderTest.java
index 548154b22..a5b5c5bbd 100644
--- a/test/org/traccar/protocol/Gps056FrameDecoderTest.java
+++ b/test/org/traccar/protocol/Gps056FrameDecoderTest.java
@@ -12,6 +12,10 @@ public class Gps056FrameDecoderTest extends ProtocolTest {
Gps056FrameDecoder decoder = new Gps056FrameDecoder();
Assert.assertEquals(
+ binary("242435314750534c5f30323836323436323033333738323934361905110f160b0b7710584e1cbd1b9b4500005b100300fb0a071700ffff23"),
+ decoder.decode(null, null, binary("242435314750534c5f30323836323436323033333738323934361905110f160b0b7710584e1cbd1b9b4500005b100300fb0a071700ffff230030")));
+
+ Assert.assertEquals(
binary("242432354c4f474e5f3131383632343632303333373832393436322e3123"),
decoder.decode(null, null, binary("242432354c4f474e5f3131383632343632303333373832393436322e3123")));
diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
index 5779853d8..f1bc069c2 100644
--- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class H02ProtocolDecoderTest extends ProtocolTest {
H02ProtocolDecoder decoder = new H02ProtocolDecoder(new H02Protocol());
+ verifyAttributes(decoder, buffer(
+ "*HQ,1700086468,LINK,180902,15,0,84,0,0,240517,FFFFFBFF#"));
+
verifyNull(decoder, buffer(
"*HQ,355488020882405,V3,095426,74001,01,010278,045142,128,-92,02DE,0,X,090517,FFFFFBFF#"));
@@ -68,7 +71,7 @@ public class H02ProtocolDecoderTest extends ProtocolTest {
verifyAttributes(decoder, buffer(
"*HQ,1600068860,NBR,110326,262,03,255,6,802,23152,23,812,49449,14,802,35382,13,802,35402,11,812,56622,09,802,23132,04,081116,FFFFFBFF#"));
- verifyNull(decoder, buffer(
+ verifyAttributes(decoder, buffer(
"*HQ,1600068860,LINK,112137,20,8,67,0,0,081116,FFFFFBFF#"));
verifyNull(decoder, buffer(