aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-09-23 06:57:16 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2016-09-23 06:57:16 +1200
commite3229237eb37654dbf7818fdf92a6f487a95c770 (patch)
tree65676a60c13689b7adb398bb96811b046e6ad74f
parent22a1aca01ec5feaef59ad2f56eda825a5926e24b (diff)
downloadtrackermap-server-e3229237eb37654dbf7818fdf92a6f487a95c770.tar.gz
trackermap-server-e3229237eb37654dbf7818fdf92a6f487a95c770.tar.bz2
trackermap-server-e3229237eb37654dbf7818fdf92a6f487a95c770.zip
Extend JT600 protocol support
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolDecoder.java90
-rw-r--r--test/org/traccar/protocol/Jt600ProtocolDecoderTest.java38
2 files changed, 106 insertions, 22 deletions
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
index b7193d24b..b30bd7b85 100644
--- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,7 +43,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return degrees + minutes / 60;
}
- private Position decodeNormalMessage(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
+ private Position decodeBinary(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
Position position = new Position();
position.setProtocol(getProtocolName());
@@ -120,7 +120,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private static final Pattern PATTERN = new PatternBuilder()
+ private static final Pattern PATTERN_W01 = new PatternBuilder()
.text("(")
.number("(d+),") // id
.text("W01,") // type
@@ -138,25 +138,22 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // gsm signal
.number("(d+),") // alert type
.any()
- .text(")")
.compile();
- private Position decodeAlertMessage(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
+ private Position decodeW01(String sentence, Channel channel, SocketAddress remoteAddress) {
- Parser parser = new Parser(PATTERN, buf.toString(StandardCharsets.US_ASCII));
+ Parser parser = new Parser(PATTERN_W01, sentence);
if (!parser.matches()) {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
-
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setLongitude(parser.nextCoordinate());
@@ -176,6 +173,68 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ 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
+ .any()
+ .compile();
+
+ private Position decodeU01(String sentence, Channel channel, SocketAddress remoteAddress) {
+
+ Parser parser = new Parser(PATTERN_U01, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ position.setValid(parser.next().equals("T"));
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+
+ position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble()));
+ position.setCourse(parser.nextDouble());
+
+ position.set(Position.KEY_SATELLITES, parser.nextInt());
+ position.set(Position.KEY_BATTERY, parser.next());
+ position.set(Position.KEY_STATUS, parser.nextInt(2));
+ 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_INDEX, parser.nextInt());
+
+ return position;
+ }
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -184,9 +243,14 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
char first = (char) buf.getByte(0);
if (first == '$') {
- return decodeNormalMessage(buf, channel, remoteAddress);
+ return decodeBinary(buf, channel, remoteAddress);
} else if (first == '(') {
- return decodeAlertMessage(buf, channel, remoteAddress);
+ String sentence = buf.toString(StandardCharsets.US_ASCII);
+ if (sentence.contains("W01")) {
+ return decodeW01(sentence, channel, remoteAddress);
+ } else {
+ return decodeU01(sentence, channel, remoteAddress);
+ }
}
return null;
diff --git a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java
index ba39b1846..4bbfb5627 100644
--- a/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Jt600ProtocolDecoderTest.java
@@ -11,15 +11,35 @@ public class Jt600ProtocolDecoderTest extends ProtocolTest {
Jt600ProtocolDecoder decoder = new Jt600ProtocolDecoder(new Jt600Protocol());
+ verifyPosition(decoder, buffer(
+ "(3301210003,U01,040812,185302,T,22.564025,N,113.242329,E,5.21,152,9,32%,00000000000011,10133,5173,22,100,1)"));
+
+ verifyPosition(decoder, buffer(
+ "(3301210003,U02,040812,185302,T,22.564025,N,113.242329,E,5,152,9,32%,00000000000011,10133,5173,22,100,1)"));
+
+ verifyPosition(decoder, buffer(
+ "(3301210003,U03,040812,185302,T,22.564025,N,113.242329,E,5,152,9,32%,00000000000011,10133,5173,22,100,1)"));
+
+ verifyNothing(decoder, buffer(
+ "(3301210003,U04)"));
+
+ verifyPosition(decoder, buffer(
+ "(3301210003,U06,1,040812,185302,T,22.564025,N,113.242329,E,5,152,9,32%,0000000000011,10133,5173,22,100,1,300,100,10)"));
+
+ verifyPosition(decoder, buffer(
+ "(3460311327,U01,220916,135251,T,9.552607,N,13.658292,W,0.31,0,9,0%,00001001000000,11012,10,27,0,0,33)"));
+
+ verifyPosition(decoder, buffer(
+ "(3460311327,U01,010100,000024,F,0.000000,N,0.000000,E,0.00,0,0,100%,00000001000000,263,1,18,0,0,33)"));
+
verifyNothing(decoder, buffer(
"(3460311327,@JT)"));
- /*verifyPosition(decoder, buffer(
- "(3460311327,U01,010100,000024,F,0.000000,N,0.000000,E,0.00,0,0,100%,00000001000000,263,1,18,0,0,33)"));*/
+ verifyPosition(decoder, buffer(
+ "(3460311327,U06,11,220916,135643,T,9.552553,N,13.658265,W,0.61,0,9,100%,00000001000000,11012,10,30,0,0,126,0,30)"));
- //(3460311327,U06,11,220916,135643,T,9.552553,N,13.658265,W,0.61,0,9,100%,00000001000000,11012,10,30,0,0,126,0,30)
- //(3460311327,U06,10,220916,140619,T,9.552495,N,13.658227,W,0.43,0,7,0%,00101001000000,11012,10,0,0,0,126,0,30)
- //(3460311327,U01,220916,135251,T,9.552607,N,13.658292,W,0.31,0,9,0%,00001001000000,11012,10,27,0,0,33)
+ verifyPosition(decoder, buffer(
+ "(3460311327,U06,10,220916,140619,T,9.552495,N,13.658227,W,0.43,0,7,0%,00101001000000,11012,10,0,0,0,126,0,30)"));
verifyPosition(decoder, binary(
"24311021600111001B16021105591022329862114046227B0598095080012327951435161F"),
@@ -41,11 +61,11 @@ public class Jt600ProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, buffer(
"(3120820029,W01,02553.3555,E,2438.0997,S,A,171012,053339,0,8,20,6,31,5,20,20)"));
- /*verifyPosition(decoder, text( ChannelBuffers.copiedBuffer(
- "(3330104377,U01,010100,010228,F,00.000000,N,000.000000,E,0,0,0,0%,00001000000000,741,14,22,0,206)", StandardCharsets.US_ASCII)));
+ verifyPosition(decoder, buffer(
+ "(3330104377,U01,010100,010228,F,00.000000,N,000.000000,E,0,0,0,0%,00001000000000,741,14,22,0,206)"));
- verifyPosition(decoder, text( ChannelBuffers.copiedBuffer(
- "(6221107674,2,U09,129,2,A,280513113036,E,02711.0500,S,1721.0876,A,030613171243,E,02756.7618,S,2300.0325,3491,538200,14400,1)",StandardCharsets.US_ASCII))));*/
+ verifyNothing(decoder, buffer(
+ "(6221107674,2,U09,129,2,A,280513113036,E,02711.0500,S,1721.0876,A,030613171243,E,02756.7618,S,2300.0325,3491,538200,14400,1)"));
}