diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/model/Position.java | 5 | ||||
-rw-r--r-- | src/org/traccar/protocol/Pt502ProtocolDecoder.java | 26 |
2 files changed, 27 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;
|