diff options
-rw-r--r-- | src/main/java/org/traccar/protocol/StartekProtocolDecoder.java | 18 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/StartekProtocolDecoderTest.java | 2 |
2 files changed, 14 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java b/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java index 1cc69c6e6..68fc511aa 100644 --- a/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java @@ -64,11 +64,17 @@ public class StartekProtocolDecoder extends BaseProtocolDecoder { .number("(x+),") // inputs .number("(x+),") // outputs .number("(x+)|") // power - .number("(x+)|") // battery - .expression("([^,]+),") // adc + .number("(x+)") // battery + .groupBegin() + .text("|") + .expression("([^,]+)").optional() // adc + .groupBegin() + .text(",") .number("d,") // extended .expression("([^,]+)?,") // fuel .expression("([^,]+)?") // temperature + .groupEnd("?") + .groupEnd("?") .number("xx") // checksum .compile(); @@ -138,9 +144,11 @@ public class StartekProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_POWER, parser.nextHexInt() * 0.01); position.set(Position.KEY_BATTERY, parser.nextHexInt() * 0.01); - String[] adc = parser.next().split("\\|"); - for (int i = 0; i < adc.length; i++) { - position.set(Position.PREFIX_ADC + (i + 1), Integer.parseInt(adc[i], 16) * 0.01); + if (parser.hasNext()) { + String[] adc = parser.next().split("\\|"); + for (int i = 0; i < adc.length; i++) { + position.set(Position.PREFIX_ADC + (i + 1), Integer.parseInt(adc[i], 16) * 0.01); + } } if (parser.hasNext()) { diff --git a/src/test/java/org/traccar/protocol/StartekProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/StartekProtocolDecoderTest.java index b4c3cd285..81f2f8f69 100644 --- a/src/test/java/org/traccar/protocol/StartekProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/StartekProtocolDecoderTest.java @@ -11,7 +11,7 @@ public class StartekProtocolDecoderTest extends ProtocolTest { var decoder = new StartekProtocolDecoder(null); - verifyNull(decoder, text( + verifyPosition(decoder, text( "&&o125,861157040554384,000,0,,210702235150,A,27.263505,153.037061,11,1.2,0,0,31,5125,505|1|7032|8C89802,20,0000002D,00,00,01E2|019DF0")); verifyAttribute(decoder, text( |