aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/CharacterDelimiterFrameDecoder.java4
-rw-r--r--src/org/traccar/protocol/Gps103Protocol.java2
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java56
-rw-r--r--test/org/traccar/protocol/Gps103ProtocolDecoderTest.java10
4 files changed, 66 insertions, 6 deletions
diff --git a/src/org/traccar/CharacterDelimiterFrameDecoder.java b/src/org/traccar/CharacterDelimiterFrameDecoder.java
index 5175f9b37..7ce83ff78 100644
--- a/src/org/traccar/CharacterDelimiterFrameDecoder.java
+++ b/src/org/traccar/CharacterDelimiterFrameDecoder.java
@@ -54,4 +54,8 @@ public class CharacterDelimiterFrameDecoder extends DelimiterBasedFrameDecoder {
super(maxFrameLength, convertDelimiters(delimiters));
}
+ public CharacterDelimiterFrameDecoder(int maxFrameLength, boolean stripDelimiter, String... delimiters) {
+ super(maxFrameLength, stripDelimiter, convertDelimiters(delimiters));
+ }
+
}
diff --git a/src/org/traccar/protocol/Gps103Protocol.java b/src/org/traccar/protocol/Gps103Protocol.java
index d112c1170..6272a3fd1 100644
--- a/src/org/traccar/protocol/Gps103Protocol.java
+++ b/src/org/traccar/protocol/Gps103Protocol.java
@@ -39,7 +39,7 @@ public class Gps103Protocol extends BaseProtocol {
addServer(new TrackerServer(false, getName()) {
@Override
protected void addProtocolHandlers(PipelineBuilder pipeline) {
- pipeline.addLast(new CharacterDelimiterFrameDecoder(2048, "\r\n", "\n", ";", "*"));
+ pipeline.addLast(new CharacterDelimiterFrameDecoder(2048, false, "\r\n", "\n", ";", "*"));
pipeline.addLast(new StringEncoder());
pipeline.addLast(new StringDecoder());
pipeline.addLast(new Gps103ProtocolEncoder());
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
index 4ef14b29b..b459f6340 100644
--- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
@@ -100,6 +100,27 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
+ private static final Pattern PATTERN_ALT = new PatternBuilder()
+ .text("imei:")
+ .number("(d+),") // imei
+ .expression("[^,]+,")
+ .expression("...,") // event
+ .expression(".{6},") // sensor id
+ .expression(".{4},") // sensor voltage
+ .number("(dd)(dd)(dd),") // time (hhmmss)
+ .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .number("(d+),") // rssi
+ .number("(d),") // gps status
+ .number("(-?d+.d+),") // latitude
+ .number("(-?d+.d+),") // longitude
+ .number("(d+),") // speed
+ .number("(d+),") // course
+ .number("(-?d+),") // altitude
+ .number("(d+.d+),") // hdop
+ .number("(d+),") // satellites
+ .any()
+ .compile();
+
private String decodeAlarm(String value) {
if (value.startsWith("T:")) {
return Position.ALARM_TEMPERATURE;
@@ -270,6 +291,39 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+
+ private Position decodeAlternative(Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN_ALT, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY));
+
+ position.set(Position.KEY_RSSI, parser.nextInt());
+
+ position.setValid(parser.nextInt() > 0);
+ position.setLatitude(parser.nextDouble());
+ position.setLongitude(parser.nextDouble());
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));
+ position.setCourse(parser.nextInt());
+ position.setAltitude(parser.nextInt());
+
+ position.set(Position.KEY_HDOP, parser.nextDouble());
+ position.set(Position.KEY_SATELLITES, parser.nextInt());
+
+ return position;
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -301,6 +355,8 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
if (sentence.contains("OBD")) {
return decodeObd(channel, remoteAddress, sentence);
+ } else if (sentence.endsWith("*")) {
+ return decodeAlternative(channel, remoteAddress, sentence);
} else {
return decodeRegular(channel, remoteAddress, sentence);
}
diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
index aac78ed1e..7dc1d36f4 100644
--- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
@@ -10,14 +10,14 @@ public class Gps103ProtocolDecoderTest extends ProtocolTest {
Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(null);
- verifyNull(decoder, text(
- "imei:861359038609986,Equipo 1,---,------,----,214734,241018,26,1,-33.42317,-70.61930,067,229,0674,1.00,08,0,1,---,"));
+ verifyPosition(decoder, text(
+ "imei:861359038609986,Equipo 1,---,------,----,214734,241018,26,1,-33.42317,-70.61930,067,229,0674,1.00,08,0,1,---,*"));
- verifyNull(decoder, text(
- "imei:861359038609986,Equipo 1,---,------,----,214812,241018,14,0,-33.42317,-70.61930,000,000,0000,99.9,00,0,1,---,"));
+ verifyPosition(decoder, text(
+ "imei:861359038609986,Equipo 1,---,------,----,214812,241018,14,0,-33.42317,-70.61930,000,000,0000,99.9,00,0,1,---,*"));
verifyNull(decoder, text(
- "imei:123451234512345,L,"));
+ "imei:123451234512345,L,*"));
verifyAttributes(decoder, text(
"imei:868683027758113,OBD,180905200218,,,,0,0,0.39%,70,9.41%,494,0.00,P0137,P0430,,;"));