diff options
Diffstat (limited to 'src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java')
-rw-r--r-- | src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java | 96 |
1 files changed, 77 insertions, 19 deletions
diff --git a/src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java index 68e9e8dd5..641a45864 100644 --- a/src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java @@ -46,6 +46,8 @@ public class Minifinder2ProtocolDecoder extends BaseProtocolDecoder { } public static final int MSG_DATA = 0x01; + public static final int MSG_CONFIGURATION = 0x02; + public static final int MSG_SERVICES = 0x03; public static final int MSG_RESPONSE = 0x7F; private String decodeAlarm(int code) { @@ -70,25 +72,44 @@ public class Minifinder2ProtocolDecoder extends BaseProtocolDecoder { return null; } - @Override - protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + private void sendResponse(Channel channel, SocketAddress remoteAddress, int index, int type, ByteBuf buf) { - ByteBuf buf = (ByteBuf) msg; + if (channel != null) { - buf.readUnsignedByte(); // header - int flags = buf.readUnsignedByte(); - buf.readUnsignedShortLE(); // length - buf.readUnsignedShortLE(); // checksum - int index = buf.readUnsignedShortLE(); - int type = buf.readUnsignedByte(); - - if (BitUtil.check(flags, 4) && channel != null) { + ByteBuf body = Unpooled.buffer(); + if (type == MSG_SERVICES) { + while (buf.isReadable()) { + int endIndex = buf.readUnsignedByte() + buf.readerIndex(); + int key = buf.readUnsignedByte(); + switch (key) { + case 0x11: + case 0x21: + case 0x22: + body.writeByte(9 + 1); // length + body.writeByte(key); + body.writeIntLE(0); // latitude + body.writeIntLE(0); // longitude + body.writeByte(0); // address + break; + case 0x12: + body.writeByte(5); // length + body.writeByte(key); + body.writeIntLE((int) (System.currentTimeMillis() / 1000)); + break; + default: + break; + } + buf.readerIndex(endIndex); + } + } else { + body.writeByte(1); // key length + body.writeByte(0); // success + } ByteBuf content = Unpooled.buffer(); - content.writeByte(MSG_RESPONSE); - content.writeByte(1); // key length - content.writeByte(0); // success + content.writeByte(type == MSG_SERVICES ? type : MSG_RESPONSE); + content.writeBytes(body); + body.release(); ByteBuf response = Unpooled.buffer(); response.writeByte(0xAB); // header @@ -101,6 +122,32 @@ public class Minifinder2ProtocolDecoder extends BaseProtocolDecoder { channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } + } + + private String readTagId(ByteBuf buf) { + StringBuilder tagId = new StringBuilder(); + for (int i = 0; i < 6; i++) { + tagId.insert(0, ByteBufUtil.hexDump(buf.readSlice(1))); + } + return tagId.toString(); + } + + @Override + protected Object decode( + Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { + + ByteBuf buf = (ByteBuf) msg; + + buf.readUnsignedByte(); // header + int flags = buf.readUnsignedByte(); + buf.readUnsignedShortLE(); // length + buf.readUnsignedShortLE(); // checksum + int index = buf.readUnsignedShortLE(); + int type = buf.readUnsignedByte(); + + if (BitUtil.check(flags, 4)) { + sendResponse(channel, remoteAddress, index, type, buf); + } if (type == MSG_DATA) { @@ -175,9 +222,10 @@ public class Minifinder2ProtocolDecoder extends BaseProtocolDecoder { } break; case 0x23: - position.set("tagId", ByteBufUtil.hexDump(buf.readSlice(6))); + position.set("tagId", readTagId(buf)); position.setLatitude(buf.readIntLE() * 0.0000001); position.setLongitude(buf.readIntLE() * 0.0000001); + position.setValid(true); hasLocation = true; break; case 0x24: @@ -188,12 +236,13 @@ public class Minifinder2ProtocolDecoder extends BaseProtocolDecoder { break; case 0x28: int beaconFlags = buf.readUnsignedByte(); - position.set("tagId", ByteBufUtil.hexDump(buf.readSlice(6))); - position.set("tagRssi", buf.readUnsignedByte()); - buf.readUnsignedByte(); // 1m rssi + position.set("tagId", readTagId(buf)); + position.set("tagRssi", (int) buf.readByte()); + position.set("tag1mRssi", (int) buf.readByte()); if (BitUtil.check(beaconFlags, 7)) { position.setLatitude(buf.readIntLE() * 0.0000001); position.setLongitude(buf.readIntLE() * 0.0000001); + position.setValid(true); hasLocation = true; } if (BitUtil.check(beaconFlags, 6)) { @@ -201,6 +250,15 @@ public class Minifinder2ProtocolDecoder extends BaseProtocolDecoder { endIndex - buf.readerIndex(), StandardCharsets.US_ASCII).toString()); } break; + case 0x2A: + buf.readUnsignedByte(); // flags + buf.skipBytes(6); // mac + buf.readUnsignedByte(); // rssi + position.setLatitude(buf.readIntLE() * 0.0000001); + position.setLongitude(buf.readIntLE() * 0.0000001); + position.setValid(true); + hasLocation = true; + break; case 0x30: buf.readUnsignedInt(); // timestamp position.set(Position.KEY_STEPS, buf.readUnsignedInt()); |