aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/ItsProtocolDecoder.java31
-rw-r--r--test/org/traccar/protocol/ItsProtocolDecoderTest.java7
2 files changed, 28 insertions, 10 deletions
diff --git a/src/org/traccar/protocol/ItsProtocolDecoder.java b/src/org/traccar/protocol/ItsProtocolDecoder.java
index 53d796b03..79eca21ce 100644
--- a/src/org/traccar/protocol/ItsProtocolDecoder.java
+++ b/src/org/traccar/protocol/ItsProtocolDecoder.java
@@ -34,18 +34,30 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder {
private static final Pattern PATTERN = new PatternBuilder()
.text("$,")
- .expression("[^,]+,") // header
+ .expression("[^,]+,") // event
+ .groupBegin()
+ .expression("[^,]+,") // vendor
+ .number("d+.d+.d+,") // firmware version
+ .groupEnd("?")
.expression("[^,]+,") // type
+ .groupBegin()
+ .number("d+,")
+ .expression("[LH],") // history
+ .groupEnd("?")
.number("(d{15}),") // imei
+ .groupBegin()
.expression("(?:NM|SP),") // status
+ .or()
+ .expression("[^,]+,") // vehicle registration
+ .number("([01]),") // valid
+ .groupEnd()
.number("(dd),(dd),(dddd),") // date (ddmmyyyy)
.number("(dd),(dd),(dd),") // time (hhmmss)
- .expression("([AV]),") // valid
+ .expression("([AV]),").optional() // valid
.number("(d+.d+),([NS]),") // latitude
.number("(d+.d+),([EW]),") // longitude
- .number("(-?d+.d+),") // altitude
+ .number("(-?d+.d+),").optional() // altitude
.number("(d+.d+),") // speed
- .number("(d+.d+),") // distance
.any()
.compile();
@@ -66,15 +78,18 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
+ if (parser.hasNext()) {
+ position.setValid(parser.nextInt() == 1);
+ }
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
- position.setValid(parser.next().equals("A"));
+ if (parser.hasNext()) {
+ position.setValid(parser.next().equals("A"));
+ }
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
- position.setAltitude(parser.nextDouble());
+ position.setAltitude(parser.nextDouble(0));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
- position.set(Position.KEY_ODOMETER, parser.nextDouble());
-
return position;
}
diff --git a/test/org/traccar/protocol/ItsProtocolDecoderTest.java b/test/org/traccar/protocol/ItsProtocolDecoderTest.java
index b8d6a1730..91ce333d6 100644
--- a/test/org/traccar/protocol/ItsProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/ItsProtocolDecoderTest.java
@@ -10,6 +10,9 @@ public class ItsProtocolDecoderTest extends ProtocolTest {
ItsProtocolDecoder decoder = new ItsProtocolDecoder(new ItsProtocol());
+ verifyPosition(decoder, text(
+ "$,04,XYZ123,0.0.1,TA,16,L,861359034100626,MH12AB1234,1,14,10,2018,04,50,52,018.489624,N,073.855980,E,000.0,039.86,13,584.1,01.11,00.75,AIRTEL,1,1,00.0,4.1,1,C,15,404,90,0c23,781a,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,1000,01,000005,13b75499,"));
+
verifyNull(decoder, text(
"$,01,XYZ123,0.0.1,861359034137271,MH12AB1234,"));
@@ -19,10 +22,10 @@ public class ItsProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, text(
"$,EPB,EMR,861359034100626,SP,00,00,0000,00,00,00,V,000.000000,N,000.000000,E,000.0,000.0,000.00,N,MH12AB1234,0000000000000,d34679e1,"));
- verifyNull(decoder, text(
+ verifyPosition(decoder, text(
"$,03,XYZ123,0.0.1,TA,16,L,861359034137271,MH12AB1234,0,00,00,0000,00,00,00,000.000000,N,000.000000,E,000.0,000.00,00,000.0,00.00,00.00,IDEAIN,1,1,00.0,4.0,1,O,16,404,22,2797,11b7,11b9,2797,-087,11b8,2797,-093,11b4,2797,-106,0000,0000,0000,1000,01,000032,8173e058,"));
- verifyNull(decoder, text(
+ verifyPosition(decoder, text(
"$,04,XYZ123,0.0.1,BR,06,L,861359034137271,MH12AB1234,0,00,00,0000,00,00,00,000.000000,N,000.000000,E,000.0,000.00,00,000.0,00.00,00.00,IDEAIN,1,1,00.0,3.8,1,O,17,404,22,2797,11b7,11b9,2797,-093,11b8,2797,-098,0000,0000,0000,0000,0000,0000,1000,00,000006,abd26284,"));
}