From d0536ccbc1b7234784c5e48288bbac00a60ef821 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 7 Jul 2024 07:33:16 -0700 Subject: Update switch statements --- .../traccar/protocol/MeiligaoProtocolDecoder.java | 60 ++++++++-------------- 1 file changed, 21 insertions(+), 39 deletions(-) (limited to 'src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java') diff --git a/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java index 1f8c4d2da..c18b29288 100644 --- a/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -209,30 +209,19 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { } private String decodeAlarm(short value) { - switch (value) { - case 0x01: - return Position.ALARM_SOS; - case 0x10: - return Position.ALARM_LOW_BATTERY; - case 0x11: - return Position.ALARM_OVERSPEED; - case 0x12: - return Position.ALARM_MOVEMENT; - case 0x13: - return Position.ALARM_GEOFENCE_ENTER; - case 0x14: - return Position.ALARM_ACCIDENT; - case 0x50: - return Position.ALARM_POWER_OFF; - case 0x53: - return Position.ALARM_GPS_ANTENNA_CUT; - case 0x72: - return Position.ALARM_BRAKING; - case 0x73: - return Position.ALARM_ACCELERATION; - default: - return null; - } + 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) { @@ -478,21 +467,14 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 4, StandardCharsets.US_ASCII); - switch (command) { - case MSG_POSITION: - case MSG_POSITION_LOGGED: - case MSG_ALARM: - case MSG_POSITION_IMAGE: - return decodeRegular(position, sentence); - case MSG_RFID: - return decodeRfid(position, sentence); - case MSG_OBD_RT: - return decodeObd(position, sentence); - case MSG_OBD_RTA: - return decodeObdA(position, sentence); - default: - return null; - } + return switch (command) { + case MSG_POSITION, MSG_POSITION_LOGGED, MSG_ALARM, MSG_POSITION_IMAGE -> + decodeRegular(position, sentence); + case MSG_RFID -> decodeRfid(position, sentence); + case MSG_OBD_RT -> decodeObd(position, sentence); + case MSG_OBD_RTA -> decodeObdA(position, sentence); + default -> null; + }; } } -- cgit v1.2.3 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 ++++++++++++++++------ .../protocol/MeiligaoProtocolDecoderTest.java | 4 ++ 2 files changed, 44 insertions(+), 15 deletions(-) (limited to 'src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java') 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; }; diff --git a/src/test/java/org/traccar/protocol/MeiligaoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MeiligaoProtocolDecoderTest.java index 8074636a3..8e2f55117 100644 --- a/src/test/java/org/traccar/protocol/MeiligaoProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/MeiligaoProtocolDecoderTest.java @@ -11,6 +11,10 @@ public class MeiligaoProtocolDecoderTest extends ProtocolTest { var decoder = inject(new MeiligaoProtocolDecoder(null)); + verifyAttribute(decoder, binary( + "242400166578902354329399034331453838d2c40d0a"), + Position.KEY_DTCS, "C1E88"); + verifyAttribute(decoder, binary( "2424008f142180340967ff99553033333233302e3030302c412c313531362e383039392c4e2c31303435322e383835352c452c302e30302c33332c3038313232302c2c2a33367c302e387c3132337c323130307c303030302c303030302c303230452c303241417c30323038303030353038394530304531434638347c31437c31373243353832437c3042a8060d0a"), Position.KEY_SATELLITES, 11); -- cgit v1.2.3