Skip to content

Commit d16df8c

Browse files
committed
Add CANMessage deep comparison operators
1 parent 7279ae2 commit d16df8c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

drivers/include/drivers/interfaces/InterfaceCAN.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,28 @@ class CANMessage : public CAN_Message {
109109
id = _id;
110110
memset(data, 0, 8);
111111
}
112+
113+
/**
114+
* "Deep" comparison operator (ie: compare value of each data member)
115+
*/
116+
bool CANMessage::operator ==(const CANMessage &b) const {
117+
if(id != b.id)
118+
return false;
119+
if(len != b.len)
120+
return false;
121+
if(format != b.format)
122+
return false;
123+
if(type != b.type)
124+
return false;
125+
if(memcmp(data, b.data, len) != 0)
126+
return false;
127+
128+
return true;
129+
}
130+
131+
bool CANMessage::operator !=(const CANMessage &b) const {
132+
return !(*this == b);
133+
}
112134
};
113135

114136
/** @}*/

0 commit comments

Comments
 (0)