Skip to main content

docan_rs/client/service/
write_mem_by_addr.rs

1//! response of Service 3D
2
3use crate::{client::DoCanClient, DoCanError, DoCanResult};
4use iso14229_1::{request, response, AddressAndLengthFormatIdentifier, Service};
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 write_memory_by_address(
16        &mut self,
17        alfi: AddressAndLengthFormatIdentifier,
18        mem_addr: u128,
19        mem_size: u128,
20        record: Vec<u8>,
21    ) -> DoCanResult<response::WriteMemByAddr> {
22        let data = request::WriteMemByAddr::new(alfi, mem_addr, mem_size, record)
23            .map_err(DoCanError::Iso14229Error)?;
24        let cfg = self.context.get_cfg().await;
25        let request = Self::make_request(Service::WriteMemByAddr, None, data, &cfg)?;
26
27        self.send_and_parse(AddressType::Physical, request, None, &cfg)
28            .await
29    }
30}