docan_rs/client/service/
dynamically_define_did.rs1use crate::{client::DoCanClient, DoCanError, DoCanResult};
4use iso14229_1::{request, 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 dynamically_define_data_by_identifier(
16 &mut self,
17 r#type: DefinitionType,
18 data: request::DynamicallyDefineDID,
19 suppress_positive: bool,
20 ) -> DoCanResult<Option<response::DynamicallyDefineDID>> {
21 let service = Service::DynamicalDefineDID;
22 let mut sub_func = 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::DynamicalDefineDID, Some(sub_func), data, &cfg)?;
28
29 let response = self
30 .suppress_positive_sr(
31 AddressType::Physical,
32 request,
33 suppress_positive,
34 Some((r#type.into(), service)),
35 &cfg,
36 )
37 .await?;
38
39 match response {
40 Some(v) => Ok(Some(v.data(&cfg).map_err(DoCanError::Iso14229Error)?)),
41 None => Ok(None),
42 }
43 }
44}