aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/GpsGateProtocolDecoder.java
diff options
context:
space:
mode:
authorHans van den Elsen <hans.elsen@esds.nl>2016-03-11 22:16:25 +0100
committerHans van den Elsen <hans.elsen@esds.nl>2016-03-11 22:16:25 +0100
commit4606737cc07b736f9c8f98ae680b928c94c082c8 (patch)
treebdd29b24a16403b1e8a3d7cd4325391063b34b8a /src/org/traccar/protocol/GpsGateProtocolDecoder.java
parent3ced99384b1967f5cde9abdf30c1c0184a5ae3f6 (diff)
parentab5d21e16ac44957e04da0f06daf148af95e96be (diff)
downloadtrackermap-server-4606737cc07b736f9c8f98ae680b928c94c082c8.tar.gz
trackermap-server-4606737cc07b736f9c8f98ae680b928c94c082c8.tar.bz2
trackermap-server-4606737cc07b736f9c8f98ae680b928c94c082c8.zip
Merge remote-tracking branch 'refs/remotes/tananaev/master'
Diffstat (limited to 'src/org/traccar/protocol/GpsGateProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/GpsGateProtocolDecoder.java60
1 files changed, 55 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;