aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-03-08 23:02:40 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-03-08 23:02:40 +1300
commite2da4f276230e3687e42b11b4d94889fb3889436 (patch)
tree1d5de1a13727cca90277d54852aa6bb8b32cccd4
parent18ec7e54839430503b5a73cbf2e63dfa2e234e7b (diff)
downloadtraccar-server-e2da4f276230e3687e42b11b4d94889fb3889436.tar.gz
traccar-server-e2da4f276230e3687e42b11b4d94889fb3889436.tar.bz2
traccar-server-e2da4f276230e3687e42b11b4d94889fb3889436.zip
Extend GpsGate protocol support
-rw-r--r--src/org/traccar/protocol/GpsGateProtocolDecoder.java60
-rw-r--r--test/org/traccar/protocol/GpsGateProtocolDecoderTest.java6
2 files changed, 61 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
index 421dc5304..b48fa6266 100644
--- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java
+++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 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.
@@ -17,6 +17,7 @@ package org.traccar.protocol;
import java.net.SocketAddress;
import java.util.regex.Pattern;
+
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.Checksum;
@@ -31,7 +32,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private static final Pattern PATTERN = new PatternBuilder()
+ private static final Pattern PATTERN_GPRMC = new PatternBuilder()
.text("$GPRMC,")
.number("(dd)(dd)(dd).?(d+)?,") // time
.expression("([AV]),") // validity
@@ -45,6 +46,24 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
+ private static final Pattern PATTERN_FRCMD = new PatternBuilder()
+ .text("$FRCMD,")
+ .number("(d+),") // imei
+ .expression("[^,]*,") // command
+ .expression("[^,]*,")
+ .number("(dd)(dd.d+),") // latitude
+ .expression("([NS]),")
+ .number("(ddd)(dd.d+),") // longitude
+ .expression("([EW]),")
+ .number("(d+.?d*),") // altitude
+ .number("(d+.?d*),") // speed
+ .number("(d+.?d*),") // course
+ .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .number("(dd)(dd)(dd).?(d+)?,") // time
+ .expression("([01]),") // validity
+ .any()
+ .compile();
+
private void send(Channel channel, String message) {
if (channel != null) {
channel.write(message + Checksum.nmea(message) + "\r\n");
@@ -85,10 +104,10 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
// Version check
send(channel, "$FRVER,1,0,GpsGate Server 1.0");
- } else if (sentence.startsWith("$GPRMC,") && hasDeviceId()) {
+ } else if (sentence.startsWith("$GPRMC,")) {
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
+ Parser parser = new Parser(PATTERN_GPRMC, sentence);
+ if (!parser.matches() || !hasDeviceId()) {
return null;
}
@@ -109,6 +128,37 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
position.setTime(dateBuilder.getDate());
return position;
+
+ } else if (sentence.startsWith("$FRCMD,")) {
+
+ Parser parser = new Parser(PATTERN_FRCMD, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
+ if (!identify(parser.next(), channel, remoteAddress)) {
+ return null;
+ }
+ position.setDeviceId(getDeviceId());
+
+ position.setLatitude(parser.nextCoordinate());
+ position.setLongitude(parser.nextCoordinate());
+ position.setAltitude(parser.nextDouble());
+ position.setSpeed(parser.nextDouble());
+ position.setCourse(parser.nextDouble());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ position.setValid(parser.next().equals("1"));
+
+ return position;
+
}
return null;
diff --git a/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java b/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java
index c4ed38656..788830e52 100644
--- a/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/GpsGateProtocolDecoderTest.java
@@ -11,6 +11,12 @@ public class GpsGateProtocolDecoderTest extends ProtocolTest {
GpsGateProtocolDecoder decoder = new GpsGateProtocolDecoder(new GpsGateProtocol());
verifyNothing(decoder, text(
+ "$FRCMD,862950025974620,_Ping,voltage=4*4F"));
+
+ verifyPosition(decoder, text(
+ "$FRCMD,862950025974620,_SendMessage, ,2721.5781,S,15259.145,E,61,0.00,61,080316,092612,1,SosButton=0,voltage=4*60"));
+
+ verifyNothing(decoder, text(
"$FRLIN,,user1,8IVHF*7A"));
verifyNothing(decoder, text(