aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/traccar/protocol/Minifinder2ProtocolDecoder.java69
-rw-r--r--src/test/java/org/traccar/protocol/Minifinder2ProtocolDecoderTest.java3
2 files changed, 57 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) {
diff --git a/src/test/java/org/traccar/protocol/Minifinder2ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Minifinder2ProtocolDecoderTest.java
index 407d065f1..1be1e347a 100644
--- a/src/test/java/org/traccar/protocol/Minifinder2ProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/Minifinder2ProtocolDecoderTest.java
@@ -13,6 +13,9 @@ public class Minifinder2ProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, binary(
"ab10150076f1320003100133353534363530373130323933303602105a"));
+ verifyNull(decoder, binary(
+ "AB101400594A01000310013836333932323033343437333734350112"));
+
verifyPositions(decoder, binary(
"ab183200c6bd020101100138363838333230343730323133363209247a0b146090087a641528c03a79ba309be5dec3c2024122c21c2407676267"));