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 | |
parent | af8875896e06ac3ac034c493b5a355d32cffb026 (diff) | |
download | trackermap-server-f839ca4c24d80dcd78b5ad1d65f10cdf534d94d8.tar.gz trackermap-server-f839ca4c24d80dcd78b5ad1d65f10cdf534d94d8.tar.bz2 trackermap-server-f839ca4c24d80dcd78b5ad1d65f10cdf534d94d8.zip |
Extend GK310 message format support
-rw-r--r-- | src/org/traccar/protocol/Gt06ProtocolDecoder.java | 5 | ||||
-rw-r--r-- | src/org/traccar/protocol/Gt06ProtocolEncoder.java | 16 | ||||
-rw-r--r-- | test/org/traccar/protocol/Gt06ProtocolDecoderTest.java | 6 |
3 files changed, 21 insertions, 6 deletions
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 2018fb6a6..bff04b36d 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -236,8 +236,11 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } } + int mcc = buf.readUnsignedShort(); + int mnc = BitUtil.check(mcc, 15) ? buf.readUnsignedShort() : buf.readUnsignedByte(); + position.setNetwork(new Network(CellTower.from( - buf.readUnsignedShort(), buf.readUnsignedByte(), buf.readUnsignedShort(), buf.readUnsignedMedium()))); + BitUtil.to(mcc, 15), mnc, buf.readUnsignedShort(), buf.readUnsignedMedium()))); if (length > 0) { buf.skipBytes(length - (hasLength ? 9 : 8)); 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; diff --git a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java index b6493e85b..7f191d664 100644 --- a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -19,6 +19,12 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest { verifyAttributes(decoder, binary( "78780B23C00122040001000818720D0A")); + /*verifyNotNull(decoder, binary( + "78782727110c070f1a338000000000000000000004002d81360104cb8a00bef30004030c02ff0004f4d20d0a"));*/ + + verifyNotNull(decoder, binary( + "78782322110c070f1b0270000000000000000000040081360104cb8a00bef3000000000523030d0a")); + verifyNotNull(decoder, binary( "787880a2110b161010140136040000591200000000009d7c01020000591200000000009d7c01020000591200000000009d7c01020000591200000000009d7c01020000591200000000009d7c01020000591200000000009d7c01020000591200000000009d7c0102ff033c1e04ddc28aa6001801eb4039c90000000000000014db84730d0a")); |