aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-01-21 22:46:34 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2020-01-21 22:46:34 -0800
commit720916a476f25f12156cdd7e07cbee4f48d1b1ad (patch)
treeee1269045315617a44a916980c8441885b82775e
parent0c40b37a389ae681152f320e47731ee3012f17eb (diff)
downloadtrackermap-server-720916a476f25f12156cdd7e07cbee4f48d1b1ad.tar.gz
trackermap-server-720916a476f25f12156cdd7e07cbee4f48d1b1ad.tar.bz2
trackermap-server-720916a476f25f12156cdd7e07cbee4f48d1b1ad.zip
Implement server response
-rw-r--r--src/main/java/org/traccar/protocol/BlueProtocolDecoder.java33
-rw-r--r--src/test/java/org/traccar/protocol/BlueProtocolDecoderTest.java3
2 files changed, 34 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/protocol/BlueProtocolDecoder.java b/src/main/java/org/traccar/protocol/BlueProtocolDecoder.java
index 98a8ae565..61edcd101 100644
--- a/src/main/java/org/traccar/protocol/BlueProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/BlueProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2019 - 2020 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,14 @@
package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.NetworkMessage;
import org.traccar.Protocol;
import org.traccar.helper.BitUtil;
+import org.traccar.helper.Checksum;
import org.traccar.helper.DateBuilder;
import org.traccar.model.Position;
@@ -41,6 +44,28 @@ public class BlueProtocolDecoder extends BaseProtocolDecoder {
return negative ? -coordinate : coordinate;
}
+ private void sendResponse(Channel channel, int deviceIndex) {
+ if (channel != null) {
+
+ ByteBuf response = Unpooled.buffer();
+ response.writeByte(0xaa);
+ response.writeShort(2 + 1 + 1 + 6 + 1);
+ response.writeByte(0x86); // version
+ response.writeByte(0);
+
+ response.writeByte(6); // data length
+ response.writeByte(0xa4); // type
+ response.writeByte(0); // server index
+ response.writeByte(deviceIndex);
+ response.writeByte(0);
+ response.writeByte(0);
+
+ response.writeByte(Checksum.xor(response.nioBuffer(1, response.writerIndex() - 1)));
+
+ channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -66,7 +91,7 @@ public class BlueProtocolDecoder extends BaseProtocolDecoder {
int frameEnd = buf.readerIndex() + buf.readUnsignedByte();
int type = buf.readUnsignedByte();
- buf.readUnsignedByte(); // reference id
+ int index = buf.readUnsignedByte();
buf.readUnsignedByte();
buf.readUnsignedByte(); // flags
@@ -102,6 +127,10 @@ public class BlueProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // status 5
buf.readUnsignedByte(); // status 6
+ } else if (type == 0x84) {
+
+ sendResponse(channel, index);
+
}
buf.readerIndex(frameEnd);
diff --git a/src/test/java/org/traccar/protocol/BlueProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/BlueProtocolDecoderTest.java
index 1d1716238..9f3254824 100644
--- a/src/test/java/org/traccar/protocol/BlueProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/BlueProtocolDecoderTest.java
@@ -11,6 +11,9 @@ public class BlueProtocolDecoderTest extends ProtocolTest {
BlueProtocolDecoder decoder = new BlueProtocolDecoder(null);
verifyPosition(decoder, binary(
+ "aa00550000813f6f840b840380001032000000002001030040008005ee1938113b26f300000000000000140114082833044d27602112030002000000b70000020000000000000000650000001601f4000000000000e4"));
+
+ verifyPosition(decoder, binary(
"aa0055860080e3e79e0b840f800010320000000020010f0040008005ee197f113b26e800000000000000130c11091a2b005ac7a621120f0002000000b7000002000000000000001a3a0000000001f40000000000003f"));
}