aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/protocol/PortmanProtocolDecoder.java83
1 files changed, 76 insertions, 7 deletions
diff --git a/src/main/java/org/traccar/protocol/PortmanProtocolDecoder.java b/src/main/java/org/traccar/protocol/PortmanProtocolDecoder.java
index 7d734c9b1..ebb93abd6 100644
--- a/src/main/java/org/traccar/protocol/PortmanProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/PortmanProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2020 - 2021 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,9 +33,9 @@ public class PortmanProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private static final Pattern PATTERN = new PatternBuilder()
+ private static final Pattern PATTERN_STANDARD = new PatternBuilder()
.text("$PTMLA,") // header
- .number("(d+),") // imei
+ .expression("([^,]+),") // id
.expression("([ABCL]),") // validity
.number("(dd)(dd)(dd)") // date (yymmdd)
.number("(dd)(dd)(dd),") // time (hhmmss)
@@ -55,11 +55,9 @@ public class PortmanProtocolDecoder extends BaseProtocolDecoder {
.number("(?:G(d+)|[^,]*)") // fuel
.compile();
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+ private Object decodeStandard(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN, (String) msg);
+ Parser parser = new Parser(PATTERN_STANDARD, sentence);
if (!parser.matches()) {
return null;
}
@@ -91,4 +89,75 @@ public class PortmanProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private static final Pattern PATTERN_EXTENDED = new PatternBuilder()
+ .text("$EXT,") // header
+ .expression("([^,]+),") // id
+ .expression("([ABCL]),") // validity
+ .number("(dd)(dd)(dd)") // date (yymmdd)
+ .number("(dd)(dd)(dd),") // time (hhmmss)
+ .expression("([NS])")
+ .number("(dd)(dd.d+)") // latitude
+ .expression("([EW])")
+ .number("(d{2,3})(dd.d+),") // longitude
+ .number("(d+),") // speed
+ .number("(d+),") // course
+ .number("(?:NA|C(-?d+)),") // temperature
+ .number("(?:NA|F(d+)),") // fuel
+ .number("(d+),") // satellites
+ .number("(d+),") // rssi
+ .number("(d+.d+),") // odometer
+ .number("(?:NA|(d+)),") // card id
+ .number("(x{8}),") // status
+ .number("(d+)") // event
+ .any()
+ .compile();
+
+ private Object decodeExtended(Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN_EXTENDED, 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.setValid(!parser.next().equals("L"));
+ position.setTime(parser.nextDateTime());
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));
+ position.setCourse(parser.nextInt());
+
+ position.set(Position.PREFIX_TEMP + 1, parser.next());
+ position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
+ position.set(Position.KEY_SATELLITES, parser.nextInt());
+ position.set(Position.KEY_RSSI, parser.nextInt());
+ position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
+ position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
+ position.set(Position.KEY_STATUS, parser.nextHexLong());
+ position.set(Position.KEY_EVENT, parser.nextInt());
+
+ return position;
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ String sentence = (String) msg;
+ if (sentence.startsWith("$PTMLA")) {
+ return decodeStandard(channel, remoteAddress, sentence);
+ } else if (sentence.startsWith("$EXT")) {
+ return decodeExtended(channel, remoteAddress, sentence);
+ } else {
+ return null;
+ }
+ }
+
}