diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-05-29 07:30:35 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-05-29 07:30:35 +1200 |
commit | 8e85055a38ed46d6f4d29f5e96adc8af4252bc7b (patch) | |
tree | 4061f6fcecc92ebcca77cd0cd92fef6e60d4a8f1 | |
parent | f2bcffcd0114b053e461257924eb687970766b5f (diff) | |
download | trackermap-server-8e85055a38ed46d6f4d29f5e96adc8af4252bc7b.tar.gz trackermap-server-8e85055a38ed46d6f4d29f5e96adc8af4252bc7b.tar.bz2 trackermap-server-8e85055a38ed46d6f4d29f5e96adc8af4252bc7b.zip |
Implement GT06 string format
-rw-r--r-- | src/org/traccar/protocol/Gt06ProtocolDecoder.java | 52 | ||||
-rw-r--r-- | test/org/traccar/protocol/Gt06ProtocolDecoderTest.java | 3 |
2 files changed, 50 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index ef2237ad1..261278539 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -70,6 +70,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_COMMAND_1 = 0x81; public static final int MSG_COMMAND_2 = 0x82; public static final int MSG_INFO = 0x94; + public static final int MSG_STRING_INFO = 0x21; private static boolean isSupported(int type) { return hasGps(type) || hasLbs(type) || hasStatus(type); @@ -238,6 +239,33 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { return position; } + private static final Pattern PATTERN_LOCATION = new PatternBuilder() + .text("Current position!") + .number("Lat:([NS])(d+.d+),") // latitude + .number("Lon:([EW])(d+.d+),") // longitude + .text("Course:").number("(d+.d+),") // course + .text("Speed:").number("(d+.d+),") // speed + .text("DateTime:") + .number("(dddd)-(dd)-(dd) ") // date + .number("(dd):(dd):(dd)") // time + .compile(); + + private Position decodeLocationString(Position position, String sentence) { + Parser parser = new Parser(PATTERN_LOCATION, sentence); + if (!parser.matches()) { + return null; + } + + position.setValid(true); + position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG)); + position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG)); + position.setCourse(parser.nextDouble()); + position.setSpeed(parser.nextDouble()); + position.setTime(parser.nextDateTime(Parser.DateTimeFormat.YMD_HMS)); + + return position; + } + protected Object decodeBasic(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception { int length = buf.readUnsignedByte(); @@ -358,15 +386,28 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { return null; } + Position position = new Position(); + position.setDeviceId(deviceSession.getDeviceId()); + position.setProtocol(getProtocolName()); + buf.readUnsignedShort(); // length int type = buf.readUnsignedByte(); - if (type == MSG_INFO) { - int subType = buf.readUnsignedByte(); + if (type == MSG_STRING_INFO) { - Position position = new Position(); - position.setDeviceId(deviceSession.getDeviceId()); - position.setProtocol(getProtocolName()); + buf.readUnsignedInt(); // server flag + String data; + if (buf.readUnsignedByte() == 1) { + data = buf.readBytes(buf.readableBytes() - 6).toString(StandardCharsets.US_ASCII); + } else { + data = buf.readBytes(buf.readableBytes() - 6).toString(StandardCharsets.UTF_16BE); + } + + return decodeLocationString(position, data); + + } else if (type == MSG_INFO) { + + int subType = buf.readUnsignedByte(); getLastLocation(position, null); @@ -389,6 +430,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { buf.readerIndex(), buf.readableBytes() - 4 - 2, StandardCharsets.US_ASCII)); } + } return null; diff --git a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java index 7893b459a..ad1ec6d47 100644 --- a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -16,6 +16,9 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "78780D01086471700328358100093F040D0A")); + verifyPosition(decoder, binary( + "7979007121000000000143757272656e7420706f736974696f6e214c61743a4e35342e3733393333322c4c6f6e3a4532352e3237333237302c436f757273653a3132362e35332c53706565643a302e303030302c4461746554696d653a323031372d30352d3236202031303a32373a3437000bbee30d0a")); + verifyAttributes(decoder, binary( "7979003F940D110315102A202141494F494C2C30322C3030382E3239302C3032392E3630302C3531394A2C303430302C3030382E3433302C302C30302C4142001678EA0D0A")); |