diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2019-01-14 21:14:42 -0800 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2019-01-14 21:14:49 -0800 |
commit | 1bac465930c1edf34202cee069362e7e82c00d95 (patch) | |
tree | 992a03c1b7d3572b3ed607e6b438818c411373bc | |
parent | ff0572b84c85f2bcfb177d1fe7a119a6dc51627a (diff) | |
download | trackermap-server-1bac465930c1edf34202cee069362e7e82c00d95.tar.gz trackermap-server-1bac465930c1edf34202cee069362e7e82c00d95.tar.bz2 trackermap-server-1bac465930c1edf34202cee069362e7e82c00d95.zip |
Support EKAS protocol
-rw-r--r-- | src/org/traccar/protocol/CellocatorProtocolDecoder.java | 62 | ||||
-rw-r--r-- | test/org/traccar/protocol/CellocatorProtocolDecoderTest.java | 3 |
2 files changed, 45 insertions, 20 deletions
diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java index fb805658a..453d8d7e7 100644 --- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java +++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2013 - 2019 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. @@ -88,6 +88,8 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { ByteBuf buf = (ByteBuf) msg; + boolean alternative = buf.getByte(buf.readerIndex() + 3) != 'P'; + buf.skipBytes(4); // system code int type = buf.readUnsignedByte(); long deviceUniqueId = buf.readUnsignedIntLE(); @@ -111,40 +113,60 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_VERSION_HW, buf.readUnsignedByte()); position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte()); - position.set("protocolVersion", buf.readUnsignedByte()); + buf.readUnsignedByte(); // protocol version - position.set(Position.KEY_STATUS, buf.getUnsignedByte(buf.readerIndex()) & 0x0f); + position.set(Position.KEY_STATUS, buf.readUnsignedByte() & 0x0f); - int operator = (buf.readUnsignedByte() & 0xf0) << 4; - operator += buf.readUnsignedByte(); + if (alternative) { + buf.readUnsignedByte(); // configuration flags + } else { + buf.readUnsignedByte(); // operator + } buf.readUnsignedByte(); // reason data position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte())); position.set("mode", buf.readUnsignedByte()); - position.set(Position.PREFIX_IO + 1, buf.readUnsignedIntLE()); - - operator <<= 8; - operator += buf.readUnsignedByte(); - position.set(Position.KEY_OPERATOR, operator); + position.set(Position.KEY_INPUT, buf.readUnsignedIntLE()); + + if (alternative) { + buf.readUnsignedByte(); // input + position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShortLE()); + position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShortLE()); + } else { + buf.readUnsignedByte(); // operator + position.set(Position.PREFIX_ADC + 1, buf.readUnsignedIntLE()); + } - position.set(Position.PREFIX_ADC + 1, buf.readUnsignedIntLE()); position.set(Position.KEY_ODOMETER, buf.readUnsignedMediumLE()); - buf.skipBytes(6); // multi-purpose data - position.set(Position.KEY_GPS, buf.readUnsignedShortLE()); - position.set("locationStatus", buf.readUnsignedByte()); - position.set("mode1", buf.readUnsignedByte()); - position.set("mode2", buf.readUnsignedByte()); + buf.skipBytes(6); // multi-purpose data + buf.readUnsignedShortLE(); // fix time + buf.readUnsignedByte(); // location status + buf.readUnsignedByte(); // mode 1 + buf.readUnsignedByte(); // mode 2 position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.setValid(true); - position.setLongitude(buf.readIntLE() / Math.PI * 180 / 100000000); - position.setLatitude(buf.readIntLE() / Math.PI * 180 / 100000000.0); + + if (alternative) { + position.setLongitude(buf.readIntLE() / 10000000.0); + position.setLatitude(buf.readIntLE() / 10000000.0); + } else { + position.setLongitude(buf.readIntLE() / Math.PI * 180 / 100000000); + position.setLatitude(buf.readIntLE() / Math.PI * 180 / 100000000); + } + position.setAltitude(buf.readIntLE() * 0.01); - position.setSpeed(UnitsConverter.knotsFromMps(buf.readIntLE() * 0.01)); - position.setCourse(buf.readUnsignedShortLE() / Math.PI * 180.0 / 1000.0); + + if (alternative) { + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedIntLE())); + position.setCourse(buf.readUnsignedShortLE() / 1000.0); + } else { + position.setSpeed(UnitsConverter.knotsFromMps(buf.readUnsignedIntLE() * 0.01)); + position.setCourse(buf.readUnsignedShortLE() / Math.PI * 180.0 / 1000.0); + } DateBuilder dateBuilder = new DateBuilder() .setTimeReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()) diff --git a/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java b/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java index 602cd4eac..769760fa5 100644 --- a/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java +++ b/test/org/traccar/protocol/CellocatorProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class CellocatorProtocolDecoderTest extends ProtocolTest { CellocatorProtocolDecoder decoder = new CellocatorProtocolDecoder(null); verifyPosition(decoder, binary( + "4d4350470041420f000402021226d8a70221d801010000000001000000000000000000000000c4d90000000ca7a741ff0096dd15a40700000000000000001619130c01e307e4")); + + verifyPosition(decoder, binary( "4D434750008AD01500080103011804000000460020000000005E750000000000000000000000C34300040204DA4DA30367195703E803000000000000000001030F0802E10778")); verifyPosition(decoder, binary( |