aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-08-30 07:55:13 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2016-08-30 07:55:13 +1200
commit4b1b94d63ee106ef8c61d9f8d976b601483ad14e (patch)
treeebcce00cb0648de2698ce33b667358741c55e689
parentcbd55752405d65132a47205748435d937610ee7a (diff)
downloadtrackermap-server-4b1b94d63ee106ef8c61d9f8d976b601483ad14e.tar.gz
trackermap-server-4b1b94d63ee106ef8c61d9f8d976b601483ad14e.tar.bz2
trackermap-server-4b1b94d63ee106ef8c61d9f8d976b601483ad14e.zip
Implement alarms for PT502 protocol
-rw-r--r--src/org/traccar/model/Position.java5
-rw-r--r--src/org/traccar/protocol/Pt502ProtocolDecoder.java26
-rw-r--r--test/org/traccar/protocol/Pt502ProtocolDecoderTest.java6
3 files changed, 33 insertions, 4 deletions
diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java
index f592ee4b9..95a5011ec 100644
--- a/src/org/traccar/model/Position.java
+++ b/src/org/traccar/model/Position.java
@@ -85,7 +85,10 @@ public class Position extends Message {
public static final String ALARM_GEOFENCE_EXIT = "geofenceExit";
public static final String ALARM_GPS_ANTENNA_CUT = "gpsAntennaCut";
public static final String ALARM_ACCIDENT = "accident";
-
+ public static final String ALARM_TOW = "tow";
+ public static final String ALARM_ACCELETATION = "hardAcceleration";
+ public static final String ALARM_BREAKING = "hardBreaking";
+ public static final String ALARM_FATIGUE_DRIVING = "fatigueDriving";
private String protocol;
diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java
index d925e1b4d..3edada78a 100644
--- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
* Copyright 2012 Luis Parada (luis.parada@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -35,8 +35,7 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
private static final Pattern PATTERN = new PatternBuilder()
.any().text("$")
- .expression("[A-Z]{3}")
- .number("d?,") // type
+ .expression("([^,]+),") // type
.number("(d+),") // id
.number("(dd)(dd)(dd).(ddd),") // time
.expression("([AV]),") // validity
@@ -57,6 +56,25 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
+ private String decodeAlarm(String value) {
+ switch (value) {
+ case "TOW":
+ return Position.ALARM_TOW;
+ case "HDA":
+ return Position.ALARM_ACCELETATION;
+ case "HDB":
+ return Position.ALARM_BREAKING;
+ case "FDA":
+ return Position.ALARM_FATIGUE_DRIVING;
+ case "SKA":
+ return Position.ALARM_VIBRATION;
+ case "PMA":
+ return Position.ALARM_MOVEMENT;
+ default:
+ return null;
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -78,6 +96,8 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position();
position.setProtocol(getProtocolName());
+ position.set(Position.KEY_ALARM, decodeAlarm(parser.next()));
+
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
diff --git a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java
index e8483fcff..333181625 100644
--- a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java
@@ -9,6 +9,12 @@ public class Pt502ProtocolDecoderTest extends ProtocolTest {
public void testDecode() throws Exception {
Pt502ProtocolDecoder decoder = new Pt502ProtocolDecoder(new Pt502Protocol());
+
+ verifyPosition(decoder, text(
+ "$DFR,40456789,083125.000,A,2232.0971,N,11400.9504,E,0.0,5.00,090714,,,A/00000,00/0,0/200076//FE7/"));
+
+ verifyPosition(decoder, text(
+ "$FDA,40456789,083125.000,A,2232.0971,N,11400.9504,E,0.0,5.00,090714,,,A/00000,00/0,0/200076//FE7/"));
verifyPosition(decoder, text(
"$POS,216769295715,163237.000,A,3258.1738,S,02755.4350,E,0.00,215.88,100915,,,A/0000,0//232300//5b3/"),