diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java | 94 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/AtrackProtocolDecoderTest.java | 3 |
2 files changed, 96 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java index ff7ef6c4a..9300acf60 100644 --- a/src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/AtrackProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2020 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 2021 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. @@ -16,6 +16,7 @@ package org.traccar.protocol; import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; @@ -24,6 +25,8 @@ import org.traccar.DeviceSession; import org.traccar.NetworkMessage; import org.traccar.Protocol; import org.traccar.config.Keys; +import org.traccar.helper.BitUtil; +import org.traccar.helper.DataConverter; import org.traccar.helper.DateBuilder; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; @@ -115,6 +118,89 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { return result; } + private void decodeBeaconData(Position position, int mode, int mask, ByteBuf data) { + int i = 1; + while (data.isReadable()) { + if (BitUtil.check(mask, 7)) { + position.set("tag" + i + "Id", ByteBufUtil.hexDump(data.readSlice(6))); + } + switch (mode) { + case 1: + if (BitUtil.check(mask, 6)) { + data.readUnsignedShort(); // major + } + if (BitUtil.check(mask, 5)) { + data.readUnsignedShort(); // minor + } + if (BitUtil.check(mask, 4)) { + data.readUnsignedByte(); // tx power + } + if (BitUtil.check(mask, 3)) { + position.set("tag" + i + "Rssi", data.readUnsignedByte()); + } + break; + case 2: + if (BitUtil.check(mask, 6)) { + data.readUnsignedShort(); // battery voltage + } + if (BitUtil.check(mask, 5)) { + position.set("tag" + i + "Temp", data.readUnsignedShort()); + } + if (BitUtil.check(mask, 4)) { + data.readUnsignedByte(); // tx power + } + if (BitUtil.check(mask, 3)) { + position.set("tag" + i + "Rssi", data.readUnsignedByte()); + } + break; + case 3: + if (BitUtil.check(mask, 6)) { + data.readUnsignedShort(); + } + if (BitUtil.check(mask, 5)) { + data.readUnsignedShort(); + } + if (BitUtil.check(mask, 3)) { + position.set("tag" + i + "Rssi", data.readUnsignedByte()); + } + if (BitUtil.check(mask, 2)) { + data.readUnsignedShort(); + } + break; + case 4: + if (BitUtil.check(mask, 6)) { + int hardwareId = data.readUnsignedByte(); + if (BitUtil.check(mask, 5)) { + switch (hardwareId) { + case 1: + case 4: + data.skipBytes(11); // fuel + break; + case 2: + data.skipBytes(2); // temperature + break; + case 3: + data.skipBytes(6); // temperature and luminosity + break; + case 5: + data.skipBytes(10); // temperature, humidity, luminosity and pressure + break; + default: + break; + } + } + } + if (BitUtil.check(mask, 4)) { + data.skipBytes(9); // name + } + break; + default: + break; + } + i += 1; + } + } + private void readTextCustomData(Position position, String data, String form) { CellTower cellTower = new CellTower(); String[] keys = form.substring(1).split("%"); @@ -208,6 +294,12 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder { case "MT": position.set(Position.KEY_MOTION, Integer.parseInt(values[i]) > 0); break; + case "BC": + String[] beaconValues = values[i].split(":"); + decodeBeaconData( + position, Integer.parseInt(beaconValues[0]), Integer.parseInt(beaconValues[1]), + Unpooled.wrappedBuffer(DataConverter.parseHex(beaconValues[2]))); + break; default: break; } diff --git a/src/test/java/org/traccar/protocol/AtrackProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/AtrackProtocolDecoderTest.java index b329f59f3..dc3f532b6 100644 --- a/src/test/java/org/traccar/protocol/AtrackProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/AtrackProtocolDecoderTest.java @@ -44,6 +44,9 @@ public class AtrackProtocolDecoderTest extends ProtocolTest { decoder.setCustom(true); verifyPositions(decoder, buffer( + "@P,7A66,153,9022,863003048505515,20210207000103,20210207000103,20210207000103,103939276,1348903,97,2,5628,8,0,0,0,0,,2000,2000,\u001a,%CI%BC,3:224:F128833445E6002C09C6\r\n")); + + verifyPositions(decoder, buffer( "@P,9493,402,143,356961075931165,1546830150,1546830151,1546830151,-88429209,44271154,54,10,0,10,1,0,0,0,1858AE010000,2000,2000,\u001A,%CI%FL%ML%VN%PD%FC%EL%ET%AT%MF%MV%BV%DT%GN%GV%ME%RL%RP%SA%SM%TR%IA%MP,0,0,2T1KR32E28C706185,0,1,0,7,251,89,118,41,0,00A5001A040800A5001A040B00A5001A040C00A5001A040900A4001C040D00A50019040900A60019040900A4001B040B00A5001A040900A7001A040E\u001A,008CFE7C03C4\u001A,356961075931165,0,0,12,0,18,5,0\n")); verifyPositions(decoder, buffer( |