diff options
-rw-r--r-- | src/org/traccar/protocol/H02ProtocolDecoder.java | 21 | ||||
-rw-r--r-- | test/org/traccar/protocol/H02ProtocolDecoderTest.java | 3 |
2 files changed, 16 insertions, 8 deletions
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java index b9b979c7d..aa3d47650 100644 --- a/src/org/traccar/protocol/H02ProtocolDecoder.java +++ b/src/org/traccar/protocol/H02ProtocolDecoder.java @@ -377,14 +377,19 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder { case "*": String sentence = buf.toString(StandardCharsets.US_ASCII); int typeStart = sentence.indexOf(',', sentence.indexOf(',') + 1) + 1; - String type = sentence.substring(typeStart, sentence.indexOf(',', typeStart)); - switch (type) { - case "NBR": - return decodeLbs(sentence, channel, remoteAddress); - case "LINK": - return decodeLink(sentence, channel, remoteAddress); - default: - return decodeText(sentence, channel, remoteAddress); + int typeEnd = sentence.indexOf(',', typeStart); + if (typeEnd > 0) { + String type = sentence.substring(typeStart, typeEnd); + switch (type) { + case "NBR": + return decodeLbs(sentence, channel, remoteAddress); + case "LINK": + return decodeLink(sentence, channel, remoteAddress); + default: + return decodeText(sentence, channel, remoteAddress); + } + } else { + return null; } case "$": return decodeBinary(buf, channel, remoteAddress); diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java index f1bc069c2..bd4de3363 100644 --- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class H02ProtocolDecoderTest extends ProtocolTest { H02ProtocolDecoder decoder = new H02ProtocolDecoder(new H02Protocol()); + verifyNull(decoder, buffer( + "*HQ,4109198974,#")); + verifyAttributes(decoder, buffer( "*HQ,1700086468,LINK,180902,15,0,84,0,0,240517,FFFFFBFF#")); |