From b7caadd9aa3da5487ca9bd64ffc6b2486f619c60 Mon Sep 17 00:00:00 2001 From: Hans van den Elsen Date: Fri, 12 Feb 2016 13:16:39 +0100 Subject: Added functionality to Minifinder protocol to send commands --- src/org/traccar/model/Command.java | 1 + 1 file changed, 1 insertion(+) (limited to 'src/org/traccar/model') diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java index 59e96be0e..5bde1c652 100644 --- a/src/org/traccar/model/Command.java +++ b/src/org/traccar/model/Command.java @@ -38,4 +38,5 @@ public class Command extends Extensible { public static final String KEY_DEVICE_PASSWORD = "devicePassword"; public static final String KEY_RADIUS = "radius"; + public static final String CUSTOM = "CUSTOM"; } -- cgit v1.2.3 From 3ced99384b1967f5cde9abdf30c1c0184a5ae3f6 Mon Sep 17 00:00:00 2001 From: Hans van den Elsen Date: Mon, 15 Feb 2016 07:28:03 +0100 Subject: Polishing up the custom commands for MiniFinder Renamed Command.CUSTOM to TYPE_CUSTOM. Put the raw command in the 'raw' attribute instead as the key for one. --- src/org/traccar/model/Command.java | 2 +- src/org/traccar/protocol/MiniFinderProtocol.java | 3 +-- src/org/traccar/protocol/MiniFinderProtocolEncoder.java | 4 ++-- test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java | 6 ++---- 4 files changed, 6 insertions(+), 9 deletions(-) (limited to 'src/org/traccar/model') diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java index 5bde1c652..dd541e643 100644 --- a/src/org/traccar/model/Command.java +++ b/src/org/traccar/model/Command.java @@ -38,5 +38,5 @@ public class Command extends Extensible { public static final String KEY_DEVICE_PASSWORD = "devicePassword"; public static final String KEY_RADIUS = "radius"; - public static final String CUSTOM = "CUSTOM"; + public static final String TYPE_CUSTOM = "CUSTOM"; } diff --git a/src/org/traccar/protocol/MiniFinderProtocol.java b/src/org/traccar/protocol/MiniFinderProtocol.java index a2dbd6c41..b22539277 100644 --- a/src/org/traccar/protocol/MiniFinderProtocol.java +++ b/src/org/traccar/protocol/MiniFinderProtocol.java @@ -18,7 +18,6 @@ package org.traccar.protocol; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.handler.codec.string.StringDecoder; -import org.jboss.netty.handler.codec.string.StringEncoder; import org.traccar.BaseProtocol; import org.traccar.CharacterDelimiterFrameDecoder; import org.traccar.TrackerServer; @@ -30,7 +29,7 @@ public class MiniFinderProtocol extends BaseProtocol { public MiniFinderProtocol() { super("minifinder"); - setSupportedCommands(Command.CUSTOM); + setSupportedCommands(Command.TYPE_CUSTOM); } @Override diff --git a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java index 5d15bc54a..729c57573 100644 --- a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java +++ b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java @@ -27,8 +27,8 @@ public class MiniFinderProtocolEncoder extends StringProtocolEncoder { protected Object encodeCommand(Command command) { switch (command.getType()) { - case Command.CUSTOM: - return command.getAttributes().keySet().iterator().next().toString(); + case Command.TYPE_CUSTOM: + return command.getAttributes().get("raw"); default: Log.warning(new UnsupportedOperationException(command.getType())); break; diff --git a/test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java b/test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java index 7beb52b51..524152bb8 100644 --- a/test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java +++ b/test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java @@ -1,8 +1,6 @@ package org.traccar.protocol; -import org.junit.Assert; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.traccar.ProtocolTest; import org.traccar.model.Command; @@ -21,8 +19,8 @@ public class MiniFinderProtocolEncoderTest extends ProtocolTest { public void testEncodeCustom() throws Exception { String expected = String.format("%sM,700", prefix); Command command = new Command(); - command.setType(Command.CUSTOM); - command.set(expected, 1); + command.setType(Command.TYPE_CUSTOM); + command.set("raw", expected); Object encoded = encoder.encodeCommand(command); assert expected.equals(encoded); } -- cgit v1.2.3