aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-03-07 23:53:46 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-03-07 23:53:46 +1300
commit77158ade988919ce63c905f8328dc6af2ac097c3 (patch)
tree0444e2d27efcd7a2822b9c7abc53864aef153133 /src
parent62ddfb226a55384fdfd1e0dd5a0436d55bb53d49 (diff)
downloadtrackermap-server-77158ade988919ce63c905f8328dc6af2ac097c3.tar.gz
trackermap-server-77158ade988919ce63c905f8328dc6af2ac097c3.tar.bz2
trackermap-server-77158ade988919ce63c905f8328dc6af2ac097c3.zip
Change Meitrack encoder implementation
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/helper/Checksum.java13
-rw-r--r--src/org/traccar/protocol/MeitrackProtocol.java1
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolEncoder.java21
3 files changed, 27 insertions, 8 deletions
diff --git a/src/org/traccar/helper/Checksum.java b/src/org/traccar/helper/Checksum.java
index e6b6cd2c8..c156e53f7 100644
--- a/src/org/traccar/helper/Checksum.java
+++ b/src/org/traccar/helper/Checksum.java
@@ -158,13 +158,20 @@ public final class Checksum {
public static String nmea(String msg) {
int checksum = 0;
- byte[] bytes = msg.getBytes(Charset.defaultCharset());
- for (int i = 1; i < msg.length(); i++) {
- checksum ^= bytes[i];
+ for (byte b : msg.getBytes(Charset.defaultCharset())) {
+ checksum ^= b;
}
return String.format("*%02x", checksum).toUpperCase();
}
+ public static String sum(String msg) {
+ byte checksum = 0;
+ for (byte b : msg.getBytes(Charset.defaultCharset())) {
+ checksum += b;
+ }
+ return String.format("%02X", checksum).toUpperCase();
+ }
+
public static long luhn(long imei) {
long checksum = 0;
long remain = imei;
diff --git a/src/org/traccar/protocol/MeitrackProtocol.java b/src/org/traccar/protocol/MeitrackProtocol.java
index e758e5f41..e5b5ddf2b 100644
--- a/src/org/traccar/protocol/MeitrackProtocol.java
+++ b/src/org/traccar/protocol/MeitrackProtocol.java
@@ -31,6 +31,7 @@ public class MeitrackProtocol extends BaseProtocol {
public MeitrackProtocol() {
super("meitrack");
setSupportedCommands(
+ Command.TYPE_POSITION_SINGLE,
Command.TYPE_ENGINE_STOP,
Command.TYPE_ENGINE_RESUME,
Command.TYPE_ALARM_ARM,
diff --git a/src/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
index 90fa5b624..381935c58 100644
--- a/src/org/traccar/protocol/MeitrackProtocolEncoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
@@ -16,25 +16,36 @@
package org.traccar.protocol;
import org.traccar.StringProtocolEncoder;
+import org.traccar.helper.Checksum;
import org.traccar.helper.Log;
import org.traccar.model.Command;
public class MeitrackProtocolEncoder extends StringProtocolEncoder {
+ private Object formatCommand(Command command, char dataId, String content) {
+ String uniqueId = getUniqueId(command.getDeviceId());
+ int length = 1 + uniqueId.length() + 1 + content.length() + 5;
+ String result = String.format("@@%c%02d,%s,%s*", dataId, length, uniqueId, content);
+ result += Checksum.sum(result) + "\r\n";
+ return result;
+ }
+
@Override
protected Object encodeCommand(Command command) {
switch (command.getType()) {
+ case Command.TYPE_POSITION_SINGLE:
+ return formatCommand(command, 'Q', "A10");
case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, "@@M33,{%s},C01,0,12222*00\r\n", Command.KEY_UNIQUE_ID);
+ return formatCommand(command, 'M', "C01,0,12222");
case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, "@@M33,{%s},C01,0,02222*00\r\n", Command.KEY_UNIQUE_ID);
+ return formatCommand(command, 'M', "C01,0,02222");
case Command.TYPE_ALARM_ARM:
- return formatCommand(command, "@@M33,{%s},C01,0,22122*00\r\n", Command.KEY_UNIQUE_ID);
+ return formatCommand(command, 'M', "C01,0,22122");
case Command.TYPE_ALARM_DISARM:
- return formatCommand(command, "@@M33,{%s},C01,0,22022*00\r\n", Command.KEY_UNIQUE_ID);
+ return formatCommand(command, 'M', "C01,0,22022");
case Command.TYPE_REQUEST_PHOTO:
- return formatCommand(command, "@@D46,{%s},D03,1,camera_picture.jpg*00\r\n", Command.KEY_UNIQUE_ID);
+ return formatCommand(command, 'D', "D03,1,camera_picture.jpg");
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;