From 62f1cb5cd3374ac0012c9c054f3556c5e43a8549 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 26 Jul 2024 18:02:32 -0700 Subject: Support TopTen TK218 OBD --- .../traccar/protocol/MeiligaoProtocolDecoder.java | 55 ++++++++++++++++------ 1 file changed, 40 insertions(+), 15 deletions(-) (limited to 'src/main/java/org/traccar/protocol') diff --git a/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java index c18b29288..524d86289 100644 --- a/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -141,6 +141,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_OBD_RT = 0x9901; public static final int MSG_OBD_RTA = 0x9902; + public static final int MSG_DTC = 0x9903; public static final int MSG_TRACK_ON_DEMAND = 0x4101; public static final int MSG_TRACK_BY_INTERVAL = 0x4102; @@ -208,20 +209,36 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { } } - private String decodeAlarm(short value) { - return switch (value) { - case 0x01 -> Position.ALARM_SOS; - case 0x10 -> Position.ALARM_LOW_BATTERY; - case 0x11 -> Position.ALARM_OVERSPEED; - case 0x12 -> Position.ALARM_MOVEMENT; - case 0x13 -> Position.ALARM_GEOFENCE_ENTER; - case 0x14 -> Position.ALARM_ACCIDENT; - case 0x50 -> Position.ALARM_POWER_OFF; - case 0x53 -> Position.ALARM_GPS_ANTENNA_CUT; - case 0x72 -> Position.ALARM_BRAKING; - case 0x73 -> Position.ALARM_ACCELERATION; - default -> null; - }; + private String decodeAlarm(String model, short value) { + if ("TK218".equals(model)) { + return switch (value) { + case 0x01 -> Position.ALARM_SOS; + case 0x10 -> Position.ALARM_LOW_BATTERY; + case 0x11 -> Position.ALARM_OVERSPEED; + case 0x12 -> Position.ALARM_MOVEMENT; + case 0x13 -> Position.ALARM_GEOFENCE; + case 0x60 -> Position.ALARM_FATIGUE_DRIVING; + case 0x71 -> Position.ALARM_BRAKING; + case 0x72 -> Position.ALARM_ACCELERATION; + case 0x73 -> Position.ALARM_ACCIDENT; + case 0x74 -> Position.ALARM_IDLE; + default -> null; + }; + } else { + return switch (value) { + case 0x01 -> Position.ALARM_SOS; + case 0x10 -> Position.ALARM_LOW_BATTERY; + case 0x11 -> Position.ALARM_OVERSPEED; + case 0x12 -> Position.ALARM_MOVEMENT; + case 0x13 -> Position.ALARM_GEOFENCE_ENTER; + case 0x14 -> Position.ALARM_ACCIDENT; + case 0x50 -> Position.ALARM_POWER_OFF; + case 0x53 -> Position.ALARM_GPS_ANTENNA_CUT; + case 0x72 -> Position.ALARM_BRAKING; + case 0x73 -> Position.ALARM_ACCELERATION; + default -> null; + }; + } } private Position decodeRegular(Position position, String sentence) { @@ -341,6 +358,12 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { return position; } + private Position decodeDtc(Position position, String sentence) { + getLastLocation(position, null); + position.set(Position.KEY_DTCS, sentence.replace(',', ' ')); + return position; + } + private List decodeRetransmission(ByteBuf buf, DeviceSession deviceSession) { List positions = new LinkedList<>(); @@ -437,7 +460,8 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { if (command == MSG_ALARM) { short alarmCode = buf.readUnsignedByte(); - position.set(Position.KEY_ALARM, decodeAlarm(alarmCode)); + String model = getDeviceModel(deviceSession); + position.set(Position.KEY_ALARM, decodeAlarm(model, alarmCode)); if (alarmCode >= 0x02 && alarmCode <= 0x05) { position.set(Position.PREFIX_IN + alarmCode, 1); } else if (alarmCode >= 0x32 && alarmCode <= 0x35) { @@ -473,6 +497,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { case MSG_RFID -> decodeRfid(position, sentence); case MSG_OBD_RT -> decodeObd(position, sentence); case MSG_OBD_RTA -> decodeObdA(position, sentence); + case MSG_DTC -> decodeDtc(position, sentence); default -> null; }; -- cgit v1.2.3