Skip to content

Commit

Permalink
Add CANMessage deep comparison operators
Browse files Browse the repository at this point in the history
  • Loading branch information
AGlass0fMilk committed May 18, 2021
1 parent 7279ae2 commit b9f2367
Showing 1 changed file with 29 additions and 0 deletions.
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

0 comments on commit b9f2367

Please sign in to comment.