iso14229_1/common/
response_on_event.rs

1//! Commons of Service 86
2
3
4use std::collections::HashSet;
5use lazy_static::lazy_static;
6use crate::{constant::POSITIVE_OFFSET, error::Error, Service};
7use crate::enum_to_vec;
8
9lazy_static!(
10    /// Table 91 — Recommended services to be used with the ResponseOnEvent service(2006)
11    /// Table 96 — Recommended services to be used with the ResponseOnEvent service(2013)
12    /// Table 137 — Recommended services to be used with the ResponseOnEvent service(2020)
13    pub static ref RECOMMENDED_SERVICES: HashSet<Service> = HashSet::from([
14        Service::ReadDID,
15        Service::ReadDTCInfo,
16        #[cfg(any(feature = "std2006", feature = "std2013"))]
17        Service::RoutineCtrl,
18        #[cfg(any(feature = "std2006", feature = "std2013"))]
19        Service::IOCtrl,
20    ]);
21);
22
23enum_to_vec!(
24    pub enum ResponseOnEventType {
25        StopResponseOnEvent = 0x00,
26        OnDTCStatusChange = 0x01,
27        OnChangeOfDataIdentifier = 0x02,
28        ReportActivatedEvents = 0x04,
29        StartResponseOnEvent = 0x05,
30        ClearResponseOnEvent = 0x06,
31        OnComparisonOfValues = 0x07,
32        ReportMostRecentDtcOnStatusChange = 0x08,
33        ReportDTCRecordInformationOnDtcStatusChange = 0x09,
34    }, u8);
35
36#[derive(Debug, Copy, Clone, Eq, PartialEq)]
37pub struct EventType {
38    pub(crate) store_event: bool,
39    pub(crate) event_type: ResponseOnEventType,
40}
41
42impl EventType {
43    #[inline]
44    pub fn new(
45        store_event: bool,
46        event_type: ResponseOnEventType
47    ) -> Self {
48        Self { store_event, event_type }
49    }
50
51    #[inline]
52    pub const fn store_event(&self) -> bool {
53        self.store_event
54    }
55
56    #[inline]
57    pub fn event_type(&self) -> ResponseOnEventType {
58        self.event_type
59    }
60}
61
62impl Into<u8> for EventType {
63    #[inline]
64    fn into(self) -> u8 {
65        let mut result: u8 = self.event_type.into();
66        if self.store_event {
67            result |= POSITIVE_OFFSET;
68        }
69
70        result
71    }
72}
73