diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-19 10:35:57 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-11-19 10:35:57 +1300 |
commit | 5d919c8489ea3c88d3182fab77b6b24b9dd86bef (patch) | |
tree | bbb38522c7966698f6f74735b0da37b6d87c9eb1 | |
parent | cc5d60ff499c39fb4db7e06b2e62fefe2a324f77 (diff) | |
download | traccar-server-5d919c8489ea3c88d3182fab77b6b24b9dd86bef.tar.gz traccar-server-5d919c8489ea3c88d3182fab77b6b24b9dd86bef.tar.bz2 traccar-server-5d919c8489ea3c88d3182fab77b6b24b9dd86bef.zip |
Implement LBS support for TK103
-rw-r--r-- | src/org/traccar/protocol/Tk103ProtocolDecoder.java | 36 | ||||
-rw-r--r-- | test/org/traccar/protocol/Tk103ProtocolDecoderTest.java | 3 |
2 files changed, 33 insertions, 6 deletions
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 95728c447..6fa4edb06 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -64,6 +64,16 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { .number("d+") // installed .compile(); + private static final Pattern PATTERN_NETWORK = new PatternBuilder() + .number("(d{12})") // device id + .text("BZ00,") + .number("(d+),") // mcc + .number("(d+),") // mnc + .number("(x+),") // lac + .number("(x+),") // cid + .any() + .compile(); + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -88,11 +98,11 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { } } + Position position = new Position(); + position.setProtocol(getProtocolName()); + Parser parser = new Parser(PATTERN_BATTERY, sentence); if (parser.matches()) { - Position position = new Position(); - position.setProtocol(getProtocolName()); - if (!identify(parser.next(), channel)) { return null; } @@ -117,14 +127,28 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { return position; } + parser = new Parser(PATTERN_NETWORK, sentence); + if (parser.matches()) { + if (!identify(parser.next(), channel)) { + return null; + } + position.setDeviceId(getDeviceId()); + + getLastLocation(position, null); + + position.set(Event.KEY_MCC, parser.nextInt()); + position.set(Event.KEY_MNC, parser.nextInt()); + position.set(Event.KEY_LAC, parser.nextInt(16)); + position.set(Event.KEY_CID, parser.nextInt(16)); + + return position; + } + parser = new Parser(PATTERN, sentence); if (!parser.matches()) { return null; } - Position position = new Position(); - position.setProtocol(getProtocolName()); - if (!identify(parser.next(), channel)) { return null; } diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index d9152ecf0..2bffbcd9a 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class Tk103ProtocolDecoderTest extends ProtocolDecoderTest { Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(new Tk103Protocol()); verifyAttributes(decoder, text( + "(088047194605BZ00,510,010,36e6,932c,43,36e6,766b,36,36e6,7668,32")); + + verifyAttributes(decoder, text( "(013632651491,ZC20,040613,040137,6,42,112,0")); verifyAttributes(decoder, text( |