iso14229_1/request/
response_on_event.rs1use bitfield_struct::bitfield;
5use crate::{Configuration, Error, enum_to_vec, EventType, RequestData, ResponseOnEventType, Service, Placeholder};
6
7enum_to_vec!(
8 pub enum ComparisonLogicID {
10 LessThan = 0x01,
11 LargerThan = 0x02,
12 Equal = 0x03,
13 NotEqual = 0x04,
14 }, u8);
15
16#[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, OnChangeOfDataIdentifier {
84 did: u16,
85 service: Service,
86 } = 0x03, ReportActivatedEvents = 0x04,
88 StartResponseOnEvent = 0x05, 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, } = 0x07, ReportMostRecentDtcOnStatusChange {
100 report_type: u8,
101 } = 0x08, ReportDTCRecordInformationOnDtcStatusChange {
103 dtc_status_mask: u8,
104 dtc_sub_func: u8,
105 dtc_ext_data_record_num: u8,
106 } = 0x09, }
108
109#[derive(Debug, Clone)]
110pub struct ResponseOnEvent {
111 pub window_time: u8, 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