File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515//! The resulting [`BitrateConfig`] contains:
1616//! - nominal/arbitration phase settings as one [`AdapterBitTiming`]
1717//! - optional CAN-FD data phase settings as one [`AdapterBitTiming`]
18+ //!
19+ //! ## Example
20+ //!
21+ //! Build a 500 kbit/s nominal bitrate configuration using the timing constants
22+ //! exposed by an adapter type:
23+ //!
24+ //! ```rust
25+ //! use automotive::can::bitrate::{AdapterTimingConst, BitTimingConst, BitrateBuilder};
26+ //! use automotive::can::{CanAdapter, Frame};
27+ //! use std::collections::VecDeque;
28+ //!
29+ //! # const TIMING: AdapterTimingConst = AdapterTimingConst {
30+ //! # nominal: BitTimingConst {
31+ //! # clock_hz: 80_000_000,
32+ //! # tseg1_min: 1,
33+ //! # tseg1_max: 16,
34+ //! # tseg2_min: 1,
35+ //! # tseg2_max: 8,
36+ //! # sjw_max: 4,
37+ //! # brp_min: 1,
38+ //! # brp_max: 1024,
39+ //! # brp_inc: 1,
40+ //! # },
41+ //! # data: None,
42+ //! # };
43+ //! # struct DummyAdapter;
44+ //! # impl CanAdapter for DummyAdapter {
45+ //! # fn send(&mut self, _frames: &mut VecDeque<Frame>) -> automotive::Result<()> {
46+ //! # unreachable!()
47+ //! # }
48+ //! #
49+ //! # fn recv(&mut self) -> automotive::Result<Vec<Frame>> {
50+ //! # unreachable!()
51+ //! # }
52+ //! #
53+ //! # fn timing_const() -> AdapterTimingConst
54+ //! # where
55+ //! # Self: Sized,
56+ //! # {
57+ //! # TIMING
58+ //! # }
59+ //! # }
60+ //! let bitrate_cfg = BitrateBuilder::new::<DummyAdapter>()
61+ //! .bitrate(500_000)
62+ //! .sample_point(0.8)
63+ //! .build()?;
64+ //!
65+ //! assert_eq!(bitrate_cfg.nominal.bitrate, 500_000);
66+ //! # Ok::<(), automotive::can::bitrate::BitrateError>(())
67+ //! ```
1868
1969use thiserror:: Error ;
2070
You can’t perform that action at this time.
0 commit comments