1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! The `frames` module houses various CAN frame representations.
//!
//! Regular CAN is a very low level technology (OSI layers 1 and 2), and as such there's a need for
//! data representations that don't impose usage patterns on the user (since hardware needs vary).
//! But at the same time, one of Rusts great strengths is its type system and most Rustaceans
//! prefer more type level sanity checks. This module contains frame representations that cater
//! to both use cases, as well as easy (and cheap) layers to convert between them.
/// A low level representation of the frames that might be sent and received on a CAN bus.
///
/// This struct can represent any CAN frame, as described in the CAN specification
/// version 2.0, published September 1991 by Bosch GmbH. They can be used for either
/// transmission or reception.
/// A low level representation of the frames that might be sent and received on a CAN FD bus.
///
/// This struct can represent any CAN FD frame, as described in the CAN FD specification
/// version 1.0, published April 2012 by Bosch GmbH. They can be used for either
/// transmission or reception.
/// Converts a CAN-FD DLC into a byte count.
///
/// NOTE: According to the CAN 2.0 spec a data length of 8 can be encoded as any DLC >= 8.
/// This function has no way of knowing the frame type, so be sure to only call it after
/// you've verified that it's a CAN-FD frame you're dealing with.
/// Converts a byte count into a CAN-FD DLC.
///
/// NOTE: Not all byte counts can be represented as DLCs, which by implication means that not all
/// byte counts are valid CAN-FD frame sizes. This function accounts for the truncation and
/// padding that may be incurred as a result of that.
///
/// If n != byte_count_to_can_fd_dlc(can_fd_dlc_to_byte_count(n)) truncation or padding will occur.