aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java')
-rw-r--r--src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java159
1 files changed, 155 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
index 675a08aef..aa85ea061 100644
--- a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
@@ -34,8 +34,10 @@ import org.traccar.model.Position;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
+import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
+import java.util.TimeZone;
public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
@@ -51,10 +53,14 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_TERMINAL_CONTROL = 0x8105;
public static final int MSG_TERMINAL_AUTH = 0x0102;
public static final int MSG_LOCATION_REPORT = 0x0200;
+ public static final int MSG_ACCELERATION = 0x2070;
public static final int MSG_LOCATION_REPORT_2 = 0x5501;
public static final int MSG_LOCATION_REPORT_BLIND = 0x5502;
public static final int MSG_LOCATION_BATCH = 0x0704;
public static final int MSG_OIL_CONTROL = 0XA006;
+ public static final int MSG_TIME_SYNC_REQUEST = 0x0109;
+ public static final int MSG_TIME_SYNC_RESPONSE = 0x8109;
+ public static final int MSG_PHOTO = 0x8888;
public static final int RESULT_SUCCESS = 0;
@@ -67,7 +73,7 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
if (shortIndex) {
buf.writeByte(1);
} else {
- buf.writeShort(1);
+ buf.writeShort(0);
}
buf.writeBytes(data);
data.release();
@@ -131,6 +137,11 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
return null;
}
+ private int readSignedWord(ByteBuf buf) {
+ int value = buf.readUnsignedShort();
+ return BitUtil.check(value, 15) ? -BitUtil.to(value, 15) : BitUtil.to(value, 15);
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -172,7 +183,7 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
formatMessage(MSG_TERMINAL_REGISTER_RESPONSE, id, false, response), remoteAddress));
}
- } else if (type == MSG_TERMINAL_AUTH || type == MSG_HEARTBEAT) {
+ } else if (type == MSG_TERMINAL_AUTH || type == MSG_HEARTBEAT || type == MSG_PHOTO) {
sendGeneralResponse(channel, remoteAddress, id, type, index);
@@ -192,8 +203,52 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
} else if (type == MSG_LOCATION_BATCH) {
+ sendGeneralResponse(channel, remoteAddress, id, type, index);
+
return decodeLocationBatch(deviceSession, buf);
+ } else if (type == MSG_TIME_SYNC_REQUEST) {
+
+ if (channel != null) {
+ Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
+ ByteBuf response = Unpooled.buffer();
+ response.writeShort(calendar.get(Calendar.YEAR));
+ response.writeByte(calendar.get(Calendar.MONTH) + 1);
+ response.writeByte(calendar.get(Calendar.DAY_OF_MONTH));
+ response.writeByte(calendar.get(Calendar.HOUR_OF_DAY));
+ response.writeByte(calendar.get(Calendar.MINUTE));
+ response.writeByte(calendar.get(Calendar.SECOND));
+ channel.writeAndFlush(new NetworkMessage(
+ formatMessage(MSG_TERMINAL_REGISTER_RESPONSE, id, false, response), remoteAddress));
+ }
+
+ } else if (type == MSG_ACCELERATION) {
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ StringBuilder data = new StringBuilder("[");
+ while (buf.readableBytes() > 2) {
+ buf.skipBytes(6); // time
+ if (data.length() > 1) {
+ data.append(",");
+ }
+ data.append("[");
+ data.append(readSignedWord(buf));
+ data.append(",");
+ data.append(readSignedWord(buf));
+ data.append(",");
+ data.append(readSignedWord(buf));
+ data.append("]");
+ }
+ data.append("]");
+
+ position.set(Position.KEY_G_SENSOR, data.toString());
+
+ return position;
+
}
return null;
@@ -211,6 +266,76 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
return null;
}
+ private void decodeExtension(Position position, ByteBuf buf, int endIndex) {
+ while (buf.readerIndex() < endIndex) {
+ int type = buf.readUnsignedByte();
+ int length = buf.readUnsignedByte();
+ switch (type) {
+ case 0x01:
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100L);
+ break;
+ case 0x02:
+ position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShort() * 0.1);
+ break;
+ case 0x03:
+ position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() * 0.1);
+ break;
+ case 0x80:
+ position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte());
+ break;
+ case 0x81:
+ position.set(Position.KEY_RPM, buf.readUnsignedShort());
+ break;
+ case 0x82:
+ position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.1);
+ break;
+ case 0x83:
+ position.set(Position.KEY_ENGINE_LOAD, buf.readUnsignedByte());
+ break;
+ case 0x84:
+ position.set(Position.KEY_COOLANT_TEMP, buf.readUnsignedByte() - 40);
+ break;
+ case 0x85:
+ position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedShort());
+ break;
+ case 0x86:
+ position.set("intakeTemp", buf.readUnsignedByte() - 40);
+ break;
+ case 0x87:
+ position.set("intakeFlow", buf.readUnsignedShort());
+ break;
+ case 0x88:
+ position.set("intakePressure", buf.readUnsignedByte());
+ break;
+ case 0x89:
+ position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
+ break;
+ case 0x8B:
+ position.set(Position.KEY_VIN, buf.readCharSequence(17, StandardCharsets.US_ASCII).toString());
+ break;
+ case 0x8C:
+ position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 100L);
+ break;
+ case 0x8D:
+ position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort() * 1000L);
+ break;
+ case 0x8E:
+ position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
+ break;
+ case 0xA0:
+ String codes = buf.readCharSequence(length, StandardCharsets.US_ASCII).toString();
+ position.set(Position.KEY_DTCS, codes.replace(',', ' '));
+ break;
+ case 0xCC:
+ position.set(Position.KEY_ICCID, buf.readCharSequence(20, StandardCharsets.US_ASCII).toString());
+ break;
+ default:
+ buf.skipBytes(length);
+ break;
+ }
+ }
+ }
+
private Position decodeLocation(DeviceSession deviceSession, ByteBuf buf) {
Position position = new Position(getProtocolName());
@@ -291,6 +416,11 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_BATTERY, Integer.parseInt(lockStatus.substring(2, 5)) * 0.01);
}
break;
+ case 0x80:
+ buf.readUnsignedByte(); // content
+ endIndex = buf.writerIndex() - 2;
+ decodeExtension(position, buf, endIndex);
+ break;
case 0x91:
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.1);
position.set(Position.KEY_RPM, buf.readUnsignedShort());
@@ -311,6 +441,13 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
Position.KEY_VIN, buf.readCharSequence(length, StandardCharsets.US_ASCII).toString());
}
break;
+ case 0xA7:
+ position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
+ position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
+ break;
+ case 0xAC:
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
+ break;
case 0xD0:
long userStatus = buf.readUnsignedInt();
if (BitUtil.check(userStatus, 3)) {
@@ -368,6 +505,16 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
}
}
break;
+ case 0xED:
+ String license = buf.readCharSequence(length, StandardCharsets.US_ASCII).toString().trim();
+ position.set("driverLicense", license);
+ break;
+ case 0xEE:
+ position.set(Position.KEY_RSSI, buf.readUnsignedByte());
+ position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
+ position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
+ position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
+ break;
default:
break;
}
@@ -429,11 +576,15 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
List<Position> positions = new LinkedList<>();
int count = buf.readUnsignedShort();
- buf.readUnsignedByte(); // location type
+ int locationType = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
int endIndex = buf.readUnsignedShort() + buf.readerIndex();
- positions.add(decodeLocation(deviceSession, buf));
+ Position position = decodeLocation(deviceSession, buf);
+ if (locationType > 0) {
+ position.set(Position.KEY_ARCHIVE, true);
+ }
+ positions.add(position);
buf.readerIndex(endIndex);
}