11//! Module for common Diagnostic trouble code data
2+ use bitflags:: bitflags;
23
34#[ derive( Debug , Copy , Clone , PartialEq , Eq , PartialOrd , Ord ) ]
45/// DTC name interpretation format specifier
@@ -27,33 +28,26 @@ pub(crate) fn dtc_format_from_uds(fmt: u8) -> DTCFormatType {
2728 }
2829}
2930
30- #[ derive( Debug , Copy , Clone , PartialEq , Eq , PartialOrd , Ord ) ]
31- /// Storage state of the DTC
32- pub enum DTCStatus {
33- /// No DTC is stored in non volatile memory
34- None ,
35- /// DTC has not met criteria for it to become active or stored,
36- /// but a failure condition has been met
37- Pending ,
38- /// DTC is no longer present, but is stored in non volatile memory
39- Stored ,
40- /// DTC is present and stored in non volatile memory
41- Active ,
42- /// Permanent (Can NOT be cleared from the ECU!)
43- Permanent ,
44- /// Unknown DTC Status
45- Unknown ( u8 ) ,
46- }
47-
48- impl DTCStatus {
49- pub ( crate ) fn from_kwp_status ( x : u8 ) -> DTCStatus {
50- match ( x & 0b01100000 ) >> 5 {
51- 0b00 => Self :: None ,
52- 0b01 => Self :: Stored ,
53- 0b10 => Self :: Pending ,
54- 0b11 => Self :: Active ,
55- _ => Self :: Unknown ( x & 0b01100000 ) , // Should never happen
56- }
31+ bitflags ! {
32+ /// DTC Status byte according to D.2 of ISO14229
33+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord ) ]
34+ pub struct DtcStatusByte : u8 {
35+ /// Most recent check has failed
36+ const TEST_FAILED = 0b00000001 ;
37+ /// Test failed at any time in the most recent operation cycle
38+ const TEST_FAILED_THIS_OPERATION_CYCLE = 0b00000010 ;
39+ /// DTC is pending
40+ const PENDING_DTC = 0b00000100 ;
41+ /// DTC is stored
42+ const CONFIRMED_DTC = 0b00001000 ;
43+ /// DTC check has not been completed since cleared
44+ const TEST_NOT_COMPLETED_SINCE_LAST_CLEAR = 0b00010000 ;
45+ /// DTC failed since the last clear
46+ const TEST_FAILED_SINCE_LAST_CLEAR = 0b00100000 ;
47+ /// DTC check has not been completed this operation cycle
48+ const TEST_NOT_COMPLETED_THIS_OP_CYCLE = 0b01000000 ;
49+ /// Check engine lamp is requested
50+ const WARNING_INDICATOR_REQUESTED = 0b10000000 ;
5751 }
5852}
5953
@@ -66,13 +60,7 @@ pub struct DTC {
6660 /// The raw value of the DTC according to the ECU
6761 pub raw : u32 ,
6862 /// Status of the DTC
69- pub status : DTCStatus ,
70- /// Indication if the DTC turns on the MIL lamp (Malfunction indicator lamp).
71- /// This usually means that the Check engine light is illuminated on the
72- /// vehicles instrument cluster
73- pub mil_on : bool ,
74- /// Indication if the DTC conditions have been met since the last clear.
75- pub readiness_flag : bool ,
63+ pub status : DtcStatusByte ,
7664}
7765
7866impl DTC {
@@ -124,9 +112,7 @@ pub mod test {
124112 let iso15031_6_dtc = DTC {
125113 format : super :: DTCFormatType :: Iso15031_6 ,
126114 raw : 8276 ,
127- status : super :: DTCStatus :: None ,
128- mil_on : false ,
129- readiness_flag : false ,
115+ status : super :: DtcStatusByte :: empty ( )
130116 } ;
131117 println ! ( "{:04X}" , iso15031_6_dtc. raw) ;
132118 println ! ( "{}" , iso15031_6_dtc. get_name_as_string( ) ) ;
0 commit comments