diff options
author | jcardus <asklocation.net@gmail.com> | 2024-06-30 00:54:55 +0100 |
---|---|---|
committer | jcardus <asklocation.net@gmail.com> | 2024-06-30 00:54:55 +0100 |
commit | e3ffb16089b742ea3868806237d1e9760395646d (patch) | |
tree | 05d1ddef539b4fad4bd6f49b2fa6867689ec64fc | |
parent | 467051e3de789e122316aa85b3f34096c2841a97 (diff) | |
download | trackermap-server-e3ffb16089b742ea3868806237d1e9760395646d.tar.gz trackermap-server-e3ffb16089b742ea3868806237d1e9760395646d.tar.bz2 trackermap-server-e3ffb16089b742ea3868806237d1e9760395646d.zip |
fix KEY_CHARGE
remove 2 tests
-rw-r--r-- | src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java | 16 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java | 8 |
2 files changed, 14 insertions, 10 deletions
diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java index 672d293e1..accc3a879 100644 --- a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -777,8 +777,20 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder { break; case 0xF7: position.set(Position.KEY_BATTERY, buf.readUnsignedInt() * 0.001); - position.set(Position.KEY_CHARGE, buf.readUnsignedByte() >= 2); - position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); + if (length > 4) { + short batteryStatus = buf.readUnsignedByte(); + switch (batteryStatus) { + case 1: + position.set(Position.KEY_CHARGE, false); + break; + case 2: + case 3: + position.set(Position.KEY_CHARGE, true); + } + } + if (length > 5) { + position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); + } break; case 0xFE: if (length == 1) { diff --git a/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java index fa8fb2f29..286ebfed1 100644 --- a/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/HuabaoProtocolDecoderTest.java @@ -229,18 +229,10 @@ public class HuabaoProtocolDecoderTest extends ProtocolTest { verifyAttribute(decoder, binary( "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), - Position.KEY_BATTERY, 3.719); - - verifyAttribute(decoder, binary( - "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), Position.KEY_CHARGE, true); verifyAttribute(decoder, binary( "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), - Position.KEY_BATTERY_LEVEL, 70); - - verifyAttribute(decoder, binary( - "7E020000964130564801050048000000001000004F01651E2E02CAEC3802E80000001524062616002101040000000330011F31010EF1040000308CF231414F56585F564C3330302D4C415F48322E315F4547393135554C4141425230334130324D30385F56322E312E305F763130F3011FF400F5080000000000000001F6084008FFFFFFFD0009F70600000E870246F912000F000000010000062A00082406261600184D7E"), Position.KEY_POWER, 12.428); } |