Skip to content

Commit

Permalink
Improve ITS decoding (fix #4144)
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Feb 11, 2019
1 parent 3d2a3ee commit c37ebc1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/org/traccar/protocol/ItsProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
* Copyright 2018 Anton Tananaev (anton@traccar.org)
* Copyright 2018 - 2019 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.
Expand Down Expand Up @@ -35,6 +35,7 @@ public ItsProtocolDecoder(Protocol protocol) {
}

private static final Pattern PATTERN = new PatternBuilder()
.expression("[^$]*")
.text("$,")
.expression("[^,]+,") // event
.groupBegin()
Expand All @@ -59,8 +60,8 @@ public ItsProtocolDecoder(Protocol protocol) {
.number("(d+.d+),([NS]),") // latitude
.number("(d+.d+),([EW]),") // longitude
.groupBegin()
.number("(d+.d+),") // speed
.number("(d+.d+),") // course
.number("(d+.?d*),") // speed
.number("(d+.?d*),") // course
.number("(d+),") // satellites
.or()
.number("(-?d+.d+),") // altitude
Expand Down Expand Up @@ -108,8 +109,8 @@ protected Object decode(
position.set(Position.KEY_SATELLITES, parser.nextInt());
}

if (parser.hasNext()) {
position.setAltitude(parser.nextDouble(0));
if (parser.hasNext(2)) {
position.setAltitude(parser.nextDouble());
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
}

Expand Down
3 changes: 3 additions & 0 deletions test/org/traccar/protocol/ItsProtocolDecoderTest.java
Expand Up @@ -10,6 +10,9 @@ public void testDecode() throws Exception {

ItsProtocolDecoder decoder = new ItsProtocolDecoder(null);

verifyPosition(decoder, text(
"$,1,CHVTS,CHVTS1.0,DT,16,L,861359039868243,861359039868243,1,05022019,071225,19.965062,N,73.736088,E,0,050,03,0632,6.67,6.75,Idea Cel,1,1,23.96,4.0,0,W,28,404,004,4e2b,49e,4e2bea86727ab3d6704e2bea7714e2be9d72,0000,00,001133,232"));

verifyPosition(decoder, text(
"$,04,XYZ123,0.0.1,TA,16,L,861359034100626,MH12AB1234,1,12,11,2018,08,53,08,018.489645,N,073.855972,E,000.0,220.04,12,593.0,01.13,00.75,AIRTEL,1,1,00.0,4.1,1,C,18,404,90,0c23,781a,5169,0c23,-093,0000,0000,0000,0000,0000,0000,0000,0000,0000,1000,01,000006,f906c65c,"));

Expand Down

0 comments on commit c37ebc1

Please sign in to comment.