From 961015781071a240c2e4f9c7c5a33a4bfaafd168 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 27 May 2019 17:55:01 -0700 Subject: Skip keep alive message --- .../traccar/protocol/TeltonikaFrameDecoder.java | 8 +++++--- .../protocol/TeltonikaFrameDecoderTest.java | 23 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/test/java/org/traccar/protocol/TeltonikaFrameDecoderTest.java (limited to 'src') diff --git a/src/main/java/org/traccar/protocol/TeltonikaFrameDecoder.java b/src/main/java/org/traccar/protocol/TeltonikaFrameDecoder.java index 4d4d79d8d..c30fee6e3 100644 --- a/src/main/java/org/traccar/protocol/TeltonikaFrameDecoder.java +++ b/src/main/java/org/traccar/protocol/TeltonikaFrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 2019 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. @@ -29,12 +29,14 @@ public class TeltonikaFrameDecoder extends BaseFrameDecoder { protected Object decode( ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { - // Check minimum length + while (buf.isReadable() && buf.getByte(buf.readerIndex()) == (byte) 0xff) { + buf.skipBytes(1); + } + if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) { return null; } - // Read packet int length = buf.getUnsignedShort(buf.readerIndex()); if (length > 0) { if (buf.readableBytes() >= (length + 2)) { diff --git a/src/test/java/org/traccar/protocol/TeltonikaFrameDecoderTest.java b/src/test/java/org/traccar/protocol/TeltonikaFrameDecoderTest.java new file mode 100644 index 000000000..8d2e70bd4 --- /dev/null +++ b/src/test/java/org/traccar/protocol/TeltonikaFrameDecoderTest.java @@ -0,0 +1,23 @@ +package org.traccar.protocol; + +import org.junit.Test; +import org.traccar.ProtocolTest; + +public class TeltonikaFrameDecoderTest extends ProtocolTest { + + @Test + public void testDecode() throws Exception { + + TeltonikaFrameDecoder decoder = new TeltonikaFrameDecoder(); + + verifyFrame( + binary("000F313233343536373839303132333435"), + decoder.decode(null, null, binary("FF000F313233343536373839303132333435"))); + + verifyFrame( + binary("000F313233343536373839303132333435"), + decoder.decode(null, null, binary("000F313233343536373839303132333435"))); + + } + +} -- cgit v1.2.3