aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/Tk103Protocol.java7
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolEncoder.java14
-rw-r--r--test/org/traccar/protocol/Tk103ProtocolEncoderTest.java79
3 files changed, 100 insertions, 0 deletions
diff --git a/src/org/traccar/protocol/Tk103Protocol.java b/src/org/traccar/protocol/Tk103Protocol.java
index 6fc00195e..07a68e2d8 100644
--- a/src/org/traccar/protocol/Tk103Protocol.java
+++ b/src/org/traccar/protocol/Tk103Protocol.java
@@ -1,4 +1,5 @@
/*
+ * Copyright 2017 Christoph Krey (c@ckrey.de)
* Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,6 +33,12 @@ public class Tk103Protocol extends BaseProtocol {
public Tk103Protocol() {
super("tk103");
setSupportedDataCommands(
+ Command.TYPE_POSITION_SINGLE,
+ Command.TYPE_POSITION_PERIODIC,
+ Command.TYPE_POSITION_STOP,
+ Command.TYPE_GET_VERSION,
+ Command.TYPE_REBOOT_DEVICE,
+ Command.TYPE_SET_ODOMETER,
Command.TYPE_ENGINE_STOP,
Command.TYPE_ENGINE_RESUME);
}
diff --git a/src/org/traccar/protocol/Tk103ProtocolEncoder.java b/src/org/traccar/protocol/Tk103ProtocolEncoder.java
index ce995a65f..9e49b6ff1 100644
--- a/src/org/traccar/protocol/Tk103ProtocolEncoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolEncoder.java
@@ -1,4 +1,5 @@
/*
+ * Copyright 2017 Christoph Krey (c@ckrey.de)
* Copyright 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,6 +26,19 @@ public class Tk103ProtocolEncoder extends StringProtocolEncoder {
protected Object encodeCommand(Command command) {
switch (command.getType()) {
+ case Command.TYPE_GET_VERSION:
+ return formatCommand(command, "({%s}AP07)", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_REBOOT_DEVICE:
+ return formatCommand(command, "({%s}AT00)", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_SET_ODOMETER:
+ return formatCommand(command, "({%s}AX01)", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_POSITION_SINGLE:
+ return formatCommand(command, "({%s}AP00)", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_POSITION_PERIODIC:
+ return formatCommand(command, "({%s}AR00%s0000)", Command.KEY_UNIQUE_ID,
+ String.format("%04X", command.getInteger(Command.KEY_FREQUENCY)));
+ case Command.TYPE_POSITION_STOP:
+ return formatCommand(command, "({%s}AR0000000000)", Command.KEY_UNIQUE_ID);
case Command.TYPE_ENGINE_STOP:
return formatCommand(command, "({%s}AV011)", Command.KEY_UNIQUE_ID);
case Command.TYPE_ENGINE_RESUME:
diff --git a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
index e934de04b..afc3b2387 100644
--- a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
@@ -20,4 +20,83 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
}
+ @Test
+ public void testEncodePositionSingle() throws Exception {
+
+ Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
+
+ Command command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_POSITION_SINGLE);
+
+ Assert.assertEquals("(123456789012345AP00)", encoder.encodeCommand(command));
+
+ }
+
+ @Test
+ public void testEncodePositionPeriodic() throws Exception {
+
+ Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
+
+ Command command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_POSITION_PERIODIC);
+ command.set(Command.KEY_FREQUENCY, 60);
+
+ Assert.assertEquals("(123456789012345AR00003C0000)", encoder.encodeCommand(command));
+
+ }
+
+ @Test
+ public void testEncodePositionStop() throws Exception {
+
+ Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
+
+ Command command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_POSITION_STOP);
+
+ Assert.assertEquals("(123456789012345AR0000000000)", encoder.encodeCommand(command));
+
+ }
+
+ @Test
+ public void testEncodeGetVersion() throws Exception {
+
+ Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
+
+ Command command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_GET_VERSION);
+
+ Assert.assertEquals("(123456789012345AP07)", encoder.encodeCommand(command));
+
+ }
+
+ @Test
+ public void testEncodeRebootDevice() throws Exception {
+
+ Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
+
+ Command command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_REBOOT_DEVICE);
+
+ Assert.assertEquals("(123456789012345AT00)", encoder.encodeCommand(command));
+
+ }
+
+ @Test
+ public void testEncodeSetOdometer() throws Exception {
+
+ Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
+
+ Command command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_SET_ODOMETER);
+
+ Assert.assertEquals("(123456789012345AX01)", encoder.encodeCommand(command));
+
+ }
+
}