diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-06-22 22:44:30 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-06-22 22:44:30 +1200 |
commit | 78b19b4bef61619bf5b5179c641b8a0dafcd88ce (patch) | |
tree | a49779e4cdbc7c96424294a28162f23d3fa1e54b /src/org/traccar | |
parent | 2f6967e7e53b70bfb0f8e20df2b6b351b8b817cb (diff) | |
download | traccar-server-78b19b4bef61619bf5b5179c641b8a0dafcd88ce.tar.gz traccar-server-78b19b4bef61619bf5b5179c641b8a0dafcd88ce.tar.bz2 traccar-server-78b19b4bef61619bf5b5179c641b8a0dafcd88ce.zip |
Support another VTFMS protocol format
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/protocol/VtfmsProtocolDecoder.java | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/VtfmsProtocolDecoder.java b/src/org/traccar/protocol/VtfmsProtocolDecoder.java index f4ff941d0..852b9a749 100644 --- a/src/org/traccar/protocol/VtfmsProtocolDecoder.java +++ b/src/org/traccar/protocol/VtfmsProtocolDecoder.java @@ -28,6 +28,8 @@ import java.util.regex.Pattern; public class VtfmsProtocolDecoder extends BaseProtocolDecoder { + private static final String[] DIRECTIONS = new String[] {"N", "NE", "E", "SE", "S", "SW", "W", "NW"}; + public VtfmsProtocolDecoder(VtfmsProtocol protocol) { super(protocol); } @@ -47,7 +49,7 @@ public class VtfmsProtocolDecoder extends BaseProtocolDecoder { .number("(dd)(dd)(dd),") // time (ddmmyy) .number("(-?d+.d+),") // latitude .number("(-?d+.d+),") // longitude - .number("(d+),") // course + .number("(?:(d+)|([NESW]{1,2})),") // course .number("(d+),") // speed .number("(d+),") // hours .number("(d+),") // idle hours @@ -56,10 +58,10 @@ public class VtfmsProtocolDecoder extends BaseProtocolDecoder { .expression("([01]),") // power status .number("(d+.d+),") // power voltage .number("[^,]*,") // reserved - .number("(d+),") // fuel level + .number("(d+)?,") // fuel level .number("(d+.d+),") // adc 1 .number("[^,]*,") // reserved - .number("(d+.d+),") // adc 2 + .number("(d+.d+)?,") // adc 2 .expression("([01]),") // di 1 .expression("([01]),") // di 2 .expression("([01]),") // di 3 @@ -116,7 +118,20 @@ public class VtfmsProtocolDecoder extends BaseProtocolDecoder { position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY)); position.setLatitude(parser.nextDouble(0)); position.setLongitude(parser.nextDouble(0)); - position.setCourse(parser.nextDouble(0)); + + if (parser.hasNext()) { + position.setCourse(parser.nextDouble(0)); + } + if (parser.hasNext()) { + String direction = parser.next(); + for (int i = 0; i < DIRECTIONS.length; i++) { + if (direction.equals(DIRECTIONS[i])) { + position.setCourse(i * 45.0); + break; + } + } + } + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0))); position.set(Position.KEY_HOURS, parser.nextInt()); |