aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-08-28 11:18:05 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2016-08-28 11:18:05 +1200
commitae5fe50416df190f5374d084526518a22096871e (patch)
tree80ad67bfdc5eb3dde63cf466f090fd9379f96752
parent726b69a642e7f4d7c54863fc7367b066f7217ad2 (diff)
downloadtraccar-server-ae5fe50416df190f5374d084526518a22096871e.tar.gz
traccar-server-ae5fe50416df190f5374d084526518a22096871e.tar.bz2
traccar-server-ae5fe50416df190f5374d084526518a22096871e.zip
Add more MiniFinder commands
-rw-r--r--src/org/traccar/model/Command.java1
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocol.java3
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocolEncoder.java47
-rw-r--r--src/org/traccar/protocol/WialonProtocolEncoder.java2
-rw-r--r--test/org/traccar/protocol/MeitrackProtocolEncoderTest.java2
-rw-r--r--test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java8
7 files changed, 48 insertions, 17 deletions
diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java
index 730f47842..67c624fcd 100644
--- a/src/org/traccar/model/Command.java
+++ b/src/org/traccar/model/Command.java
@@ -58,7 +58,6 @@ public class Command extends Message {
public static final String KEY_TIMEZONE = "timezone";
public static final String KEY_DEVICE_PASSWORD = "devicePassword";
public static final String KEY_RADIUS = "radius";
- public static final String KEY_PHONE_NUMBER = "phoneNumber";
public static final String KEY_MESSAGE = "message";
public static final String KEY_ENABLE = "enable";
public static final String KEY_DATA = "data";
diff --git a/src/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
index 04cb39637..784b3b917 100644
--- a/src/org/traccar/protocol/MeitrackProtocolEncoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
@@ -52,7 +52,7 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder {
return formatCommand(command, 'D', "D03,1,camera_picture.jpg");
case Command.TYPE_SEND_SMS:
return formatCommand(command, 'f', "C02,0,"
- + attributes.get(Command.KEY_PHONE_NUMBER) + "," + attributes.get(Command.KEY_MESSAGE));
+ + attributes.get(Command.KEY_PHONE) + "," + attributes.get(Command.KEY_MESSAGE));
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/src/org/traccar/protocol/MiniFinderProtocol.java b/src/org/traccar/protocol/MiniFinderProtocol.java
index bdd3337ed..8da621ee4 100644
--- a/src/org/traccar/protocol/MiniFinderProtocol.java
+++ b/src/org/traccar/protocol/MiniFinderProtocol.java
@@ -38,7 +38,8 @@ public class MiniFinderProtocol extends BaseProtocol {
Command.TYPE_SET_AGPS,
Command.TYPE_ALARM_FALL,
Command.TYPE_MODE_POWER_SAVING,
- Command.TYPE_MODE_DEEP_SLEEP);
+ Command.TYPE_MODE_DEEP_SLEEP,
+ Command.TYPE_SOS_NUMBER);
}
@Override
diff --git a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
index 4d1d5b576..c5210aa0b 100644
--- a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
+++ b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
@@ -19,33 +19,56 @@ import org.traccar.StringProtocolEncoder;
import org.traccar.helper.Log;
import org.traccar.model.Command;
-public class MiniFinderProtocolEncoder extends StringProtocolEncoder {
+public class MiniFinderProtocolEncoder extends StringProtocolEncoder implements StringProtocolEncoder.ValueFormatter {
- private int getEnabledFlag(Command command) {
- return (Boolean) command.getAttributes().get(Command.KEY_ENABLE) ? 1 : 0;
+ @Override
+ public String formatValue(String key, Object value) {
+
+ if (key.equals(Command.KEY_ENABLE)) {
+ return (Boolean) value ? "1" : "0";
+ } else if (key.equals(Command.KEY_TIMEZONE)) {
+ return String.format("%+03d", ((Number) value).longValue() / 3600);
+ } else if (key.equals(Command.KEY_INDEX)) {
+ switch (((Number) value).intValue()) {
+ case 0:
+ return "A";
+ case 1:
+ return "B";
+ case 2:
+ return "C";
+ default:
+ return null;
+ }
+ }
+
+ return null;
}
@Override
protected Object encodeCommand(Command command) {
+ initDevicePassword(command, "123456");
+
switch (command.getType()) {
case Command.TYPE_SET_TIMEZONE:
- return String.format("123456L%+03d",
- ((Number) command.getAttributes().get(Command.KEY_TIMEZONE)).longValue() / 3600);
+ return formatCommand(command, "{%s}L{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_TIMEZONE);
case Command.TYPE_VOICE_MONITORING:
- return String.format("123456L%d", getEnabledFlag(command));
+ return formatCommand(command, "{%s}P{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
case Command.TYPE_ALARM_SPEED:
- return formatCommand(command, "123456J1{%s}", Command.KEY_DATA);
+ return formatCommand(command, "{%s}J1{%s}", Command.KEY_DEVICE_PASSWORD, Command.KEY_DATA);
case Command.TYPE_ALARM_GEOFENCE:
- return formatCommand(command, "123456R1{%s}", Command.KEY_RADIUS);
+ return formatCommand(command, "{%s}R1{%s}", Command.KEY_DEVICE_PASSWORD, Command.KEY_RADIUS);
case Command.TYPE_SET_AGPS:
- return String.format("123456AGPS%d", getEnabledFlag(command));
+ return formatCommand(command, "{%s}AGPS{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
case Command.TYPE_ALARM_FALL:
- return String.format("123456F%d", getEnabledFlag(command));
+ return formatCommand(command, "{%s}F{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
case Command.TYPE_MODE_POWER_SAVING:
- return String.format("123456SP%d", getEnabledFlag(command));
+ return formatCommand(command, "{%s}SP{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
case Command.TYPE_MODE_DEEP_SLEEP:
- return String.format("123456DS%d", getEnabledFlag(command));
+ return formatCommand(command, "{%s}DS{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
+ case Command.TYPE_SOS_NUMBER:
+ return formatCommand(command, "{%s}{%s}1,{%s}", this,
+ Command.KEY_DEVICE_PASSWORD, Command.KEY_INDEX, Command.KEY_PHONE);
default:
Log.warning(new UnsupportedOperationException(command.getType()));
return null;
diff --git a/src/org/traccar/protocol/WialonProtocolEncoder.java b/src/org/traccar/protocol/WialonProtocolEncoder.java
index 7cdc0c63c..b68dacd79 100644
--- a/src/org/traccar/protocol/WialonProtocolEncoder.java
+++ b/src/org/traccar/protocol/WialonProtocolEncoder.java
@@ -28,7 +28,7 @@ public class WialonProtocolEncoder extends StringProtocolEncoder {
case Command.TYPE_REBOOT_DEVICE:
return formatCommand(command, "reboot\r\n");
case Command.TYPE_SEND_USSD:
- return formatCommand(command, "USSD:{%s}\r\n", Command.KEY_PHONE_NUMBER);
+ return formatCommand(command, "USSD:{%s}\r\n", Command.KEY_PHONE);
case Command.TYPE_IDENTIFICATION:
return formatCommand(command, "VER?\r\n");
case Command.TYPE_OUTPUT_CONTROL:
diff --git a/test/org/traccar/protocol/MeitrackProtocolEncoderTest.java b/test/org/traccar/protocol/MeitrackProtocolEncoderTest.java
index 3e0a870d0..771712420 100644
--- a/test/org/traccar/protocol/MeitrackProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/MeitrackProtocolEncoderTest.java
@@ -20,7 +20,7 @@ public class MeitrackProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_SEND_SMS);
- command.set(Command.KEY_PHONE_NUMBER, "15360853789");
+ command.set(Command.KEY_PHONE, "15360853789");
command.set(Command.KEY_MESSAGE, "Meitrack");
Assert.assertEquals("@@f48,123456789012345,C02,0,15360853789,Meitrack*B0\r\n", encoder.encodeCommand(command));
diff --git a/test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java b/test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java
index 875bfa13e..99b250ebc 100644
--- a/test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java
@@ -19,6 +19,14 @@ public class MiniFinderProtocolEncoderTest extends ProtocolTest {
Assert.assertEquals("123456L+01", encoder.encodeCommand(command));
+ command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_SOS_NUMBER);
+ command.set(Command.KEY_INDEX, 2);
+ command.set(Command.KEY_PHONE, "1111111111");
+
+ Assert.assertEquals("123456C1,1111111111", encoder.encodeCommand(command));
+
}
}