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

Add CANMessage deep comparison operators #14662

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions drivers/include/drivers/interfaces/InterfaceCAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,35 @@ class CANMessage : public CAN_Message {
id = _id;
memset(data, 0, 8);
}

/**
* "Deep" comparison operator (ie: compare value of each data member)
*/
bool operator ==(const CANMessage &b) const
{
if (id != b.id) {
return false;
}
if (len != b.len) {
return false;
}
if (format != b.format) {
return false;
}
if (type != b.type) {
return false;
}
if (memcmp(data, b.data, len) != 0) {
return false;
}

return true;
}

bool operator !=(const CANMessage &b) const
{
return !(*this == b);
}
};

/** @}*/
Expand Down