Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplexed signal implementation #33

Merged
merged 27 commits into from
Apr 15, 2021

Conversation

marcelbuesing
Copy link
Contributor

This is currently work in progress. Whats basically missing right now, besides a cleanup, is adding the signal fns to the multiplex structs.

Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some drive-by comments

Like the apporoach of constructing enums with a ref to the raw data slice. I would however like to point out that referencing what is at most 8 bytes with a fat pointer is in the best case (on 32bit ARM) as fast as just copying the whole slice! 😉

src/lib.rs Outdated Show resolved Hide resolved
testing/can-messages/src/messages.rs Outdated Show resolved Hide resolved
@marcelbuesing
Copy link
Contributor Author

Some drive-by comments

Like the apporoach of constructing enums with a ref to the raw data slice. I would however like to point out that referencing what is at most 8 bytes with a fat pointer is in the best case (on 32bit ARM) as fast as just copying the whole slice! wink

I think for standard can frames I agree it's probably not worth passing refs compared to copying. It looks like (example here shows a message with 33 bytes payload) dbc-files is maybe used with CAN-FD (max 64 bytes) or ISO-TP (max 4095 bytes) though. Copy nevertheless as it's maybe an edge case?

@killercup
Copy link
Member

killercup commented Mar 28, 2021 via email

Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry for dropping this over easter! How far along is this? I've added some small comments here and there, but I also saw you had a TODO comment. Want to get this into a state where we can merge it even if it's not 100% complete?

testing/dbc-examples/example.dbc Outdated Show resolved Hide resolved
testing/can-messages/src/messages.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
@marcelbuesing
Copy link
Contributor Author

marcelbuesing commented Apr 12, 2021

Hey, sorry for dropping this over easter! How far along is this? I've added some small comments here and there, but I also saw you had a TODO comment. Want to get this into a state where we can merge it even if it's not 100% complete?

It's usable now, still needs tests against the cantools implementation for verification. I am not particularly happy with the way setting multiplexed signal variants works. See the all.rs pack_unpack_message_containing_multiplexed_signals for a demo. It'd be great if anyone has a better idea for this. The only alternative I see right now is passing some lambda that modifies the values. E.g. something along:

set_M0(|m0| {
   mo.set_multiplexed_signal_zero_a_raw(1.2)?
      .set_multiplexed_signal_zero_b_raw(2.0))?;
   Ok(())
}

@killercup
Copy link
Member

Wow, amazing work!

Fist off: Why did you change all setters to _raw? IIRC the raw getter is only useful when you want to raw bits from an enum representation. I'd argue that the default should always be the non-raw version.

Thinking about setters, I'm again conflicted about the borrowing of the data… I think the ideal API is msg.set_M0(MultiplexTestMultiplexorM0::new(1.0. 1.5)?). This does not require creating a signal with a default value and changing it in a closure as it is correct by construction. Do you agree?

We can achieve this by either making the enum own its bytes, or by making it a wrapper around Cow. I'd go for making everything more simple and just use the owned data until we run into issues :)

@marcelbuesing
Copy link
Contributor Author

marcelbuesing commented Apr 13, 2021

Wow, amazing work!

Fist off: Why did you change all setters to _raw? IIRC the raw getter is only useful when you want to raw bits from an enum representation. I'd argue that the default should always be the non-raw version.

Thinking about setters, I'm again conflicted about the borrowing of the data… I think the ideal API is msg.set_M0(MultiplexTestMultiplexorM0::new(1.0. 1.5)?). This does not require creating a signal with a default value and changing it in a closure as it is correct by construction. Do you agree?

We can achieve this by either making the enum own its bytes, or by making it a wrapper around Cow. I'd go for making everything more simple and just use the owned data until we run into issues :)

I reverted the _raw suffix changes. I think it would be great in the future to have a more convenient, safer new fn that takes e.g. enums as parameters where available and the same for setters. Anyway this should not be part of this PR see #39 .

Regardings the setters, I will try it with owned data and see how it turns out, I agree for now it probably should not be an issue and it's better to change it later when the need comes up.

@marcelbuesing
Copy link
Contributor Author

marcelbuesing commented Apr 13, 2021

Ok I changed it, I think it looks better now. Any ideas how to do the whole thing without bitvec::BitArray for bitwise or ?

Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick update again!

testing/can-messages/src/messages.rs Outdated Show resolved Hide resolved
testing/can-messages/src/messages.rs Outdated Show resolved Hide resolved
Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick update again again!

I saw you fixed some clippy errors, can you also fix the "use of or_insert followed by a function call" ones?

writeln!(
&mut w,
"_ => Err(CanError::InvalidMultiplexor {{ message_id: {}}}),",
msg.message_id().0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, looking at this again, do you think we should include the mulitplexor value? Can we always convert it to a u16 or something? Upside: Better debugging. Downside: Larger size of CanError type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think it's safe to say that it should be possible to convert into u16. I would probably even assume you'll never need more than u8. I think it certainly helps to add the value, otherwise it's hard to debug. So I think it's worth the downside. Went with u16 now, but like i said i can not imagine a use case that requires more than u8 and if there is such a use case that would at least to a compile time error with the generated code.

@killercup
Copy link
Member

I think this is good to merge besides the small comments above. What do you think?

@marcelbuesing
Copy link
Contributor Author

marcelbuesing commented Apr 14, 2021

I think this is good to merge besides the small comments above. What do you think?

Yes I think it's good now, besides the error type u8/u16 question it should be fine now. I fixed the clippy warnings. Besides that I removed the associated switch index constant as now one can not set the raw value of multiplexor anyway, I don't think it adds value otherwise.

@killercup
Copy link
Member

Alright, let's merge this then!

Thanks again for working on this for weeks -- super impressive!

@killercup killercup merged commit c55cd4f into technocreatives:main Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants