aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-03-19 10:00:17 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-03-19 10:00:17 +1300
commit238e800a04b7bba6e83032f18e72086f7ec00deb (patch)
treef54dd4c9b9bc9c356ebcf3b67b5e8cbef520de8a /src/org
parent1e6fec776c579ab11b190cef38fc9af13784f241 (diff)
downloadtrackermap-server-238e800a04b7bba6e83032f18e72086f7ec00deb.tar.gz
trackermap-server-238e800a04b7bba6e83032f18e72086f7ec00deb.tar.bz2
trackermap-server-238e800a04b7bba6e83032f18e72086f7ec00deb.zip
Decode RFID card for GNX protocol
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/protocol/GnxProtocolDecoder.java48
1 files changed, 36 insertions, 12 deletions
diff --git a/src/org/traccar/protocol/GnxProtocolDecoder.java b/src/org/traccar/protocol/GnxProtocolDecoder.java
index 88cc90df2..0928e476a 100644
--- a/src/org/traccar/protocol/GnxProtocolDecoder.java
+++ b/src/org/traccar/protocol/GnxProtocolDecoder.java
@@ -20,7 +20,6 @@ import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -34,9 +33,7 @@ public class GnxProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$GNX_")
- .expression("...,") // type
+ private static final Pattern PATTERN_LOCATION = new PatternBuilder()
.number("(d+),") // imei
.number("d+,") // length
.expression("([01]),") // history
@@ -49,9 +46,20 @@ public class GnxProtocolDecoder extends BaseProtocolDecoder {
.expression("([NS]),")
.number("(ddd.d+),") // longitude
.expression("([EW]),")
- .number("(d+.?d*),") // speed
- .number("(d+.?d*),") // course
- .number("(d+),") // satellites
+ .compile();
+
+ private static final Pattern PATTERN_MIF = new PatternBuilder()
+ .text("$GNX_MIF,")
+ .expression(PATTERN_LOCATION.pattern())
+ .expression("[01],") // valid card
+ .expression("([^,]+),") // rfid
+ .any()
+ .compile();
+
+ private static final Pattern PATTERN_OTHER = new PatternBuilder()
+ .text("$GNX_")
+ .expression("...,")
+ .expression(PATTERN_LOCATION.pattern())
.any()
.compile();
@@ -59,7 +67,20 @@ public class GnxProtocolDecoder extends BaseProtocolDecoder {
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- Parser parser = new Parser(PATTERN, (String) msg);
+ String sentence = (String) msg;
+ String type = sentence.substring(5, 8);
+
+ Pattern pattern;
+ switch (type) {
+ case "MIF":
+ pattern = PATTERN_MIF;
+ break;
+ default:
+ pattern = PATTERN_OTHER;
+ break;
+ }
+
+ Parser parser = new Parser(pattern, sentence);
if (!parser.matches()) {
return null;
}
@@ -93,10 +114,13 @@ public class GnxProtocolDecoder extends BaseProtocolDecoder {
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
- position.setCourse(parser.nextDouble());
-
- position.set(Event.KEY_SATELLITES, parser.nextInt());
+ switch (type) {
+ case "MIF":
+ position.set(Event.KEY_RFID, parser.next());
+ break;
+ default:
+ break;
+ }
return position;
}