docan_rs/
client.rs

1mod context;
2
3#[cfg(not(feature = "async"))]
4mod synchronous;
5#[cfg(not(feature = "async"))]
6pub use synchronous::*;
7
8use iso14229_1::{request, response, *};
9use iso15765_2::{Address, AddressType};
10use rs_can::CanResult;
11use crate::{SecurityAlgo};
12
13pub trait Client {
14    type Channel;
15    // type Device;
16    type Error;
17
18    fn update_address(&mut self,
19                      channel: Self::Channel,
20                      address: Address
21    ) -> CanResult<(), Self::Error>;
22    fn update_security_algo(&mut self,
23                            channel: Self::Channel,
24                            algo: SecurityAlgo
25    ) -> CanResult<(), Self::Error>;
26    fn add_data_identifier(&mut self,
27                           channel: Self::Channel,
28                           did: DataIdentifier,
29                           length: usize
30    ) -> CanResult<(), Self::Error>;
31    fn remove_data_identifier(&mut self,
32                              channel: Self::Channel,
33                              did: DataIdentifier
34    ) -> CanResult<(), Self::Error>;
35    fn set_address_of_byte_order(&mut self,
36                                 channel: Self::Channel,
37                                 bo: ByteOrder
38    ) -> CanResult<(), Self::Error>;
39    fn set_memory_size_of_byte_order(&mut self,
40                                     channel: Self::Channel,
41                                     bo: ByteOrder
42    ) -> CanResult<(), Self::Error>;
43    /** - Diagnostic and communication management functional unit - **/
44    fn session_ctrl(&mut self,
45                    channel: Self::Channel,
46                    r#type: SessionType,
47                    suppress_positive: bool,
48                    addr_type: AddressType,
49    ) -> CanResult<(), Self::Error>;
50    fn ecu_reset(&mut self,
51                 channel: Self::Channel,
52                 r#type: ECUResetType,
53                 suppress_positive: bool,
54                 addr_type: AddressType,
55    ) -> CanResult<(), Self::Error>;
56    fn security_access(&mut self,
57                       channel: Self::Channel,
58                       level: u8,
59                       params: Vec<u8>,
60    ) -> CanResult<Vec<u8>, Self::Error>;
61    fn unlock_security_access(&mut self,
62                              channel: Self::Channel,
63                              level: u8,
64                              params: Vec<u8>,
65                              salt: Vec<u8>,
66    ) -> CanResult<(), Self::Error>;
67    fn communication_control(&mut self,
68                             channel: Self::Channel,
69                             ctrl_type:CommunicationCtrlType,
70                             comm_type: CommunicationType,
71                             node_id: Option<request::NodeId>,
72                             suppress_positive: bool,
73                             addr_type: AddressType,
74    ) -> CanResult<(), Self::Error>;
75    #[cfg(feature = "std2020")]
76    fn authentication(&mut self,
77                      channel: Self::Channel,
78                      auth_task: AuthenticationTask,
79                      data: request::Authentication,
80    ) -> CanResult<response::Authentication, Self::Error>;
81    fn tester_present(&mut self,
82                      channel: Self::Channel,
83                      r#type: TesterPresentType,
84                      suppress_positive: bool,
85                      addr_type: AddressType,
86    ) -> CanResult<(), Self::Error>;
87    #[cfg(any(feature = "std2006", feature = "std2013"))]
88    fn access_timing_parameter(&mut self,
89                               channel: Self::Channel,
90                               r#type: TimingParameterAccessType,
91                               parameter: Vec<u8>,
92                               suppress_positive: bool,
93    ) -> CanResult<Option<response::AccessTimingParameter>, Self::Error>;
94    fn secured_data_transmit(&mut self,
95                             channel: Self::Channel,
96                             apar: AdministrativeParameter,
97                             signature: SignatureEncryptionCalculation,
98                             anti_replay_cnt: u16,
99                             service: u8,
100                             service_data: Vec<u8>,
101                             signature_data: Vec<u8>,
102    ) -> CanResult<response::SecuredDataTrans, Self::Error>;
103    fn control_dtc_setting(&mut self,
104                           channel: Self::Channel,
105                           r#type: DTCSettingType,
106                           parameter: Vec<u8>,
107                           suppress_positive: bool,
108    ) -> CanResult<(), Self::Error>;
109    fn response_on_event(&mut self,
110                         channel: Self::Channel,
111    ) -> CanResult<(), Self::Error>;
112    fn link_control(&mut self,
113                    channel: Self::Channel,
114                    r#type: LinkCtrlType,
115                    data: request::LinkCtrl,
116                    suppress_positive: bool,
117    ) -> CanResult<(), Self::Error>;
118    fn read_data_by_identifier(&mut self,
119                               channel: Self::Channel,
120                               did: DataIdentifier,
121                               others: Vec<DataIdentifier>,
122    ) -> CanResult<response::ReadDID, Self::Error>;
123    fn read_memory_by_address(&mut self,
124                              channel: Self::Channel,
125                              mem_loc: MemoryLocation,
126    ) -> CanResult<Vec<u8>, Self::Error>;
127    fn read_scaling_data_by_identifier(&mut self,
128                                       channel: Self::Channel,
129                                       did: DataIdentifier,
130    ) -> CanResult<response::ReadScalingDID, Self::Error>;
131    /** - Data transmission functional unit - **/
132    fn read_data_by_period_identifier(&mut self,
133                                      channel: Self::Channel,
134                                      mode: request::TransmissionMode,
135                                      did: Vec<u8>,
136    ) -> CanResult<response::ReadDataByPeriodId, Self::Error>;
137    fn dynamically_define_data_by_identifier(&mut self,
138                                             channel: Self::Channel,
139                                             r#type: DefinitionType,
140                                             data: request::DynamicallyDefineDID,
141                                             suppress_positive: bool,
142    ) -> CanResult<Option<response::DynamicallyDefineDID>, Self::Error>;
143    fn write_data_by_identifier(&mut self,
144                                channel: Self::Channel,
145                                did: DataIdentifier,
146                                data: Vec<u8>,
147    ) -> CanResult<(), Self::Error>;
148    fn write_memory_by_address(&mut self,
149                               channel: Self::Channel,
150                               alfi: AddressAndLengthFormatIdentifier,
151                               mem_addr: u128,
152                               mem_size: u128,
153                               record: Vec<u8>,
154    ) -> CanResult<response::WriteMemByAddr, Self::Error>;
155    /** Stored data transmission functional unit - **/
156    fn clear_dtc_info(&mut self,
157                      channel: Self::Channel,
158                      group: utils::U24,
159                      #[cfg(any(feature = "std2020"))]
160                      mem_sel: Option<u8>,
161                      addr_type: AddressType,
162    ) -> CanResult<(), Self::Error>;
163    fn read_dtc_info(&mut self,
164                     channel: Self::Channel,
165                     r#type: DTCReportType,
166                     data: request::DTCInfo,
167    ) -> CanResult<response::DTCInfo, Self::Error>;
168    /** - InputOutput control functional unit - **/
169    fn io_control(&mut self,
170                  channel: Self::Channel,
171                  did: DataIdentifier,
172                  param: IOCtrlParameter,
173                  state: Vec<u8>,
174                  mask: Vec<u8>,
175    ) -> CanResult<response::IOCtrl, Self::Error>;
176    /** - Remote activation of routine functional unit - **/
177    fn routine_control(&mut self,
178                       channel: Self::Channel,
179                       r#type: RoutineCtrlType,
180                       routine_id: u16,
181                       option_record: Vec<u8>,
182    ) -> CanResult<response::RoutineCtrl, Self::Error>;
183    /** - Upload download functional unit - **/
184    fn request_download(&mut self,
185                        channel: Self::Channel,
186                        alfi: AddressAndLengthFormatIdentifier,
187                        mem_addr: u128,
188                        mem_size: u128,
189                        dfi: Option<DataFormatIdentifier>,
190    ) -> CanResult<response::RequestDownload, Self::Error>;
191    fn request_upload(&mut self,
192                      channel: Self::Channel,
193                      alfi: AddressAndLengthFormatIdentifier,
194                      mem_addr: u128,
195                      mem_size: u128,
196                      dfi: Option<DataFormatIdentifier>,
197    ) -> CanResult<response::RequestUpload, Self::Error>;
198    fn transfer_data(&mut self,
199                     channel: Self::Channel,
200                     sequence: u8,
201                     data: Vec<u8>,
202    ) -> CanResult<response::TransferData, Self::Error>;
203    fn request_transfer_exit(&mut self,
204                             channel: Self::Channel,
205                             parameter: Vec<u8>,
206    ) -> CanResult<Vec<u8>, Self::Error>;
207    fn request_file_transfer(&mut self,
208                             channel: Self::Channel,
209                             operation: ModeOfOperation,
210                             data: request::RequestFileTransfer,
211    ) -> CanResult<response::RequestFileTransfer, Self::Error>;
212}