diff options
-rw-r--r-- | src/org/traccar/protocol/UlbotechProtocolDecoder.java | 20 | ||||
-rw-r--r-- | test/org/traccar/protocol/UlbotechProtocolDecoderTest.java | 7 |
2 files changed, 25 insertions, 2 deletions
diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index 97912e128..b5d60431d 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -22,6 +22,7 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.Context; import org.traccar.DeviceSession; import org.traccar.helper.BitUtil; +import org.traccar.helper.Checksum; import org.traccar.helper.DateBuilder; import org.traccar.helper.ObdDecoder; import org.traccar.helper.Parser; @@ -340,8 +341,27 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer buf = (ChannelBuffer) msg; if (buf.getUnsignedByte(buf.readerIndex()) == 0xF8) { + + if (channel != null) { + ChannelBuffer response = ChannelBuffers.dynamicBuffer(); + response.writeByte(0xF8); + response.writeByte(DATA_GPS); + response.writeByte(0xFE); + response.writeShort(buf.getShort(response.writerIndex() - 1 - 2)); + response.writeShort(Checksum.crc16(Checksum.CRC16_XMODEM, response.toByteBuffer(1, 4))); + response.writeByte(0xF8); + channel.write(response); + } + return decodeBinary(channel, remoteAddress, buf); } else { + + if (channel != null) { + channel.write(ChannelBuffers.copiedBuffer(String.format("*TS01,ACK:%04X#", + Checksum.crc16(Checksum.CRC16_XMODEM, buf.toByteBuffer(1, buf.writerIndex() - 2))), + StandardCharsets.US_ASCII)); + } + return decodeText(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII)); } } diff --git a/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java b/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java index c76912f18..cb2a06ba9 100644 --- a/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java +++ b/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class UlbotechProtocolDecoderTest extends ProtocolTest { UlbotechProtocolDecoder decoder = new UlbotechProtocolDecoder(new UlbotechProtocol()); + verifyNothing(decoder, buffer( + "*TS01,353323081464660#")); + verifyAttributes(decoder, buffer( "*TS01,868323025245751,134955140317,WFE:0#")); @@ -40,8 +43,8 @@ public class UlbotechProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, binary( "f8010103515790566431569e5fbb9d010e015ee2b906bde4a000000000009f03040a4000000404000115fe05060340173f22030711310583410c0000310d00312f834131000008040000b78c09077320290082c021100101120af8")); - verifyNothing(decoder, binary( - "2a545330312c33353430343330353133383934363023")); + verifyNothing(decoder, buffer( + "*TS01,354043051389460#")); verifyPosition(decoder, binary( "f8010108679650230646339de69054010e015ee17506bde2c60000000000ac0304024000000404000009f705060390181422170711310583410c0000310d00312f834131018608040003130a100101136cf8")); |