aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java9
-rw-r--r--src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java15
2 files changed, 11 insertions, 13 deletions
diff --git a/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java
index 3c81ec27f..8deb2328b 100644
--- a/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java
@@ -42,13 +42,11 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder {
}
public static final int MSG_POSITION = 0x14;
- public static final int MSG_COMMAND = 0x07;
private void sendResponse(Channel channel, int type, int index, ByteBuf imei) {
if (channel != null) {
ByteBuf response = Unpooled.buffer();
- response.writeByte(0xfa);
- response.writeByte(0xaf);
+ response.writeShort(Xexun2ProtocolEncoder.FLAG);
response.writeShort(type);
response.writeShort(index);
@@ -57,8 +55,7 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder {
response.writeShort(0xfffe); // checksum
response.writeByte(1); // response
- response.writeByte(0xfa);
- response.writeByte(0xaf);
+ response.writeShort(Xexun2ProtocolEncoder.FLAG);
channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
}
@@ -100,7 +97,7 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- if (type != MSG_COMMAND) {
+ if (type != Xexun2ProtocolEncoder.MSG_COMMAND) {
sendResponse(channel, type, index, imei);
}
diff --git a/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
index c31d6e747..f876853bf 100644
--- a/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
@@ -62,17 +62,17 @@ public class Xexun2ProtocolEncoder extends BaseProtocolEncoder {
return result;
}
- private static int checksum(byte[] data) {
+ private static int udpchecksum(ByteBuf data) {
int sum = 0;
- int len = data.length;
+ int len = data.capacity();
for (int j = 0; len > 1; len--) {
- sum += data[j++] & 0xff;
+ sum += data.readByte() & 0xff;
if ((sum & 0x80000000) > 0) {
sum = (sum & 0xffff) + (sum >> 16);
}
}
if (len == 1) {
- sum += data[data.length - 1] & 0xff;
+ sum += data.readByte() & 0xff;
}
while ((sum >> 16) > 0) {
sum = (sum & 0xffff) + sum >> 16;
@@ -85,14 +85,15 @@ public class Xexun2ProtocolEncoder extends BaseProtocolEncoder {
private static ByteBuf encodeContent(String uniqueId, String content) {
ByteBuf buf = Unpooled.buffer();
- byte[] message = content.getBytes();
+ ByteBuf message = Unpooled.copiedBuffer(content.getBytes());
buf.writeShort(FLAG);
buf.writeShort(MSG_COMMAND);
buf.writeShort(1); // index
buf.writeBytes(DataConverter.parseHex(uniqueId + "0"));
- buf.writeShort(message.length);
- buf.writeShort(checksum(message));
+ buf.writeShort(message.capacity());
+ buf.writeShort(udpchecksum(message));
+ message.resetReaderIndex();
buf.writeBytes(message);
buf.writeShort(FLAG);