uds_client/uds_client/services/
ecu_reset.rs1use crate::{
5 socket_can::CanSocketTx,
6 uds_client::{DiagError, PciByte, UdsClient},
7};
8use automotive_diag::uds::UdsCommand;
9
10#[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 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 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 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 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 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 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 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 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}