Skip to content

Commit

Permalink
Fix backward compatibility issue with len and dlc
Browse files Browse the repository at this point in the history
  • Loading branch information
twast92 committed Oct 6, 2022
1 parent b5d366c commit 488e19b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/modm/architecture/interface/can_message.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ namespace modm::can
/// @ingroup modm_architecture_can
struct Message
{
inline Message(uint32_t inIdentifier = 0, uint8_t inDlc = 0) :
identifier(inIdentifier), flags(), length(inDlc)
inline Message(uint32_t inIdentifier = 0, uint8_t inLength = 0) :
identifier(inIdentifier), flags()
{
setLength(inLength);
}

inline Message(uint32_t inIdentifier, uint8_t inDlc, const uint64_t &inData, bool extended = false) :
Message(inIdentifier, inDlc)
inline Message(uint32_t inIdentifier, uint8_t inLength, const uint64_t &inData, bool extended = false) :
Message(inIdentifier, inLength)
{
flags.extended = extended;
const uint8_t *inDataB = reinterpret_cast<const uint8_t *>(&inData);
Expand Down Expand Up @@ -103,8 +104,10 @@ struct Message
setDataLengthCode(uint8_t inDlc)
{
while (dlcConversionTable[inDlc] > capacity) inDlc--;

dlc = inDlc;
length = dlcConversionTable[inDlc];
if (dlc > 8) setFlexibleData();
}

inline void
Expand All @@ -124,7 +127,7 @@ struct Message
inline uint8_t
getDataLengthCode() const
{
return length;
return dlc;
}

public:
Expand Down Expand Up @@ -153,6 +156,7 @@ public:
operator == (const modm::can::Message& rhs) const
{
return ((this->identifier == rhs.identifier) and
(this->dlc == rhs.dlc) and
(this->length == rhs.length) and
(this->flags.fd == rhs.flags.fd) and
(this->flags.brs == rhs.flags.brs) and
Expand All @@ -165,6 +169,7 @@ public:
operator = (const modm::can::Message& rhs)
{
this->identifier = rhs.identifier;
this->dlc = rhs.dlc;
this->length = rhs.length;
this->flags.fd = rhs.flags.fd;
this->flags.brs = rhs.flags.brs;
Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/can/stm32-fdcan/can.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ readMsg(modm::can::Message& message, uint8_t fifoIndex, uint8_t* filter_id, uint
}

const uint8_t dlcValue = MessageRam::RxDlc_t::get(rxHeader);
message.setLength(dlcValue);
message.setDataLengthCode(dlcValue);

// required for optimization in MessageRam::readData()
static_assert((std::size(decltype(message.data){}) % 4) == 0);
Expand Down

0 comments on commit 488e19b

Please sign in to comment.