aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-10-02 20:48:20 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-10-02 20:48:20 +1300
commitc74cded271c4e16c6fe122692de6b253b244d211 (patch)
tree6393ec7df30ed8723c4c12345d4bf426a23f7564 /src/org
parent8862d4f45712f6bee956c27380800d89105034e8 (diff)
downloadtrackermap-server-c74cded271c4e16c6fe122692de6b253b244d211.tar.gz
trackermap-server-c74cded271c4e16c6fe122692de6b253b244d211.tar.bz2
trackermap-server-c74cded271c4e16c6fe122692de6b253b244d211.zip
Fix some issues in JT600 decoder
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/helper/Checksum.java9
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolDecoder.java43
2 files changed, 15 insertions, 37 deletions
diff --git a/src/org/traccar/helper/Checksum.java b/src/org/traccar/helper/Checksum.java
index dde174545..815962be0 100644
--- a/src/org/traccar/helper/Checksum.java
+++ b/src/org/traccar/helper/Checksum.java
@@ -195,12 +195,11 @@ public final class Checksum {
}
public static int xor(String string) {
- byte[] bytes = string.getBytes(StandardCharsets.US_ASCII);
- byte sum = 0;
- for (byte b : bytes) {
- sum ^= b;
+ byte checksum = 0;
+ for (byte b : string.getBytes(StandardCharsets.US_ASCII)) {
+ checksum ^= b;
}
- return sum;
+ return checksum;
}
public static String nmea(String msg) {
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
index 6d066299a..e42ae5e09 100644
--- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -21,7 +21,6 @@ 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;
@@ -219,8 +218,8 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // lac
.number("(d+),") // gsm signal
.number("(d+),") // odometer
- .number("(d+),?") // serial number
- .number("(xx)").optional() // checksum
+ .number("(d+)") // serial number
+ .number(",(xx)").optional() // checksum
.any()
.compile();
@@ -236,7 +235,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- String messageType = parser.next();
+ String type = parser.next();
Position position = new Position();
position.setProtocol(getProtocolName());
@@ -263,30 +262,15 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_ODOMETER, parser.nextLong() * 1000);
position.set(Position.KEY_INDEX, parser.nextInt());
- switch (messageType) {
- case "U01":
- case "U02":
- case "U03":
- // support protocol with check sum
- if (parser.hasNext(2)) {
- int checkSum = parser.nextInt(16);
- int calculatedCheckSum = Checksum.xor(sentence.substring(1, sentence.length() - 3));
- if (checkSum == calculatedCheckSum) {
- sendResponse(channel, "(S39)");
- return position;
- } else {
- return null;
- }
- // support protocol without check sum
- } else {
- return position;
- }
- case "U06":
- sendResponse(channel, "(S20)");
- return position;
- default:
- return null;
+ if (channel != null) {
+ if (type.equals("U01") || type.equals("U02") || type.equals("U03")) {
+ channel.write("(S39)");
+ } else if (type.equals("U06")) {
+ channel.write("(S20)");
+ }
}
+
+ return position;
}
@Override
@@ -310,9 +294,4 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- private void sendResponse(Channel channel, String response) {
- if (channel != null) {
- channel.write(ChannelBuffers.copiedBuffer(response, StandardCharsets.US_ASCII));
- }
- }
}