aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorseym45 <seym45@gmail.com>2023-07-24 20:15:47 +0400
committerseym45 <seym45@gmail.com>2023-07-24 20:52:46 +0400
commit1ee9e9396d7274f057f5e6d2d69e72ec1a5c0135 (patch)
tree7383334559adc484a546713bcc51a843f985e8a9 /src/main/java
parent6cb4db1f6bb4f93ad42b013a38ace9a6a3b735f6 (diff)
downloadtrackermap-server-1ee9e9396d7274f057f5e6d2d69e72ec1a5c0135.tar.gz
trackermap-server-1ee9e9396d7274f057f5e6d2d69e72ec1a5c0135.tar.bz2
trackermap-server-1ee9e9396d7274f057f5e6d2d69e72ec1a5c0135.zip
Add method to encodeId
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/protocol/GatorProtocolEncoder.java36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java
index 452fde275..df85a712c 100644
--- a/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java
+++ b/src/main/java/org/traccar/protocol/GatorProtocolEncoder.java
@@ -21,6 +21,7 @@ import org.traccar.BaseProtocolEncoder;
import org.traccar.Protocol;
import org.traccar.config.Keys;
import org.traccar.helper.Checksum;
+import org.traccar.helper.DataConverter;
import org.traccar.helper.model.AttributeUtil;
import org.traccar.model.Command;
import org.traccar.model.Device;
@@ -33,9 +34,38 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder {
super(protocol);
}
- private ByteBuf encodeContent(long deviceId, String content) {
+
+ public static String encodeId(long deviceId) {
+ StringBuilder encodedId = new StringBuilder();
+
+ String imei = String.valueOf(deviceId);
+ String a = imei.substring(1, 3);
+ String b = imei.substring(3, 5);
+ String c = imei.substring(5, 7);
+ String d = imei.substring(7, 9);
+ String e = imei.substring(9);
+ String[] arr = {b, c, d, e};
+
+ String binaryFirstDigit = Integer.toBinaryString(Integer.valueOf(a) - 30);
+ binaryFirstDigit = String.format("%4s", binaryFirstDigit).replace(' ', '0');
+
+ for (int i = 0; i < 4; i++) {
+ int sum = Integer.parseInt(arr[i]) + Integer.parseInt(String.valueOf(binaryFirstDigit.charAt(i)) + "0000000", 2);
+ arr[i] = Integer.toHexString(sum).toUpperCase();
+ arr[i] = String.format("%2s", arr[i]).replace(' ', '0');
+ }
+
+ for (String s : arr) {
+ encodedId.append(s);
+ }
+
+ return encodedId.toString();
+ }
+
+
+ private ByteBuf encodeContent(long deviceId, String mainOrder, String content) {
// FIXME: implement this method
- return null;
+ return null;
}
@Override
@@ -43,7 +73,7 @@ public class GatorProtocolEncoder extends BaseProtocolEncoder {
switch (command.getType()) {
case Command.TYPE_ROLLCALL:
- return encodeContent(command.getDeviceId(), "0x30");
+ return encodeContent(command.getDeviceId(), "30", null);
default:
return null;
}