aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
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 /src/org/traccar/protocol
parentcbd55752405d65132a47205748435d937610ee7a (diff)
downloadtraccar-server-4b1b94d63ee106ef8c61d9f8d976b601483ad14e.tar.gz
traccar-server-4b1b94d63ee106ef8c61d9f8d976b601483ad14e.tar.bz2
traccar-server-4b1b94d63ee106ef8c61d9f8d976b601483ad14e.zip
Implement alarms for PT502 protocol
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/Pt502ProtocolDecoder.java26
1 files changed, 23 insertions, 3 deletions
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;