diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2020-06-24 22:51:12 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2020-06-24 22:51:12 -0700 |
commit | fb78c6a42f7e947b818044461414ef2470fc22f6 (patch) | |
tree | 4d1ae26732237feae87e45d8ea91b22050410c55 | |
parent | ae09c5920d0a89c1243cea81abe300272994ff6b (diff) | |
download | traccar-server-fb78c6a42f7e947b818044461414ef2470fc22f6.tar.gz traccar-server-fb78c6a42f7e947b818044461414ef2470fc22f6.tar.bz2 traccar-server-fb78c6a42f7e947b818044461414ef2470fc22f6.zip |
Decode GPS Sky China alarms
-rw-r--r-- | src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java | 42 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/Tk103ProtocolDecoderTest.java | 4 |
2 files changed, 44 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java index 11053e3b1..325d2ebeb 100644 --- a/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -47,10 +47,16 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .groupBegin() .expression("(.{12})") // device id .or() - .expression("(.+),") // device id + .expression("([^,]+),") // device id .groupEnd() .expression("(.{4}),?") // command + .groupBegin() .number("(d*)") + .or() + .text(",ALARM,") + .number("(d),") // alarm type + .number("d+,") + .groupEnd() .number("(dd)(dd)(dd),?") // date (mmddyy if comma-delimited, otherwise yyddmm) .expression("([AV]),?") // validity .number(" *(d+)(dd.d+)") // latitude @@ -146,6 +152,30 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { private void decodeType(Position position, String type, String data) { switch (type) { + case "BQ81": + switch (Integer.parseInt(data)) { + case 0: + position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); + break; + case 1: + position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED); + break; + case 2: + position.set(Position.KEY_ALARM, Position.ALARM_IDLE); + break; + case 3: + position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION); + break; + case 4: + position.set(Position.KEY_ALARM, Position.ALARM_BRAKING); + break; + case 5: + position.set(Position.KEY_ALARM, Position.ALARM_TEMPERATURE); + break; + default: + break; + } + break; case "BO01": position.set(Position.KEY_ALARM, decodeAlarm(data.charAt(0) - '0')); break; @@ -393,7 +423,15 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - decodeType(position, parser.next(), parser.next()); + String type = parser.next(); + String data = null; + if (parser.hasNext()) { + data = parser.next(); + } + if (parser.hasNext()) { + data = parser.next(); + } + decodeType(position, type, data); DateBuilder dateBuilder = new DateBuilder(); if (alternative) { diff --git a/src/test/java/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Tk103ProtocolDecoderTest.java index f27a3e0c7..48a72447c 100644 --- a/src/test/java/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -11,6 +11,10 @@ public class Tk103ProtocolDecoderTest extends ProtocolTest { Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(null); + verifyAttribute(decoder, text( + "(044027395704BQ81,ALARM,1,164,151101A2238.5237N11349.4571E0.7031241010.0000,00000000)"), + Position.KEY_ALARM, Position.ALARM_OVERSPEED); + verifyPosition(decoder, text( "(027023361470BR00200617A4000.5775N 8415.4076W 46.0173725 87.3101000000L00000000)")); |