diff options
author | Stefan Clark <stefanclark@gmail.com> | 2022-07-25 13:34:02 +0000 |
---|---|---|
committer | Stefan Clark <stefanclark@gmail.com> | 2022-07-25 13:34:02 +0000 |
commit | 8b63ce5c51fca9462e0e561b8ce07ae49afce6f8 (patch) | |
tree | 65f591f36e36aae69056216bd01b3a68973ae9b8 /src | |
parent | 032d02b584553f4374c4bc6ae9f7c8e819595c42 (diff) | |
download | trackermap-server-8b63ce5c51fca9462e0e561b8ce07ae49afce6f8.tar.gz trackermap-server-8b63ce5c51fca9462e0e561b8ce07ae49afce6f8.tar.bz2 trackermap-server-8b63ce5c51fca9462e0e561b8ce07ae49afce6f8.zip |
Update Xexun2 Encoder
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java | 6 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/Xexun2ProtocolEncoderTest.java | 8 |
2 files changed, 7 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java index d85c6734b..287364cf2 100644 --- a/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java @@ -32,8 +32,8 @@ public class Xexun2ProtocolEncoder extends BaseProtocolEncoder { } private static ByteBuf encodeFrame(ByteBuf buf) { - buf.clear(); - if (buf.readableBytes() < 5) { + int bufLength = buf.readableBytes(); + if (bufLength < 5) { return null; } @@ -41,7 +41,7 @@ public class Xexun2ProtocolEncoder extends BaseProtocolEncoder { result.writeBytes(buf.readBytes(2)); - while (buf.readerIndex() < buf.capacity() - 2) { + while (buf.readerIndex() < bufLength - 2) { int b = buf.readUnsignedByte(); if (b == 0xfa && buf.isReadable() && buf.getUnsignedByte(buf.readerIndex()) == 0xaf) { buf.readUnsignedByte(); diff --git a/src/test/java/org/traccar/protocol/Xexun2ProtocolEncoderTest.java b/src/test/java/org/traccar/protocol/Xexun2ProtocolEncoderTest.java index 6d3b3e065..483bc85fa 100644 --- a/src/test/java/org/traccar/protocol/Xexun2ProtocolEncoderTest.java +++ b/src/test/java/org/traccar/protocol/Xexun2ProtocolEncoderTest.java @@ -14,15 +14,15 @@ public class Xexun2ProtocolEncoderTest extends ProtocolTest { Command command; command = new Command(); - command.setDeviceId(604080829351806311L); + command.setDeviceId(1); command.setType(Command.TYPE_POWER_OFF); - verifyCommand(encoder, command, binary("FAAF0007000186220505123456700004FEBC6F663D31FAAF")); + verifyCommand(encoder, command, binary("FAAF0007000112345678901234500004FEBC6F663D31FAAF")); command = new Command(); - command.setDeviceId(604080829351806311L); + command.setDeviceId(1); command.setType(Command.TYPE_POSITION_PERIODIC); command.set(Command.KEY_FREQUENCY, 150); - verifyCommand(encoder, command, binary("FAAF0007000186220505123456700015F90E747261636B696E675F73656E643D3135302C313530FAAF")); + verifyCommand(encoder, command, binary("FAAF0007000112345678901234500015F90E747261636B696E675F73656E643D3135302C313530FAAF")); } |