diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2013-03-01 21:02:09 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2013-03-01 21:02:09 +1300 |
commit | f78f17199b8f00ac92e1a96c6c8b6981876020a2 (patch) | |
tree | 0bd62b426d47059bb0db25915776d3476fb07eff | |
parent | 30cd5be2c39bd7472461a7bfc9de210824cd4244 (diff) | |
download | traccar-server-f78f17199b8f00ac92e1a96c6c8b6981876020a2.tar.gz traccar-server-f78f17199b8f00ac92e1a96c6c8b6981876020a2.tar.bz2 traccar-server-f78f17199b8f00ac92e1a96c6c8b6981876020a2.zip |
Improve TK103 protocol decoder
-rw-r--r-- | src/org/traccar/protocol/Tk103ProtocolDecoder.java | 20 | ||||
-rw-r--r-- | test/org/traccar/protocol/Tk103ProtocolDecoderTest.java | 3 |
2 files changed, 18 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 9d28256e3..6f58b17d2 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -36,10 +36,9 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { * Regular expressions pattern */ static private Pattern pattern = Pattern.compile( - "\\(" + "(\\d{12})" + // Device ID ".{4}" + // Command - "\\d+" + // IMEI (?) + "\\d*" + // IMEI (?) "(\\d{2})(\\d{2})(\\d{2})" + // Date (YYMMDD) "([AV])" + // Validity "(\\d{2})(\\d{2}\\.\\d{4})" + // Latitude (DDMM.MMMM) @@ -59,6 +58,12 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; + // Find message start + int beginIndex = sentence.indexOf('('); + if (beginIndex != -1) { + sentence = sentence.substring(beginIndex + 1); + } + // TODO: Send answer? //(090411121854AP05) @@ -74,12 +79,17 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { Integer index = 1; // Get device by IMEI - String imei = "000" + parser.group(index++); + String imei = parser.group(index++); try { position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); } catch(Exception error) { - Log.warning("Unknown device - " + imei); - return null; + // Compatibility mode (remove in future) + try { + position.setDeviceId(getDataManager().getDeviceByImei("000" + imei).getId()); + } catch(Exception error2) { + Log.warning("Unknown device - " + imei); + return null; + } } // Date diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index 607287210..50ce21e6b 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -26,6 +26,9 @@ public class Tk103ProtocolDecoderTest { assertNotNull(decoder.decode(null, null, "(013666666666BO012110925A1234.5678N01234.5678W000.0025948118.7200000000L000024DE")); + assertNotNull(decoder.decode(null, null, + "\n\n\n(088045133878BR00130228A5124.5526N00117.7152W000.0233614352.2200000000L01B0CF1C")); + } } |