File tree 1 file changed +17
-5
lines changed
1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -170,13 +170,13 @@ impl Frame {
170
170
Self :: new ( Id :: new_extended ( id) , data)
171
171
}
172
172
173
- /// Sets the remote transmission (RTR) flag. Marks the frame as a remote frame.
173
+ /// Marks the frame as a remote frame with configurable data length code (DLC) .
174
174
///
175
175
/// Remote frames do not contain any data, even if the frame was created with a
176
176
/// non-empty data buffer.
177
- pub fn with_rtr ( & mut self , rtr : bool ) -> & mut Self {
178
- self . id = self . id . with_rtr ( rtr ) ;
179
- self . dlc = 0 ;
177
+ pub fn with_rtr ( & mut self , dlc : usize ) -> & mut Self {
178
+ self . id = self . id . with_rtr ( true ) ;
179
+ self . dlc = dlc ;
180
180
self
181
181
}
182
182
@@ -205,9 +205,21 @@ impl Frame {
205
205
self . id
206
206
}
207
207
208
+ /// Returns the data length code (DLC) which is in the range 0..8.
209
+ ///
210
+ /// For data frames the DLC value always matches the lenght of the data.
211
+ /// Remote frames no not carry any data, yet the DLC can be greater than 0.
212
+ pub fn dlc ( & self ) -> usize {
213
+ self . dlc
214
+ }
215
+
208
216
/// Returns the frame data (0..8 bytes in length).
209
217
pub fn data ( & self ) -> & [ u8 ] {
210
- & self . data [ 0 ..self . dlc ]
218
+ if self . is_data_frame ( ) {
219
+ & self . data [ 0 ..self . dlc ]
220
+ } else {
221
+ & [ ]
222
+ }
211
223
}
212
224
}
213
225
You can’t perform that action at this time.
0 commit comments