diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2021-07-03 16:27:59 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2021-07-03 16:27:59 -0700 |
commit | 827a781e49c74e6573a407119fd5519050b091e3 (patch) | |
tree | 4766e470972a836b51fdca0606216df4938422f5 | |
parent | 841612ab1112dddfb1f3cb23e879381cce32de61 (diff) | |
download | traccar-server-827a781e49c74e6573a407119fd5519050b091e3.tar.gz traccar-server-827a781e49c74e6573a407119fd5519050b091e3.tar.bz2 traccar-server-827a781e49c74e6573a407119fd5519050b091e3.zip |
Support iStartek PT60 format
-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( |