aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java10
-rw-r--r--src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java2
2 files changed, 9 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java
index c16a0752d..f8aaeb996 100644
--- a/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/MegastekProtocolDecoder.java
@@ -257,6 +257,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
.number("(x+)?,") // cid
.number("(d+)?,") // gsm
.groupBegin()
+ .number("(ddd),").optional() // heart rate
.number("([01]{4})?,") // input
.number("([01]{4})?,") // output
.number("(d+)?,") // adc1
@@ -277,11 +278,13 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
.number("(-?d+.?d*)") // temperature 2
.or().text(" ")
.groupEnd("?").text(",")
+ .groupBegin()
.number("(d+)?,") // rfid
.number("([01])(d)?").optional() // charge and belt status
.expression("[^,]*,")
.number("(d+)?,") // battery
.expression("([^,]*)[,;]") // alert
+ .groupEnd("?")
.any()
.compile();
@@ -336,7 +339,8 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
}
}
- if (parser.hasNext(5)) {
+ if (parser.hasNext(6)) {
+ position.set(Position.KEY_HEART_RATE, parser.nextInt());
position.set(Position.KEY_INPUT, parser.nextBinInt(0));
position.set(Position.KEY_OUTPUT, parser.nextBinInt(0));
for (int i = 1; i <= 3; i++) {
@@ -373,7 +377,9 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_BATTERY, Integer.parseInt(battery));
}
- position.set(Position.KEY_ALARM, decodeAlarm(parser.next()));
+ if (parser.hasNext()) {
+ position.set(Position.KEY_ALARM, decodeAlarm(parser.next()));
+ }
return position;
}
diff --git a/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java
index bdfe712c5..d64ec833b 100644
--- a/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/MegastekProtocolDecoderTest.java
@@ -11,7 +11,7 @@ public class MegastekProtocolDecoderTest extends ProtocolTest {
var decoder = inject(new MegastekProtocolDecoder(null));
- verifyNull(decoder, text(
+ verifyPosition(decoder, text(
"0226$MGV002,860537065044539,,S,020824,120719,V,5339.11529,N,01011.15575,E,00,00,00,99.9,3.255,,52.1,,262,01,FFFE,277A602,14,000,0000,0000,0,,,,,01000,078,Timer,dc15c8984804:65|50e63698d1d5:70|44053fdacd6e:73|e0516314f2a7:88,,0,,;!"));
verifyPosition(decoder, text(