From 81d4920ba7e45d762f7e276195b9b085e88249a4 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 20 Feb 2019 22:29:15 -0800 Subject: Decode additional data --- src/org/traccar/protocol/HuabaoProtocolDecoder.java | 21 +++++++++++++++++++-- .../traccar/protocol/HuabaoProtocolDecoderTest.java | 3 +++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/org/traccar/protocol/HuabaoProtocolDecoder.java index 2eb75a710..f5e73c1f9 100644 --- a/src/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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. @@ -193,7 +193,24 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { .setSecond(BcdUtil.readInteger(buf, 2)); position.setTime(dateBuilder.getDate()); - // additional information + while (buf.readableBytes() > 2) { + int subtype = buf.readUnsignedByte(); + int length = buf.readUnsignedByte(); + switch (subtype) { + case 0x01: + position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100); + break; + case 0x30: + position.set(Position.KEY_RSSI, buf.readUnsignedByte()); + break; + case 0x31: + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + break; + default: + buf.skipBytes(length); + break; + } + } return position; } diff --git a/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java b/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java index 8f8b5fe24..d4ae3b50c 100644 --- a/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/HuabaoProtocolDecoderTest.java @@ -13,6 +13,9 @@ public class HuabaoProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "7E01000021013345678906000F002C012F373031313142534A2D4D3742203030303030303001D4C1423838383838B47E")); + verifyPosition(decoder, binary( + "7e020000400303000002280042000000000000000301618ab406c31ec800000000000518092116145701040000047830011031010aeb16000c00b28986011780108622216500060089ffffffffc37e")); + verifyPosition(decoder, binary( "7E0200002A013833501744001900000000000000C201597FA806CC01580080000000081508180721210104000002F502020000030200009F7E")); -- cgit v1.2.3