diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-10-26 07:12:37 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-10-26 07:12:37 +1300 |
commit | dcc7e0c6ed949604af5e62c671e293f582146bc0 (patch) | |
tree | d8b3f121d1576992e960c0bff58f3a156771a5c9 | |
parent | 5cc40c6fabb4223b0c283164b56c63af310e2eac (diff) | |
download | trackermap-server-dcc7e0c6ed949604af5e62c671e293f582146bc0.tar.gz trackermap-server-dcc7e0c6ed949604af5e62c671e293f582146bc0.tar.bz2 trackermap-server-dcc7e0c6ed949604af5e62c671e293f582146bc0.zip |
Implement Meitrack CCE format
-rw-r--r-- | src/org/traccar/protocol/MeitrackProtocolDecoder.java | 102 | ||||
-rw-r--r-- | test/org/traccar/protocol/MeitrackProtocolDecoderTest.java | 3 |
2 files changed, 101 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 9f6e25d89..5b67aebe3 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -112,7 +112,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { } } - private Position decodeRegularMessage(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { + private Position decodeRegular(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { Parser parser = new Parser(PATTERN, buf.toString(StandardCharsets.US_ASCII)); if (!parser.matches()) { @@ -237,7 +237,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { return position; } - private List<Position> decodeBinaryMessage(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { + private List<Position> decodeBinaryC(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { List<Position> positions = new LinkedList<>(); String flag = buf.toString(2, 1, StandardCharsets.US_ASCII); @@ -311,6 +311,98 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { return positions; } + private List<Position> decodeBinaryE(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) { + List<Position> positions = new LinkedList<>(); + + buf.readerIndex(buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',') + 1); + String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII); + buf.skipBytes(1 + 3 + 1); + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei); + if (deviceSession == null) { + return null; + } + + buf.readUnsignedInt(); // remaining cache + int count = buf.readUnsignedShort(); + + for (int i = 0; i < count; i++) { + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + buf.readUnsignedShort(); // length + buf.readUnsignedShort(); // index + + int paramCount = buf.readUnsignedByte(); + for (int j = 0; j < paramCount; j++) { + int id = buf.readUnsignedByte(); + switch (id) { + case 0x01: + position.set(Position.KEY_EVENT, buf.readUnsignedByte()); + break; + case 0x05: + position.setValid(buf.readUnsignedByte() > 0); + break; + case 0x06: + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); + break; + default: + buf.readUnsignedByte(); + break; + } + } + + paramCount = buf.readUnsignedByte(); + for (int j = 0; j < paramCount; j++) { + int id = buf.readUnsignedByte(); + switch (id) { + case 0x08: + position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort())); + break; + case 0x09: + position.setCourse(buf.readUnsignedShort() * 0.1); + break; + case 0x0B: + position.setAltitude(buf.readShort()); + break; + default: + buf.readUnsignedShort(); + break; + } + } + + paramCount = buf.readUnsignedByte(); + for (int j = 0; j < paramCount; j++) { + int id = buf.readUnsignedByte(); + switch (id) { + case 0x02: + position.setLatitude(buf.readInt() * 0.000001); + break; + case 0x03: + position.setLongitude(buf.readInt() * 0.000001); + break; + case 0x04: + position.setTime(new Date((946684800 + buf.readUnsignedInt()) * 1000)); // 2000-01-01 + break; + default: + buf.readUnsignedInt(); + break; + } + } + + paramCount = buf.readUnsignedByte(); + for (int j = 0; j < paramCount; j++) { + buf.readUnsignedByte(); // id + buf.skipBytes(buf.readUnsignedByte()); // value + } + + positions.add(position); + } + + return positions; + } + private void requestPhotoPacket(Channel channel, String imei, int index) { if (channel != null) { String content = "D00,camera_picture.jpg," + index; @@ -366,9 +458,11 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { requestPhotoPacket(channel, imei, 0); return null; case "CCC": - return decodeBinaryMessage(channel, remoteAddress, buf); + return decodeBinaryC(channel, remoteAddress, buf); + case "CCE": + return decodeBinaryE(channel, remoteAddress, buf); default: - return decodeRegularMessage(channel, remoteAddress, buf); + return decodeRegular(channel, remoteAddress, buf); } } diff --git a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java index 34b2ad579..4ec2211bc 100644 --- a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java +++ b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class MeitrackProtocolDecoderTest extends ProtocolTest { MeitrackProtocolDecoder decoder = new MeitrackProtocolDecoder(new MeitrackProtocol()); + verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN, + "24245f3237382c3836353738393032313434373233322c4343452c5b00000003005000130006012305010608070d15001b0006080000091e010a09000b2e0019a1011af90106025c033300039be60c06044f6678210c6f1806000d48db06001c41000000010e0cf60113002005912b830001ff5000130006012305010608070d15001b0006080000091e010a09000b2e0019a0011af90106025c033300039be60c0604506678210c6f1806000d49db06001c41000000010e0cf60113002005912b830001ff5000130006012305010608070d15001b0006080000091e010a09000b2e0019a1011af90106025c033300039be60c0604516678210c6f1806000d4adb06001c41000000010e0cf60113002005912b830001ff2a37460d0a")); + verifyPosition(decoder, buffer( "$$V177,863835026871173,AAA,35,34.516428,10.470160,170915154043,A,9,12,68,74,0.9,9,1988259,525882,605|2|008C|0007B5A6,0200,0003|0000|0000|01A6|0571,00000001,,3,0000,06FB2E,360,511*74")); |