44//! on [`crate::can::AsyncCanAdapter`] for background polling, retry logic, and
55//! async send/receive orchestration.
66
7+ use super :: common:: nominal_bitrate_from_config;
78use super :: common:: { self , can_id_flags, parse_can_id, J2534Channel , J2534Device , PassThruMsg } ;
89use super :: constants:: { Protocol , Status , CAN_ID_BOTH } ;
910use super :: error:: Error as J2534Error ;
@@ -16,22 +17,20 @@ use std::collections::VecDeque;
1617/// Poll the J2534 channel without blocking the `AsyncCanAdapter` process loop.
1718const IO_TIMEOUT_MS : u32 = 0 ;
1819
19- // J2534 does not expose portable timing metadata for raw CAN channels, so use a
20- // permissive nominal-only timing range to drive BitrateBuilder.
21- const J2534_NOMINAL_BTC : BitTimingConst = BitTimingConst {
22- clock_hz : 80_000_000 ,
23- tseg1_min : 1 ,
24- tseg1_max : 1 << 8 ,
25- tseg2_min : 1 ,
26- tseg2_max : 1 << 7 ,
27- sjw_max : 1 << 7 ,
28- brp_min : 1 ,
29- brp_max : 1 << 10 ,
30- brp_inc : 1 ,
31- } ;
32-
20+ // J2534 does not expose portable timing metadata for CAN channel setup, so
21+ // use a permissive nominal-only timing range to drive BitrateBuilder.
3322const J2534_TIMING_CONST : AdapterTimingConst = AdapterTimingConst {
34- nominal : J2534_NOMINAL_BTC ,
23+ nominal : BitTimingConst {
24+ clock_hz : 80_000_000 ,
25+ tseg1_min : 1 ,
26+ tseg1_max : 1 << 8 ,
27+ tseg2_min : 1 ,
28+ tseg2_max : 1 << 7 ,
29+ sjw_max : 1 << 7 ,
30+ brp_min : 1 ,
31+ brp_max : 1 << 10 ,
32+ brp_inc : 1 ,
33+ } ,
3534 data : None ,
3635} ;
3736
@@ -68,7 +67,7 @@ impl J2534CanAdapter {
6867 /// * `bitrate_cfg` — nominal CAN bitrate configuration. CAN-FD data phase
6968 /// settings are currently rejected.
7069 pub fn new ( dll_path : Option < & str > , bitrate_cfg : BitrateConfig ) -> Result < Self > {
71- let bitrate = Self :: nominal_bitrate ( & bitrate_cfg) ?;
70+ let bitrate = nominal_bitrate_from_config ( & bitrate_cfg) ?;
7271 let device = common:: open_device ( dll_path) ?;
7372 Self :: new_on_device_with_bitrate ( device, bitrate)
7473 }
@@ -80,20 +79,10 @@ impl J2534CanAdapter {
8079 /// channel was closed).
8180 ///
8281 pub fn new_on_device ( device : J2534Device , bitrate_cfg : BitrateConfig ) -> Result < Self > {
83- let bitrate = Self :: nominal_bitrate ( & bitrate_cfg) ?;
82+ let bitrate = nominal_bitrate_from_config ( & bitrate_cfg) ?;
8483 Self :: new_on_device_with_bitrate ( device, bitrate)
8584 }
8685
87- fn nominal_bitrate ( bitrate_cfg : & BitrateConfig ) -> Result < u32 > {
88- if bitrate_cfg. data . is_some ( ) {
89- return Err ( crate :: Error :: InvalidBitrate (
90- "J2534 CAN adapter does not support CAN-FD bitrate configuration" . to_string ( ) ,
91- ) ) ;
92- }
93-
94- Ok ( bitrate_cfg. nominal . bitrate )
95- }
96-
9786 fn new_on_device_with_bitrate ( device : J2534Device , bitrate : u32 ) -> Result < Self > {
9887 let channel =
9988 common:: connect_channel_with_flags ( & device, Protocol :: Can , CAN_ID_BOTH , bitrate) ?;
0 commit comments