aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/helper/Checksum.java9
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolDecoder.java12
2 files changed, 11 insertions, 10 deletions
diff --git a/src/org/traccar/helper/Checksum.java b/src/org/traccar/helper/Checksum.java
index 2a4b1191d..dde174545 100644
--- a/src/org/traccar/helper/Checksum.java
+++ b/src/org/traccar/helper/Checksum.java
@@ -194,6 +194,15 @@ public final class Checksum {
return checksum;
}
+ public static int xor(String string) {
+ byte[] bytes = string.getBytes(StandardCharsets.US_ASCII);
+ byte sum = 0;
+ for (byte b : bytes) {
+ sum ^= b;
+ }
+ return sum;
+ }
+
public static String nmea(String msg) {
int checksum = 0;
for (byte b : msg.getBytes(StandardCharsets.US_ASCII)) {
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
index 827d6fbb5..de4510d17 100644
--- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -21,6 +21,7 @@ import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.BcdUtil;
+import org.traccar.helper.Checksum;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
@@ -267,7 +268,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
case "U02":
case "U03":
int checkSum = parser.nextInt(16);
- int calculatedCheckSum = checkSum(sentence.substring(1, sentence.length() - 3));
+ int calculatedCheckSum = Checksum.xor(sentence.substring(1, sentence.length() - 3));
if (checkSum == calculatedCheckSum) {
sendResponse(channel, "(S39)");
return position;
@@ -303,15 +304,6 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- private byte checkSum(String sentence) {
- byte[] bytes = sentence.getBytes(StandardCharsets.US_ASCII);
- byte sum = 0;
- for (byte b : bytes) {
- sum ^= b;
- }
- return sum;
- }
-
private void sendResponse(Channel channel, String response) {
if (channel != null) {
channel.write(ChannelBuffers.copiedBuffer(response, StandardCharsets.US_ASCII));