diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2021-06-24 11:32:20 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-24 11:32:20 -0700 |
commit | cd2f5a5a65e9f5068995831277c37b45df2a20f4 (patch) | |
tree | 0d79883b808dd2705acb31310638f5cb424083fb /src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java | |
parent | 229a96994136ad468264f8a084748c4fc17d35f1 (diff) | |
parent | a7aca62f89a69711ff489dbd7753be005e968aec (diff) | |
download | trackermap-server-cd2f5a5a65e9f5068995831277c37b45df2a20f4.tar.gz trackermap-server-cd2f5a5a65e9f5068995831277c37b45df2a20f4.tar.bz2 trackermap-server-cd2f5a5a65e9f5068995831277c37b45df2a20f4.zip |
Merge pull request #4706 from Elsensee/megastek-fixes
Improve compatibility with megastek devices
Diffstat (limited to 'src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java')
-rw-r--r-- | src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java | 33 |
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..e63dd3b32 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 (endIndex < 0) { + 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)) { |