aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-11-01 21:26:02 -0700
committerAnton Tananaev <anton@traccar.org>2022-11-01 21:26:02 -0700
commit49646eccd5ec57013c78ea0a0776c206f812cb0b (patch)
tree8540e7c8f43773eaffd04308ee2c3887d44709a7 /src/main/java/org/traccar/protocol
parentd5ac6aa371b5dfd9a6613e693a6afc711fb740df (diff)
downloadtrackermap-server-49646eccd5ec57013c78ea0a0776c206f812cb0b.tar.gz
trackermap-server-49646eccd5ec57013c78ea0a0776c206f812cb0b.tar.bz2
trackermap-server-49646eccd5ec57013c78ea0a0776c206f812cb0b.zip
Better Meiligao commands
Diffstat (limited to 'src/main/java/org/traccar/protocol')
-rw-r--r--src/main/java/org/traccar/protocol/MeiligaoProtocol.java1
-rw-r--r--src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java47
2 files changed, 37 insertions, 11 deletions
diff --git a/src/main/java/org/traccar/protocol/MeiligaoProtocol.java b/src/main/java/org/traccar/protocol/MeiligaoProtocol.java
index 2c853f0e1..492094ce3 100644
--- a/src/main/java/org/traccar/protocol/MeiligaoProtocol.java
+++ b/src/main/java/org/traccar/protocol/MeiligaoProtocol.java
@@ -30,6 +30,7 @@ public class MeiligaoProtocol extends BaseProtocol {
setSupportedDataCommands(
Command.TYPE_POSITION_SINGLE,
Command.TYPE_POSITION_PERIODIC,
+ Command.TYPE_OUTPUT_CONTROL,
Command.TYPE_ENGINE_STOP,
Command.TYPE_ENGINE_RESUME,
Command.TYPE_ALARM_GEOFENCE,
diff --git a/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java b/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java
index 21f9f8801..03f0e7ecf 100644
--- a/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java
@@ -24,8 +24,10 @@ import org.traccar.helper.Checksum;
import org.traccar.helper.DataConverter;
import org.traccar.helper.model.AttributeUtil;
import org.traccar.model.Command;
+import org.traccar.model.Device;
import java.nio.charset.StandardCharsets;
+import java.util.Set;
import java.util.TimeZone;
public class MeiligaoProtocolEncoder extends BaseProtocolEncoder {
@@ -57,15 +59,36 @@ public class MeiligaoProtocolEncoder extends BaseProtocolEncoder {
return buf;
}
- @Override
- protected Object encodeCommand(Command command) {
+ private ByteBuf encodeOutputCommand(long deviceId, int index, int value) {
+
+ int outputCount;
+ int outputType;
+
+ String model = getCacheManager().getObject(Device.class, deviceId).getModel();
- boolean alternative = AttributeUtil.lookup(
- getCacheManager(), Keys.PROTOCOL_ALTERNATIVE.withPrefix(getProtocolName()), command.getDeviceId());
+ if (model != null && Set.of("TK510", "GT08", "TK208", "TK228", "MT05").contains(model)) {
+ outputCount = 5;
+ outputType = MeiligaoProtocolDecoder.MSG_OUTPUT_CONTROL_1;
+ } else {
+ outputCount = 1;
+ boolean alternative = AttributeUtil.lookup(
+ getCacheManager(), Keys.PROTOCOL_ALTERNATIVE.withPrefix(getProtocolName()), deviceId);
+ outputType = alternative
+ ? MeiligaoProtocolDecoder.MSG_OUTPUT_CONTROL_1
+ : MeiligaoProtocolDecoder.MSG_OUTPUT_CONTROL_2;
+ }
+
+ ByteBuf content = Unpooled.buffer();
- int outputControlMessageType = alternative
- ? MeiligaoProtocolDecoder.MSG_OUTPUT_CONTROL_1
- : MeiligaoProtocolDecoder.MSG_OUTPUT_CONTROL_2;
+ for (int i = 1; i <= outputCount; i++) {
+ content.writeByte(i == index ? value : 2);
+ }
+
+ return encodeContent(deviceId, outputType, content);
+ }
+
+ @Override
+ protected Object encodeCommand(Command command) {
ByteBuf content = Unpooled.buffer();
@@ -75,12 +98,14 @@ public class MeiligaoProtocolEncoder extends BaseProtocolEncoder {
case Command.TYPE_POSITION_PERIODIC:
content.writeShort(command.getInteger(Command.KEY_FREQUENCY) / 10);
return encodeContent(command.getDeviceId(), MeiligaoProtocolDecoder.MSG_TRACK_BY_INTERVAL, content);
+ case Command.TYPE_OUTPUT_CONTROL:
+ int index = Integer.parseInt(command.getString(Command.KEY_INDEX)) - 1;
+ int value = Integer.parseInt(command.getString(Command.KEY_DATA));
+ return encodeOutputCommand(command.getDeviceId(), index, value);
case Command.TYPE_ENGINE_STOP:
- content.writeByte(0x01);
- return encodeContent(command.getDeviceId(), outputControlMessageType, content);
+ return encodeOutputCommand(command.getDeviceId(), 1, 1);
case Command.TYPE_ENGINE_RESUME:
- content.writeByte(0x00);
- return encodeContent(command.getDeviceId(), outputControlMessageType, content);
+ return encodeOutputCommand(command.getDeviceId(), 1, 0);
case Command.TYPE_ALARM_GEOFENCE:
content.writeShort(command.getInteger(Command.KEY_RADIUS));
return encodeContent(command.getDeviceId(), MeiligaoProtocolDecoder.MSG_MOVEMENT_ALARM, content);