aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorVitaly Litvak <vitavaque@gmail.com>2016-10-01 09:14:33 +0300
committerVitaly Litvak <vitavaque@gmail.com>2016-10-01 09:14:33 +0300
commit69d0cc47d63d9052218a8d87cf436e46165e716c (patch)
tree24f44abee2c380cf48442140542a8bba4a23ff88 /src/org
parent82909a81eb01cfd76f38fec7cccff5a5c87b5232 (diff)
downloadtrackermap-server-69d0cc47d63d9052218a8d87cf436e46165e716c.tar.gz
trackermap-server-69d0cc47d63d9052218a8d87cf436e46165e716c.tar.bz2
trackermap-server-69d0cc47d63d9052218a8d87cf436e46165e716c.zip
For JT600c - added checksum verification and replying for alarms/positions messages
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolDecoder.java75
1 files changed, 55 insertions, 20 deletions
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
index fd2448c0d..0c235a4b5 100644
--- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -201,24 +201,25 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
private static final Pattern PATTERN_U01 = new PatternBuilder()
.text("(")
- .number("(d+),") // id
- .number("Udd,") // type
- .number("d+,").optional() // alarm
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .number("(dd)(dd)(dd),") // time
- .expression("([TF]),") // validity
- .number("(d+.d+),([NS]),") // latitude
- .number("(d+.d+),([EW]),") // longitude
- .number("(d+.?d*),") // speed
- .number("(d+),") // course
- .number("(d+),") // satellites
- .number("(d+%),") // battery
- .expression("([01]+),") // status
- .number("(d+),") // cid
- .number("(d+),") // lac
- .number("(d+),") // gsm signal
- .number("(d+),") // odometer
- .number("(d+)") // index
+ .number("(d+),") // id
+ .number("(Udd),") // type
+ .number("d+,").optional() // alarm
+ .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .number("(dd)(dd)(dd),") // time
+ .expression("([TF]),") // validity
+ .number("(d+.d+),([NS]),") // latitude
+ .number("(d+.d+),([EW]),") // longitude
+ .number("(d+.?d*),") // speed
+ .number("(d+),") // course
+ .number("(d+),") // satellites
+ .number("(d+%),") // battery
+ .expression("([01]+),") // status
+ .number("(d+),") // cid
+ .number("(d+),") // lac
+ .number("(d+),") // gsm signal
+ .number("(d+),") // odometer
+ .number("(d+),") // serial number
+ .expression("([0-9A-F][0-9A-F])").optional() // checksum
.any()
.compile();
@@ -234,6 +235,8 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
+ String messageType = parser.next();
+
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
@@ -256,11 +259,29 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_CID, parser.nextInt());
position.set(Position.KEY_LAC, parser.nextInt());
position.set(Position.KEY_GSM, parser.nextInt());
- position.set(Position.KEY_ODOMETER, parser.nextLong() * 1000);
+ position.set(Position.KEY_ODOMETER, parser.nextLong() * 100);
position.set(Position.KEY_INDEX, parser.nextInt());
- return position;
+ switch (messageType) {
+ case "U01":
+ case "U02":
+ case "U03":
+ String checkSum = parser.next();
+ int calculatedCheckSum = checkSum(sentence.substring(1, sentence.length() - checkSum.length() - 1));
+ if (Integer.parseInt(checkSum, 16) == calculatedCheckSum) {
+ sendResponse(channel, "(S39)");
+ return position;
+ } else {
+ return null;
+ }
+ case "U06":
+ sendResponse(channel, "(S20)");
+ return position;
+ default:
+ return null;
+ }
}
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -282,4 +303,18 @@ 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));
+ }
+ }
}