diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-02-20 06:52:26 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-02-20 06:52:26 +1300 |
commit | 2449895139fa658d082c1085185003a001225bc3 (patch) | |
tree | 8b657c86e799e13d2ee981f23339c0db5ce92015 | |
parent | e024acd5226383375c00b2632f72114d6345f446 (diff) | |
download | trackermap-server-2449895139fa658d082c1085185003a001225bc3.tar.gz trackermap-server-2449895139fa658d082c1085185003a001225bc3.tar.bz2 trackermap-server-2449895139fa658d082c1085185003a001225bc3.zip |
Implement TAIP protocol variant
-rw-r--r-- | src/org/traccar/protocol/TaipProtocolDecoder.java | 33 | ||||
-rw-r--r-- | test/org/traccar/ProtocolTest.java | 2 | ||||
-rw-r--r-- | test/org/traccar/protocol/TaipProtocolDecoderTest.java | 6 |
3 files changed, 29 insertions, 12 deletions
diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java index 7927c28e6..c53538223 100644 --- a/src/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/org/traccar/protocol/TaipProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +48,8 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { .groupEnd("?") .number("(d{5})") // seconds .or() - .text("RGP") // type + .expression("(?:RGP|RCQ|RBR)") // type + .number("(?:dd)?") .number("(dd)(dd)(dd)") // date .number("(dd)(dd)(dd)") // time .groupEnd() @@ -56,6 +57,13 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { .number("([-+]ddd)(d{5})") // longitude .number("(ddd)") // speed .number("(ddd)") // course + .groupBegin() + .number("(xx)") // input + .number("(xx)") // satellites + .number("(ddd)") // battery + .number("(x{8})") // odometer + .number("[01]") // gps power + .groupEnd("?") .number("(d)") // fix mode .any() .compile(); @@ -93,15 +101,10 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(); position.setProtocol(getProtocolName()); - String week = parser.next(); - String day = parser.next(); - String seconds = parser.next(); - if (seconds != null) { - if (week != null && day != null) { - position.setTime(getTime(Integer.parseInt(week), Integer.parseInt(day), Integer.parseInt(seconds))); - } else { - position.setTime(getTime(Integer.parseInt(seconds))); - } + if (parser.hasNext(2)) { + position.setTime(getTime(parser.nextInt(), parser.nextInt(), parser.nextInt())); + } else if (parser.hasNext()) { + position.setTime(getTime(parser.nextInt())); } if (parser.hasNext(6)) { @@ -115,6 +118,14 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG)); position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble())); position.setCourse(parser.nextDouble()); + + if (parser.hasNext(4)) { + position.set(Position.KEY_INPUT, parser.nextInt(16)); + position.set(Position.KEY_SATELLITES, parser.nextInt(16)); + position.set(Position.KEY_BATTERY, parser.nextInt()); + position.set(Position.KEY_ODOMETER, parser.nextLong(16)); + } + position.setValid(parser.nextInt() != 0); String[] attributes = null; diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java index d4543a06d..f4072ad24 100644 --- a/test/org/traccar/ProtocolTest.java +++ b/test/org/traccar/ProtocolTest.java @@ -145,7 +145,7 @@ public class ProtocolTest extends BaseTest { } else { Assert.assertNotNull(position.getFixTime()); - Assert.assertTrue("year > 2000", position.getFixTime().after(new Date(946684800000L))); + Assert.assertTrue("year > 1999", position.getFixTime().after(new Date(915148800000L))); Assert.assertTrue("time < +25 hours", position.getFixTime().getTime() < System.currentTimeMillis() + 25 * 3600000); diff --git a/test/org/traccar/protocol/TaipProtocolDecoderTest.java b/test/org/traccar/protocol/TaipProtocolDecoderTest.java index 871ec84b3..74956f51c 100644 --- a/test/org/traccar/protocol/TaipProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TaipProtocolDecoderTest.java @@ -11,6 +11,12 @@ public class TaipProtocolDecoderTest extends ProtocolTest { TaipProtocolDecoder decoder = new TaipProtocolDecoder(new TaipProtocol(), false); verifyPosition(decoder, text( + ">RCQ09000000000000-3460365-058381460000007F0000000000000115000FFFF1099;#0000;ID=555224;*05<")); + + verifyPosition(decoder, text( + ">RBR00130217040848-3462200-05846708000175FF0022900003B3C13010800001118410+24061A;ID=555224;*07<")); + + verifyPosition(decoder, text( ">REV451891352379+0307152+1016143700000012;SV=8;BL=4416;VO=8055;ID=356612026322000<")); verifyPosition(decoder, text( |