diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-06-26 12:12:46 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-06-26 12:12:46 +1200 |
commit | 4e084ebd790286392225e44ce462f987a2c3046a (patch) | |
tree | 3e5dcc7c95f6194f7e4e95c005fbc3e11ca6a559 | |
parent | 9a597a7f902eea46405a345d4398139c13f69655 (diff) | |
download | trackermap-server-4e084ebd790286392225e44ce462f987a2c3046a.tar.gz trackermap-server-4e084ebd790286392225e44ce462f987a2c3046a.tar.bz2 trackermap-server-4e084ebd790286392225e44ce462f987a2c3046a.zip |
Decode Atrack INFO messages
-rw-r--r-- | src/org/traccar/protocol/AtrackProtocolDecoder.java | 52 | ||||
-rw-r--r-- | test/org/traccar/protocol/AtrackProtocolDecoderTest.java | 3 |
2 files changed, 47 insertions, 8 deletions
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java index 3566631f0..79b3c36cc 100644 --- a/src/org/traccar/protocol/AtrackProtocolDecoder.java +++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java @@ -22,6 +22,8 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; import org.traccar.helper.DateBuilder; +import org.traccar.helper.Parser; +import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; import org.traccar.model.CellTower; import org.traccar.model.Network; @@ -34,6 +36,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.regex.Pattern; public class AtrackProtocolDecoder extends BaseProtocolDecoder { @@ -195,29 +198,62 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { } } - private Position decodeString(Channel channel, SocketAddress remoteAddress, String sentence) { - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); - if (deviceSession == null) { - return null; - } + private static final Pattern PATTERN_INFO = new PatternBuilder() + .text("$INFO=") + .number("(d+),") // unit id + .expression("([^,]+),") // model + .expression("([^,]+),") // firmware version + .number("d+,") // imei + .number("d+,") // imsi + .number("d+,") // sim card id + .number("(d+),") // power + .number("(d+),") // battery + .number("(d+),") // satellites + .number("d+,") // gsm status + .number("(d+),") // rssi + .number("d+,") // connection status + .number("d+") // antenna status + .any() + .compile(); + private Position decodeString(Channel channel, SocketAddress remoteAddress, String sentence) { Position position = new Position(); position.setProtocol(getProtocolName()); - position.setDeviceId(deviceSession.getDeviceId()); getLastLocation(position, null); + DeviceSession deviceSession; + if (sentence.startsWith("$INFO")) { - return null; + Parser parser = new Parser(PATTERN_INFO, sentence); + if (!parser.matches()) { + return null; + } + + deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + + position.set("model", parser.next()); + position.set(Position.KEY_VERSION_FW, parser.next()); + position.set(Position.KEY_POWER, parser.nextInt() * 0.1); + position.set(Position.KEY_BATTERY, parser.nextInt() * 0.1); + position.set(Position.KEY_SATELLITES, parser.nextInt()); + position.set(Position.KEY_RSSI, parser.nextInt()); } else { + deviceSession = getDeviceSession(channel, remoteAddress); + position.set(Position.KEY_RESULT, sentence); } - return position; + if (deviceSession == null) { + return null; + } else { + position.setDeviceId(deviceSession.getDeviceId()); + return position; + } } @Override diff --git a/test/org/traccar/protocol/AtrackProtocolDecoderTest.java b/test/org/traccar/protocol/AtrackProtocolDecoderTest.java index 756c09cef..b5271f511 100644 --- a/test/org/traccar/protocol/AtrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/AtrackProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class AtrackProtocolDecoderTest extends ProtocolTest { AtrackProtocolDecoder decoder = new AtrackProtocolDecoder(new AtrackProtocol()); + verifyAttributes(decoder, buffer( + "$INFO=358683066267395,AX7,Rev.0.61 Build.1624,358683066267395,466924131626767,89886920041316267670,144,0,9,1,12,1,0\r\n")); + decoder.setLongDate(true); verifyPositions(decoder, binary( |