aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2023-08-29 06:44:03 -0700
committerGitHub <noreply@github.com>2023-08-29 06:44:03 -0700
commit84faee331312363f0930593c6e24bbcb55a871a5 (patch)
tree01591224e6204eab08822ba44f4a195bbbb3df81 /src/main/java/org/traccar/protocol/GatorProtocolEncoder.java
parent88bff45bd959ec932e00db9b3642e337abbcf1be (diff)
parenteaacc24b7461efc6f939efcf7ecc17ae646b13a5 (diff)
downloadtrackermap-server-84faee331312363f0930593c6e24bbcb55a871a5.tar.gz
trackermap-server-84faee331312363f0930593c6e24bbcb55a871a5.tar.bz2
trackermap-server-84faee331312363f0930593c6e24bbcb55a871a5.zip
Merge pull request #5155 from seym45/gator-commands-engine
Add more commands for Gator protocol
Diffstat (limited to 'src/main/java/org/traccar/protocol/GatorProtocolEncoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/GatorProtocolEncoder.java23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java
index 3d38b7455..6c6b9a54a 100644
--- a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java
@@ -43,18 +43,23 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder {
return buf;
}
- private ByteBuf encodeContent(long deviceId, int type) {
+ private ByteBuf encodeContent(long deviceId, int type, ByteBuf content) {
ByteBuf buf = Unpooled.buffer();
buf.writeByte(0x24);
buf.writeByte(0x24);
buf.writeByte(type);
buf.writeByte(0x00);
- buf.writeByte(4 + 1 + 1); // ip 4 bytes, checksum and end byte
+
+ buf.writeByte(4 + 1 + (content != null ? content.readableBytes() : 0) + 1); // length
ByteBuf pseudoIPAddress = encodeId(deviceId);
buf.writeBytes(pseudoIPAddress);
+ if (content != null) {
+ buf.writeBytes(content);
+ }
+
int checksum = Checksum.xor(buf.nioBuffer());
buf.writeByte(checksum);
@@ -66,9 +71,21 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
+ ByteBuf content = Unpooled.buffer();
+
switch (command.getType()) {
case Command.TYPE_POSITION_SINGLE:
- return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_REQUEST);
+ return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_POSITION_REQUEST, null);
+ case Command.TYPE_ENGINE_STOP:
+ return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_CLOSE_OIL_DUCT, null);
+ case Command.TYPE_ENGINE_RESUME:
+ return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESTORE_OIL_DUCT, null);
+ case Command.TYPE_SET_SPEED_LIMIT:
+ content.writeByte(command.getInteger(Command.KEY_DATA));
+ return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_RESET_MILEAGE, content);
+ case Command.TYPE_SET_ODOMETER:
+ content.writeShort(command.getInteger(Command.KEY_DATA));
+ return encodeContent(command.getDeviceId(), GatorProtocolDecoder.MSG_OVERSPEED_ALARM, content);
default:
return null;
}