aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java6
-rw-r--r--src/test/java/org/traccar/protocol/Xexun2ProtocolEncoderTest.java8
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"));
}