1
1
//! Controller Area Network
2
2
3
- use core:: convert:: TryInto ;
4
- use core:: convert:: TryFrom ;
5
-
6
3
use nb;
7
4
8
5
/// A type that can either be `BaseId` or `ExtendedId`
9
6
#[ cfg( feature = "unproven" ) ]
10
- pub trait Id : Sized {
11
- /// The BaseId variant
12
- type BaseId : BaseId + Into < Self > + TryFrom < Self > ;
7
+ pub trait Id {
8
+ /// The (11-bit) BaseId variant.
9
+ type BaseId ;
13
10
14
- /// The ExtendedId variant
15
- type ExtendedId : ExtendedId + Into < Self > + TryFrom < Self > ;
16
- }
11
+ /// The (29-bit) ExtendedId variant.
12
+ type ExtendedId ;
17
13
18
- /// A Can (11-bit) ID
19
- #[ cfg( feature = "unproven" ) ]
20
- pub trait BaseId : Sized {
21
- /// A generic ID type that encapsulate this type
22
- type Id : Id + From < Self > + TryInto < Self > ;
23
- }
14
+ /// Returns `Some(base_id)` if this Can-ID is 11-bit.
15
+ /// Returns `None` if this Can-ID is 29-bit.
16
+ fn base_id ( & self ) -> Option < Self :: BaseId > ;
24
17
25
- /// A Can Extended (28-bit) ID
26
- #[ cfg( feature = "unproven" ) ]
27
- pub trait ExtendedId : Sized {
28
- /// A generic ID type that encapsulate this type
29
- type Id : Id + From < Self > + TryInto < Self > ;
18
+ /// Returns `Some(extended_id)` if this Can-ID is 29-bit.
19
+ /// Returns `None` if this Can-ID is 11-bit.
20
+ fn extended_id ( & self ) -> Option < Self :: ExtendedId > ;
30
21
}
31
22
23
+
32
24
/// A Can Frame
33
25
#[ cfg( feature = "unproven" ) ]
34
26
pub trait Frame {
35
27
/// The Id type of this Frame
36
28
type Id : Id ;
37
29
30
+ /// Returns true if this `Frame` is a remote frame
31
+ fn is_remote_frame ( & self ) -> bool ;
32
+
33
+ /// Returns true if this `Frame` is a data frame
34
+ fn is_data_frame ( & self ) -> bool ;
35
+
36
+ /// Returns true if this `Frame` is a extended id frame
37
+ fn is_base_id_frame ( & self ) -> bool {
38
+ self . id ( ) . base_id ( ) . is_some ( )
39
+ }
40
+
41
+ /// Returns true if this `Frame` is a extended id frame
42
+ fn is_extended_id_frame ( & self ) -> bool {
43
+ self . id ( ) . extended_id ( ) . is_some ( )
44
+ }
45
+
38
46
/// Returns the Can-ID
39
47
fn id ( & self ) -> Self :: Id ;
40
48
@@ -55,6 +63,22 @@ pub trait FdFrame {
55
63
/// Returns false if this frame would/has be(en) transmitted as a "ordinary" Can frame.
56
64
fn is_fd_frame ( & self ) -> bool ;
57
65
66
+ /// Returns true if this `Frame` is a remote frame
67
+ fn is_remote_frame ( & self ) -> bool ;
68
+
69
+ /// Returns true if this `Frame` is a data frame
70
+ fn is_data_frame ( & self ) -> bool ;
71
+
72
+ /// Returns true if this `Frame` is a extended id frame
73
+ fn is_base_id_frame ( & self ) -> bool {
74
+ self . id ( ) . base_id ( ) . is_some ( )
75
+ }
76
+
77
+ /// Returns true if this `Frame` is a extended id frame
78
+ fn is_extended_id_frame ( & self ) -> bool {
79
+ self . id ( ) . extended_id ( ) . is_some ( )
80
+ }
81
+
58
82
/// Returns the Can-ID
59
83
fn id ( & self ) -> Self :: Id ;
60
84
0 commit comments