aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-06-01 11:36:16 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2019-06-01 11:36:16 -0700
commit48b7368edb18985265dcba2fdaf4d80fc9f19bae (patch)
tree14395bb36ba2cd9d83d6c6955f8495cf6a23ad61
parentaf8c41c0b0ce8cd2ce942f6e665dbfaba86a1703 (diff)
downloadtrackermap-server-48b7368edb18985265dcba2fdaf4d80fc9f19bae.tar.gz
trackermap-server-48b7368edb18985265dcba2fdaf4d80fc9f19bae.tar.bz2
trackermap-server-48b7368edb18985265dcba2fdaf4d80fc9f19bae.zip
Decode additional parameters
-rw-r--r--src/main/java/org/traccar/protocol/T800xProtocolDecoder.java55
-rw-r--r--src/test/java/org/traccar/protocol/T800xProtocolDecoderTest.java5
2 files changed, 42 insertions, 18 deletions
diff --git a/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java b/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
index 6b7f47afd..940d43a56 100644
--- a/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
@@ -33,6 +33,7 @@ import org.traccar.model.Position;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
+import java.util.Date;
public class T800xProtocolDecoder extends BaseProtocolDecoder {
@@ -92,6 +93,17 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
}
}
+ private Date readDate(ByteBuf buf) {
+ return 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))
+ .getDate();
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -110,10 +122,33 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
return null;
}
+ if (type != MSG_GPS && type != MSG_ALARM) {
+ sendResponse(channel, header, type, index, imei, 0);
+ }
+
if (type == MSG_GPS || type == MSG_ALARM) {
return decodePosition(channel, deviceSession, buf, header, type, index, imei);
+ } else if (type == MSG_NETWORK) {
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, readDate(buf));
+
+ position.set(Position.KEY_OPERATOR, buf.readCharSequence(
+ buf.readUnsignedByte(), StandardCharsets.UTF_16LE).toString());
+ position.set("networkTechnology", buf.readCharSequence(
+ buf.readUnsignedByte(), StandardCharsets.US_ASCII).toString());
+ position.set("networkBand", buf.readCharSequence(
+ buf.readUnsignedByte(), StandardCharsets.US_ASCII).toString());
+ buf.readCharSequence(buf.readUnsignedByte(), StandardCharsets.US_ASCII); // imsi
+ position.set(Position.KEY_ICCID, buf.readCharSequence(
+ buf.readUnsignedByte(), StandardCharsets.US_ASCII).toString());
+
+ return position;
+
} else if (type == MSG_COMMAND) {
Position position = new Position(getProtocolName());
@@ -125,14 +160,10 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_RESULT, buf.toString(StandardCharsets.UTF_16LE));
- sendResponse(channel, header, type, index, imei, 0);
-
return position;
}
- sendResponse(channel, header, type, index, imei, 0);
-
return null;
}
@@ -196,18 +227,10 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
}
- 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));
-
if (BitUtil.check(status, 6)) {
position.setValid(!BitUtil.check(status, 7));
- position.setTime(dateBuilder.getDate());
+ position.setTime(readDate(buf));
position.setAltitude(buf.readFloatLE());
position.setLongitude(buf.readFloatLE());
position.setLatitude(buf.readFloatLE());
@@ -216,7 +239,7 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
} else {
- getLastLocation(position, dateBuilder.getDate());
+ getLastLocation(position, readDate(buf));
int mcc = buf.readUnsignedShortLE();
int mnc = buf.readUnsignedShortLE();
@@ -237,9 +260,9 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(5); // acceleration
position.set(Position.KEY_BATTERY_LEVEL, BcdUtil.readInteger(buf, 2));
position.set(Position.KEY_DEVICE_TEMP, (int) buf.readByte());
- buf.readUnsignedByte(); // front light sensor voltage
+ position.set("lightSensor", BcdUtil.readInteger(buf, 2) * 0.1);
position.set(Position.KEY_BATTERY, BcdUtil.readInteger(buf, 2) * 0.1);
- buf.readUnsignedByte(); // solar panel voltage
+ position.set("solarPanel", BcdUtil.readInteger(buf, 2) * 0.1);
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
position.set(Position.KEY_STATUS, buf.readUnsignedShort());
diff --git a/src/test/java/org/traccar/protocol/T800xProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/T800xProtocolDecoderTest.java
index 9b564c895..c1bd8161e 100644
--- a/src/test/java/org/traccar/protocol/T800xProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/T800xProtocolDecoderTest.java
@@ -11,8 +11,9 @@ public class T800xProtocolDecoderTest extends ProtocolTest {
T800xProtocolDecoder decoder = new T800xProtocolDecoder(null);
- verifyNull(decoder, binary(
- "272705005e000108664250328807851905301107481054002d004d006f00620069006c006500074341542d4e42310a4c54452042414e4420340f333130323430323030303032333030143839303132343032303531303030323330303746"));
+ verifyAttribute(decoder, binary(
+ "272705005e000108664250328807851905301107481054002d004d006f00620069006c006500074341542d4e42310a4c54452042414e4420340f333130323430323030303032333030143839303132343032303531303030323330303746"),
+ Position.KEY_OPERATOR, "T-Mobile");
verifyPosition(decoder, binary(
"272702004904a90866425032880785c800190530080350000000000705eec29bf50842000000000008008090502a003700000a9e358002003c000003841900001e3f90000000000000272702004904aa0866425032880785c800190530081851000000000705eec29bf50842000000000008008090602e003700000a9e358002003c000003841900001e3f90000000000000"));