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 +++ .../traccar/protocol/Tk103ProtocolEncoderTest.java | 30 ++++++++++++++++++++++ 3 files changed, 35 insertions(+) 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: diff --git a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java index e934de04b..b198612b0 100644 --- a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java @@ -1,3 +1,20 @@ +/* + * 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; @@ -20,4 +37,17 @@ 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)); + + } + } -- cgit v1.2.3