From f78da0d7ead0e445f129eac486cc468bedff7c73 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 5 Nov 2021 22:32:05 -0700 Subject: Extend Mobilogix protocol support --- .../traccar/protocol/MobilogixProtocolDecoder.java | 57 ++++++++++++++++++---- .../protocol/MobilogixProtocolDecoderTest.java | 5 +- 2 files changed, 51 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java b/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java index ba70a8884..7947d0c26 100644 --- a/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MobilogixProtocolDecoder.java @@ -40,11 +40,13 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder { .number("(dddd)-(dd)-(dd) ") // date (yyyymmdd) .number("(dd):(dd):(dd),") // time (hhmmss) .number("Td+,") // type - .number("d+,") // device type + .number("(d),") // archive .expression("[^,]+,") // protocol version .expression("([^,]+),") // serial number .number("(xx),") // status - .number("(d+.d+),") // battery + .number("(d+.d+)") // battery + .groupBegin() + .text(",") .number("(d)") // valid .number("(d)") // rssi .number("(d),") // satellites @@ -52,9 +54,31 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder { .number("(-?d+.d+),") // longitude .number("(d+.?d*),") // speed .number("(d+.?d*)") // course + .groupEnd("?") .any() .compile(); + private String decodeAlarm(String type) { + switch (type) { + case "T8": + return Position.ALARM_LOW_BATTERY; + case "T9": + return Position.ALARM_VIBRATION; + case "T10": + return Position.ALARM_POWER_CUT; + case "T11": + return Position.ALARM_LOW_POWER; + case "T12": + return Position.ALARM_GEOFENCE_EXIT; + case "T13": + return Position.ALARM_OVERSPEED; + case "T15": + return Position.ALARM_TOW; + default: + return null; + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -80,7 +104,10 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(getProtocolName()); - position.setTime(parser.nextDateTime()); + position.setDeviceTime(parser.nextDateTime()); + if (parser.nextInt() == 0) { + position.set(Position.KEY_ARCHIVE, true); + } DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); if (deviceSession == null) { @@ -89,6 +116,7 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); position.set(Position.KEY_TYPE, type); + position.set(Position.KEY_ALARM, decodeAlarm(type)); int status = parser.nextHexInt(); position.set(Position.KEY_IGNITION, BitUtil.check(status, 2)); @@ -97,15 +125,24 @@ public class MobilogixProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_BATTERY, parser.nextDouble()); - position.setValid(parser.nextInt() > 0); + if (parser.hasNext(7)) { + + position.setValid(parser.nextInt() > 0); + position.setFixTime(position.getDeviceTime()); - position.set(Position.KEY_RSSI, parser.nextInt()); - position.set(Position.KEY_SATELLITES, parser.nextInt()); + position.set(Position.KEY_RSSI, parser.nextInt()); + position.set(Position.KEY_SATELLITES, parser.nextInt()); - position.setLatitude(parser.nextDouble()); - position.setLongitude(parser.nextDouble()); - position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); - position.setCourse(parser.nextDouble()); + position.setLatitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); + position.setCourse(parser.nextDouble()); + + } else { + + getLastLocation(position, position.getDeviceTime()); + + } return position; } diff --git a/src/test/java/org/traccar/protocol/MobilogixProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MobilogixProtocolDecoderTest.java index efa46b9f6..aca6b9f29 100644 --- a/src/test/java/org/traccar/protocol/MobilogixProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/MobilogixProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class MobilogixProtocolDecoderTest extends ProtocolTest { var decoder = new MobilogixProtocolDecoder(null); + verifyAttributes(decoder, text( + "[2021-08-20 19:27:14,T14,1,V1.3.5,201909000982,53,12.18")); + verifyNull(decoder, text( "[2020-12-01 14:00:22,T1,1,V1.1.1,201951132031,,,12345678,724108005415815,359366080211420")); @@ -29,7 +32,7 @@ public class MobilogixProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "[2021-10-25 20:54:11,T12,1,V1.2.3,201951132044,3F,9.23,991,-25.909262,-47.045387,1,341")); - verifyNull(decoder, text( + verifyAttributes(decoder, text( "[2021-10-25 20:48:14,T14,1,V1.2.3,201951132044,51,0.50")); verifyPosition(decoder, text( -- cgit v1.2.3