aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-10-30 02:10:14 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2017-10-30 02:10:14 +1300
commita23453cdeb6285db91af5544686192c966ad03c4 (patch)
treeabc473f427f2f47f2fa953ec77d8aa43eaa0c1c3
parent9bc7deb97f2751ee0fd7e5ba198d2c030d149e01 (diff)
downloadtrackermap-server-a23453cdeb6285db91af5544686192c966ad03c4.tar.gz
trackermap-server-a23453cdeb6285db91af5544686192c966ad03c4.tar.bz2
trackermap-server-a23453cdeb6285db91af5544686192c966ad03c4.zip
Support Topin D3 micro messages
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolDecoder.java79
-rw-r--r--test/org/traccar/protocol/Gt06FrameDecoderTest.java20
-rw-r--r--test/org/traccar/protocol/Gt06ProtocolDecoderTest.java24
3 files changed, 90 insertions, 33 deletions
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
index fbd1adfc6..177c0b653 100644
--- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -21,6 +21,7 @@ import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
import org.traccar.DeviceSession;
+import org.traccar.helper.BcdUtil;
import org.traccar.helper.BitUtil;
import org.traccar.helper.Checksum;
import org.traccar.helper.DateBuilder;
@@ -67,6 +68,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_SATELLITE = 0x14;
public static final int MSG_STRING = 0x15;
public static final int MSG_GPS_LBS_STATUS_1 = 0x16;
+ public static final int MSG_WIFI = 0x17;
public static final int MSG_GPS_LBS_STATUS_2 = 0x26;
public static final int MSG_GPS_LBS_STATUS_3 = 0x27;
public static final int MSG_LBS_MULTIPLE = 0x28;
@@ -81,6 +83,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_X1_GPS = 0x34;
public static final int MSG_X1_PHOTO_INFO = 0x35;
public static final int MSG_X1_PHOTO_DATA = 0x36;
+ public static final int MSG_WIFI_2 = 0x69;
public static final int MSG_COMMAND_0 = 0x80;
public static final int MSG_COMMAND_1 = 0x81;
public static final int MSG_COMMAND_2 = 0x82;
@@ -107,17 +110,21 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
|| type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2 || type == MSG_GPS_LBS_STATUS_3;
}
- private void sendResponse(Channel channel, boolean extended, int type) {
+ private void sendResponse(Channel channel, boolean extended, int type, ChannelBuffer content) {
if (channel != null) {
ChannelBuffer response = ChannelBuffers.dynamicBuffer();
+ int length = 5 + (content != null ? content.readableBytes() : 0);
if (extended) {
response.writeShort(0x7979);
- response.writeShort(5);
+ response.writeShort(length);
} else {
response.writeShort(0x7878);
- response.writeByte(5);
+ response.writeByte(length);
}
response.writeByte(type);
+ if (content != null) {
+ response.writeBytes(content);
+ }
response.writeShort(++serverIndex);
response.writeShort(Checksum.crc16(Checksum.CRC16_X25,
response.toByteBuffer(2, response.writerIndex() - 2)));
@@ -127,21 +134,12 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
}
private void sendPhotoRequest(Channel channel, int pictureId) {
- if (channel != null) {
- ChannelBuffer photo = photos.get(pictureId);
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeShort(0x7878); // header
- response.writeByte(15); // size
- response.writeByte(MSG_X1_PHOTO_DATA);
- response.writeInt(pictureId);
- response.writeInt(photo.writerIndex());
- response.writeShort(Math.min(photo.writableBytes(), 1024));
- response.writeShort(++serverIndex);
- response.writeShort(Checksum.crc16(Checksum.CRC16_X25,
- response.toByteBuffer(2, response.writerIndex() - 2)));
- response.writeByte('\r'); response.writeByte('\n'); // ending
- channel.write(response);
- }
+ ChannelBuffer photo = photos.get(pictureId);
+ ChannelBuffer content = ChannelBuffers.dynamicBuffer();
+ content.writeInt(pictureId);
+ content.writeInt(photo.writerIndex());
+ content.writeShort(Math.min(photo.writableBytes(), 1024));
+ sendResponse(channel, false, MSG_X1_PHOTO_DATA, content);
}
private boolean decodeGps(Position position, ChannelBuffer buf, boolean hasLength) {
@@ -347,7 +345,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
}
if (getDeviceSession(channel, remoteAddress, imei) != null) {
- sendResponse(channel, false, type);
+ sendResponse(channel, false, type, null);
}
} else if (type == MSG_X1_GPS) {
@@ -385,6 +383,43 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
photos.put(pictureId, photo);
sendPhotoRequest(channel, pictureId);
+ } else if (type == MSG_WIFI || type == MSG_WIFI_2) {
+
+ Position position = new Position();
+ position.setDeviceId(deviceSession.getDeviceId());
+ position.setProtocol(getProtocolName());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setYear(BcdUtil.readInteger(buf, 2))
+ .setMonth(BcdUtil.readInteger(buf, 2))
+ .setDay(BcdUtil.readInteger(buf, 2))
+ .setHour(BcdUtil.readInteger(buf, 2))
+ .setMinute(BcdUtil.readInteger(buf, 2))
+ .setSecond(BcdUtil.readInteger(buf, 2));
+ getLastLocation(position, dateBuilder.getDate());
+
+ Network network = new Network();
+
+ int wifiCount = buf.getByte(2);
+ for (int i = 0; i < wifiCount; i++) {
+ String mac = String.format("%02x:%02x:%02x:%02x:%02x:%02x",
+ buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte(),
+ buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
+ network.addWifiAccessPoint(WifiAccessPoint.from(mac, buf.readUnsignedByte()));
+ }
+
+ int cellCount = buf.readUnsignedByte();
+ int mcc = buf.readUnsignedShort();
+ int mnc = buf.readUnsignedByte();
+ for (int i = 0; i < cellCount; i++) {
+ network.addCellTower(CellTower.from(
+ mcc, mnc, buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedByte()));
+ }
+
+ position.setNetwork(network);
+
+ return position;
+
} else {
return decodeBasicOther(channel, buf, deviceSession, type, dataLength);
@@ -476,13 +511,13 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(dataLength);
if (type != MSG_COMMAND_0 && type != MSG_COMMAND_1 && type != MSG_COMMAND_2) {
- sendResponse(channel, false, type);
+ sendResponse(channel, false, type, null);
}
return null;
}
- sendResponse(channel, false, type);
+ sendResponse(channel, false, type, null);
return position;
}
@@ -602,7 +637,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(buf.readUnsignedByte()); // reserved extension
- sendResponse(channel, true, type);
+ sendResponse(channel, true, type, null);
return position;
diff --git a/test/org/traccar/protocol/Gt06FrameDecoderTest.java b/test/org/traccar/protocol/Gt06FrameDecoderTest.java
index ff9d4f51d..97230695a 100644
--- a/test/org/traccar/protocol/Gt06FrameDecoderTest.java
+++ b/test/org/traccar/protocol/Gt06FrameDecoderTest.java
@@ -11,35 +11,39 @@ public class Gt06FrameDecoderTest extends ProtocolTest {
Gt06FrameDecoder decoder = new Gt06FrameDecoder();
- Assert.assertEquals(
+ verifyFrame(
+ binary("787803691604130318491475905BD30E25001E10BBF7635D14759006E626560501CC0028660F213228660F1F2828660EA81E286610731428660F20140D0A"),
+ decoder.decode(null, null, binary("787803691604130318491475905BD30E25001E10BBF7635D14759006E626560501CC0028660F213228660F1F2828660EA81E286610731428660F20140D0A")));
+
+ verifyFrame(
binary("78780d0103563140414198583c0d0a"),
decoder.decode(null, null, binary("78780d0103563140414198583c0d0a")));
- Assert.assertEquals(
+ verifyFrame(
binary("787800691709261259400700cc0400d376714600d37a3d5000d37a3c5000d393505a00d3765d5a00d376735a00d32e6b640d0a"),
decoder.decode(null, null, binary("787800691709261259400700cc0400d376714600d37a3d5000d37a3c5000d393505a00d3765d5a00d376735a00d32e6b640d0a")));
- Assert.assertEquals(
+ verifyFrame(
binary("7878121011091c0b1e2e98058507f80097a6ac03344a0d0a"),
decoder.decode(null, null, binary("7878121011091c0b1e2e98058507f80097a6ac03344a0d0a")));
- Assert.assertEquals(
+ verifyFrame(
binary("787808171709281135331491827b75594dc8d719a9708452cad719a9708550cad719a97086521491827b75574cac9e17b308085dc8d71939633947cad71939633a480700cc0400d37a3d5a00d37a3d5a00d37a3d5a00d37a3d5a00d37a3d5a00d37a3d5a00d37a3d5a0d0a"),
decoder.decode(null, null, binary("787808171709281135331491827b75594dc8d719a9708452cad719a9708550cad719a97086521491827b75574cac9e17b308085dc8d71939633947cad71939633a480700cc0400d37a3d5a00d37a3d5a00d37a3d5a00d37a3d5a00d37a3d5a00d37a3d5a00d37a3d5a0d0a")));
- Assert.assertEquals(
+ verifyFrame(
binary("787808134606020002044dc5050d0a"),
decoder.decode(null, null, binary("787808134606020002044dc5050d0a")));
- Assert.assertEquals(
+ verifyFrame(
binary("78781f1210020e14061dcc0476fcd0003e3faf3e14b20000000000000000044ef6740d0a"),
decoder.decode(null, null, binary("78781f1210020e14061dcc0476fcd0003e3faf3e14b20000000000000000044ef6740d0a")));
- Assert.assertEquals(
+ verifyFrame(
binary("78780d010352887071911998000479d00d0a"),
decoder.decode(null, null, binary("78780d010352887071911998000479d00d0a")));
- Assert.assertEquals(
+ verifyFrame(
binary("78782516000000000000c000000000000000000020000900fa0210ef00fb620006640301000468030d0a"),
decoder.decode(null, null, binary("78782516000000000000c000000000000000000020000900fa0210ef00fb620006640301000468030d0a")));
diff --git a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java
index 05acd314e..ede2f385c 100644
--- a/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gt06ProtocolDecoderTest.java
@@ -16,13 +16,31 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, binary(
"78780D01086471700328358100093F040D0A"));
+ verifyNotNull(decoder, binary(
+ "787803691604130318491475905BD30E25001E10BBF7635D14759006E626560501CC0028660F213228660F1F2828660EA81E286610731428660F20140D0A"));
+
+ verifyNotNull(decoder, binary(
+ "787800691710231108500200cc080c4e2fa5640c4e2fa66e0d0a"));
+
+ verifyNotNull(decoder, binary(
+ "787800171710231108290200cc080c4e2fa5640c4e2fa5640d0a"));
+
+ verifyNotNull(decoder, binary(
+ "787800691710231109200400cc080c4e2fa55a0c4ec0025a0c4e2fa6640c583918640d0a"));
+
+ verifyNotNull(decoder, binary(
+ "787800691710231111210700cc080c4e2fa55a0c4ec0025a0c4e39295a0c583918640c4e2fa6640c4e2fa4640c4ec854640d0a"));
+
+ verifyNotNull(decoder, binary(
+ "787800171710231112510600cc080c4e2fa55a0c4e2fa55a0c4e2fa55a0c4e2fa55a0c4e2fa55a0c4e2fa55a0d0a"));
+
verifyPosition(decoder, binary(
"7878121011091c0b1b2999058508040097a89e0034520d0a"));
- verifyNull(decoder, binary(
+ verifyNotNull(decoder, binary(
"78780869170928113413ac9e17b30808514494fcf6e148596cb0ce2c67bd4a6eb0ce2c67bd4b0018e7d4333e55ec086be7f2df5fe48d8c94fc6657e48d8cb8f378510600cc0400d37a3d4600d37a3c5000d37a3b6400d376716400d305ac6400d393506e0d0a"));
- verifyNull(decoder, binary(
+ verifyNotNull(decoder, binary(
"787808171709281135331491827b75594dc8d719a9708452cad719a9708550cad719a97086521491827b75574cac9e17b308085dc8d71939633947cad71939633a480700cc0400d37a3d5a00d37a3d5a00d37a3d5a00d37a3d5a00d37a3d5a00d37a3d5a00d37a3d5a0d0a"));
verifyNotNull(decoder, binary(
@@ -179,7 +197,7 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, binary(
"78780d010359339075005244340d0a"));
- verifyNull(decoder, binary(
+ verifyNotNull(decoder, binary(
"787800691709261259400700cc0400d376714600d37a3d5000d37a3c5000d393505a00d3765d5a00d376735a00d32e6b640d0a"));
verifyNull(decoder, binary(