diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-09-28 01:34:29 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-09-28 09:35:26 +1300 |
commit | 64a9af3090914eede02a2cc6d33960b9324c5d49 (patch) | |
tree | b259e6556ce53358262dc5d273d7173f7b69c712 | |
parent | f6fc3fb5431e0904bde0d3afe35d622b7bdbe935 (diff) | |
download | trackermap-server-64a9af3090914eede02a2cc6d33960b9324c5d49.tar.gz trackermap-server-64a9af3090914eede02a2cc6d33960b9324c5d49.tar.bz2 trackermap-server-64a9af3090914eede02a2cc6d33960b9324c5d49.zip |
Decode Tramigo direction (fix #2377)
-rw-r--r-- | src/org/traccar/protocol/TramigoProtocolDecoder.java | 9 | ||||
-rw-r--r-- | test/org/traccar/protocol/TramigoProtocolDecoderTest.java | 9 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/org/traccar/protocol/TramigoProtocolDecoder.java b/src/org/traccar/protocol/TramigoProtocolDecoder.java index af81616d8..74c6df9e3 100644 --- a/src/org/traccar/protocol/TramigoProtocolDecoder.java +++ b/src/org/traccar/protocol/TramigoProtocolDecoder.java @@ -43,6 +43,8 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_COMPACT = 0x0100; public static final int MSG_FULL = 0x00FE; + private static final String[] DIRECTIONS = new String[] { "N", "NE", "E", "SE", "S", "SW", "W", "NW" }; + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -119,8 +121,13 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder { pattern = Pattern.compile("([NSWE]{1,2}) with speed (\\d+) km/h"); matcher = pattern.matcher(sentence); if (matcher.find()) { + for (int i = 0; i < DIRECTIONS.length; i++) { + if (matcher.group(1).equals(DIRECTIONS[i])) { + position.setCourse(i * 45.0); + break; + } + } position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(matcher.group(2)))); - position.setCourse(0); // matcher.group(1) for course } pattern = Pattern.compile("(\\d{1,2}:\\d{2} \\w{3} \\d{1,2})"); diff --git a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java index 9cf7b9006..6da14ba64 100644 --- a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java @@ -13,6 +13,9 @@ public class TramigoProtocolDecoderTest extends ProtocolTest { TramigoProtocolDecoder decoder = new TramigoProtocolDecoder(new TramigoProtocol()); verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "80009e08b00086000101bc1803778a59c58dea57546573742054323320547261636b65723a204d6f76696e672c20312e3639206b6d204e57206f66205574656b6f6e2c2045646f2c204e472c20362e34363137302c20352e36313938322c20452077697468207370656564203333206b6d2f682c2031363a3138205365702032372020454f46")); + + verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "8000853eb000b8000101fcff032f14665a89e2564176656e7369732053797353657276653a2049676e6974696f6e206f6e2064657465637465642c206d6f76696e672c20302e3135206b6d205357206f66204261626120416e696d61736861756e205374726565742d426f64652054686f6d61732053742e2c20537572756c6572652c204c61676f7320436974792c204e472c20362e34383736352c20332e33343735352c2031303a3031204d6172203131202020454f46")); verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, @@ -39,12 +42,6 @@ public class TramigoProtocolDecoderTest extends ProtocolTest { verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN, "8000011bb0009e0001015b93032ef6f35994a9545472616d69676f3a204d6f76696e672c20302e3930206b6d205345206f66204372616e6562726f6f6b20466972652053746174696f6e2c2050656e726974682c205379646e65792c2041552c202d33332e37303732322c203135302e37313735392c2053452077697468207370656564203337206b6d2f682c2031393a3438204a616e20342020454f46")); - // Tramigo: Parked, 0.12 km E of McDonald's H.V. dela Costa, Makati, 11:07 Mar 27 - // Tramigo: Moving, 0.90 km SE of Cranebrook Fire Station, Penrith, Sydney, AU, -33.70722, 150.71759, SE with speed 37 km/h, 19:48 Jan 4 EOF - - //verifyPosition(decoder, text( ChannelBuffers.wrappedBuffer(BcdUtil.convertArray( - // new int[] {0x68,0x68,0x25,0x00,0x00,0x01,0x23,0x45,0x67,0x89,0x01,0x23,0x45,0x00,0x01,0x10,0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x6B,0x3F,0x3E,0x02,0x6B,0x3F,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x0D,0x0A})))); - } } |