aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
authorStefan Clark <stefanclark@gmail.com>2022-07-25 19:49:37 +0000
committerStefan Clark <stefanclark@gmail.com>2022-07-25 19:49:37 +0000
commite91402cddad8763658572eb8e383fa8a16d69190 (patch)
treec625a68427fc98325d055b2c49e2d6ee7dd4fe4e /src/main/java/org/traccar
parent1f0965d02081d0257a969927ba58de5b39e051bd (diff)
downloadtrackermap-server-e91402cddad8763658572eb8e383fa8a16d69190.tar.gz
trackermap-server-e91402cddad8763658572eb8e383fa8a16d69190.tar.bz2
trackermap-server-e91402cddad8763658572eb8e383fa8a16d69190.zip
Update Xexun2 Encoder
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java6
-rw-r--r--src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java24
2 files changed, 16 insertions, 14 deletions
diff --git a/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java
index bdeb0fa78..3c81ec27f 100644
--- a/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Xexun2ProtocolDecoder.java
@@ -100,12 +100,14 @@ public class Xexun2ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
+ if (type != MSG_COMMAND) {
+ sendResponse(channel, type, index, imei);
+ }
+
buf.readUnsignedShort(); // attributes
buf.readUnsignedShort(); // checksum
if (type == MSG_POSITION) {
- sendResponse(channel, type, index, imei);
-
List<Integer> lengths = new ArrayList<>();
List<Position> positions = new ArrayList<>();
diff --git a/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java b/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
index 287364cf2..c31d6e747 100644
--- a/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/Xexun2ProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2022 Stefan Clark (stefan@stefanclark.co.uk)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,15 +22,15 @@ import org.traccar.helper.DataConverter;
import org.traccar.model.Command;
import org.traccar.Protocol;
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
-
public class Xexun2ProtocolEncoder extends BaseProtocolEncoder {
public Xexun2ProtocolEncoder(Protocol protocol) {
super(protocol);
}
+ public static final int FLAG = 0xfaaf;
+ public static final int MSG_COMMAND = 0x07;
+
private static ByteBuf encodeFrame(ByteBuf buf) {
int bufLength = buf.readableBytes();
if (bufLength < 5) {
@@ -62,8 +62,7 @@ public class Xexun2ProtocolEncoder extends BaseProtocolEncoder {
return result;
}
- private static int checksum(byte[] data)
- {
+ private static int checksum(byte[] data) {
int sum = 0;
int len = data.length;
for (int j = 0; len > 1; len--) {
@@ -88,14 +87,14 @@ public class Xexun2ProtocolEncoder extends BaseProtocolEncoder {
byte[] message = content.getBytes();
- buf.writeShort(0xFAAF);
- buf.writeShort(0x0007);
- buf.writeShort(0x0001);
- buf.writeBytes(DataConverter.parseHex(uniqueId + "0"),0,8);
+ 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.writeBytes(message);
- buf.writeShort(0xFAAF);
+ buf.writeShort(FLAG);
return encodeFrame(buf);
}
@@ -108,7 +107,8 @@ public class Xexun2ProtocolEncoder extends BaseProtocolEncoder {
case Command.TYPE_CUSTOM:
return encodeContent(uniqueId, command.getString(Command.KEY_DATA));
case Command.TYPE_POSITION_PERIODIC:
- return encodeContent(uniqueId, String.format("tracking_send=%1$d,%1$d", command.getInteger(Command.KEY_FREQUENCY)));
+ return encodeContent(uniqueId,
+ String.format("tracking_send=%1$d,%1$d", command.getInteger(Command.KEY_FREQUENCY)));
case Command.TYPE_POWER_OFF:
return encodeContent(uniqueId, "of=1");
case Command.TYPE_REBOOT_DEVICE: