uds_client/uds_client/services/
ecu_reset.rs

1//!  Provides methods to reset the ECU that includes soft-reset, hard-reset, ...
2//!
3
4use crate::{
5    socket_can::CanSocketTx,
6    uds_client::{DiagError, PciByte, UdsClient},
7};
8use automotive_diag::uds::UdsCommand;
9
10/// Reset ECU subcommand
11#[repr(u8)]
12#[derive(Debug)]
13pub enum ResetType {
14    RealTime = 0x40,
15    Telematic = 0x41,
16    Imx = 0x42,
17    Esp32Wifi = 0x43,
18    Esp32Ble = 0x44,
19    Lte = 0x45,
20    Lizard = 0x46,
21    Cendric = 0x47,
22}
23
24impl From<ResetType> for u8 {
25    fn from(reset_type: ResetType) -> Self {
26        reset_type as u8
27    }
28}
29
30impl TryFrom<i32> for ResetType {
31    type Error = ();
32    fn try_from(reset_type: i32) -> Result<Self, Self::Error> {
33        match reset_type as u8 {
34            0x40 => Ok(ResetType::RealTime),
35            0x41 => Ok(ResetType::Telematic),
36            0x42 => Ok(ResetType::Imx),
37            0x43 => Ok(ResetType::Esp32Wifi),
38            0x44 => Ok(ResetType::Esp32Ble),
39            0x45 => Ok(ResetType::Lte),
40            0x46 => Ok(ResetType::Lizard),
41            0x47 => Ok(ResetType::Cendric),
42            _ => Err(()),
43        }
44    }
45}
46
47#[allow(dead_code)]
48impl<T: CanSocketTx> UdsClient<'_, T> {
49    /// Service ID: 0x11 - ECU Reset
50    ///     Sub-ID: 0x40
51    /// Description:
52    ///     The function will request an ECU reset event for Realtime chip.
53    pub async fn uds_reset_118(&mut self) -> Result<(), DiagError> {
54        dbg!("UDS: send reset 118");
55        let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
56        self.send_command_with_response(
57            pci_byte,
58            UdsCommand::ECUReset,
59            &[ResetType::RealTime.into()],
60        )
61        .await?;
62        Ok(())
63    }
64
65    /// Service ID: 0x11 - ECU Reset
66    ///     Sub-ID: 0x41
67    /// Description:
68    ///     The function will request an ECU reset event for Telematic chip.
69    pub async fn uds_reset_148(&mut self) -> Result<(), DiagError> {
70        dbg!("UDS: send reset 148");
71        let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
72        self.send_command_with_response(
73            pci_byte,
74            UdsCommand::ECUReset,
75            &[ResetType::Telematic.into()],
76        )
77        .await?;
78        Ok(())
79    }
80
81    /// Service ID: 0x11 - ECU Reset
82    ///     Sub-ID: 0x42
83    /// Description:
84    ///     The function will request an ECU reset event for IMX chip.
85    pub async fn uds_reset_imx(&mut self) -> Result<(), DiagError> {
86        dbg!("UDS: send reset imx");
87        let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
88        self.send_command_with_response(pci_byte, UdsCommand::ECUReset, &[ResetType::Imx.into()])
89            .await?;
90        Ok(())
91    }
92
93    /// Service ID: 0x11 - ECU Reset
94    ///     Sub-ID: 0x43
95    /// Description:
96    ///     The function will request an ECU reset event for Esp-Wifi chip.
97    pub async fn uds_reset_esp32_wifi(&mut self) -> Result<(), DiagError> {
98        dbg!("UDS: send reset esp-wifi");
99        let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
100        self.send_command_with_response(
101            pci_byte,
102            UdsCommand::ECUReset,
103            &[ResetType::Esp32Wifi.into()],
104        )
105        .await?;
106        Ok(())
107    }
108
109    /// Service ID: 0x11 - ECU Reset
110    ///     Sub-ID: 0x44
111    /// Description:
112    ///     The function will request an ECU reset event for Esp-Ble chip.
113    pub async fn uds_reset_esp32_ble(&mut self) -> Result<(), DiagError> {
114        dbg!("UDS: send reset esp-ble");
115        let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
116        self.send_command_with_response(
117            pci_byte,
118            UdsCommand::ECUReset,
119            &[ResetType::Esp32Ble.into()],
120        )
121        .await?;
122        Ok(())
123    }
124
125    /// Service ID: 0x11 - ECU Reset
126    ///     Sub-ID: 0x45
127    /// Description:
128    ///     The function will request an ECU reset event for LTE chip.
129    pub async fn uds_reset_lte(&mut self) -> Result<(), DiagError> {
130        dbg!("UDS: send reset lte");
131        let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
132        self.send_command_with_response(pci_byte, UdsCommand::ECUReset, &[ResetType::Lte.into()])
133            .await?;
134        Ok(())
135    }
136
137    /// Service ID: 0x11 - ECU Reset
138    ///     Sub-ID: 0x46
139    /// Description:
140    ///     The function will request an ECU reset event for Lizard chip.
141    pub async fn uds_reset_lizard(&mut self) -> Result<(), DiagError> {
142        dbg!("UDS: send reset lizard");
143        let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
144        self.send_command_with_response(
145            pci_byte,
146            UdsCommand::ECUReset,
147            &[ResetType::Lizard.into()],
148        )
149        .await?;
150        Ok(())
151    }
152
153    /// Service ID: 0x11 - ECU Reset
154    ///     Sub-ID: 0x47
155    /// Description:
156    ///     The function will request an ECU reset event for Cendric chip.
157    pub async fn uds_reset_cendric(&mut self) -> Result<(), DiagError> {
158        dbg!("UDS: send reset cendric");
159        let pci_byte = PciByte::new(crate::uds_client::PciType::SingleFrame, 2);
160        self.send_command_with_response(
161            pci_byte,
162            UdsCommand::ECUReset,
163            &[ResetType::Cendric.into()],
164        )
165        .await?;
166        Ok(())
167    }
168}