aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2024-07-09 20:33:15 -0700
committerAnton Tananaev <anton@traccar.org>2024-07-09 20:33:15 -0700
commitb1a8f303c90f087dcefdabfd06c3d312aa1f6212 (patch)
tree27c74a010a80156a81d7151484bc93902e95a75c /src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java
parentb48e4a456f0e44a91d563a8d5b42295e131ebdaf (diff)
downloadtrackermap-server-b1a8f303c90f087dcefdabfd06c3d312aa1f6212.tar.gz
trackermap-server-b1a8f303c90f087dcefdabfd06c3d312aa1f6212.tar.bz2
trackermap-server-b1a8f303c90f087dcefdabfd06c3d312aa1f6212.zip
Support Meitrack custom commands
Diffstat (limited to 'src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java
index b66fc3241..9b43f3988 100644
--- a/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2024 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,18 +22,16 @@ import org.traccar.helper.Checksum;
import org.traccar.helper.model.AttributeUtil;
import org.traccar.model.Command;
-import java.util.Map;
-
public class MeitrackProtocolEncoder extends StringProtocolEncoder {
public MeitrackProtocolEncoder(Protocol protocol) {
super(protocol);
}
- private Object formatCommand(Command command, char dataId, String content) {
+ private Object formatCommand(Command command, 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);
+ String result = String.format("@@A%02d,%s,%s*", length, uniqueId, content);
result += Checksum.sum(result) + "\r\n";
return result;
}
@@ -41,23 +39,25 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
- Map<String, Object> attributes = command.getAttributes();
-
boolean alternative = AttributeUtil.lookup(
getCacheManager(), Keys.PROTOCOL_ALTERNATIVE.withPrefix(getProtocolName()), command.getDeviceId());
return switch (command.getType()) {
- case Command.TYPE_POSITION_SINGLE -> formatCommand(command, 'Q', "A10");
- case Command.TYPE_ENGINE_STOP -> formatCommand(command, 'M', "C01,0,12222");
- case Command.TYPE_ENGINE_RESUME -> formatCommand(command, 'M', "C01,0,02222");
- case Command.TYPE_ALARM_ARM -> formatCommand(command, 'M', alternative ? "B21,1" : "C01,0,22122");
- case Command.TYPE_ALARM_DISARM -> formatCommand(command, 'M', alternative ? "B21,0" : "C01,0,22022");
+ case Command.TYPE_CUSTOM -> formatCommand(command, command.getString(Command.KEY_DATA));
+ case Command.TYPE_POSITION_SINGLE -> formatCommand(command, "A10");
+ case Command.TYPE_ENGINE_STOP -> formatCommand(command, "C01,0,12222");
+ case Command.TYPE_ENGINE_RESUME -> formatCommand(command, "C01,0,02222");
+ case Command.TYPE_ALARM_ARM -> formatCommand(command, alternative ? "B21,1" : "C01,0,22122");
+ case Command.TYPE_ALARM_DISARM -> formatCommand(command, alternative ? "B21,0" : "C01,0,22022");
case Command.TYPE_REQUEST_PHOTO -> {
int index = command.getInteger(Command.KEY_INDEX);
- yield formatCommand(command, 'D', "D03," + (index > 0 ? index : 1) + ",camera_picture.jpg");
+ yield formatCommand(command, "D03," + (index > 0 ? index : 1) + ",camera_picture.jpg");
+ }
+ case Command.TYPE_SEND_SMS -> {
+ String phone = command.getString(Command.KEY_PHONE);
+ String message = command.getString(Command.KEY_MESSAGE);
+ yield formatCommand(command, "C02,0," + phone + "," + message);
}
- case Command.TYPE_SEND_SMS -> formatCommand(command, 'f', "C02,0,"
- + attributes.get(Command.KEY_PHONE) + "," + attributes.get(Command.KEY_MESSAGE));
default -> null;
};
}