aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-03-15 22:16:47 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-03-15 22:16:47 +1300
commitd8552cb2975ec8a78ed07e0ec0f1ba1c7d34086a (patch)
treee4857c25617e5fd8eb29fe92742ea60138475f74
parent357209a5aafe18688d5bd230d3db1ddf3c79fd59 (diff)
downloadtraccar-server-d8552cb2975ec8a78ed07e0ec0f1ba1c7d34086a.tar.gz
traccar-server-d8552cb2975ec8a78ed07e0ec0f1ba1c7d34086a.tar.bz2
traccar-server-d8552cb2975ec8a78ed07e0ec0f1ba1c7d34086a.zip
Implement send SMS Meitrack command
-rw-r--r--src/org/traccar/model/Command.java7
-rw-r--r--src/org/traccar/protocol/MeitrackProtocol.java3
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolEncoder.java7
-rw-r--r--test/org/traccar/protocol/MeitrackProtocolEncoderTest.java7
4 files changed, 21 insertions, 3 deletions
diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java
index dd541e643..eda5f61d1 100644
--- a/src/org/traccar/model/Command.java
+++ b/src/org/traccar/model/Command.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Command extends Extensible {
+ public static final String TYPE_CUSTOM = "custom";
public static final String TYPE_POSITION_SINGLE = "positionSingle";
public static final String TYPE_POSITION_PERIODIC = "positionPeriodic";
public static final String TYPE_POSITION_STOP = "positionStop";
@@ -31,12 +32,14 @@ public class Command extends Extensible {
public static final String TYPE_REQUEST_PHOTO = "requestPhoto";
public static final String TYPE_REBOOT_DEVICE = "rebootDevice";
public static final String TYPE_MOVEMENT_ALARM = "movementAlarm";
+ public static final String TYPE_SEND_SMS = "sendSms";
public static final String KEY_UNIQUE_ID = "uniqueId";
public static final String KEY_FREQUENCY = "frequency";
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 TYPE_CUSTOM = "CUSTOM";
}
diff --git a/src/org/traccar/protocol/MeitrackProtocol.java b/src/org/traccar/protocol/MeitrackProtocol.java
index e5b5ddf2b..a004d5cb6 100644
--- a/src/org/traccar/protocol/MeitrackProtocol.java
+++ b/src/org/traccar/protocol/MeitrackProtocol.java
@@ -36,7 +36,8 @@ public class MeitrackProtocol extends BaseProtocol {
Command.TYPE_ENGINE_RESUME,
Command.TYPE_ALARM_ARM,
Command.TYPE_ALARM_DISARM,
- Command.TYPE_REQUEST_PHOTO);
+ Command.TYPE_REQUEST_PHOTO,
+ Command.TYPE_SEND_SMS);
}
@Override
diff --git a/src/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
index 381935c58..04cb39637 100644
--- a/src/org/traccar/protocol/MeitrackProtocolEncoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
@@ -20,6 +20,8 @@ import org.traccar.helper.Checksum;
import org.traccar.helper.Log;
import org.traccar.model.Command;
+import java.util.Map;
+
public class MeitrackProtocolEncoder extends StringProtocolEncoder {
private Object formatCommand(Command command, char dataId, String content) {
@@ -33,6 +35,8 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
+ Map<String, Object> attributes = command.getAttributes();
+
switch (command.getType()) {
case Command.TYPE_POSITION_SINGLE:
return formatCommand(command, 'Q', "A10");
@@ -46,6 +50,9 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder {
return formatCommand(command, 'M', "C01,0,22022");
case Command.TYPE_REQUEST_PHOTO:
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));
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/test/org/traccar/protocol/MeitrackProtocolEncoderTest.java b/test/org/traccar/protocol/MeitrackProtocolEncoderTest.java
index 64812c1da..3e0a870d0 100644
--- a/test/org/traccar/protocol/MeitrackProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/MeitrackProtocolEncoderTest.java
@@ -18,6 +18,13 @@ public class MeitrackProtocolEncoderTest extends ProtocolTest {
Assert.assertEquals("@@Q25,123456789012345,A10*68\r\n", encoder.encodeCommand(command));
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_SEND_SMS);
+ command.set(Command.KEY_PHONE_NUMBER, "15360853789");
+ command.set(Command.KEY_MESSAGE, "Meitrack");
+
+ Assert.assertEquals("@@f48,123456789012345,C02,0,15360853789,Meitrack*B0\r\n", encoder.encodeCommand(command));
+
}
}