diff options
Diffstat (limited to 'src/org/traccar/protocol')
5 files changed, 46 insertions, 20 deletions
diff --git a/src/org/traccar/protocol/MegastekFrameDecoder.java b/src/org/traccar/protocol/MegastekFrameDecoder.java index ba2cc1d25..da77d95fd 100644 --- a/src/org/traccar/protocol/MegastekFrameDecoder.java +++ b/src/org/traccar/protocol/MegastekFrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,10 +39,16 @@ public class MegastekFrameDecoder extends FrameDecoder { return buf.readBytes(length); } } else { + while (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n') { + buf.skipBytes(1); + } int delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n")); + if (delimiter == -1) { + delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '!'); + } if (delimiter != -1) { ChannelBuffer result = buf.readBytes(delimiter - buf.readerIndex()); - buf.skipBytes(2); + buf.skipBytes(1); return result; } } diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index 81349ce3e..a330947b1 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -241,9 +241,9 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { .number("(dd),") // satellites .number("dd,") .number("(d+.d+),") // hdop - .number("(d+.d+),") // speed - .number("(d+.d+),") // course - .number("(d+.d+),") // altitude + .number("(d+.d+)?,") // speed + .number("(d+.d+)?,") // course + .number("(-?d+.d+),") // altitude .number("(d+.d+)?,") // odometer .number("(d+),") // mcc .number("(d+),") // mnc diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java index d925e1b4d..7dc4fbe5e 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,19 +56,31 @@ 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 {
String sentence = (String) msg;
- if (sentence.startsWith("$PHO")) {
- if (channel != null) {
- channel.write("#PHD0," + sentence.substring(4));
- }
- return null;
- }
-
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
@@ -78,6 +89,16 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder { Position position = new Position();
position.setProtocol(getProtocolName());
+ String type = parser.next();
+
+ if (type.startsWith("PHO")) {
+ if (channel != null) {
+ channel.write("#PHD0," + type.substring(3) + "\r\n");
+ }
+ }
+
+ position.set(Position.KEY_ALARM, decodeAlarm(type));
+
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index ac99a1440..90c80be71 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -41,9 +41,9 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .number("d*") // imei? .number("(dd)(dd)(dd),?") // date .expression("([AV]),?") // validity - .number("(dd)(dd.d+)") // latitude + .number("(d+)(dd.d+)") // latitude .expression("([NS]),?") - .number("(ddd)(dd.d+)") // longitude + .number("(d+)(dd.d+)") // longitude .expression("([EW]),?") .number("(d+.d)(?:d*,)?") // speed .number("(dd)(dd)(dd),?") // time @@ -211,7 +211,6 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { position.setCourse(parser.nextDouble()); - // Status String status = parser.next(); if (status != null) { position.set(Position.KEY_STATUS, status); // binary status diff --git a/src/org/traccar/protocol/XexunFrameDecoder.java b/src/org/traccar/protocol/XexunFrameDecoder.java index 9b3438aaa..184e2f57b 100644 --- a/src/org/traccar/protocol/XexunFrameDecoder.java +++ b/src/org/traccar/protocol/XexunFrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,7 +49,7 @@ public class XexunFrameDecoder extends FrameDecoder { return null; } - buf.skipBytes(beginIndex); + buf.skipBytes(beginIndex - buf.readerIndex()); return buf.readBytes(endIndex - beginIndex + 1); } |