aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-03-01 21:02:09 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2013-03-01 21:02:09 +1300
commitf78f17199b8f00ac92e1a96c6c8b6981876020a2 (patch)
tree0bd62b426d47059bb0db25915776d3476fb07eff /src
parent30cd5be2c39bd7472461a7bfc9de210824cd4244 (diff)
downloadtraccar-server-f78f17199b8f00ac92e1a96c6c8b6981876020a2.tar.gz
traccar-server-f78f17199b8f00ac92e1a96c6c8b6981876020a2.tar.bz2
traccar-server-f78f17199b8f00ac92e1a96c6c8b6981876020a2.zip
Improve TK103 protocol decoder
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java20
1 files changed, 15 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