aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-03-27 20:05:05 -0700
committerAnton Tananaev <anton@traccar.org>2023-03-27 20:05:05 -0700
commitc68e92043cb52f859de724781f2e5774c60d465b (patch)
tree90854306ce71f69bd951c84bf10d2dd6f050461d /src/main/java/org
parent1d1fc57b3dd44013bd467a825b970ac06749e125 (diff)
downloadtrackermap-server-c68e92043cb52f859de724781f2e5774c60d465b.tar.gz
trackermap-server-c68e92043cb52f859de724781f2e5774c60d465b.tar.bz2
trackermap-server-c68e92043cb52f859de724781f2e5774c60d465b.zip
Add HuaSheng output control
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/protocol/HuaShengProtocol.java1
-rw-r--r--src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java2
-rw-r--r--src/main/java/org/traccar/protocol/HuaShengProtocolEncoder.java22
3 files changed, 21 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/protocol/HuaShengProtocol.java b/src/main/java/org/traccar/protocol/HuaShengProtocol.java
index 4a0ebe5d7..1f8bafc57 100644
--- a/src/main/java/org/traccar/protocol/HuaShengProtocol.java
+++ b/src/main/java/org/traccar/protocol/HuaShengProtocol.java
@@ -29,6 +29,7 @@ public class HuaShengProtocol extends BaseProtocol {
public HuaShengProtocol(Config config) {
setSupportedDataCommands(
Command.TYPE_POSITION_PERIODIC,
+ Command.TYPE_OUTPUT_CONTROL,
Command.TYPE_ALARM_ARM,
Command.TYPE_ALARM_DISARM,
Command.TYPE_SET_SPEED_LIMIT);
diff --git a/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java
index 993e36978..2d952c759 100644
--- a/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/HuaShengProtocolDecoder.java
@@ -50,6 +50,8 @@ public class HuaShengProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_HSO_RSP = 0x0003;
public static final int MSG_SET_REQ = 0xAA04;
public static final int MSG_SET_RSP = 0xFF05;
+ public static final int MSG_CTRL_REQ = 0xAA16;
+ public static final int MSG_CTRL_RSP = 0xFF17;
private void sendResponse(Channel channel, int type, int index, ByteBuf content) {
if (channel != null) {
diff --git a/src/main/java/org/traccar/protocol/HuaShengProtocolEncoder.java b/src/main/java/org/traccar/protocol/HuaShengProtocolEncoder.java
index 636196ec4..dc34f7b4e 100644
--- a/src/main/java/org/traccar/protocol/HuaShengProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/HuaShengProtocolEncoder.java
@@ -27,13 +27,13 @@ public class HuaShengProtocolEncoder extends BaseProtocolEncoder {
super(protocol);
}
- private ByteBuf encodeContent(ByteBuf content) {
+ private ByteBuf encodeContent(int type, ByteBuf content) {
ByteBuf buf = Unpooled.buffer();
buf.writeByte(0xC0);
buf.writeShort(0x0000); // flag and version
buf.writeShort(12 + content.readableBytes());
- buf.writeShort(HuaShengProtocolDecoder.MSG_SET_REQ);
+ buf.writeShort(type);
buf.writeShort(0); // checksum
buf.writeInt(1); // index
buf.writeBytes(content);
@@ -52,17 +52,31 @@ public class HuaShengProtocolEncoder extends BaseProtocolEncoder {
content.writeShort(0x0002);
content.writeShort(6); // length
content.writeShort(command.getInteger(Command.KEY_FREQUENCY));
- return encodeContent(content);
+ return encodeContent(HuaShengProtocolDecoder.MSG_SET_REQ, content);
+ case Command.TYPE_OUTPUT_CONTROL:
+ /*
+0x01: Lock the relay1; //relay on
+0x02: Unlock the relay1; //relay off
+0x03: Lock the relay2; //relay2 on
+0x04: Unlock the relay2; //relay2 off
+0x05: Lock the relay3; //relay3 on
+0x06: Unlock the relay3; //realy3 off
+ */
+ content.writeByte(
+ (command.getInteger(Command.KEY_INDEX) - 1) * 2
+ + (2 - command.getInteger(Command.KEY_DATA)));
+ return encodeContent(HuaShengProtocolDecoder.MSG_CTRL_REQ, content);
case Command.TYPE_ALARM_ARM:
case Command.TYPE_ALARM_DISARM:
content.writeShort(0x0001);
content.writeShort(5); // length
content.writeByte(command.getType().equals(Command.TYPE_ALARM_ARM) ? 1 : 0);
+ return encodeContent(HuaShengProtocolDecoder.MSG_SET_REQ, content);
case Command.TYPE_SET_SPEED_LIMIT:
content.writeShort(0x0004);
content.writeShort(6); // length
content.writeShort(command.getInteger(Command.KEY_DATA));
- return encodeContent(content);
+ return encodeContent(HuaShengProtocolDecoder.MSG_SET_REQ, content);
default:
return null;
}