nana
Diff: CANMsg.h
- Revision:
- 2:2b8425b12d05
- Parent:
- 1:34738eb16cf7
- Child:
- 3:4e42fdc0459f
--- a/CANMsg.h Sat Mar 18 23:09:30 2017 +0000 +++ b/CANMsg.h Thu Mar 29 18:56:19 2018 +0000 @@ -44,32 +44,20 @@ */ template<class T> CANMsg &operator<<(const T val) { - if(len + sizeof(T) <= 8) { - *reinterpret_cast < T * > (&data[len]) = val; - len += sizeof(T); - } -#if DEBUG - else { - printf("Error: Cannot append data - exceeding CAN data length!\r\n"); - } -#endif - return *this; + MBED_ASSERT(len + sizeof(T) <= 8); + *reinterpret_cast<T*>(&data[len]) = val; + len += sizeof(T); + return *this; } /** Extract operator: Extracts data (value) from CAN message */ template<class T> CANMsg &operator>>(T& val) { - if(sizeof(T) <= len) { - val = *reinterpret_cast < T * > (&data[0]); - len -= sizeof(T); - memcpy(data, data + sizeof(T), len); - } -#if DEBUG - else { - printf("Error: Cannot extract data - exceeding CAN data length!\r\n"); - } -#endif + MBED_ASSERT(sizeof(T) <= len); + val = *reinterpret_cast<T*>(&data[0]); + len -= sizeof(T); + memcpy(data, data + sizeof(T), len); return *this; } };