From 1313ec644a58c3988528a27491c16602094286bf Mon Sep 17 00:00:00 2001 From: parveenkumaryadav Date: Fri, 13 Apr 2018 10:59:55 +0530 Subject: Tk103 Output Control command support added --- test/org/traccar/protocol/Tk103ProtocolEncoderTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test/org/traccar') 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 @@ -8,6 +8,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 { -- cgit v1.2.3 From cc835f74f47a7f1e4f052d1f7ed77965cf1be133 Mon Sep 17 00:00:00 2001 From: parveenkumaryadav Date: Sat, 14 Apr 2018 12:22:51 +0530 Subject: Tk103 Output Control command refactored --- src/org/traccar/protocol/Tk103ProtocolEncoder.java | 8 +------- test/org/traccar/protocol/Tk103ProtocolEncoderTest.java | 1 - 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'test/org/traccar') diff --git a/src/org/traccar/protocol/Tk103ProtocolEncoder.java b/src/org/traccar/protocol/Tk103ProtocolEncoder.java index 3375d4ee4..3ec562cc3 100644 --- a/src/org/traccar/protocol/Tk103ProtocolEncoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolEncoder.java @@ -98,13 +98,7 @@ public class Tk103ProtocolEncoder extends StringProtocolEncoder { 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); - } - } + return formatCommand(command, "({%s}AV00{%s})", Command.KEY_UNIQUE_ID, Command.KEY_DATA); 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 f0a21334e..25968a0fe 100644 --- a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java @@ -16,7 +16,6 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest { 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)); -- cgit v1.2.3