diff options
author | Anton Tananaev <anton@traccar.org> | 2024-07-26 18:02:32 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2024-07-26 18:02:32 -0700 |
commit | 62f1cb5cd3374ac0012c9c054f3556c5e43a8549 (patch) | |
tree | 4ed80c71afeef1a404ab781e0253addc4a6dacf6 | |
parent | 1f6028589096a89fbec98cbe20e609ce6d6c974a (diff) | |
download | trackermap-server-62f1cb5cd3374ac0012c9c054f3556c5e43a8549.tar.gz trackermap-server-62f1cb5cd3374ac0012c9c054f3556c5e43a8549.tar.bz2 trackermap-server-62f1cb5cd3374ac0012c9c054f3556c5e43a8549.zip |
Support TopTen TK218 OBD
-rw-r--r-- | src/main/java/org/traccar/protocol/MeiligaoProtocolDecoder.java | 55 | ||||
-rw-r--r-- | src/test/java/org/traccar/protocol/MeiligaoProtocolDecoderTest.java | 4 |
2 files changed, 44 insertions, 15 deletions
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<Position> decodeRetransmission(ByteBuf buf, DeviceSession deviceSession) { List<Position> 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 @@ -12,6 +12,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); |