From 0befd0a50001f2246a657ebc9fe06a548d227234 Mon Sep 17 00:00:00 2001 From: jcardus Date: Mon, 7 Oct 2024 16:54:52 +0100 Subject: [PATCH 1/5] KEY_TYPE --- src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java index 7e5489f19db..5e76a4f89df 100644 --- a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -716,7 +716,7 @@ private Position decodeLocation(DeviceSession deviceSession, ByteBuf buf) { } break; case 0xF6: - buf.readUnsignedByte(); // data type + position.set(Position.KEY_TYPE, buf.readUnsignedByte()); int fieldMask = buf.readUnsignedByte(); if (BitUtil.check(fieldMask, 0)) { buf.readUnsignedShort(); // light From 9bc800fb4a662ff100af220ef8781d8ca71ffb76 Mon Sep 17 00:00:00 2001 From: jcardus Date: Mon, 7 Oct 2024 17:29:18 +0100 Subject: [PATCH 2/5] KEY_EVENT --- src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java index 5e76a4f89df..654f5386c1f 100644 --- a/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/HuabaoProtocolDecoder.java @@ -716,7 +716,7 @@ private Position decodeLocation(DeviceSession deviceSession, ByteBuf buf) { } break; case 0xF6: - position.set(Position.KEY_TYPE, buf.readUnsignedByte()); + position.set(Position.KEY_EVENT, buf.readUnsignedByte()); int fieldMask = buf.readUnsignedByte(); if (BitUtil.check(fieldMask, 0)) { buf.readUnsignedShort(); // light From e21135abfa603cf2c782afaa07e0d8a3ab8c4b1f Mon Sep 17 00:00:00 2001 From: Nikutrax <112165998+Nikutrax@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:25:09 +0200 Subject: [PATCH 3/5] Update TrvProtocolDecoder.java No response for following IWAP Commands: AP76 AP77 Attached is the protocol where the changes are visible. On page 22 you can see AP76/AP77. --- src/main/java/org/traccar/protocol/TrvProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)); } From 25629b99ba1153ecb1ace68761e4214587151152 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 8 Oct 2024 21:24:30 -0700 Subject: [PATCH 4/5] Padlocks G-360P G-508P support --- .../org/traccar/protocol/HuabaoProtocol.java | 2 + .../protocol/HuabaoProtocolDecoder.java | 88 +++++++++++-------- .../protocol/HuabaoProtocolEncoder.java | 25 +++--- 3 files changed, 66 insertions(+), 49 deletions(-) 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 654f5386c1f..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 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); } From 90a8749b04ee6823a8e565e1611857aaa932c7ac Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 10 Oct 2024 15:30:49 -0700 Subject: [PATCH 5/5] Fix position drop check --- src/main/java/org/traccar/schedule/TaskHealthCheck.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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;