diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-12-08 04:47:26 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-12-08 04:47:26 +1300 |
commit | f839ca4c24d80dcd78b5ad1d65f10cdf534d94d8 (patch) | |
tree | bfd49d986a21fea69460948e114dfb0f018f0d2e /src/org/traccar/protocol/Gt06ProtocolEncoder.java | |
parent | af8875896e06ac3ac034c493b5a355d32cffb026 (diff) | |
download | trackermap-server-f839ca4c24d80dcd78b5ad1d65f10cdf534d94d8.tar.gz trackermap-server-f839ca4c24d80dcd78b5ad1d65f10cdf534d94d8.tar.bz2 trackermap-server-f839ca4c24d80dcd78b5ad1d65f10cdf534d94d8.zip |
Extend GK310 message format support
Diffstat (limited to 'src/org/traccar/protocol/Gt06ProtocolEncoder.java')
-rw-r--r-- | src/org/traccar/protocol/Gt06ProtocolEncoder.java | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/org/traccar/protocol/Gt06ProtocolEncoder.java index a3e0a2264..daf045f4f 100644 --- a/src/org/traccar/protocol/Gt06ProtocolEncoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolEncoder.java @@ -27,14 +27,16 @@ import java.nio.charset.StandardCharsets; public class Gt06ProtocolEncoder extends BaseProtocolEncoder { - private ChannelBuffer encodeContent(String content) { + private ChannelBuffer encodeContent(long deviceId, String content) { + + boolean language = Context.getIdentityManager().lookupAttributeBoolean(deviceId, "gt06.language", false, true); ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); buf.writeByte(0x78); buf.writeByte(0x78); - buf.writeByte(1 + 1 + 4 + content.length() + 2 + 2); // message length + buf.writeByte(1 + 1 + 4 + content.length() + 2 + 2 + (language ? 2 : 0)); // message length buf.writeByte(0x80); // message type @@ -42,6 +44,10 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { buf.writeInt(0); buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII)); // command + if (language) { + buf.writeShort(2); // english language + } + buf.writeShort(0); // message index buf.writeShort(Checksum.crc16(Checksum.CRC16_X25, buf.toByteBuffer(2, buf.writerIndex() - 2))); @@ -60,11 +66,11 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder { switch (command.getType()) { case Command.TYPE_ENGINE_STOP: - return encodeContent(alternative ? "DYD,123456#" : "Relay,1#"); + return encodeContent(command.getDeviceId(), alternative ? "DYD,123456#" : "Relay,1#"); case Command.TYPE_ENGINE_RESUME: - return encodeContent(alternative ? "HFYD,123456#" : "Relay,0#"); + return encodeContent(command.getDeviceId(), alternative ? "HFYD,123456#" : "Relay,0#"); case Command.TYPE_CUSTOM: - return encodeContent(command.getString(Command.KEY_DATA)); + return encodeContent(command.getDeviceId(), command.getString(Command.KEY_DATA)); default: Log.warning(new UnsupportedOperationException(command.getType())); break; |