diff options
author | Renaud Allard <renaud@allard.it> | 2016-10-20 08:31:57 +0200 |
---|---|---|
committer | Renaud Allard <renaud@allard.it> | 2016-10-20 08:31:57 +0200 |
commit | 1104c2738e19579c5865db5c030388e1e320f0b4 (patch) | |
tree | a6571455b6f5d88581c8034bd1059968d506ed01 /src/org/traccar/protocol | |
parent | 0d347cd7aac2ebfad01c1635f3893964be2e67ae (diff) | |
parent | 4f7356cc1c6962f46ca522246d5b63dc06a2d268 (diff) | |
download | trackermap-server-1104c2738e19579c5865db5c030388e1e320f0b4.tar.gz trackermap-server-1104c2738e19579c5865db5c030388e1e320f0b4.tar.bz2 trackermap-server-1104c2738e19579c5865db5c030388e1e320f0b4.zip |
Merge branch 'master' of https://github.com/tananaev/traccar
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r-- | src/org/traccar/protocol/H02FrameDecoder.java | 16 | ||||
-rw-r--r-- | src/org/traccar/protocol/H02Protocol.java | 2 | ||||
-rw-r--r-- | src/org/traccar/protocol/RuptelaProtocolDecoder.java | 32 |
3 files changed, 36 insertions, 14 deletions
diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java index feba8033d..2a005e760 100644 --- a/src/org/traccar/protocol/H02FrameDecoder.java +++ b/src/org/traccar/protocol/H02FrameDecoder.java @@ -22,6 +22,9 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder; public class H02FrameDecoder extends FrameDecoder { + private static final int MESSAGE_SHORT = 32; + private static final int MESSAGE_LONG = 45; + private int messageLength; public H02FrameDecoder(int messageLength) { @@ -49,10 +52,17 @@ public class H02FrameDecoder extends FrameDecoder { return buf.readBytes(index + 1 - buf.readerIndex()); } - } else if (marker == '$' && buf.readableBytes() >= messageLength) { + } else if (marker == '$') { - // Return binary message - return buf.readBytes(messageLength); + if (messageLength > 0 && buf.readableBytes() >= messageLength) { + return buf.readBytes(messageLength); + } else if (buf.readableBytes() >= MESSAGE_SHORT) { + if (buf.getUnsignedByte(buf.readerIndex() + MESSAGE_SHORT - 1) == 0) { + return buf.readBytes(MESSAGE_SHORT); + } else if (buf.readableBytes() >= MESSAGE_LONG) { + return buf.readBytes(MESSAGE_LONG); + } + } } diff --git a/src/org/traccar/protocol/H02Protocol.java b/src/org/traccar/protocol/H02Protocol.java index 06ac2a6fa..089721aed 100644 --- a/src/org/traccar/protocol/H02Protocol.java +++ b/src/org/traccar/protocol/H02Protocol.java @@ -43,7 +43,7 @@ public class H02Protocol extends BaseProtocol { serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { @Override protected void addSpecificHandlers(ChannelPipeline pipeline) { - int messageLength = Context.getConfig().getInteger(getName() + ".messageLength", 32); + int messageLength = Context.getConfig().getInteger(getName() + ".messageLength"); pipeline.addLast("frameDecoder", new H02FrameDecoder(messageLength)); pipeline.addLast("stringEncoder", new StringEncoder()); pipeline.addLast("objectEncoder", new H02ProtocolEncoder()); diff --git a/src/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/org/traccar/protocol/RuptelaProtocolDecoder.java index 224c027f3..84cc0e101 100644 --- a/src/org/traccar/protocol/RuptelaProtocolDecoder.java +++ b/src/org/traccar/protocol/RuptelaProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2014 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder { } public static final int MSG_RECORDS = 1; + public static final int MSG_EXTENDED_RECORDS = 68; public static final int MSG_SMS_VIA_GPRS = 108; @Override @@ -53,7 +54,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder { int type = buf.readUnsignedByte(); - if (type == MSG_RECORDS) { + if (type == MSG_RECORDS || type == MSG_EXTENDED_RECORDS) { List<Position> positions = new LinkedList<>(); buf.readUnsignedByte(); // records left @@ -67,45 +68,56 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder { position.setTime(new Date(buf.readUnsignedInt() * 1000)); buf.readUnsignedByte(); // timestamp extension + if (type == MSG_EXTENDED_RECORDS) { + buf.readUnsignedByte(); // record extension + } + buf.readUnsignedByte(); // priority (reserved) + position.setValid(true); position.setLongitude(buf.readInt() / 10000000.0); position.setLatitude(buf.readInt() / 10000000.0); position.setAltitude(buf.readUnsignedShort() / 10.0); position.setCourse(buf.readUnsignedShort() / 100.0); - int satellites = buf.readUnsignedByte(); - position.set(Position.KEY_SATELLITES, satellites); - position.setValid(satellites >= 3); + position.set(Position.KEY_SATELLITES, buf.readUnsignedByte()); position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort())); position.set(Position.KEY_HDOP, buf.readUnsignedByte() / 10.0); - buf.readUnsignedByte(); + if (type == MSG_EXTENDED_RECORDS) { + buf.readUnsignedShort(); // event + } else { + buf.readUnsignedByte(); // event + } // Read 1 byte data int cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - position.set(Position.PREFIX_IO + buf.readUnsignedByte(), buf.readUnsignedByte()); + int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte(); + position.set(Position.PREFIX_IO + id, buf.readUnsignedByte()); } // Read 2 byte data cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - position.set(Position.PREFIX_IO + buf.readUnsignedByte(), buf.readUnsignedShort()); + int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte(); + position.set(Position.PREFIX_IO + id, buf.readUnsignedShort()); } // Read 4 byte data cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - position.set(Position.PREFIX_IO + buf.readUnsignedByte(), buf.readUnsignedInt()); + int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte(); + position.set(Position.PREFIX_IO + id, buf.readUnsignedInt()); } // Read 8 byte data cnt = buf.readUnsignedByte(); for (int j = 0; j < cnt; j++) { - position.set(Position.PREFIX_IO + buf.readUnsignedByte(), buf.readLong()); + int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte(); + position.set(Position.PREFIX_IO + id, buf.readLong()); } positions.add(position); |