aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2024-08-03 20:52:00 -0600
committerIván Ávalos <avalos@disroot.org>2024-08-03 20:52:00 -0600
commit55f6d92c09a5b1d8566b53633d07be3d31010d3b (patch)
treeb86bed801b0bbadb72c7e839296dae1d28b12bbb /src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java
parentc04ad7d48331253c095fc123ded1b00f6ff871d3 (diff)
parent2788174193def918a3a1a5be3bbed24c9613323f (diff)
downloadtrackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.tar.gz
trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.tar.bz2
trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.zip
Merge tag 'tags/v6.3'
Diffstat (limited to 'src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java46
1 files changed, 20 insertions, 26 deletions
diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolEncoder.java
index 365dbb35a..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,31 +39,27 @@ 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());
- switch (command.getType()) {
- case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, 'Q', "A10");
- case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, 'M', "C01,0,12222");
- case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, 'M', "C01,0,02222");
- case Command.TYPE_ALARM_ARM:
- return formatCommand(command, 'M', alternative ? "B21,1" : "C01,0,22122");
- case Command.TYPE_ALARM_DISARM:
- return formatCommand(command, 'M', alternative ? "B21,0" : "C01,0,22022");
- case Command.TYPE_REQUEST_PHOTO:
+ return switch (command.getType()) {
+ 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);
- return formatCommand(command, 'D', "D03," + (index > 0 ? index : 1) + ",camera_picture.jpg");
- case Command.TYPE_SEND_SMS:
- return formatCommand(command, 'f', "C02,0,"
- + attributes.get(Command.KEY_PHONE) + "," + attributes.get(Command.KEY_MESSAGE));
- default:
- return null;
- }
+ 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);
+ }
+ default -> null;
+ };
}
}