aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java69
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) {