aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java60
-rw-r--r--src/test/java/org/traccar/protocol/Jt600ProtocolDecoderTest.java3
2 files changed, 63 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java
index dc4bd3486..b4b70091b 100644
--- a/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -374,6 +374,64 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private static final Pattern PATTERN_P45 = new PatternBuilder()
+ .text("(")
+ .number("(d+),") // id
+ .text("P45,") // type
+ .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .number("(dd)(dd)(dd),") // time (hhmmss)
+ .number("(d+.d+),([NS]),") // latitude
+ .number("(d+.d+),([EW]),") // longitude
+ .expression("([AV]),") // validity
+ .number("(d+),") // speed
+ .number("(d+),") // course
+ .number("d+,") // event source
+ .number("d+,") // unlock verification
+ .number("(d+),") // rfid
+ .number("d+,") // password verification
+ .number("d+,") // incorrect password count
+ .number("(d+),") // index
+ .any()
+ .compile();
+
+ private Position decodeP45(String sentence, Channel channel, SocketAddress remoteAddress) {
+
+ Parser parser = new Parser(PATTERN_P45, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
+
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setValid(parser.next().equals("A"));
+
+ position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble()));
+ position.setCourse(parser.nextDouble());
+
+ String rfid = parser.next();
+ if (!rfid.equals("0000000000")) {
+ position.set(Position.KEY_DRIVER_UNIQUE_ID, rfid);
+ }
+
+ int index = parser.nextInt();
+
+ if (channel != null) {
+ channel.writeAndFlush(new NetworkMessage("(P69,0," + index + ")", remoteAddress));
+ }
+
+ return position;
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -387,6 +445,8 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
String sentence = buf.toString(StandardCharsets.US_ASCII);
if (sentence.contains("W01")) {
return decodeW01(sentence, channel, remoteAddress);
+ } else if (sentence.contains("P45")) {
+ return decodeP45(sentence, channel, remoteAddress);
} else {
return decodeU01(sentence, channel, remoteAddress);
}
diff --git a/src/test/java/org/traccar/protocol/Jt600ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Jt600ProtocolDecoderTest.java
index 3c681ec58..3bf01c1ae 100644
--- a/src/test/java/org/traccar/protocol/Jt600ProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/Jt600ProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class Jt600ProtocolDecoderTest extends ProtocolTest {
var decoder = new Jt600ProtocolDecoder(null);
+ verifyPosition(decoder, buffer(
+ "(8000632862,P45,290322,132412,25.28217,S,57.54683,W,A,0,0,5,0,0000000000,0,0,9,0)"));
+
verifyPositions(decoder, binary(
"2480413009781914003406102107544354193631006213423b00000000006c070000000020e064f91ea0671d00020f0f0f0f0f0f0f0f0f0f07f100ea0f6e"));