technocreatives / dbc-codegen

Generate Rust structs for messages from a dbc (CAN bus definition) file.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement multiplexed signals

marcelbuesing opened this issue · comments

Messages may contain multiplexed signals e.g.

MessageA:
SignalA (Plain / Normal signal)
Signal multiplexorX
SignalY multiplexed by multiplexorX
SignalZ multiplexed by multiplexorX

Basically this means here the multiplexorX indicates whether SignalY or SignalZ ist send as part of this frame. A "plain" signal is always included in the frame (not multiplexed). A message may contain zero, one or multiple multiplexors.
Whether a signal is multiplexed or not is indicated by the MultiplexIndicator.

Designwise I think multiplexed signals can be represented in two ways:

  • A function that returns an Option e.g. here signal_y_raw(&self) -> Option<...>
  • A function that returns an Enum e.g. here signal_x_raw(&self) -> SignalXMultiplexed where the SignalXMultiplexed enum would basically be Y or Z.

I think from an API perspective it's actually more convenient to use the enum variant as it makes it clear what signals are part of which multiplexor and saves some comparsions with Option values that can not even be Some.

I would also prefer enum variant.