diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2021-06-30 21:25:06 -0700 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2021-06-30 21:25:06 -0700 |
commit | 08d7ce0017f7113f3db961ae19cae7b85e386278 (patch) | |
tree | 2ae20638f3fba675316b18ca3b96d50efd9e1e95 /src/main/java | |
parent | 49724e51630410e9a2c99a27ec7963a315f6575e (diff) | |
download | traccar-server-08d7ce0017f7113f3db961ae19cae7b85e386278.tar.gz traccar-server-08d7ce0017f7113f3db961ae19cae7b85e386278.tar.bz2 traccar-server-08d7ce0017f7113f3db961ae19cae7b85e386278.zip |
Fix services response
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java | 69 |
1 files changed, 54 insertions, 15 deletions
diff --git a/src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java index 68e9e8dd5..70f1b1485 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 { - - ByteBuf buf = (ByteBuf) msg; + private void sendResponse(Channel channel, SocketAddress remoteAddress, int index, int type, ByteBuf buf) { - buf.readUnsignedByte(); // header - int flags = buf.readUnsignedByte(); - buf.readUnsignedShortLE(); // length - buf.readUnsignedShortLE(); // checksum - int index = buf.readUnsignedShortLE(); - int type = buf.readUnsignedByte(); + if (channel != null) { - 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,24 @@ public class Minifinder2ProtocolDecoder extends BaseProtocolDecoder { channel.writeAndFlush(new NetworkMessage(response, remoteAddress)); } + } + + @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) { |