pub struct SamplePoint(/* private fields */);Expand description
Bit-timing sample point as a fraction of the bit time.
Stored internally as per-mille (e.g., 875 for 87.5%). The CAN
specification recommends sample points in the 70%–87.5% range; this type
enforces [500, 950] per-mille (50%–95%) so out-of-range values are
rejected before they reach a backend’s timing solver.
Construct via SamplePoint::from_per_mille (const fn, so out-of-range
literals fail at compile time when wrapped in a const context), or via
the preset constants:
use can_hal::SamplePoint;
// Compile-time literal (asserted at compile time when used in a const context):
const SP_87_5: SamplePoint = SamplePoint::from_per_mille(875);
assert_eq!(SP_87_5.per_mille(), 875);
// Or use a preset:
assert_eq!(SamplePoint::NOMINAL_DEFAULT.per_mille(), 700);
assert_eq!(SamplePoint::DATA_DEFAULT.per_mille(), 800);Out-of-range per-mille values panic - at compile time in a const
context, or at runtime otherwise:
const TOO_HIGH: SamplePoint = SamplePoint::from_per_mille(2000);// Runtime construction with an out-of-range value panics.
SamplePoint::from_per_mille(2000);Implementations§
Source§impl SamplePoint
impl SamplePoint
Sourcepub const NOMINAL_DEFAULT: Self
pub const NOMINAL_DEFAULT: Self
Default nominal-phase sample point: 70%. Matches the cross-adapter interop convention used by the PCAN and Kvaser backends in this workspace.
Sourcepub const DATA_DEFAULT: Self
pub const DATA_DEFAULT: Self
Default data-phase sample point: 80%. Matches the cross-adapter interop convention used by the PCAN and Kvaser backends in this workspace.
Sourcepub const PCT_87_5: Self
pub const PCT_87_5: Self
87.5% sample point - a common industrial recommendation for classic CAN at modest bus lengths.
Sourcepub const fn from_per_mille(per_mille: u16) -> Self
pub const fn from_per_mille(per_mille: u16) -> Self
Construct from per-mille (e.g., 875 for 87.5%, 700 for 70%).
Panics if per_mille is outside [500, 950]. In a const context
(i.e., when initializing a const binding or inside const { ... }),
this panic occurs at compile time.
Sourcepub fn as_fraction(self) -> f32
pub fn as_fraction(self) -> f32
Convert to a fraction (e.g., 0.875 for 87.5%). Not const
because f32 division isn’t const-stable on this crate’s MSRV.
Trait Implementations§
Source§impl Clone for SamplePoint
impl Clone for SamplePoint
Source§fn clone(&self) -> SamplePoint
fn clone(&self) -> SamplePoint
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for SamplePoint
Source§impl Debug for SamplePoint
impl Debug for SamplePoint
impl Eq for SamplePoint
Source§impl PartialEq for SamplePoint
impl PartialEq for SamplePoint
Source§fn eq(&self, other: &SamplePoint) -> bool
fn eq(&self, other: &SamplePoint) -> bool
self and other values to be equal, and is used by ==.