aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/FleetGuideProtocolDecoder.java68
-rw-r--r--src/test/java/org/traccar/protocol/FleetGuideProtocolDecoderTest.java3
2 files changed, 66 insertions, 5 deletions
diff --git a/src/main/java/org/traccar/protocol/FleetGuideProtocolDecoder.java b/src/main/java/org/traccar/protocol/FleetGuideProtocolDecoder.java
index 9fddec922..ba4d9cfae 100644
--- a/src/main/java/org/traccar/protocol/FleetGuideProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/FleetGuideProtocolDecoder.java
@@ -19,8 +19,10 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.NetworkMessage;
import org.traccar.Protocol;
import org.traccar.helper.BitUtil;
+import org.traccar.helper.Checksum;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import org.traccar.session.DeviceSession;
@@ -38,9 +40,13 @@ public class FleetGuideProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- public static final int MSG_DATA = 0x10;
- public static final int MSG_HEARTBEAT = 0x1A;
- public static final int MSG_RESPONSE = 0x1C;
+ public static final int MSG_EMPTY = 0;
+ public static final int MSG_SYNC_REQ = 1;
+ public static final int MSG_SYNC_ACK = 2;
+ public static final int MSG_DATA_R_ACK = 3;
+ public static final int MSG_DATA_N_ACK = 4;
+ public static final int MSG_REP_R_ACK = 5;
+ public static final int MSG_REP_N_ACK = 6;
@Override
protected Object decode(
@@ -53,9 +59,12 @@ public class FleetGuideProtocolDecoder extends BaseProtocolDecoder {
int length = BitUtil.to(options, 11);
DeviceSession deviceSession;
+ Long deviceId;
if (BitUtil.check(options, 11)) {
- deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(buf.readUnsignedIntLE()));
+ deviceId = buf.readUnsignedIntLE();
+ deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(deviceId));
} else {
+ deviceId = null;
deviceSession = getDeviceSession(channel, remoteAddress);
}
if (deviceSession == null) {
@@ -63,12 +72,24 @@ public class FleetGuideProtocolDecoder extends BaseProtocolDecoder {
}
int type;
+ Integer index;
if (BitUtil.check(options, 12)) {
- type = BitUtil.to(buf.readUnsignedByte(), 4);
+ int value = buf.readUnsignedByte();
+ type = BitUtil.to(value, 4);
+ index = BitUtil.from(value, 4);
} else {
type = 0;
+ index = null;
}
+ Integer responseType;
+ if (type == MSG_SYNC_REQ) {
+ responseType = MSG_SYNC_ACK;
+ } else {
+ responseType = null;
+ }
+ sendResponse(channel, remoteAddress, deviceId, responseType, index);
+
if (BitUtil.check(options, 13)) {
buf.readUnsignedShortLE(); // acknowledgement
}
@@ -153,6 +174,43 @@ public class FleetGuideProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+
+ private void sendResponse(
+ Channel channel, SocketAddress remoteAddress, Long deviceId, Integer type, Integer index) {
+ if (channel != null) {
+
+ ByteBuf response = Unpooled.buffer();
+ response.writeByte(0x53); // signature
+
+ int options = 0;
+ if (deviceId != null) {
+ options |= 1 << 11;
+ }
+ if (type != null) {
+ options |= 1 << 12;
+ }
+ if (index != null) {
+ options |= 1 << 13;
+ }
+ response.writeShortLE(options);
+
+ if (deviceId != null) {
+ response.writeIntLE(deviceId.intValue());
+ }
+ if (type != null) {
+ response.writeByte(type);
+ }
+ if (index != null) {
+ int mask = (1 << (index + 1)) - 1;
+ response.writeShortLE(mask);
+ }
+ response.writeShortLE(Checksum.crc16(
+ Checksum.CRC16_CCITT_FALSE, response.nioBuffer(1, response.writerIndex() - 1)));
+
+ channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
+ }
+ }
+
private int readVarSize(ByteBuf buf) {
int b;
int y = 0;
diff --git a/src/test/java/org/traccar/protocol/FleetGuideProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/FleetGuideProtocolDecoderTest.java
index 34b15d14b..363f33c5b 100644
--- a/src/test/java/org/traccar/protocol/FleetGuideProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/FleetGuideProtocolDecoderTest.java
@@ -10,6 +10,9 @@ public class FleetGuideProtocolDecoderTest extends ProtocolTest {
var decoder = inject(new FleetGuideProtocolDecoder(null));
+ verifyNull(decoder, binary(
+ "5300188f8a020001f36a"));
+
verifyPositions(decoder, binary(
"539e598f8a020003020700e378351ac39f040c04ffa92e806a28a13b1f00b638030c000067052c06ffffffff033006808001180003200100000700e478351ac40204303dab2e80cb27a13b1c00ac40021b30e778351ac502043082a72e8054020530bf30021b30e978351ac69f0d0c0433a72e80c123a13b2000df3807002579351ac79f06020a170000df28021b476179351ac8020f30021c81279d79351ac9020f30021c8207d979351aca020f30021c8157157a351acb022b8140517a351acc022b608d7a351acd022b60c97a351ace022b30057b351acf022b30417b351ad0022b307d7b351ad1020f3048021b30b97b351ad2020f3070030c004066021630f57b351ad30213841080021730317c351ad4021330c00217306d7c351ad5020f3050021b30a97c351ad602138170021830e57c351ad7020f3058021b30217d351ad8021385500218305d7d351ad9022b8110997d351ada022b8170d57d351adb022b30117e351adc020f3068030ce184680216304d7e351add020f3060030ce34469021630897e351ade021260e4021830c57e351adf021230e5021830017f351ae002293022f2"));