diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-03-19 10:00:17 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-03-19 10:00:17 +1300 |
commit | 238e800a04b7bba6e83032f18e72086f7ec00deb (patch) | |
tree | f54dd4c9b9bc9c356ebcf3b67b5e8cbef520de8a | |
parent | 1e6fec776c579ab11b190cef38fc9af13784f241 (diff) | |
download | trackermap-server-238e800a04b7bba6e83032f18e72086f7ec00deb.tar.gz trackermap-server-238e800a04b7bba6e83032f18e72086f7ec00deb.tar.bz2 trackermap-server-238e800a04b7bba6e83032f18e72086f7ec00deb.zip |
Decode RFID card for GNX protocol
-rw-r--r-- | src/org/traccar/protocol/GnxProtocolDecoder.java | 48 | ||||
-rw-r--r-- | test/org/traccar/protocol/GnxProtocolDecoderTest.java | 3 |
2 files changed, 39 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; } diff --git a/test/org/traccar/protocol/GnxProtocolDecoderTest.java b/test/org/traccar/protocol/GnxProtocolDecoderTest.java index c1b8860d8..d89c96ac3 100644 --- a/test/org/traccar/protocol/GnxProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GnxProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class GnxProtocolDecoderTest extends ProtocolTest { GnxProtocolDecoder decoder = new GnxProtocolDecoder(new GnxProtocol()); verifyPosition(decoder, text( + "$GNX_MIF,865733022354161,143,0,172642,180316,172642,180316,1,13.034581,N,080.234521,E,0,05396274,ROUTE_2#########,Deo ############,GNX04008,B0*")); + + verifyPosition(decoder, text( "$GNX_LOC,865733022352132,095,0,102134,280914,102134,280914,1,18.765432,N,073.752811,W,032,165.32,12,25,0,A,E,2,000099.9,000099.5,GNX01001,12*")); verifyNothing(decoder, text( |