From a0f389cf98e42a1794355be2a44167f61ad43557 Mon Sep 17 00:00:00 2001 From: Christoph Krey Date: Fri, 23 Jun 2017 19:46:58 +0200 Subject: add Command.TYPE_POSITION_SINGLE to Tk103 protocol --- src/org/traccar/protocol/Tk103Protocol.java | 2 ++ src/org/traccar/protocol/Tk103ProtocolEncoder.java | 3 +++ 2 files changed, 5 insertions(+) (limited to 'src/org') diff --git a/src/org/traccar/protocol/Tk103Protocol.java b/src/org/traccar/protocol/Tk103Protocol.java index 6fc00195e..1d3497bfb 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,7 @@ public class Tk103Protocol extends BaseProtocol { public Tk103Protocol() { super("tk103"); setSupportedDataCommands( + Command.TYPE_POSITION_SINGLE, 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..d3005296a 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,8 @@ public class Tk103ProtocolEncoder extends StringProtocolEncoder { protected Object encodeCommand(Command command) { switch (command.getType()) { + case Command.TYPE_POSITION_SINGLE: + return formatCommand(command, "({%s}AP00)", Command.KEY_UNIQUE_ID); case Command.TYPE_ENGINE_STOP: return formatCommand(command, "({%s}AV011)", Command.KEY_UNIQUE_ID); case Command.TYPE_ENGINE_RESUME: -- cgit v1.2.3 From 6790c1b7e78543d427d8b93105e56e719f8ab6af Mon Sep 17 00:00:00 2001 From: Christoph Krey Date: Sat, 24 Jun 2017 09:20:41 +0200 Subject: add TYPE_POSITION_PERIODIC, TYPE_POSITION_STOP, TYPE_GET_VERSION, TYPE_REBOOT_DEVICE, and TYPE_SET_ODOMETER to Tk103 protocol --- src/org/traccar/protocol/Tk103Protocol.java | 5 ++ src/org/traccar/protocol/Tk103ProtocolEncoder.java | 20 +++++++ .../traccar/protocol/Tk103ProtocolEncoderTest.java | 66 ++++++++++++++++++++++ 3 files changed, 91 insertions(+) (limited to 'src/org') diff --git a/src/org/traccar/protocol/Tk103Protocol.java b/src/org/traccar/protocol/Tk103Protocol.java index 1d3497bfb..07a68e2d8 100644 --- a/src/org/traccar/protocol/Tk103Protocol.java +++ b/src/org/traccar/protocol/Tk103Protocol.java @@ -34,6 +34,11 @@ public class Tk103Protocol extends BaseProtocol { 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 d3005296a..66cfc8dd2 100644 --- a/src/org/traccar/protocol/Tk103ProtocolEncoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolEncoder.java @@ -26,12 +26,32 @@ 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: return formatCommand(command, "({%s}AV010)", Command.KEY_UNIQUE_ID); + default: Log.warning(new UnsupportedOperationException(command.getType())); break; diff --git a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java index b198612b0..68a281003 100644 --- a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java @@ -50,4 +50,70 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest { } + @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)); + + } + } -- cgit v1.2.3 From e450c36389fed6e32a6b7e9fb47c739a425e4df2 Mon Sep 17 00:00:00 2001 From: Christoph Krey Date: Sun, 25 Jun 2017 08:10:20 +0200 Subject: style fixes --- src/org/traccar/protocol/Tk103ProtocolEncoder.java | 11 +---------- test/org/traccar/protocol/Tk103ProtocolEncoderTest.java | 17 ----------------- 2 files changed, 1 insertion(+), 27 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/Tk103ProtocolEncoder.java b/src/org/traccar/protocol/Tk103ProtocolEncoder.java index 66cfc8dd2..9e49b6ff1 100644 --- a/src/org/traccar/protocol/Tk103ProtocolEncoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolEncoder.java @@ -28,30 +28,21 @@ public class Tk103ProtocolEncoder extends StringProtocolEncoder { 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, + 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: return formatCommand(command, "({%s}AV010)", Command.KEY_UNIQUE_ID); - default: Log.warning(new UnsupportedOperationException(command.getType())); break; diff --git a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java index 68a281003..afc3b2387 100644 --- a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java @@ -1,20 +1,3 @@ -/* - * Copyright 2017 Christoph Krey (c@ckrey.de) - * Copyright 2017 Anton Tananaev (anton@traccar.org) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - package org.traccar.protocol; import org.junit.Assert; -- cgit v1.2.3