iso14229_1/request/
response_on_event.rs

1//! request of Service 86
2
3
4use bitfield_struct::bitfield;
5use crate::{Configuration, Error, enum_to_vec, EventType, RequestData, ResponseOnEventType, Service, Placeholder};
6
7enum_to_vec!(
8    /// Table 142 — Comparison logic parameter definition
9    pub enum ComparisonLogicID {
10        LessThan = 0x01,
11        LargerThan = 0x02,
12        Equal = 0x03,
13        NotEqual = 0x04,
14    }, u8);
15
16/// Table 143 — Localization of value 16 bit bitfield parameter definition
17///
18/// ### Repr: `u16`
19/// | Field   | Size (bits) | note |
20/// |---------|-------------|-------------------------------------------------------|
21/// | sign    | 1           | 0 means comparison without sign.                      |
22/// |         |             | 1 means comparison with sign.                         |
23/// | length  | 5           | The value 0x00 shall be used to compare all 4 bytes.  |
24/// |         |             | All other values shall set the size in bits.          |
25/// |         |             | With 5 bits, the maximal size of a length is 31 bits. |
26/// | offset  | 10          | Offset on the positive response message from where to |
27/// |         |             | extract the data identifier value.                    |
28#[bitfield(u16, order = Msb)]
29pub struct Localization {
30    #[bits(1)]
31    sign: bool,
32    #[bits(5)]
33    length: u8,
34    #[bits(10)]
35    offset: u16,
36}
37
38impl Localization {
39    #[inline]
40    pub const fn is_sign(&self) -> bool {
41        self.sign()
42    }
43
44    #[inline]
45    pub fn sign_set(&mut self, value: bool) -> &mut Self {
46        self.set_sign(value);
47        self
48    }
49
50    #[inline]
51    pub const fn length_value(&self) -> u8 {
52        self.length()
53    }
54
55    #[inline]
56    pub fn length_set(&mut self, value: u8) -> &mut Self {
57        self.set_length(value);
58        self
59    }
60
61    #[inline]
62    pub const fn offset_value(&self) -> u16 {
63        self.offset()
64    }
65
66    #[inline]
67    pub fn offset_set(&mut self, value: u16) -> &mut Self {
68        self.set_offset(value);
69        self
70    }
71}
72
73#[repr(u8)]
74#[derive(Debug, Clone)]
75pub enum EventTypeParameter {
76    StopResponseOnEvent = 0x00,
77    OnDTCStatusChange {
78        test_failed: u8,
79        service: Service,
80        sub_func: u8,
81        dtc_status_mask: u8,
82    } = 0x01,   // Comparison Parameter < Measured Value
83    OnChangeOfDataIdentifier {
84        did: u16,
85        service: Service,
86    } = 0x03,   // Comparison Parameter > Measured Value
87    ReportActivatedEvents = 0x04,
88    StartResponseOnEvent = 0x05,        //
89    ClearResponseOnEvent = 0x06,
90    OnComparisonOfValues {
91        did: u16,
92        logic_id: ComparisonLogicID,
93        comparison_ref: u32,
94        hysteresis_value: u8,
95        localization: Localization,
96        service: Service,
97        response_did: u16,      //
98    } = 0x07,        // C2
99    ReportMostRecentDtcOnStatusChange {
100        report_type: u8,
101    } = 0x08,   // C2
102    ReportDTCRecordInformationOnDtcStatusChange {
103        dtc_status_mask: u8,
104        dtc_sub_func: u8,
105        dtc_ext_data_record_num: u8,
106    } = 0x09, // C2
107}
108
109#[derive(Debug, Clone)]
110pub struct ResponseOnEvent {
111    pub window_time: u8,            // unit of window time is `s`(seconds)
112    pub param: EventTypeParameter,
113}
114
115#[allow(unused_variables)]
116impl<'a> TryFrom<&'a [u8]> for ResponseOnEvent {
117    type Error = Error;
118    fn try_from(data: &'a [u8]) -> Result<Self, Self::Error> {
119        return Err(Error::OtherError("This library does not yet support".to_string()))
120    }
121}
122
123impl Into<Vec<u8>> for ResponseOnEvent {
124    fn into(self) -> Vec<u8> {
125        panic!("This library does not yet support");
126    }
127}
128
129impl RequestData for ResponseOnEvent {
130    type SubFunc = Placeholder;
131    #[inline]
132    fn try_parse(data: &[u8], _: Option<Self::SubFunc>, _: &Configuration) -> Result<Self, Error> {
133        Self::try_from(data)
134    }
135    #[inline]
136    fn to_vec(self, _: &Configuration) -> Vec<u8> {
137        self.into()
138    }
139}
140