aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/model/Command.java1
-rw-r--r--src/org/traccar/protocol/Pt502Protocol.java2
-rw-r--r--src/org/traccar/protocol/Pt502ProtocolEncoder.java6
-rw-r--r--test/org/traccar/protocol/Pt502ProtocolEncoderTest.java33
4 files changed, 39 insertions, 3 deletions
diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java
index d15eb9e70..d1b9aa793 100644
--- a/src/org/traccar/model/Command.java
+++ b/src/org/traccar/model/Command.java
@@ -44,6 +44,7 @@ public class Command extends Message {
public static final String TYPE_ALARM_SOS = "alarmSos";
public static final String TYPE_ALARM_REMOVE = "alarmRemove";
public static final String TYPE_ALARM_CLOCK = "alarmClock";
+ public static final String TYPE_ALARM_SPEED = "alarmSpeed";
public static final String KEY_UNIQUE_ID = "uniqueId";
public static final String KEY_FREQUENCY = "frequency";
diff --git a/src/org/traccar/protocol/Pt502Protocol.java b/src/org/traccar/protocol/Pt502Protocol.java
index 04c758b22..75fe0f628 100644
--- a/src/org/traccar/protocol/Pt502Protocol.java
+++ b/src/org/traccar/protocol/Pt502Protocol.java
@@ -31,6 +31,8 @@ public class Pt502Protocol extends BaseProtocol {
public Pt502Protocol() {
super("pt502");
setSupportedCommands(
+ Command.TYPE_SET_TIMEZONE,
+ Command.TYPE_ALARM_SPEED,
Command.TYPE_OUTPUT_CONTROL);
}
diff --git a/src/org/traccar/protocol/Pt502ProtocolEncoder.java b/src/org/traccar/protocol/Pt502ProtocolEncoder.java
index 86c6703d4..b8ca8ab15 100644
--- a/src/org/traccar/protocol/Pt502ProtocolEncoder.java
+++ b/src/org/traccar/protocol/Pt502ProtocolEncoder.java
@@ -26,7 +26,11 @@ public class Pt502ProtocolEncoder extends StringProtocolEncoder {
switch (command.getType()) {
case Command.TYPE_OUTPUT_CONTROL:
- return formatCommand(command, "000000OPC{%s},{%s}", Command.KEY_INDEX, Command.KEY_DATA);
+ return formatCommand(command, "#OPC{%s},{%s}\r\n", Command.KEY_INDEX, Command.KEY_DATA);
+ case Command.TYPE_SET_TIMEZONE:
+ return formatCommand(command, "#TMZ{%s}\r\n", Command.KEY_TIMEZONE);
+ case Command.TYPE_ALARM_SPEED:
+ return formatCommand(command, "#SPD{%s}\r\n", Command.KEY_DATA);
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/test/org/traccar/protocol/Pt502ProtocolEncoderTest.java b/test/org/traccar/protocol/Pt502ProtocolEncoderTest.java
index 889323ae0..ab6446010 100644
--- a/test/org/traccar/protocol/Pt502ProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/Pt502ProtocolEncoderTest.java
@@ -8,7 +8,7 @@ import org.traccar.model.Command;
public class Pt502ProtocolEncoderTest extends ProtocolTest {
@Test
- public void testEncode() throws Exception {
+ public void testEncodeOutputControl() throws Exception {
Pt502ProtocolEncoder encoder = new Pt502ProtocolEncoder();
@@ -18,7 +18,36 @@ public class Pt502ProtocolEncoderTest extends ProtocolTest {
command.set(Command.KEY_INDEX, 2);
command.set(Command.KEY_DATA, 1);
- Assert.assertEquals("000000OPC2,1", encoder.encodeCommand(command));
+ Assert.assertEquals("#OPC2,1\r\n", encoder.encodeCommand(command));
+
+ }
+
+ @Test
+ public void testEncodeTimezone() throws Exception {
+
+ Pt502ProtocolEncoder encoder = new Pt502ProtocolEncoder();
+
+ Command command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_SET_TIMEZONE);
+ command.set(Command.KEY_TIMEZONE, 8);
+
+ Assert.assertEquals("#TMZ8\r\n", encoder.encodeCommand(command));
+
+ }
+
+
+ @Test
+ public void testEncodeAlarmSpeed() throws Exception {
+
+ Pt502ProtocolEncoder encoder = new Pt502ProtocolEncoder();
+
+ Command command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_ALARM_SPEED);
+ command.set(Command.KEY_DATA, 120);
+
+ Assert.assertEquals("#SPD120\r\n", encoder.encodeCommand(command));
}