diff options
-rw-r--r-- | src/org/traccar/protocol/UlbotechProtocolDecoder.java | 32 | ||||
-rw-r--r-- | test/org/traccar/protocol/UlbotechProtocolDecoderTest.java | 3 |
2 files changed, 30 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index c4ddca219..ec45be3d1 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -136,6 +136,31 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { return null; } + private void decodeAdc(Position position, ChannelBuffer buf, int length) { + for (int i = 0; i < length / 2; i++) { + int value = buf.readUnsignedShort(); + int id = BitUtil.from(value, 12); + value = BitUtil.to(value, 12); + switch (id) { + case 0: + position.set(Position.KEY_POWER, value * (100 + 10) / 4096.0 - 10); + break; + case 1: + position.set(Position.PREFIX_TEMP + 1, value * (125 + 55) / 4096.0 - 55); + break; + case 2: + position.set(Position.KEY_BATTERY, value * (100 + 10) / 4096.0 - 10); + break; + case 3: + position.set(Position.PREFIX_ADC + 1, value * (100 + 10) / 4096.0 - 10); + break; + default: + position.set(Position.PREFIX_IO + id, value); + break; + } + } + } + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -210,10 +235,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { break; case DATA_ADC: - for (int i = 0; i < length / 2; i++) { - int value = buf.readUnsignedShort(); - position.set(Position.PREFIX_ADC + BitUtil.from(value, 12), BitUtil.to(value, 12)); - } + decodeAdc(position, buf, length); break; case DATA_GEOFENCE: diff --git a/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java b/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java index 2c271976e..9a70080ae 100644 --- a/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java +++ b/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class UlbotechProtocolDecoderTest extends ProtocolTest { UlbotechProtocolDecoder decoder = new UlbotechProtocolDecoder(new UlbotechProtocol()); verifyPosition(decoder, binary( + "f8010108675210214191372010e042010e0292dcd601a999c9000c00900269030400420000040400d87d6e0506034f1754220b070d31056d410c0000310d00312f4a1005f000000200947df8")); + + verifyPosition(decoder, binary( "f8010103515810532780699f7e2e3f010e015ee4c906bde45c00000000008b0304004000000404002c776005060373193622110b00240b00fee8ffff807dffff606d0b00fee9af000000af0000000b00feee7d78807dffffffff100101cc2af8")); verifyPosition(decoder, binary( |