Skip to content

Commit

Permalink
Additional TopFlyTech attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Aug 11, 2021
1 parent a7288ed commit 0caa8a3
Showing 1 changed file with 83 additions and 5 deletions.
88 changes: 83 additions & 5 deletions src/main/java/org/traccar/protocol/T800xProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public T800xProtocolDecoder(Protocol protocol) {
public static final int MSG_GPS = 0x02;
public static final int MSG_HEARTBEAT = 0x03;
public static final int MSG_ALARM = 0x04;
public static final int MSG_NETWORK = 0x05;
public static final int MSG_NETWORK = 0x05; // 0x2727
public static final int MSG_DRIVER_BEHAVIOR_1 = 0x05; // 0x2626
public static final int MSG_DRIVER_BEHAVIOR_2 = 0x06; // 0x2626
public static final int MSG_BLE = 0x10;
public static final int MSG_COMMAND = 0x81;

Expand Down Expand Up @@ -140,7 +142,7 @@ protected Object decode(

return decodePosition(channel, deviceSession, buf, type, index, imei);

} else if (type == MSG_NETWORK) {
} else if (type == MSG_NETWORK && header == 0x2727) {

Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
Expand All @@ -159,6 +161,52 @@ protected Object decode(

return position;

} else if ((type == MSG_DRIVER_BEHAVIOR_1 || type == MSG_DRIVER_BEHAVIOR_2) && header == 0x2626) {

Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());

switch (buf.readUnsignedByte()) {
case 0:
case 4:
position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
break;
case 1:
case 3:
case 5:
position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
break;
case 2:
if (type == MSG_DRIVER_BEHAVIOR_1) {
position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
} else {
position.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
}
break;
default:
break;
}

position.setTime(readDate(buf));

if (type == MSG_DRIVER_BEHAVIOR_2) {
int status = buf.readUnsignedByte();
position.setValid(!BitUtil.check(status, 7));
buf.skipBytes(5); // acceleration
} else {
position.setValid(true);
}

position.setAltitude(buf.readFloatLE());
position.setLongitude(buf.readFloatLE());
position.setLatitude(buf.readFloatLE());
position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4) * 0.1));
position.setCourse(buf.readUnsignedShort());

position.set(Position.KEY_RPM, buf.readUnsignedShort());

return position;

} else if (type == MSG_BLE) {

return decodeBle(channel, deviceSession, buf, type, index, imei);
Expand Down Expand Up @@ -389,10 +437,40 @@ private Position decodePosition(
buf.readUnsignedShort(); // distance upload interval
buf.readUnsignedByte(); // heartbeat

} else if (buf.readableBytes() >= 2) {

position.set(Position.KEY_POWER, BcdUtil.readInteger(buf, 4) * 0.01);
} else {

if (buf.readableBytes() >= 2) {
position.set(Position.KEY_POWER, BcdUtil.readInteger(buf, 4) * 0.01);
}
if (buf.readableBytes() >= 19) {
position.set(Position.KEY_OBD_SPEED, BcdUtil.readInteger(buf, 4) * 0.01);
position.set(Position.KEY_FUEL_USED, buf.readUnsignedInt() * 0.001);
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt() * 0.001);
position.set(Position.KEY_RPM, buf.readUnsignedShort());
int value;
value = buf.readUnsignedByte();
if (value != 0xff) {
position.set("airInput", value);
}
if (value != 0xff) {
position.set("airPressure", value);
}
if (value != 0xff) {
position.set(Position.KEY_COOLANT_TEMP, value - 40);
}
if (value != 0xff) {
position.set("airTemp", value - 40);
}
if (value != 0xff) {
position.set(Position.KEY_ENGINE_LOAD, value);
}
if (value != 0xff) {
position.set(Position.KEY_THROTTLE, value);
}
if (value != 0xff) {
position.set(Position.KEY_FUEL_LEVEL, value);
}
}
}

sendResponse(channel, header, type, index, imei, alarm);
Expand Down

0 comments on commit 0caa8a3

Please sign in to comment.