docan_rs/client/service/
ecu_reset.rs1use crate::{client::DoCanClient, DoCanError, DoCanResult};
4use iso14229_1::{response, *};
5use iso15765_2::can::AddressType;
6use rs_can::{CanDevice, CanFrame};
7use std::{fmt::Display, hash::Hash, time::Duration};
8
9impl<D, C, F> DoCanClient<D, C, F>
10where
11 D: CanDevice<Channel = C, Frame = F> + Clone + Send + 'static,
12 C: Clone + Eq + Display + Hash + Send + Sync + 'static,
13 F: CanFrame<Channel = C> + Clone + Display + 'static,
14{
15 pub async fn ecu_reset(
16 &mut self,
17 r#type: ECUResetType,
18 suppress_positive: bool,
19 addr_type: AddressType,
20 ) -> DoCanResult<()> {
21 let service = Service::ECUReset;
22 let mut sub_func: u8 = r#type.into();
23 if suppress_positive {
24 sub_func |= SUPPRESS_POSITIVE;
25 }
26 let cfg = self.context.get_cfg().await;
27 let request = Self::make_request(service, Some(sub_func), vec![], &cfg)?;
28
29 if let Some(response) = self
30 .suppress_positive_sr(
31 addr_type,
32 request,
33 suppress_positive,
34 Some((r#type.into(), service)),
35 &cfg,
36 )
37 .await?
38 {
39 let resp = response
40 .data::<response::ECUReset>(&cfg)
41 .map_err(DoCanError::Iso14229Error)?;
42 if let Some(seconds) = resp.second {
43 tokio::time::sleep(Duration::from_secs(seconds as u64)).await;
44 }
45 }
46
47 Ok(())
48 }
49}