From e193ae4656a6e0555565b35e8c657ae0777b156b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 6 Feb 2020 23:16:11 -0800 Subject: Decode additional data --- .../org/traccar/protocol/BlueProtocolDecoder.java | 30 +++++++++++++++++++++- .../traccar/protocol/BlueProtocolDecoderTest.java | 13 ++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/protocol/BlueProtocolDecoder.java b/src/main/java/org/traccar/protocol/BlueProtocolDecoder.java index 61edcd101..f35ac6fbe 100644 --- a/src/main/java/org/traccar/protocol/BlueProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/BlueProtocolDecoder.java @@ -66,6 +66,19 @@ public class BlueProtocolDecoder extends BaseProtocolDecoder { } } + private String decodeAlarm(int value) { + switch (value) { + case 1: + return Position.ALARM_SOS; + case 8: + return Position.ALARM_OVERSPEED; + case 19: + return Position.ALARM_LOW_POWER; + default: + return null; + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -123,10 +136,25 @@ public class BlueProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // status 2 buf.readUnsignedByte(); // status 3 - buf.readUnsignedByte(); // status 4 + + status = buf.readUnsignedByte(); // status 4 + int ignition = BitUtil.between(status, 2, 4); + if (ignition == 0b01) { + position.set(Position.KEY_IGNITION, false); + } + if (ignition == 0b10) { + position.set(Position.KEY_IGNITION, true); + } + buf.readUnsignedByte(); // status 5 buf.readUnsignedByte(); // status 6 + position.set(Position.KEY_STATUS, buf.readUnsignedShort()); + + } else if (type == 0x81) { + + position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); + } else if (type == 0x84) { sendResponse(channel, index); diff --git a/src/test/java/org/traccar/protocol/BlueProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/BlueProtocolDecoderTest.java index 9f3254824..4aa50e56b 100644 --- a/src/test/java/org/traccar/protocol/BlueProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/BlueProtocolDecoderTest.java @@ -2,6 +2,7 @@ package org.traccar.protocol; import org.junit.Test; import org.traccar.ProtocolTest; +import org.traccar.model.Position; public class BlueProtocolDecoderTest extends ProtocolTest { @@ -10,6 +11,18 @@ public class BlueProtocolDecoderTest extends ProtocolTest { BlueProtocolDecoder decoder = new BlueProtocolDecoder(null); + verifyAttribute(decoder, binary( + "AA0056860080E3E79E0C811F80000114020207170520011F00407F8005EE1938113B270000000000000000140202071705005AC7A621121F0002000100B7000080110000000000001A3A0000000001F400000000000078"), + Position.KEY_ALARM, Position.ALARM_SOS); + + verifyAttribute(decoder, binary( + "AA004A860080E3E79E20015FBE40148005EE193B113B263700000000000000140202080C09005AC7A621125F0002000000BB000000000000000000001A3A0007000001F400000000000008"), + Position.KEY_IGNITION, true); + + verifyAttribute(decoder, binary( + "AA004A860080E3E79E200160BE40148005EE193B113B263700000000000000140202080C13005AC7A62112600002000000B7000000110000000000001A3A0007000001F400000000000012"), + Position.KEY_STATUS, 0x11); + verifyPosition(decoder, binary( "aa00550000813f6f840b840380001032000000002001030040008005ee1938113b26f300000000000000140114082833044d27602112030002000000b70000020000000000000000650000001601f4000000000000e4")); -- cgit v1.2.3