aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-05-24 22:26:02 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-05-24 22:26:02 -0700
commit76e4b63061674a58d5692d4318668494d1ed8b25 (patch)
tree15e6cb128f6a89d9656bb4157c8af28924808a10
parent77980d05fa389d77ddd4e52720394406d79c8e49 (diff)
downloadtraccar-server-76e4b63061674a58d5692d4318668494d1ed8b25.tar.gz
traccar-server-76e4b63061674a58d5692d4318668494d1ed8b25.tar.bz2
traccar-server-76e4b63061674a58d5692d4318668494d1ed8b25.zip
Fix time and decode cell info
-rw-r--r--src/main/java/org/traccar/protocol/FlexibleReportProtocolDecoder.java22
-rw-r--r--src/test/java/org/traccar/protocol/FlexibleReportProtocolDecoderTest.java3
2 files changed, 22 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/protocol/FlexibleReportProtocolDecoder.java b/src/main/java/org/traccar/protocol/FlexibleReportProtocolDecoder.java
index 44a2ae6e1..ce75a65c1 100644
--- a/src/main/java/org/traccar/protocol/FlexibleReportProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/FlexibleReportProtocolDecoder.java
@@ -24,6 +24,7 @@ import org.traccar.DeviceSession;
import org.traccar.NetworkMessage;
import org.traccar.Protocol;
import org.traccar.helper.BitUtil;
+import org.traccar.helper.DateBuilder;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
@@ -49,6 +50,18 @@ public class FlexibleReportProtocolDecoder extends BaseProtocolDecoder {
}
}
+ private Date decodeTime(ByteBuf buf) {
+ int timestamp = buf.readInt();
+ return new DateBuilder()
+ .setSecond(timestamp % 60)
+ .setMinute((timestamp / 60) % 60)
+ .setHour((timestamp / (60 * 60)) % 24)
+ .setDay(1 + timestamp / (60 * 60 * 24) % 31)
+ .setMonth(1 + timestamp / (60 * 60 * 24 * 31) % 12)
+ .setYear(2000 + timestamp / (60 * 60 * 24 * 31 * 12))
+ .getDate();
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -70,7 +83,7 @@ public class FlexibleReportProtocolDecoder extends BaseProtocolDecoder {
sendResponse(channel, remoteAddress, index);
}
- Date time = new Date(buf.readUnsignedInt() * 1000);
+ Date time = decodeTime(buf);
int event = buf.readUnsignedByte();
buf.readUnsignedByte(); // length
@@ -93,7 +106,7 @@ public class FlexibleReportProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // product id
}
if (BitUtil.check(mask, 1)) {
- position.setFixTime(new Date(buf.readUnsignedInt() * 1000));
+ position.setFixTime(decodeTime(buf));
}
if (BitUtil.check(mask, 2)) {
position.setValid(true);
@@ -123,7 +136,10 @@ public class FlexibleReportProtocolDecoder extends BaseProtocolDecoder {
position.set("solarPower", buf.readUnsignedShort() * 0.01);
}
if (BitUtil.check(mask, 10)) {
- buf.skipBytes(5); // cell info
+ int cellService = buf.readUnsignedByte();
+ position.set(Position.KEY_ROAMING, BitUtil.check(cellService, 7));
+ position.set("service", BitUtil.to(cellService, 7));
+ buf.skipBytes(4); // cell info
}
if (BitUtil.check(mask, 11)) {
buf.readUnsignedByte(); // rssi
diff --git a/src/test/java/org/traccar/protocol/FlexibleReportProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/FlexibleReportProtocolDecoderTest.java
index 068447074..8763887a5 100644
--- a/src/test/java/org/traccar/protocol/FlexibleReportProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/FlexibleReportProtocolDecoderTest.java
@@ -10,6 +10,9 @@ public class FlexibleReportProtocolDecoderTest extends ProtocolTest {
var decoder = new FlexibleReportProtocolDecoder(null);
+ verifyPosition(decoder, binary(
+ "7d010015875000013001001028fd98991830002e7fffffff0c28fd989903f6540a07f250ed00000f02f2140f5ea20000000000000202d4000a1f8b0100000708ffff"));
+
verifyAttributes(decoder, binary(
"7D010860112040978399000027E3CFC30130002E7FFFFFFF0C00000000055D4A800ABA9500000000000000002F5D0E800000000000FFFFFFFF158A0000000000FFFF"));