aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java19
-rw-r--r--test/org/traccar/protocol/Tk103ProtocolDecoderTest.java6
2 files changed, 20 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++));
diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
index 91d438f58..ab2dc2c19 100644
--- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java
@@ -35,6 +35,12 @@ public class Tk103ProtocolDecoderTest {
verify(decoder.decode(null, null,
"(013012345678BR00130515A4843.9703N01907.6211E000.019232800000000000000L00009239"));
+
+ verify(decoder.decode(null, null,
+ "(012345678901BP05000012345678901130520A3439.9629S05826.3504W000.1175622323.8700000000L000450AC"));
+
+ verify(decoder.decode(null, null,
+ "(012345678901BR00130520A3439.9629S05826.3504W000.1175622323.8700000000L000450AC"));
}