mirror of
https://github.com/traccar/traccar.git
synced 2025-01-08 11:47:49 +08:00
Padlocks G-360P G-508P support
This commit is contained in:
parent
2dd264f84f
commit
25629b99ba
@ -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) {
|
||||
|
@ -41,6 +41,7 @@ import java.util.Calendar;
|
||||
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 class HuabaoProtocolDecoder extends BaseProtocolDecoder {
|
||||
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 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
|
||||
}
|
||||
}
|
||||
|
||||
private String decodeAlarm(long value) {
|
||||
if (BitUtil.check(value, 0)) {
|
||||
return Position.ALARM_SOS;
|
||||
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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private int readSignedWord(ByteBuf buf) {
|
||||
@ -404,10 +414,10 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
|
||||
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 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
|
||||
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
|
||||
|
@ -24,6 +24,7 @@ import org.traccar.helper.DataConverter;
|
||||
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 @@ public class HuabaoProtocolEncoder extends BaseProtocolEncoder {
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user