@@ -98,10 +98,11 @@ pub struct ISO15765Config {
9898unsafe impl Send for ISO15765Config { }
9999unsafe impl Sync for ISO15765Config { }
100100
101- #[ derive( Debug , Copy , Clone ) ]
101+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , PartialOrd , Ord ) ]
102102pub enum FilterType {
103- Pass ,
104- Block ,
103+ Pass { id : u32 , mask : u32 } ,
104+ Block { id : u32 , mask : u32 } ,
105+ IsoTP { id : u32 , mask : u32 , fc : u32 } ,
105106}
106107
107108#[ derive( Debug , Clone ) ]
@@ -224,8 +225,11 @@ pub trait ComServer: Send + Sync + Debug {
224225 /// ## Returns
225226 /// The number of CAN Frames successfully written to the vehicle, if Timeout is 0, this
226227 /// number will always be equal to the number of frames that were provided.
227- fn send_can_packets ( & mut self , data : & [ CanFrame ] , timeout_ms : u32 )
228- -> Result < usize , ComServerError > ;
228+ fn send_can_packets (
229+ & mut self ,
230+ data : & [ CanFrame ] ,
231+ timeout_ms : u32 ,
232+ ) -> Result < usize , ComServerError > ;
229233
230234 /// Returns a boolean indicating if there is at least 1 channel communicating with the car
231235 fn is_connected ( & self ) -> bool ;
@@ -326,27 +330,14 @@ pub trait ComServer: Send + Sync + Debug {
326330 ///
327331 /// ## Returns
328332 /// The filter ID provided by the adapter. Use this when destroying the filter
329- fn add_can_filter ( & mut self , filter : FilterType , id : u32 , mask : u32 )
330- -> Result < u32 , ComServerError > ;
333+ fn add_can_filter ( & mut self , f : FilterType ) -> Result < u32 , ComServerError > ;
331334
332335 /// Tells the adapter to remove an active filter on an open CAN channel
333336 /// # Params
334337 /// * filter_idx - Filter ID to remove, this should be the value given by [`add_can_filter`](fn@add_can_filter)
335338 fn rem_can_filter ( & mut self , filter_idx : u32 ) -> Result < ( ) , ComServerError > ;
336339
337- fn add_iso15765_filter ( & mut self , id : u32 , mask : u32 , fc_id : u32 ) -> Result < u32 , ComServerError > ;
338-
339- fn configure_iso15765 ( & mut self , cfg : & ISO15765Config ) -> Result < u32 , ComServerError > {
340- self . add_iso15765_filter ( cfg. recv_id , 0xFFFF , cfg. send_id )
341- . and_then ( |idx| {
342- self . set_iso15765_params ( cfg. sep_time , cfg. block_size )
343- . map ( |_| idx)
344- . map_err ( |e| match self . rem_iso15765_filter ( idx) {
345- Ok ( _) => e,
346- Err ( e1) => e1,
347- } )
348- } )
349- }
340+ fn add_iso15765_filter ( & mut self , f : FilterType ) -> Result < u32 , ComServerError > ;
350341
351342 /// Tells the adapter to remove an active filter on an open ISO15765 channel
352343 /// # Params
@@ -369,33 +360,6 @@ pub trait ComServer: Send + Sync + Debug {
369360 block_size : u32 ,
370361 ) -> Result < ( ) , ComServerError > ;
371362
372- /// Sends an ISOTP payload and attempts to read the ECUs response
373- /// IMPORTANT - This function assumes the ISO15765 interface is ALREADY open
374- fn send_receive_iso15765 (
375- & self ,
376- p : ISO15765Data ,
377- max_timeout_ms : u128 ,
378- max_resp : usize ,
379- ) -> Result < Vec < ISO15765Data > , ComServerError > {
380- self . clear_iso15765_rx_buffer ( ) ?; // Clear the receive buffer
381- self . send_iso15765_data ( & [ p] , 0 ) ?; // Send data
382- let mut timeout = max_timeout_ms;
383- let mut payloads: Vec < ISO15765Data > = Vec :: new ( ) ;
384- let start = Instant :: now ( ) ;
385- while start. elapsed ( ) . as_millis ( ) < timeout {
386- if let Ok ( d) = self . read_iso15765_packets ( 0 , 10 ) {
387- for msg in d {
388- payloads. push ( msg) ;
389- if max_resp != 0 && payloads. len ( ) >= max_resp {
390- timeout = 0 ; // Return now!
391- }
392- }
393- }
394- std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 1 ) ) ;
395- }
396- Ok ( payloads)
397- }
398-
399363 /// Tells the adapter to clear any data in its Rx buffer
400364 /// that is from CAN protocol
401365 fn clear_can_rx_buffer ( & self ) -> Result < ( ) , ComServerError > ;
0 commit comments