aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorseym45 <seym45@gmail.com>2023-07-27 02:19:03 +0400
committerseym45 <seym45@gmail.com>2023-07-27 02:55:53 +0400
commitfb4db390187fbfcf1220dc05fa03565799a829e8 (patch)
tree651a3d4a1e5a0687fa19e6153e6660d634747b59 /src/main/java/org
parent18c1e761fd203c994445ac85e808ca6f672d0ec5 (diff)
downloadtrackermap-server-fb4db390187fbfcf1220dc05fa03565799a829e8.tar.gz
trackermap-server-fb4db390187fbfcf1220dc05fa03565799a829e8.tar.bz2
trackermap-server-fb4db390187fbfcf1220dc05fa03565799a829e8.zip
Simplify encodeId method for Gator Protocol
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/protocol/GatorProtocolEncoder.java28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java
index f2c522067..3d38b7455 100644
--- a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java
@@ -22,43 +22,33 @@ import org.traccar.Protocol;
import org.traccar.helper.Checksum;
import org.traccar.model.Command;
-import java.util.ArrayList;
-import java.util.List;
-
public class GatorProtocolEncoder extends BaseProtocolEncoder {
public GatorProtocolEncoder(Protocol protocol) {
super(protocol);
}
- public static ByteBuf encodeId(long deviceId) {
+ public ByteBuf encodeId(long deviceId) {
ByteBuf buf = Unpooled.buffer();
- String deviceIdStrVal = String.valueOf(deviceId);
- List<String> partialDigits = new ArrayList<>();
- for (int i = 1; i < deviceIdStrVal.length(); i += 2) {
- partialDigits.add(deviceIdStrVal.substring(i, i + 2));
- }
-
- int firstDigit = Integer.parseInt(partialDigits.get(0)) - 30;
+ String id = getUniqueId(deviceId);
- for (int i = 1; i < partialDigits.size(); i++) {
- int shiftCount = 4 - i;
- int addend = ((firstDigit & (1 << shiftCount)) >> shiftCount) << 7;
- int sum = Integer.parseInt(partialDigits.get(i)) | addend;
+ int firstDigit = Integer.parseInt(id.substring(1, 3)) - 30;
- buf.writeByte(sum);
- }
+ buf.writeByte(Integer.parseInt(id.substring(3, 5)) | (((firstDigit >> 3) & 1) << 7));
+ buf.writeByte(Integer.parseInt(id.substring(5, 7)) | (((firstDigit >> 2) & 1) << 7));
+ buf.writeByte(Integer.parseInt(id.substring(7, 9)) | (((firstDigit >> 1) & 1) << 7));
+ buf.writeByte(Integer.parseInt(id.substring(9)) | ((firstDigit & 1) << 7));
return buf;
}
- private ByteBuf encodeContent(long deviceId, int mainOrder) {
+ private ByteBuf encodeContent(long deviceId, int type) {
ByteBuf buf = Unpooled.buffer();
buf.writeByte(0x24);
buf.writeByte(0x24);
- buf.writeByte(mainOrder);
+ buf.writeByte(type);
buf.writeByte(0x00);
buf.writeByte(4 + 1 + 1); // ip 4 bytes, checksum and end byte