aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/Tk103ProtocolDecoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol/Tk103ProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index d83f1bce4..d90cdd7d7 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -33,7 +33,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
super(serverManager);
}
- static private Pattern pattern = Pattern.compile(
+ private static final Pattern pattern = Pattern.compile(
"(\\d{12})" + // Device ID
".{4}" + // Command
"\\d*" + // IMEI (?)
@@ -61,9 +61,18 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
if (beginIndex != -1) {
sentence = sentence.substring(beginIndex + 1);
}
-
- // TODO: Send answer?
- //(090411121854AP05)
+
+ // Send response
+ if (channel != null) {
+ String id = sentence.substring(0, 12);
+ String type = sentence.substring(12, 16);
+ if (type.equals("BP00")) {
+ String content = sentence.substring(sentence.length() - 3);
+ channel.write("(" + id + "AP01" + content + ")");
+ } else if (type.equals("BP05")) {
+ channel.write("(" + id + "AP05)");
+ }
+ }
// Parse message
Matcher parser = pattern.matcher(sentence);
@@ -98,7 +107,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++)));
// Validity
- position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);
+ position.setValid(parser.group(index++).compareTo("A") == 0);
// Latitude
Double latitude = Double.valueOf(parser.group(index++));