aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-09-21 17:23:01 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-09-21 17:23:01 +1200
commited822c06151973668d37c98ad2856b8a8834da1a (patch)
tree8323042acedc46d6da5a1e56e50adbaa609930e2 /src/org/traccar/protocol
parent902135f2821c86f650ef13dbfe27ae6ef00ece61 (diff)
downloadtrackermap-server-ed822c06151973668d37c98ad2856b8a8834da1a.tar.gz
trackermap-server-ed822c06151973668d37c98ad2856b8a8834da1a.tar.bz2
trackermap-server-ed822c06151973668d37c98ad2856b8a8834da1a.zip
Implement TZ RD06 temperature tags
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/TzoneProtocolDecoder.java133
1 files changed, 91 insertions, 42 deletions
diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java
index 6f6ff3878..1537c0107 100644
--- a/src/org/traccar/protocol/TzoneProtocolDecoder.java
+++ b/src/org/traccar/protocol/TzoneProtocolDecoder.java
@@ -57,6 +57,53 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
}
}
+ private boolean decodeGps(Position position, ByteBuf buf, int hardware) {
+
+ int blockLength = buf.readUnsignedShort();
+ int blockEnd = buf.readerIndex() + blockLength;
+
+ if (blockLength < 22) {
+ return false;
+ }
+
+ position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
+
+ double lat;
+ double lon;
+
+ if (hardware == 0x10A || hardware == 0x10B) {
+ lat = buf.readUnsignedInt() / 600000.0;
+ lon = buf.readUnsignedInt() / 600000.0;
+ } else {
+ lat = buf.readUnsignedInt() / 100000.0 / 60.0;
+ lon = buf.readUnsignedInt() / 100000.0 / 60.0;
+ }
+
+ position.setFixTime(new DateBuilder()
+ .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
+ .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).getDate());
+
+ position.setSpeed(buf.readUnsignedShort() * 0.01);
+
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
+
+ int flags = buf.readUnsignedShort();
+ position.setCourse(BitUtil.to(flags, 9));
+ if (!BitUtil.check(flags, 10)) {
+ lat = -lat;
+ }
+ position.setLatitude(lat);
+ if (BitUtil.check(flags, 9)) {
+ lon = -lon;
+ }
+ position.setLongitude(lon);
+ position.setValid(BitUtil.check(flags, 11));
+
+ buf.readerIndex(blockEnd);
+
+ return true;
+ }
+
private void decodeCards(Position position, ByteBuf buf) {
int index = 1;
@@ -108,6 +155,38 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
}
+ private void decodeTags(Position position, ByteBuf buf) {
+
+ int blockLength = buf.readUnsignedShort();
+ int blockEnd = buf.readerIndex() + blockLength;
+
+ if (blockLength > 0) {
+
+ buf.readUnsignedByte(); // tag type
+
+ int count = buf.readUnsignedByte();
+ int tagLength = buf.readUnsignedByte();
+
+ for (int i = 1; i <= count; i++) {
+ int tagEnd = buf.readerIndex() + tagLength;
+
+ buf.readUnsignedByte(); // status
+ buf.readUnsignedShortLE(); // battery voltage
+
+ position.set(Position.PREFIX_TEMP + i, (buf.readShortLE() & 0x3fff) * 0.1);
+
+ buf.readUnsignedByte(); // humidity
+ buf.readUnsignedByte(); // rssi
+
+ buf.readerIndex(tagEnd);
+ }
+
+ }
+
+ buf.readerIndex(blockEnd);
+
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -140,54 +219,18 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
// GPS info
- int blockLength = buf.readUnsignedShort();
- int blockEnd = buf.readerIndex() + blockLength;
-
- if (blockLength < 22) {
- return null;
- }
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
+ if (hardware == 0x406 || !decodeGps(position, buf, hardware)) {
- double lat;
- double lon;
+ getLastLocation(position, position.getDeviceTime());
- if (hardware == 0x10A || hardware == 0x10B) {
- lat = buf.readUnsignedInt() / 600000.0;
- lon = buf.readUnsignedInt() / 600000.0;
- } else {
- lat = buf.readUnsignedInt() / 100000.0 / 60.0;
- lon = buf.readUnsignedInt() / 100000.0 / 60.0;
}
- position.setFixTime(new DateBuilder()
- .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).getDate());
-
- position.setSpeed(buf.readUnsignedShort() * 0.01);
-
- position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
-
- int flags = buf.readUnsignedShort();
- position.setCourse(BitUtil.to(flags, 9));
- if (!BitUtil.check(flags, 10)) {
- lat = -lat;
- }
- position.setLatitude(lat);
- if (BitUtil.check(flags, 9)) {
- lon = -lon;
- }
- position.setLongitude(lon);
- position.setValid(BitUtil.check(flags, 11));
-
- buf.readerIndex(blockEnd);
-
// LBS info
- blockLength = buf.readUnsignedShort();
- blockEnd = buf.readerIndex() + blockLength;
+ int blockLength = buf.readUnsignedShort();
+ int blockEnd = buf.readerIndex() + blockLength;
- if (blockLength > 0 && (hardware == 0x10A || hardware == 0x10B)) {
+ if (blockLength > 0 && (hardware == 0x10A || hardware == 0x10B || hardware == 0x406)) {
position.setNetwork(new Network(
CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort())));
}
@@ -226,7 +269,7 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
buf.readerIndex(blockEnd);
- if (hardware == 0x10A || hardware == 0x10B) {
+ if (hardware == 0x10B) {
decodeCards(position, buf);
@@ -237,6 +280,12 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
}
+ if (hardware == 0x406) {
+
+ decodeTags(position, buf);
+
+ }
+
return position;
}