diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-22 23:41:29 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2019-03-22 23:41:29 -0700 |
commit | ad087c64207c28b5aa0026e9ad198ec677f79fd4 (patch) | |
tree | 1f8049deda7e5c5d162c13030f3e238151ea2ec5 | |
parent | 409995a6ec0fe83ead8701f938fcac9e795d084a (diff) | |
download | traccar-server-ad087c64207c28b5aa0026e9ad198ec677f79fd4.tar.gz traccar-server-ad087c64207c28b5aa0026e9ad198ec677f79fd4.tar.bz2 traccar-server-ad087c64207c28b5aa0026e9ad198ec677f79fd4.zip |
Support ITS alarms
-rw-r--r-- | src/org/traccar/protocol/ItsProtocolDecoder.java | 26 | ||||
-rw-r--r-- | test/org/traccar/protocol/ItsProtocolDecoderTest.java | 6 |
2 files changed, 31 insertions, 1 deletions
diff --git a/src/org/traccar/protocol/ItsProtocolDecoder.java b/src/org/traccar/protocol/ItsProtocolDecoder.java index a12b75961..482f34e65 100644 --- a/src/org/traccar/protocol/ItsProtocolDecoder.java +++ b/src/org/traccar/protocol/ItsProtocolDecoder.java @@ -49,7 +49,7 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder { .groupEnd() .number("(d{15}),") // imei .groupBegin() - .expression("(?:NM|SP),") // status + .expression("(..),") // status .or() .expression("[^,]*,") // vehicle registration .number("([01]),") // valid @@ -86,6 +86,26 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private String decodeAlarm(String status) { + switch (status) { + case "WD": + case "EA": + return Position.ALARM_SOS; + case "BL": + return Position.ALARM_LOW_BATTERY; + case "HB": + return Position.ALARM_BRAKING; + case "HA": + return Position.ALARM_ACCELERATION; + case "RT": + return Position.ALARM_CORNERING; + case "OS": + return Position.ALARM_OVERSPEED; + default: + return null; + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -110,6 +130,10 @@ public class ItsProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(deviceSession.getDeviceId()); if (parser.hasNext()) { + position.set(Position.KEY_ALARM, decodeAlarm(parser.next())); + } + + if (parser.hasNext()) { position.setValid(parser.nextInt() == 1); } position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS)); diff --git a/test/org/traccar/protocol/ItsProtocolDecoderTest.java b/test/org/traccar/protocol/ItsProtocolDecoderTest.java index 8fef81bbc..7523e29a0 100644 --- a/test/org/traccar/protocol/ItsProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ItsProtocolDecoderTest.java @@ -11,6 +11,12 @@ public class ItsProtocolDecoderTest extends ProtocolTest { ItsProtocolDecoder decoder = new ItsProtocolDecoder(null); verifyPosition(decoder, text( + "$NRM,ROADRPA,1.8AIS,EA,01,L,869867036341099,,1,11032019,231048,19.25166667,N,73.04615167,E,0.0,230.21,17,12.8,0.80,0.80,airtel,0,1,13.5,4.2,0,O,22,404,90,0CC9,EBC8,19,0CC9,8992,16,0CC9,AB49,15,0CC9,AB44,14,0CC9,F03C,0000,00,002080,C9FBBF99")); + + verifyPosition(decoder, text( + "$NRM,ROADRPA,1.7AIS,NR,01,L,869867036345389,,1,25022019,051716,25.12891000,N,75.85587833,E,7.6,350.00,14,284.8,1.00,1.00,AIRTEL,1,1,28.0,4.2,0,C,13,404,70,4E3B,3C84,11,4E3B,39B8,08,4E3B,3965,07,4E3B,48B5,07,4E3B,3C85,0000,00,000551,71978C6B")); + + verifyPosition(decoder, text( "$,03,XYZ123,0.0.1,TA,16,L,869867035297185,MH12AB1234,1,20,02,2019,10,59,13,023.482630,N,086.399673,E,000.1,015.19,21,212.3,01.12,00.58,NOSERV,0,1,00.0,4.6,1,C,11,404,75,082a,db3a,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,01,000013,01dbd51f,")); verifyPosition(decoder, text( |