@@ -74,6 +74,10 @@ pub struct Config<'a> {
74
74
#[ builder( default ) ]
75
75
pub impl_error : FeatureConfig < ' a > ,
76
76
77
+ /// Optional: Generate `embedded_can::Frame` impl for each frame. Default: `Always`
78
+ #[ builder( default = FeatureConfig :: Always ) ]
79
+ pub impl_embedded_can_frame : FeatureConfig < ' a > ,
80
+
77
81
/// Optional: Validate min and max values in generated signal setters. Default: `Always`
78
82
#[ builder( default = FeatureConfig :: Always ) ]
79
83
pub check_ranges : FeatureConfig < ' a > ,
@@ -428,6 +432,8 @@ fn render_message(mut w: impl Write, config: &Config<'_>, msg: &Message, dbc: &D
428
432
writeln ! ( w, "}}" ) ?;
429
433
writeln ! ( w) ?;
430
434
435
+ render_embedded_can_frame ( & mut w, config, msg) ?;
436
+
431
437
render_debug_impl ( & mut w, config, msg) ?;
432
438
433
439
render_arbitrary ( & mut w, config, msg) ?;
@@ -1285,6 +1291,56 @@ fn multiplexed_enum_variant_name(
1285
1291
) )
1286
1292
}
1287
1293
1294
+ fn render_embedded_can_frame (
1295
+ w : & mut impl Write ,
1296
+ config : & Config < ' _ > ,
1297
+ msg : & Message ,
1298
+ ) -> Result < ( ) , std:: io:: Error > {
1299
+ config. impl_embedded_can_frame . fmt_cfg ( w, |w| {
1300
+ writeln ! (
1301
+ w,
1302
+ "\
1303
+ impl embedded_can::Frame for {0} {{
1304
+ fn new(id: impl Into<Id>, data: &[u8]) -> Option<Self> {{
1305
+ if id.into() != Self::MESSAGE_ID {{
1306
+ None
1307
+ }} else {{
1308
+ data.try_into().ok()
1309
+ }}
1310
+ }}
1311
+
1312
+ fn new_remote(_id: impl Into<Id>, _dlc: usize) -> Option<Self> {{
1313
+ unimplemented!()
1314
+ }}
1315
+
1316
+ fn is_extended(&self) -> bool {{
1317
+ match self.id() {{
1318
+ Id::Standard(_) => false,
1319
+ Id::Extended(_) => true,
1320
+ }}
1321
+ }}
1322
+
1323
+ fn is_remote_frame(&self) -> bool {{
1324
+ false
1325
+ }}
1326
+
1327
+ fn id(&self) -> Id {{
1328
+ Self::MESSAGE_ID
1329
+ }}
1330
+
1331
+ fn dlc(&self) -> usize {{
1332
+ self.raw.len()
1333
+ }}
1334
+
1335
+ fn data(&self) -> &[u8] {{
1336
+ &self.raw
1337
+ }}
1338
+ }}" ,
1339
+ type_name( msg. message_name( ) )
1340
+ )
1341
+ } )
1342
+ }
1343
+
1288
1344
fn render_debug_impl ( mut w : impl Write , config : & Config < ' _ > , msg : & Message ) -> Result < ( ) > {
1289
1345
match & config. impl_debug {
1290
1346
FeatureConfig :: Always => { }
0 commit comments