Skip to content

Commit b9f2367

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

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

drivers/include/drivers/interfaces/InterfaceCAN.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,35 @@ 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 operator ==(const CANMessage &b) const
117+
{
118+
if (id != b.id) {
119+
return false;
120+
}
121+
if (len != b.len) {
122+
return false;
123+
}
124+
if (format != b.format) {
125+
return false;
126+
}
127+
if (type != b.type) {
128+
return false;
129+
}
130+
if (memcmp(data, b.data, len) != 0) {
131+
return false;
132+
}
133+
134+
return true;
135+
}
136+
137+
bool operator !=(const CANMessage &b) const
138+
{
139+
return !(*this == b);
140+
}
112141
};
113142

114143
/** @}*/

0 commit comments

Comments
 (0)