Skip to content

Commit

Permalink
Handle short Totem messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Dec 16, 2017
1 parent b3e1a81 commit b0151a4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/org/traccar/protocol/TotemFrameDecoder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013 Anton Tananaev (anton@traccar.org)
* Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,8 +42,7 @@ protected Object decode(

int length;

int separatorIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '|');
if (separatorIndex > 0 && separatorIndex - beginIndex > 19) {
if (buf.getByte(buf.readerIndex() + 2) == (byte) '0') {
length = Integer.parseInt(buf.toString(buf.readerIndex() + 2, 4, StandardCharsets.US_ASCII));
} else {
length = Integer.parseInt(buf.toString(buf.readerIndex() + 2, 2, StandardCharsets.US_ASCII), 16);
Expand Down
4 changes: 4 additions & 0 deletions test/org/traccar/protocol/TotemFrameDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public void testDecode() throws Exception {

TotemFrameDecoder decoder = new TotemFrameDecoder();

verifyFrame(
binary("24243030323542423836323031303033373239343836313345"),
decoder.decode(null, null, binary("24243030323542423836323031303033373239343836313345")));

verifyFrame(
binary("24243030363545363836313137323033353932363639357c3137303931323135333235372c2d37392e3337333835332c34332e3736353631392c302c302c7c3441"),
decoder.decode(null, null, binary("24243030363545363836313137323033353932363639357c3137303931323135333235372c2d37392e3337333835332c34332e3736353631392c302c302c7c3441")));
Expand Down

0 comments on commit b0151a4

Please sign in to comment.