diff options
-rw-r--r-- | src/org/traccar/protocol/Tk103Protocol.java | 3 | ||||
-rw-r--r-- | src/org/traccar/protocol/Tk103ProtocolEncoder.java | 8 | ||||
-rw-r--r-- | test/org/traccar/protocol/Tk103ProtocolEncoderTest.java | 15 |
3 files changed, 25 insertions, 1 deletions
diff --git a/src/org/traccar/protocol/Tk103Protocol.java b/src/org/traccar/protocol/Tk103Protocol.java index 6ef9c0a56..e23982c74 100644 --- a/src/org/traccar/protocol/Tk103Protocol.java +++ b/src/org/traccar/protocol/Tk103Protocol.java @@ -47,7 +47,8 @@ public class Tk103Protocol extends BaseProtocol { Command.TYPE_REBOOT_DEVICE, Command.TYPE_SET_ODOMETER, Command.TYPE_ENGINE_STOP, - Command.TYPE_ENGINE_RESUME); + Command.TYPE_ENGINE_RESUME, + Command.TYPE_OUTPUT_CONTROL); } @Override diff --git a/src/org/traccar/protocol/Tk103ProtocolEncoder.java b/src/org/traccar/protocol/Tk103ProtocolEncoder.java index 946f3ad73..3375d4ee4 100644 --- a/src/org/traccar/protocol/Tk103ProtocolEncoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolEncoder.java @@ -97,6 +97,14 @@ public class Tk103ProtocolEncoder extends StringProtocolEncoder { return formatCommand(command, "({%s}AV010)", Command.KEY_UNIQUE_ID); case Command.TYPE_ENGINE_RESUME: return formatCommand(command, "({%s}AV011)", Command.KEY_UNIQUE_ID); + case Command.TYPE_OUTPUT_CONTROL: + if (command.getAttributes().containsKey(Command.KEY_DATA)) { + if (command.getAttributes().get(Command.KEY_DATA).equals("1")) { + return formatCommand(command, "({%s}AV001)", Command.KEY_UNIQUE_ID); + } else { + return formatCommand(command, "({%s}AV000)", Command.KEY_UNIQUE_ID); + } + } default: Log.warning(new UnsupportedOperationException(command.getType())); return null; diff --git a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java index 565f6bb88..f0a21334e 100644 --- a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java @@ -9,6 +9,21 @@ import static org.junit.Assert.assertEquals; public class Tk103ProtocolEncoderTest extends ProtocolTest { @Test + public void testEncodeOutputControl() { + + Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder(); + + Command command = new Command(); + command.setDeviceId(1); + command.setType(Command.TYPE_OUTPUT_CONTROL); + command.set(Command.KEY_INDEX, 0); + command.set(Command.KEY_DATA, "1"); + + assertEquals("(123456789012345AV001)", encoder.encodeCommand(command)); + + } + + @Test public void testEncodeEngineStop() throws Exception { Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder(); |