From 42a0fef17757082442e3dea4d1fc0f57750c0f90 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 9 Jan 2020 16:13:24 -0800 Subject: Fix PST protocol issues --- .../java/org/traccar/protocol/PstProtocolDecoder.java | 15 ++++++++++----- .../java/org/traccar/protocol/PstProtocolDecoderTest.java | 6 ++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/traccar/protocol/PstProtocolDecoder.java b/src/main/java/org/traccar/protocol/PstProtocolDecoder.java index a93dd251f..23e2afbbd 100644 --- a/src/main/java/org/traccar/protocol/PstProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PstProtocolDecoder.java @@ -41,14 +41,16 @@ public class PstProtocolDecoder extends BaseProtocolDecoder { .setYear((int) BitUtil.between(value, 26, 32)) .setMonth((int) BitUtil.between(value, 22, 26)) .setDay((int) BitUtil.between(value, 17, 22)) - .setMonth((int) BitUtil.between(value, 12, 17)) - .setMonth((int) BitUtil.between(value, 6, 12)) - .setMonth((int) BitUtil.between(value, 0, 6)).getDate(); + .setHour((int) BitUtil.between(value, 12, 17)) + .setMinute((int) BitUtil.between(value, 6, 12)) + .setSecond((int) BitUtil.between(value, 0, 6)).getDate(); } private double readCoordinate(ByteBuf buf) { long value = buf.readUnsignedInt(); - return (BitUtil.from(value, 16) + BitUtil.to(value, 16) * 0.00001) / 60; + int sign = BitUtil.check(value, 31) ? -1 : 1; + value = BitUtil.to(value, 31); + return sign * (BitUtil.from(value, 16) + BitUtil.to(value, 16) * 0.00001) / 60; } @Override @@ -85,7 +87,10 @@ public class PstProtocolDecoder extends BaseProtocolDecoder { switch (tag) { case 0x0D: - position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte() * 5); + int battery = buf.readUnsignedByte(); + if (battery <= 20) { + position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte() * 5); + } break; case 0x10: position.setFixTime(readDate(buf)); diff --git a/src/test/java/org/traccar/protocol/PstProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/PstProtocolDecoderTest.java index cab8dc1a0..a5db8872d 100644 --- a/src/test/java/org/traccar/protocol/PstProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/PstProtocolDecoderTest.java @@ -10,6 +10,12 @@ public class PstProtocolDecoderTest extends ProtocolTest { PstProtocolDecoder decoder = new PstProtocolDecoder(null); + verifyPosition(decoder, binary( + "2faf9ab606000004c7055052ec88c0070b04000015050c09b500a25271c733e0720d01fe0f045052ec8410145052ba07858413918af325e7020802fe010001051103ffff0015023bbdc87d")); + + verifyPosition(decoder, binary( + "2faf9ab606000004c7055052ec88c0070b04000015050c09b500a25271c733e0720d01fe0f045052ec8410145052ba07858413918af325e7020802fe010001051103ffff0015023bbdc87d")); + verifyNull(decoder, binary( "2faf9b4c0600000012054f36ec194000bfa9")); -- cgit v1.2.3