aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/HuabaoProtocolDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-06-25 07:09:17 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-06-25 07:09:17 +1200
commit3c492dc734d79d13ce0ea9d5a8c7667fc82b9377 (patch)
tree0ec1622e2b9fa73991a0e52b4124c53c2aa278e1 /src/org/traccar/protocol/HuabaoProtocolDecoder.java
parent05139e49bce1d7b5bf90f3ecbe78739450e3c0bf (diff)
downloadtrackermap-server-3c492dc734d79d13ce0ea9d5a8c7667fc82b9377.tar.gz
trackermap-server-3c492dc734d79d13ce0ea9d5a8c7667fc82b9377.tar.bz2
trackermap-server-3c492dc734d79d13ce0ea9d5a8c7667fc82b9377.zip
Support Huabao batched locations
Diffstat (limited to 'src/org/traccar/protocol/HuabaoProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/HuabaoProtocolDecoder.java92
1 files changed, 60 insertions, 32 deletions
diff --git a/src/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/org/traccar/protocol/HuabaoProtocolDecoder.java
index afb29e3c3..b92840dfc 100644
--- a/src/org/traccar/protocol/HuabaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/HuabaoProtocolDecoder.java
@@ -31,6 +31,8 @@ import org.traccar.model.Position;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
+import java.util.LinkedList;
+import java.util.List;
import java.util.TimeZone;
public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
@@ -44,6 +46,7 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_TERMINAL_REGISTER_RESPONSE = 0x8100;
public static final int MSG_TERMINAL_AUTH = 0x0102;
public static final int MSG_LOCATION_REPORT = 0x0200;
+ public static final int MSG_LOCATION_BATCH = 0x0704;
public static final int MSG_OIL_CONTROL = 0XA006;
public static final int RESULT_SUCCESS = 0;
@@ -134,52 +137,77 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
} else if (type == MSG_LOCATION_REPORT) {
- Position position = new Position(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
+ return decodeLocation(deviceSession, buf);
- position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedInt()));
+ } else if (type == MSG_LOCATION_BATCH) {
- int flags = buf.readInt();
+ return decodeLocationBatch(deviceSession, buf);
- position.set(Position.KEY_IGNITION, BitUtil.check(flags, 0));
+ }
- position.setValid(BitUtil.check(flags, 1));
+ return null;
+ }
- double lat = buf.readUnsignedInt() * 0.000001;
- double lon = buf.readUnsignedInt() * 0.000001;
+ private Position decodeLocation(DeviceSession deviceSession, ByteBuf buf) {
- if (BitUtil.check(flags, 2)) {
- position.setLatitude(-lat);
- } else {
- position.setLatitude(lat);
- }
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
- if (BitUtil.check(flags, 3)) {
- position.setLongitude(-lon);
- } else {
- position.setLongitude(lon);
- }
+ position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedInt()));
- position.setAltitude(buf.readShort());
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1));
- position.setCourse(buf.readUnsignedShort());
+ int flags = buf.readInt();
- DateBuilder dateBuilder = new DateBuilder(TimeZone.getTimeZone("GMT+8"))
- .setYear(BcdUtil.readInteger(buf, 2))
- .setMonth(BcdUtil.readInteger(buf, 2))
- .setDay(BcdUtil.readInteger(buf, 2))
- .setHour(BcdUtil.readInteger(buf, 2))
- .setMinute(BcdUtil.readInteger(buf, 2))
- .setSecond(BcdUtil.readInteger(buf, 2));
- position.setTime(dateBuilder.getDate());
+ position.set(Position.KEY_IGNITION, BitUtil.check(flags, 0));
- // additional information
+ position.setValid(BitUtil.check(flags, 1));
- return position;
+ double lat = buf.readUnsignedInt() * 0.000001;
+ double lon = buf.readUnsignedInt() * 0.000001;
+ if (BitUtil.check(flags, 2)) {
+ position.setLatitude(-lat);
+ } else {
+ position.setLatitude(lat);
}
- return null;
+ if (BitUtil.check(flags, 3)) {
+ position.setLongitude(-lon);
+ } else {
+ position.setLongitude(lon);
+ }
+
+ position.setAltitude(buf.readShort());
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1));
+ position.setCourse(buf.readUnsignedShort());
+
+ DateBuilder dateBuilder = new DateBuilder(TimeZone.getTimeZone("GMT+8"))
+ .setYear(BcdUtil.readInteger(buf, 2))
+ .setMonth(BcdUtil.readInteger(buf, 2))
+ .setDay(BcdUtil.readInteger(buf, 2))
+ .setHour(BcdUtil.readInteger(buf, 2))
+ .setMinute(BcdUtil.readInteger(buf, 2))
+ .setSecond(BcdUtil.readInteger(buf, 2));
+ position.setTime(dateBuilder.getDate());
+
+ // additional information
+
+ return position;
+ }
+
+ private List<Position> decodeLocationBatch(DeviceSession deviceSession, ByteBuf buf) {
+
+ List<Position> positions = new LinkedList<>();
+
+ int count = buf.readUnsignedShort();
+ buf.readUnsignedByte(); // location type
+
+ for (int i = 0; i < count; i++) {
+ int endIndex = buf.readUnsignedShort() + buf.readerIndex();
+ positions.add(decodeLocation(deviceSession, buf));
+ buf.readerIndex(endIndex);
+ }
+
+ return positions;
}
}