Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge upstream for version 6.5.1 #37

Merged
merged 8 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/org/traccar/protocol/HuabaoProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class HuabaoProtocol extends BaseProtocol {
@Inject
public HuabaoProtocol(Config config) {
setSupportedDataCommands(
Command.TYPE_ALARM_ARM,
Command.TYPE_ALARM_DISARM,
Command.TYPE_ENGINE_STOP,
Command.TYPE_ENGINE_RESUME);
addServer(new TrackerServer(config, getName(), false) {
Expand Down
90 changes: 52 additions & 38 deletions src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;

public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
Expand Down Expand Up @@ -68,6 +69,7 @@ public HuabaoProtocolDecoder(Protocol protocol) {
public static final int MSG_TIME_SYNC_RESPONSE = 0x8109;
public static final int MSG_PHOTO = 0x8888;
public static final int MSG_TRANSPARENT = 0x0900;
public static final int MSG_PARAMETER_SETTING = 0x0310;

public static final int RESULT_SUCCESS = 0;

Expand Down Expand Up @@ -112,42 +114,50 @@ private void sendGeneralResponse2(
}
}

private String decodeAlarm(long value) {
if (BitUtil.check(value, 0)) {
return Position.ALARM_SOS;
}
if (BitUtil.check(value, 1)) {
return Position.ALARM_OVERSPEED;
}
if (BitUtil.check(value, 5)) {
return Position.ALARM_GPS_ANTENNA_CUT;
}
if (BitUtil.check(value, 4) || BitUtil.check(value, 9)
|| BitUtil.check(value, 10) || BitUtil.check(value, 11)) {
return Position.ALARM_FAULT;
}
if (BitUtil.check(value, 7) || BitUtil.check(value, 18)) {
return Position.ALARM_LOW_BATTERY;
}
if (BitUtil.check(value, 8)) {
return Position.ALARM_POWER_OFF;
}
if (BitUtil.check(value, 15)) {
return Position.ALARM_VIBRATION;
}
if (BitUtil.check(value, 16) || BitUtil.check(value, 17)) {
return Position.ALARM_TAMPERING;
}
if (BitUtil.check(value, 20)) {
return Position.ALARM_GEOFENCE;
}
if (BitUtil.check(value, 28)) {
return Position.ALARM_MOVEMENT;
}
if (BitUtil.check(value, 29) || BitUtil.check(value, 30)) {
return Position.ALARM_ACCIDENT;
private void decodeAlarm(Position position, String model, long value) {
if (model != null && Set.of("G-360P", "G-508P").contains(model)) {
if (BitUtil.check(value, 0) || BitUtil.check(value, 4)) {
position.addAlarm(Position.ALARM_REMOVING);
}
if (BitUtil.check(value, 1)) {
position.addAlarm(Position.ALARM_TAMPERING);
}
} else {
if (BitUtil.check(value, 0)) {
position.addAlarm(Position.ALARM_SOS);
}
if (BitUtil.check(value, 1)) {
position.addAlarm(Position.ALARM_OVERSPEED);
}
if (BitUtil.check(value, 5)) {
position.addAlarm(Position.ALARM_GPS_ANTENNA_CUT);
}
if (BitUtil.check(value, 4) || BitUtil.check(value, 9)
|| BitUtil.check(value, 10) || BitUtil.check(value, 11)) {
position.addAlarm(Position.ALARM_FAULT);
}
if (BitUtil.check(value, 7) || BitUtil.check(value, 18)) {
position.addAlarm(Position.ALARM_LOW_BATTERY);
}
if (BitUtil.check(value, 8)) {
position.addAlarm(Position.ALARM_POWER_OFF);
}
if (BitUtil.check(value, 15)) {
position.addAlarm(Position.ALARM_VIBRATION);
}
if (BitUtil.check(value, 16) || BitUtil.check(value, 17)) {
position.addAlarm(Position.ALARM_TAMPERING);
}
if (BitUtil.check(value, 20)) {
position.addAlarm(Position.ALARM_GEOFENCE);
}
if (BitUtil.check(value, 28)) {
position.addAlarm(Position.ALARM_MOVEMENT);
}
if (BitUtil.check(value, 29) || BitUtil.check(value, 30)) {
position.addAlarm(Position.ALARM_ACCIDENT);
}
}
return null;
}

private int readSignedWord(ByteBuf buf) {
Expand Down Expand Up @@ -404,10 +414,10 @@ private Position decodeLocation(DeviceSession deviceSession, ByteBuf buf) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());

position.addAlarm(decodeAlarm(buf.readUnsignedInt()));

String model = getDeviceModel(deviceSession);

decodeAlarm(position, model, buf.readUnsignedInt());

decodeCoordinates(position, deviceSession, buf);

position.setAltitude(buf.readShort());
Expand Down Expand Up @@ -517,6 +527,10 @@ private Position decodeLocation(DeviceSession deviceSession, ByteBuf buf) {
buf.readUnsignedByte(); // alarm status
position.set("dmsAlarm", buf.readUnsignedByte());
break;
case 0x67:
stringValue = buf.readCharSequence(8, StandardCharsets.US_ASCII).toString();
position.set("password", stringValue);
break;
case 0x70:
buf.readUnsignedInt(); // alarm serial number
buf.readUnsignedByte(); // alarm status
Expand Down Expand Up @@ -716,7 +730,7 @@ private Position decodeLocation(DeviceSession deviceSession, ByteBuf buf) {
}
break;
case 0xF6:
buf.readUnsignedByte(); // data type
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
int fieldMask = buf.readUnsignedByte();
if (BitUtil.check(fieldMask, 0)) {
buf.readUnsignedShort(); // light
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.traccar.helper.model.AttributeUtil;
import org.traccar.model.Command;

import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;

Expand All @@ -46,25 +47,25 @@ protected Object encodeCommand(Command command) {
byte[] time = DataConverter.parseHex(new SimpleDateFormat("yyMMddHHmmss").format(new Date()));

switch (command.getType()) {
case Command.TYPE_ALARM_ARM:
case Command.TYPE_ALARM_DISARM:
data.writeByte(1); // number of parameters
data.writeByte(0x24); // parameter id
String username = "user";
data.writeByte(1 + username.length()); // parameter value length
data.writeByte(command.getType().equals(Command.TYPE_ALARM_ARM) ? 0x01 : 0x00);
data.writeCharSequence(username, StandardCharsets.US_ASCII);
return HuabaoProtocolDecoder.formatMessage(
HuabaoProtocolDecoder.MSG_PARAMETER_SETTING, id, false, data);
case Command.TYPE_ENGINE_STOP:
if (alternative) {
data.writeByte(0x01);
data.writeBytes(time);
return HuabaoProtocolDecoder.formatMessage(
HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, false, data);
} else {
data.writeByte(0xf0);
return HuabaoProtocolDecoder.formatMessage(
HuabaoProtocolDecoder.MSG_TERMINAL_CONTROL, id, false, data);
}
case Command.TYPE_ENGINE_RESUME:
if (alternative) {
data.writeByte(0x00);
data.writeByte(command.getType().equals(Command.TYPE_ENGINE_STOP) ? 0x01 : 0x00);
data.writeBytes(time);
return HuabaoProtocolDecoder.formatMessage(
HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, false, data);
} else {
data.writeByte(0xf1);
data.writeByte(command.getType().equals(Command.TYPE_ENGINE_STOP) ? 0xf0 : 0xf1);
return HuabaoProtocolDecoder.formatMessage(
HuabaoProtocolDecoder.MSG_TERMINAL_CONTROL, id, false, data);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/traccar/protocol/TrvProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ protected Object decode(
channel.writeAndFlush(new NetworkMessage(responseHeader + "," + time + ",0#", remoteAddress));
} else if (type.equals("AP14") && !id.equals("IW")) {
channel.writeAndFlush(new NetworkMessage(responseHeader + ",0.000,0.000#", remoteAddress));
} else if (!Set.of("AP12", "AP14", "AP33", "AP34", "AP84", "AP85").contains(type)
} else if (!Set.of("AP12", "AP14", "AP33", "AP34", "AP76", "AP77", "AP84", "AP85").contains(type)
&& !sentence.substring(responseHeader.length() + 1).matches("^\\d{6}$")) {
channel.writeAndFlush(new NetworkMessage(responseHeader + "#", remoteAddress));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/traccar/schedule/TaskHealthCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void run() {

int messageCurrentTotal = statisticsManager.messageStoredCount();
int messageCurrentPeriod = messageCurrentTotal - messageLastTotal;
if (dropThreshold > 0 && messageLastPeriod > 0) {
if (dropThreshold > 0 && messageLastPeriod > 0 && messageCurrentPeriod > 0) {
double drop = messageCurrentPeriod / (double) messageLastPeriod;
if (drop < dropThreshold) {
success = false;
Expand Down