From cec63a8b62f20c1b23d92664676409510226a9e2 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 14 Dec 2018 22:48:13 -0800 Subject: Additional ArknavX8 attributes --- .../traccar/protocol/ArknavX8ProtocolDecoder.java | 55 +++++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'src/org') 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; + } + } -- cgit v1.2.3