aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java20
-rw-r--r--test/org/traccar/protocol/Tk103ProtocolDecoderTest.java3
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"));
+
}
}