aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java
diff options
context:
space:
mode:
authorOliver Schramm <oliver.schramm97@gmail.com>2021-06-24 19:39:18 +0200
committerOliver Schramm <oliver.schramm97@gmail.com>2021-06-24 19:39:18 +0200
commitc10c4b985002d9b39213f6a4e33466212705f66d (patch)
tree14a9c21c2c5674a8cd0c5d89cfc2e6d1c6614aed /src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java
parent48670633fd49e3ec2bd781f858b11ccd2083878d (diff)
downloadtraccar-server-c10c4b985002d9b39213f6a4e33466212705f66d.tar.gz
traccar-server-c10c4b985002d9b39213f6a4e33466212705f66d.tar.bz2
traccar-server-c10c4b985002d9b39213f6a4e33466212705f66d.zip
Improve compatibility with megastek devices
Megastek devices send some data which either is not fully compliant with the megastek protocol (by omitting some data) or which is (for our purposes) garbage data, which is only delimited with a single LF (0x0A).
Diffstat (limited to 'src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java
index f0c0df8a6..2ce5b9dae 100644
--- a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java
@@ -141,6 +141,9 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
beginIndex = endIndex + 2;
endIndex = sentence.indexOf('*', beginIndex) + 3;
+ if (beginIndex > endIndex) {
+ return null;
+ }
location = sentence.substring(beginIndex, endIndex);
beginIndex = endIndex + 1;
@@ -243,13 +246,13 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
.number("dd,")
.number("(dd),") // satellites
.number("dd,")
- .number("(d+.d+),") // hdop
+ .number("(d+.d+)?,") // hdop
.number("(d+.d+)?,") // speed
.number("(d+.d+)?,") // course
.number("(-?d+.d+)?,") // altitude
.number("(d+.d+)?,") // odometer
- .number("(d+),") // mcc
- .number("(d+),") // mnc
+ .number("(d+)?,") // mcc
+ .number("(d+)?,") // mnc
.number("(xxxx)?,") // lac
.number("(x+)?,") // cid
.number("(d+)?,") // gsm
@@ -276,7 +279,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
.groupEnd("?").text(",")
.number("(d+)?,") // rfid
.number("([01])(d)?").optional() // charge and belt status
- .expression("[^,]*,").optional()
+ .expression("[^,]*,")
.number("(d+)?,") // battery
.expression("([^,]*)[,;]") // alert
.any()
@@ -318,17 +321,19 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
}
- int mcc = parser.nextInt();
- int mnc = parser.nextInt();
- Integer lac = parser.nextHexInt();
- Integer cid = parser.nextHexInt();
- Integer rssi = parser.nextInt();
- if (lac != null && cid != null) {
- CellTower tower = CellTower.from(mcc, mnc, lac, cid);
- if (rssi != null) {
- tower.setSignalStrength(rssi);
+ if (parser.hasNext(5)) {
+ int mcc = parser.nextInt();
+ int mnc = parser.nextInt();
+ Integer lac = parser.nextHexInt();
+ Integer cid = parser.nextHexInt();
+ Integer rssi = parser.nextInt();
+ if (lac != null && cid != null) {
+ CellTower tower = CellTower.from(mcc, mnc, lac, cid);
+ if (rssi != null) {
+ tower.setSignalStrength(rssi);
+ }
+ position.setNetwork(new Network(tower));
}
- position.setNetwork(new Network(tower));
}
if (parser.hasNext(5)) {