mdrobnak / isa-ivt-shunt-rs

Rust code to support the Isabellenhuette IVT-S high voltage shunt
MIT License
4 stars 1 forks source link

Consider dbc to rust #1

Open marcelbuesing opened 3 years ago

marcelbuesing commented 3 years ago

I noticed this project by coincidence, you could try dbc-codegen or dbcc, at least their documentation states they provide dbcs. Not sure if it's really worth it here with that number of messages, but I'd be curious=).

mdrobnak commented 3 years ago

dbc-codegen was pretty cool, but the problem is that all of the IDs are configurable :-/ So there's been a few spins on the C side to write something powerful (EVTV version), or easy to use (@Isaac96 version). I have a project in Rust that I will be using it in, and I want to be able to support all of the options, but have a easy-to-use-default.

The code generated did this:

impl Messages {
    /// Read message from CAN frame
    #[inline(never)]
    pub fn from_can_message(id: u32, payload: &[u8]) -> Result<Self, CanError> {
        use core::convert::TryFrom;

        let res = match id {
            1313 => Messages::Msg0x521(Msg0x521::try_from(payload)?),
            1314 => Messages::Msg0x522(Msg0x522::try_from(payload)?),
            1315 => Messages::Msg0x523(Msg0x523::try_from(payload)?),
            1316 => Messages::Msg0x524(Msg0x524::try_from(payload)?),
            n => return Err(CanError::UnknownMessageId(n)),
        };
        Ok(res)
    }
}

which is what I wanted to do, but because they are structure values, it was unclear to me how to do so. Keep in mind I've jumped way into the deep end here by starting with embedded, I've only started working with Rust in mid September.

So if you have suggestions on how to clean up my mess, that's awesome. If not, thanks for pointing out the existence of those projects, maybe it'll come in handy later.

-Matt