docan_rs/client/service/
session_ctrl.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};
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 session_ctrl(
16 &mut self,
17 r#type: SessionType,
18 suppress_positive: bool,
19 addr_type: AddressType,
20 ) -> DoCanResult<()> {
21 let service = Service::SessionCtrl;
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 let timing = match 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 Some(resp) => Some(
40 resp.data::<response::SessionCtrl>(&cfg)
41 .map_err(DoCanError::Iso14229Error)?
42 .0,
43 ),
44 None => None,
45 };
46
47 if let Some(timing) = timing {
48 self.context.set_session_timing(timing).await;
49 }
50
51 Ok(())
52 }
53}