diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-12-14 22:48:13 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-12-14 22:48:13 -0800 |
commit | cec63a8b62f20c1b23d92664676409510226a9e2 (patch) | |
tree | 38387396cf6788b6275db9b24b3bbe85bb19e714 | |
parent | 9c4dcf3c38aa1a40025df55c344cb2311e0784a5 (diff) | |
download | traccar-server-cec63a8b62f20c1b23d92664676409510226a9e2.tar.gz traccar-server-cec63a8b62f20c1b23d92664676409510226a9e2.tar.bz2 traccar-server-cec63a8b62f20c1b23d92664676409510226a9e2.zip |
Additional ArknavX8 attributes
-rw-r--r-- | src/org/traccar/protocol/ArknavX8ProtocolDecoder.java | 55 | ||||
-rw-r--r-- | test/org/traccar/protocol/ArknavX8ProtocolDecoderTest.java | 6 |
2 files changed, 59 insertions, 2 deletions
diff --git a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java index 62ad09a52..b570f5423 100644 --- a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java +++ b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java @@ -32,7 +32,7 @@ public class ArknavX8ProtocolDecoder extends BaseProtocolDecoder { super(protocol); } - private static final Pattern PATTERN = new PatternBuilder() + private static final Pattern PATTERN_1G = new PatternBuilder() .expression("(..),") // type .number("(dd)(dd)(dd)") // date (yymmdd) .number("(dd)(dd)(dd),") // time (hhmmss) @@ -45,6 +45,17 @@ public class ArknavX8ProtocolDecoder extends BaseProtocolDecoder { .number("(d+)") // status .compile(); + private static final Pattern PATTERN_2G = new PatternBuilder() + .expression("..,") // type + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) + .number("(d+),") // satellites + .number("(d+.d+),") // altitude + .number("(d+.d+),") // power + .number("(d+.d+),") // battery + .number("(d+.d+)") // odometer + .compile(); + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -56,7 +67,21 @@ public class ArknavX8ProtocolDecoder extends BaseProtocolDecoder { return null; } - Parser parser = new Parser(PATTERN, sentence); + switch (sentence.substring(0, 2)) { + case "1G": + case "1R": + case "1M": + return decode1G(channel, remoteAddress, sentence); + case "2G": + return decode2G(channel, remoteAddress, sentence); + default: + return null; + } + } + + private Position decode1G(Channel channel, SocketAddress remoteAddress, String sentence) { + + Parser parser = new Parser(PATTERN_1G, sentence); if (!parser.matches()) { return null; } @@ -85,4 +110,30 @@ public class ArknavX8ProtocolDecoder extends BaseProtocolDecoder { return position; } + private Position decode2G(Channel channel, SocketAddress remoteAddress, String sentence) { + + Parser parser = new Parser(PATTERN_2G, sentence); + if (!parser.matches()) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null) { + return null; + } + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + getLastLocation(position, parser.nextDateTime()); + + position.set(Position.KEY_SATELLITES, parser.nextInt()); + position.setAltitude(parser.nextDouble()); + position.set(Position.KEY_POWER, parser.nextDouble()); + position.set(Position.KEY_BATTERY, parser.nextDouble()); + position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1852 / 3600); + + return position; + } + } diff --git a/test/org/traccar/protocol/ArknavX8ProtocolDecoderTest.java b/test/org/traccar/protocol/ArknavX8ProtocolDecoderTest.java index 818318787..dfe1435d1 100644 --- a/test/org/traccar/protocol/ArknavX8ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ArknavX8ProtocolDecoderTest.java @@ -13,6 +13,12 @@ public class ArknavX8ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, text( "351856045213782,241111")); + verifyPosition(decoder, text( + "1G,181213092101,A,0347.0756N,09842.7435E,0.0,183,1.1,11008000")); + + verifyAttributes(decoder, text( + "2G,181213092101,08,4084.0,00.04,04.01,000396255.0")); + verifyNull(decoder, text( "2R,090214235955,00,,00.04,03.76,001892024.9")); |