Skip to main content

docan_rs/client/service/
request_download.rs

1//! response of Service 34
2
3use iso14229_1::{
4    request, response, AddressAndLengthFormatIdentifier, DataFormatIdentifier, MemoryLocation,
5    Service,
6};
7use iso15765_2::can::AddressType;
8use rs_can::{CanDevice, CanFrame};
9use std::{fmt::Display, hash::Hash};
10
11use crate::{DoCanClient, DoCanError, DoCanResult};
12
13impl<D, C, F> DoCanClient<D, C, F>
14where
15    D: CanDevice<Channel = C, Frame = F> + Clone + Send + 'static,
16    C: Clone + Eq + Display + Hash + Send + Sync + 'static,
17    F: CanFrame<Channel = C> + Clone + Display + 'static,
18{
19    pub async fn request_download(
20        &mut self,
21        alfi: AddressAndLengthFormatIdentifier,
22        mem_addr: u128,
23        mem_size: u128,
24        dfi: Option<DataFormatIdentifier>,
25    ) -> DoCanResult<response::RequestDownload> {
26        let data = request::RequestDownload {
27            dfi: dfi.unwrap_or_default(),
28            mem_loc: MemoryLocation::new(alfi, mem_addr, mem_size)
29                .map_err(DoCanError::Iso14229Error)?,
30        };
31        let cfg = self.context.get_cfg().await;
32        let request = Self::make_request(Service::RequestDownload, None, data, &cfg)?;
33
34        self.send_and_parse(AddressType::Physical, request, None, &cfg)
35            .await
36    }
37}