diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocol.java b/src/main/java/org/traccar/protocol/HuabaoProtocol.java index 575d15b020f..2f8692325a3 100644 --- a/src/main/java/org/traccar/protocol/HuabaoProtocol.java +++ b/src/main/java/org/traccar/protocol/HuabaoProtocol.java @@ -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) { diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java index 7e5489f19db..911fe633fd4 100644 --- a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -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 { @@ -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; @@ -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) { @@ -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()); @@ -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 @@ -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 diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java index ada7e3fba4c..11e34c4e1b6 100644 --- a/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/HuabaoProtocolEncoder.java @@ -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; @@ -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); } diff --git a/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java b/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java index 7ce1b510cc1..c609f18c28d 100644 --- a/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/TrvProtocolDecoder.java @@ -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)); } diff --git a/src/main/java/org/traccar/schedule/TaskHealthCheck.java b/src/main/java/org/traccar/schedule/TaskHealthCheck.java index 56ac4b91d3c..f6621118b62 100644 --- a/src/main/java/org/traccar/schedule/TaskHealthCheck.java +++ b/src/main/java/org/traccar/schedule/TaskHealthCheck.java @@ -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;