From e36c69db0c5e610d30977de7b2fa71e715d9a1ae Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 15 Nov 2018 10:55:43 +1300 Subject: Support Sysomate TMD-300 format --- .../traccar/protocol/TrakMateProtocolDecoder.java | 74 +++++++++++++--------- .../protocol/TrakMateProtocolDecoderTest.java | 3 + 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/src/org/traccar/protocol/TrakMateProtocolDecoder.java b/src/org/traccar/protocol/TrakMateProtocolDecoder.java index f677ab36e..4d5cb18f5 100644 --- a/src/org/traccar/protocol/TrakMateProtocolDecoder.java +++ b/src/org/traccar/protocol/TrakMateProtocolDecoder.java @@ -45,7 +45,8 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { .compile(); private static final Pattern PATTERN_PER = new PatternBuilder() - .text("^TMPER|") + .text("^TM") + .expression("...|") // type .expression("([^ ]+)|") // uid .number("(d+)|") // seq .number("(d+.d+)|") // latitude @@ -54,17 +55,23 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { .number("(dd)(dd)(dd)|") // date (ddmmyy) .number("(d+.d+)|") // speed .number("(d+.d+)|") // heading - .number("(d+)|") // ignition + .number("(d+)|").optional() // satellites + .number("([01])|") // ignition + .groupBegin() .number("(d+)|") // dop1 .number("(d+)|") // dop2 .number("(d+.d+)|") // analog .number("(d+.d+)|") // internal battery + .or() + .number("-?d+ -?d+ -?d+|") // accelerometer + .number("([01])|") // movement + .groupEnd() .number("(d+.d+)|") // vehicle battery .number("(d+.d+)|") // gps odometer - .number("(d+.d+)|") // pulse odometer - .number("(d+)|") // main power status - .number("(d+)|") // gps data validity - .number("(d+)|") // live or cache + .number("(d+.d+)|").optional() // pulse odometer + .number("([01])|") // main power status + .number("([01])|") // gps data validity + .number("([01])|") // live or cache .any() .compile(); @@ -111,8 +118,8 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - position.setLatitude(parser.nextDouble(0)); - position.setLongitude(parser.nextDouble(0)); + position.setLatitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY)); @@ -138,16 +145,16 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); parser.next(); // seq - position.set(Position.KEY_ALARM, decodeAlarm(parser.nextInt(0))); + position.set(Position.KEY_ALARM, decodeAlarm(parser.nextInt())); parser.next(); // alert status or data - position.setLatitude(parser.nextDouble(0)); - position.setLongitude(parser.nextDouble(0)); + position.setLatitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY)); - position.setSpeed(parser.nextDouble(0)); - position.setCourse(parser.nextDouble(0)); + position.setSpeed(parser.nextDouble()); + position.setCourse(parser.nextDouble()); return position; } @@ -169,27 +176,36 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { parser.next(); // seq - position.setLatitude(parser.nextDouble(0)); - position.setLongitude(parser.nextDouble(0)); + position.setLatitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY)); - position.setSpeed(parser.nextDouble(0)); - position.setCourse(parser.nextDouble(0)); + position.setSpeed(parser.nextDouble()); + position.setCourse(parser.nextDouble()); + + position.set(Position.KEY_SATELLITES, parser.nextInt()); + position.set(Position.KEY_IGNITION, parser.nextInt() > 0); + + if (parser.hasNext(4)) { + position.set("dop1", parser.nextInt()); + position.set("dop2", parser.nextInt()); + position.set(Position.PREFIX_ADC + 1, parser.nextDouble()); + position.set(Position.KEY_BATTERY, parser.nextDouble()); + } + + if (parser.hasNext()) { + position.set(Position.KEY_MOTION, parser.nextInt(0) > 0); + } - position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1); - position.set("dop1", parser.next()); - position.set("dop2", parser.next()); - position.set(Position.KEY_INPUT, parser.next()); - position.set(Position.KEY_BATTERY, parser.nextDouble(0)); position.set(Position.KEY_POWER, parser.nextDouble()); - position.set(Position.KEY_ODOMETER, parser.nextDouble(0)); - position.set("pulseOdometer", parser.next()); - position.set(Position.KEY_STATUS, parser.nextInt(0)); + position.set(Position.KEY_ODOMETER, parser.nextDouble()); + position.set("pulseOdometer", parser.nextDouble()); + position.set(Position.KEY_STATUS, parser.nextInt()); - position.setValid(parser.nextInt(0) != 0); + position.setValid(parser.nextInt() > 0); - position.set(Position.KEY_ARCHIVE, parser.nextInt(0) == 1); + position.set(Position.KEY_ARCHIVE, parser.nextInt() > 0); return position; } @@ -209,10 +225,8 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder { return decodeAlt(channel, remoteAddress, sentence); case "SRT": return decodeSrt(channel, remoteAddress, sentence); - case "PER": - return decodePer(channel, remoteAddress, sentence); default: - return null; + return decodePer(channel, remoteAddress, sentence); } } diff --git a/test/org/traccar/protocol/TrakMateProtocolDecoderTest.java b/test/org/traccar/protocol/TrakMateProtocolDecoderTest.java index acfac6f4b..4352fc935 100644 --- a/test/org/traccar/protocol/TrakMateProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TrakMateProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class TrakMateProtocolDecoderTest extends ProtocolTest { TrakMateProtocolDecoder decoder = new TrakMateProtocolDecoder(null); + verifyPosition(decoder, text( + "^TMSTP|352984083995323|116|13.07809|77.55979|131508|131118|0.0|146.51|7|0|71 -2 248|0|13.1|0.0|10.5|1|0|0|0|#")); + verifyPosition(decoder, text( "^TMPER|354678456723764|1|12.59675|77.56789|123456|030414|2.3|34.0|1|0|0|0.015|3.9|12.0|23.4|23.4|1|1|0|#")); -- cgit v1.2.3