modm-io / modm

modm: a C++23 library generator for AVR and ARM Cortex-M devices
https://modm.io
Mozilla Public License 2.0
720 stars 128 forks source link

CAN messages set to extended by default in only one constructor #1178

Open calebchalmers opened 3 weeks ago

calebchalmers commented 3 weeks ago

Inside can_message.hpp, there are three constructors for modm::can::Message: The first one leaves the message data initialized with all zeros and keep the default flags; this results in extended being true by default. The remaining two constructors allow for initializing with data and have an extended parameter which is false by default.

I realize this is a relatively small and breaking change, but I think it would be ideal if extended was always false by default, and if the first constructor had an extended parameter, to avoid having to declare an extra array like this:

uint8_t inData[8]{};  // all zeros array
modm::can::Message message(MESSAGE_IDENTIFIER, MESSAGE_LENGTH, inData, false);
salkinium commented 3 weeks ago

I'm also tending more towards having all bits zero initialized (thus extended=0) in the default constructor. However, if we're going to break the behavior (silent failure), then we should also break the interface entirely (compilation failure). I personally don't like the CAN Message class very much, perhaps there is a better way to model this.