Skip to content

Commit

Permalink
Fix time and decode cell info
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed May 25, 2021
1 parent 77980d0 commit 76e4b63
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;

Expand All @@ -49,6 +50,18 @@ private void sendResponse(Channel channel, SocketAddress remoteAddress, int inde
}
}

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 {
Expand All @@ -70,7 +83,7 @@ protected Object decode(
sendResponse(channel, remoteAddress, index);
}

Date time = new Date(buf.readUnsignedInt() * 1000);
Date time = decodeTime(buf);
int event = buf.readUnsignedByte();

buf.readUnsignedByte(); // length
Expand All @@ -93,7 +106,7 @@ protected Object decode(
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);
Expand Down Expand Up @@ -123,7 +136,10 @@ protected Object decode(
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public void testDecode() throws Exception {

var decoder = new FlexibleReportProtocolDecoder(null);

verifyPosition(decoder, binary(
"7d010015875000013001001028fd98991830002e7fffffff0c28fd989903f6540a07f250ed00000f02f2140f5ea20000000000000202d4000a1f8b0100000708ffff"));

verifyAttributes(decoder, binary(
"7D010860112040978399000027E3CFC30130002E7FFFFFFF0C00000000055D4A800ABA9500000000000000002F5D0E800000000000FFFFFFFF158A0000000000FFFF"));

Expand Down

0 comments on commit 76e4b63

Please sign in to comment.