Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
329 changes: 248 additions & 81 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ std = []

[dependencies]
anyhow = "1.0.101"
can-dbc = "8.0.1"
can-dbc = "9.0.0"
embedded-can = "0.4.1"
heck = "0.5.0"
prettyplease = "0.2.37"
Expand Down
13 changes: 9 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use typed_builder::TypedBuilder;

pub use crate::feature_config::FeatureConfig;
use crate::pad::PadAdapter;
use crate::signal_type::ValType;
use crate::signal_type::{IntSize, ValType};
use crate::utils::{
enum_name, enum_variant_name, multiplex_enum_name, multiplexed_enum_variant_name,
multiplexed_enum_variant_wrapper_name, MessageExt as _, SignalExt as _,
Expand Down Expand Up @@ -580,8 +580,8 @@ impl Config<'_> {
writeln!(w, "/// - Value type: {:?}", signal.value_type)?;
writeln!(w, "#[inline(always)]")?;
let field = signal.field_name();
let typ = ValType::from_signal(signal);
writeln!(w, "pub fn {field}_raw(&self) -> {typ} {{")?;
let signal_typ = ValType::from_signal(signal);
writeln!(w, "pub fn {field}_raw(&self) -> {signal_typ} {{")?;
{
let mut w = PadAdapter::wrap(w);
signal_from_payload(&mut w, signal, msg).context("signal from payload")?;
Expand Down Expand Up @@ -623,9 +623,14 @@ impl Config<'_> {
multiplexed_enum_variant_name(msg, signal, *multiplexer_index)?,
)?;
}
let to_u16 = match signal_typ {
ValType::UnsignedInt(IntSize::Size8) => "multiplexor.into()",
ValType::UnsignedInt(IntSize::Size16) => "multiplexor",
_ => "u16::try_from(multiplexor).unwrap_or(u16::MAX)",
};
writeln!(
w,
"multiplexor => Err(CanError::InvalidMultiplexor {{ message_id: {}::MESSAGE_ID, multiplexor: multiplexor.into() }}),",
"multiplexor => Err(CanError::InvalidMultiplexor {{ message_id: {}::MESSAGE_ID, multiplexor: {to_u16} }}),",
msg.type_name(),
)?;
}
Expand Down
10 changes: 5 additions & 5 deletions src/signal_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl ValType {

#[cfg(test)]
mod tests {
use can_dbc::{Signal, ValueType};
use can_dbc::{ByteOrder, MultiplexIndicator, NumericValue, Signal, ValueType};

use super::*;

Expand All @@ -205,15 +205,15 @@ mod tests {
name: String::new(),
start_bit: 0,
size: u64::from(signal_size),
byte_order: can_dbc::ByteOrder::LittleEndian,
byte_order: ByteOrder::LittleEndian,
value_type: sign,
factor: factor as f64,
offset: offset as f64,
min: 0.0,
max: 0.0,
min: NumericValue::Double(0.0),
max: NumericValue::Double(0.0),
unit: String::new(),
receivers: vec![],
multiplexer_indicator: can_dbc::MultiplexIndicator::Plain,
multiplexer_indicator: MultiplexIndicator::Plain,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl ExtMuxCascaded {
multiplexor => {
Err(CanError::InvalidMultiplexor {
message_id: ExtMuxCascaded::MESSAGE_ID,
multiplexor: multiplexor.into(),
multiplexor: u16::try_from(multiplexor).unwrap_or(u16::MAX),
})
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl ExtMuxCascaded {
multiplexor => {
Err(CanError::InvalidMultiplexor {
message_id: ExtMuxCascaded::MESSAGE_ID,
multiplexor: multiplexor.into(),
multiplexor: u16::try_from(multiplexor).unwrap_or(u16::MAX),
})
}
}
Expand Down Expand Up @@ -207,7 +207,7 @@ impl ExtMuxCascaded {
multiplexor => {
Err(CanError::InvalidMultiplexor {
message_id: ExtMuxCascaded::MESSAGE_ID,
multiplexor: multiplexor.into(),
multiplexor: u16::try_from(multiplexor).unwrap_or(u16::MAX),
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,37 +101,6 @@ error[E0592]: duplicate definitions with name `set_m1`
245 | pub fn set_m1(&mut self, value: ExtMuxCascadedMuxAM1) -> Result<(), CanError> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ duplicate definitions for `set_m1`

error[E0277]: the trait bound `u16: From<i8>` is not satisfied
--> tests-snapshots/dbc-cantools/issue_184_extended_mux_cascaded_dumped.snap.rs:128:46
|
128 | multiplexor: multiplexor.into(),
| ^^^^ the trait `From<i8>` is not implemented for `u16`
|
help: the following other types implement trait `From<T>`
--> $RUST/core/src/ascii/ascii_char.rs
|
| impl const From<AsciiChar> for $ty {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `u16` implements `From<std::ascii::Char>`
...
| into_int_impl!(u8 u16 u32 u64 u128 char);
| ---------------------------------------- in this macro invocation
|
::: $RUST/core/src/convert/num.rs
|
| impl const From<$Small> for $Large {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| `u16` implements `From<bool>`
| `u16` implements `From<u8>`
...
| impl_from!(bool => u16);
| ----------------------- in this macro invocation
...
| impl_from!(u8 => u16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
| -------------------------------------------------------------------------------- in this macro invocation
= note: required for `i8` to implement `Into<u16>`
= note: this error originates in the macro `into_int_impl` which comes from the expansion of the macro `impl_from` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type `ExtMuxCascadedMuxAIndex`
--> tests-snapshots/dbc-cantools/issue_184_extended_mux_cascaded_dumped.snap.rs:195:21
|
Expand All @@ -155,34 +124,3 @@ help: an enum with a similar name exists
202 - ExtMuxCascadedMuxAIndex::M1(ExtMuxCascadedMuxAM1 {
202 + ExtMuxCascadedMuxedA2MuxBIndex::M1(ExtMuxCascadedMuxAM1 {
|

error[E0277]: the trait bound `u16: From<i8>` is not satisfied
--> tests-snapshots/dbc-cantools/issue_184_extended_mux_cascaded_dumped.snap.rs:210:46
|
210 | multiplexor: multiplexor.into(),
| ^^^^ the trait `From<i8>` is not implemented for `u16`
|
help: the following other types implement trait `From<T>`
--> $RUST/core/src/ascii/ascii_char.rs
|
| impl const From<AsciiChar> for $ty {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `u16` implements `From<std::ascii::Char>`
...
| into_int_impl!(u8 u16 u32 u64 u128 char);
| ---------------------------------------- in this macro invocation
|
::: $RUST/core/src/convert/num.rs
|
| impl const From<$Small> for $Large {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| `u16` implements `From<bool>`
| `u16` implements `From<u8>`
...
| impl_from!(bool => u16);
| ----------------------- in this macro invocation
...
| impl_from!(u8 => u16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
| -------------------------------------------------------------------------------- in this macro invocation
= note: required for `i8` to implement `Into<u16>`
= note: this error originates in the macro `into_int_impl` which comes from the expansion of the macro `impl_from` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl ExtMuxIndepMultiplexors {
multiplexor => {
Err(CanError::InvalidMultiplexor {
message_id: ExtMuxIndepMultiplexors::MESSAGE_ID,
multiplexor: multiplexor.into(),
multiplexor: u16::try_from(multiplexor).unwrap_or(u16::MAX),
})
}
}
Expand Down Expand Up @@ -235,7 +235,7 @@ impl ExtMuxIndepMultiplexors {
multiplexor => {
Err(CanError::InvalidMultiplexor {
message_id: ExtMuxIndepMultiplexors::MESSAGE_ID,
multiplexor: multiplexor.into(),
multiplexor: u16::try_from(multiplexor).unwrap_or(u16::MAX),
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,37 +152,6 @@ error[E0592]: duplicate definitions with name `set_m2`
291 | | ) -> Result<(), CanError> {
| |_____________________________^ duplicate definitions for `set_m2`

error[E0277]: the trait bound `u16: From<i8>` is not satisfied
--> tests-snapshots/dbc-cantools/issue_184_extended_mux_independent_multiplexors.snap.rs:137:46
|
137 | multiplexor: multiplexor.into(),
| ^^^^ the trait `From<i8>` is not implemented for `u16`
|
help: the following other types implement trait `From<T>`
--> $RUST/core/src/ascii/ascii_char.rs
|
| impl const From<AsciiChar> for $ty {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `u16` implements `From<std::ascii::Char>`
...
| into_int_impl!(u8 u16 u32 u64 u128 char);
| ---------------------------------------- in this macro invocation
|
::: $RUST/core/src/convert/num.rs
|
| impl const From<$Small> for $Large {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| `u16` implements `From<bool>`
| `u16` implements `From<u8>`
...
| impl_from!(bool => u16);
| ----------------------- in this macro invocation
...
| impl_from!(u8 => u16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
| -------------------------------------------------------------------------------- in this macro invocation
= note: required for `i8` to implement `Into<u16>`
= note: this error originates in the macro `into_int_impl` which comes from the expansion of the macro `impl_from` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type `ExtMuxIndepMultiplexorsMuxAIndex`
--> tests-snapshots/dbc-cantools/issue_184_extended_mux_independent_multiplexors.snap.rs:216:21
|
Expand Down Expand Up @@ -218,34 +187,3 @@ help: an enum with a similar name exists
230 - ExtMuxIndepMultiplexorsMuxAIndex::M2(ExtMuxIndepMultiplexorsMuxAM2 {
230 + ExtMuxIndepMultiplexorsMuxBIndex::M2(ExtMuxIndepMultiplexorsMuxAM2 {
|

error[E0277]: the trait bound `u16: From<i8>` is not satisfied
--> tests-snapshots/dbc-cantools/issue_184_extended_mux_independent_multiplexors.snap.rs:238:46
|
238 | multiplexor: multiplexor.into(),
| ^^^^ the trait `From<i8>` is not implemented for `u16`
|
help: the following other types implement trait `From<T>`
--> $RUST/core/src/ascii/ascii_char.rs
|
| impl const From<AsciiChar> for $ty {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `u16` implements `From<std::ascii::Char>`
...
| into_int_impl!(u8 u16 u32 u64 u128 char);
| ---------------------------------------- in this macro invocation
|
::: $RUST/core/src/convert/num.rs
|
| impl const From<$Small> for $Large {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| `u16` implements `From<bool>`
| `u16` implements `From<u8>`
...
| impl_from!(bool => u16);
| ----------------------- in this macro invocation
...
| impl_from!(u8 => u16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
| -------------------------------------------------------------------------------- in this macro invocation
= note: required for `i8` to implement `Into<u16>`
= note: this error originates in the macro `into_int_impl` which comes from the expansion of the macro `impl_from` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl ExtMuxIndepMultiplexors {
multiplexor => {
Err(CanError::InvalidMultiplexor {
message_id: ExtMuxIndepMultiplexors::MESSAGE_ID,
multiplexor: multiplexor.into(),
multiplexor: u16::try_from(multiplexor).unwrap_or(u16::MAX),
})
}
}
Expand Down Expand Up @@ -235,7 +235,7 @@ impl ExtMuxIndepMultiplexors {
multiplexor => {
Err(CanError::InvalidMultiplexor {
message_id: ExtMuxIndepMultiplexors::MESSAGE_ID,
multiplexor: multiplexor.into(),
multiplexor: u16::try_from(multiplexor).unwrap_or(u16::MAX),
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,37 +152,6 @@ error[E0592]: duplicate definitions with name `set_m2`
291 | | ) -> Result<(), CanError> {
| |_____________________________^ duplicate definitions for `set_m2`

error[E0277]: the trait bound `u16: From<i8>` is not satisfied
--> tests-snapshots/dbc-cantools/issue_184_extended_mux_independent_multiplexors_dumped.snap.rs:137:46
|
137 | multiplexor: multiplexor.into(),
| ^^^^ the trait `From<i8>` is not implemented for `u16`
|
help: the following other types implement trait `From<T>`
--> $RUST/core/src/ascii/ascii_char.rs
|
| impl const From<AsciiChar> for $ty {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `u16` implements `From<std::ascii::Char>`
...
| into_int_impl!(u8 u16 u32 u64 u128 char);
| ---------------------------------------- in this macro invocation
|
::: $RUST/core/src/convert/num.rs
|
| impl const From<$Small> for $Large {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| `u16` implements `From<bool>`
| `u16` implements `From<u8>`
...
| impl_from!(bool => u16);
| ----------------------- in this macro invocation
...
| impl_from!(u8 => u16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
| -------------------------------------------------------------------------------- in this macro invocation
= note: required for `i8` to implement `Into<u16>`
= note: this error originates in the macro `into_int_impl` which comes from the expansion of the macro `impl_from` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared type `ExtMuxIndepMultiplexorsMuxAIndex`
--> tests-snapshots/dbc-cantools/issue_184_extended_mux_independent_multiplexors_dumped.snap.rs:216:21
|
Expand Down Expand Up @@ -218,34 +187,3 @@ help: an enum with a similar name exists
230 - ExtMuxIndepMultiplexorsMuxAIndex::M2(ExtMuxIndepMultiplexorsMuxAM2 {
230 + ExtMuxIndepMultiplexorsMuxBIndex::M2(ExtMuxIndepMultiplexorsMuxAM2 {
|

error[E0277]: the trait bound `u16: From<i8>` is not satisfied
--> tests-snapshots/dbc-cantools/issue_184_extended_mux_independent_multiplexors_dumped.snap.rs:238:46
|
238 | multiplexor: multiplexor.into(),
| ^^^^ the trait `From<i8>` is not implemented for `u16`
|
help: the following other types implement trait `From<T>`
--> $RUST/core/src/ascii/ascii_char.rs
|
| impl const From<AsciiChar> for $ty {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `u16` implements `From<std::ascii::Char>`
...
| into_int_impl!(u8 u16 u32 u64 u128 char);
| ---------------------------------------- in this macro invocation
|
::: $RUST/core/src/convert/num.rs
|
| impl const From<$Small> for $Large {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| `u16` implements `From<bool>`
| `u16` implements `From<u8>`
...
| impl_from!(bool => u16);
| ----------------------- in this macro invocation
...
| impl_from!(u8 => u16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
| -------------------------------------------------------------------------------- in this macro invocation
= note: required for `i8` to implement `Into<u16>`
= note: this error originates in the macro `into_int_impl` which comes from the expansion of the macro `impl_from` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl ExtMuxMultipleValues {
multiplexor => {
Err(CanError::InvalidMultiplexor {
message_id: ExtMuxMultipleValues::MESSAGE_ID,
multiplexor: multiplexor.into(),
multiplexor: u16::try_from(multiplexor).unwrap_or(u16::MAX),
})
}
}
Expand Down
Loading