Skip to main content

docan_rs/client/service/
communication_ctrl.rs

1//! response of Service 28
2
3use crate::{client::DoCanClient, DoCanError, DoCanResult};
4use iso14229_1::{request, *};
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 communication_control(
16        &mut self,
17        ctrl_type: CommunicationCtrlType,
18        comm_type: CommunicationType,
19        node_id: Option<request::NodeId>,
20        suppress_positive: bool,
21        addr_type: AddressType,
22    ) -> DoCanResult<()> {
23        let service = Service::CommunicationCtrl;
24        let mut sub_func = ctrl_type.into();
25        if suppress_positive {
26            sub_func |= SUPPRESS_POSITIVE;
27        }
28        let data = request::CommunicationCtrl::new(ctrl_type, comm_type, node_id)
29            .map_err(DoCanError::Iso14229Error)?;
30        let cfg = self.context.get_cfg().await;
31        let req = Self::make_request(service, Some(sub_func), data, &cfg)?;
32
33        let _ = self
34            .suppress_positive_sr(
35                addr_type,
36                req,
37                suppress_positive,
38                Some((ctrl_type.into(), service)),
39                &cfg,
40            )
41            .await?;
42
43        Ok(())
44    }
45}