aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
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 /src/main/java
parent0c40b37a389ae681152f320e47731ee3012f17eb (diff)
downloadtraccar-server-720916a476f25f12156cdd7e07cbee4f48d1b1ad.tar.gz
traccar-server-720916a476f25f12156cdd7e07cbee4f48d1b1ad.tar.bz2
traccar-server-720916a476f25f12156cdd7e07cbee4f48d1b1ad.zip
Implement server response
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/traccar/protocol/BlueProtocolDecoder.java33
1 files changed, 31 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);