CAN message container. Defines "<<" and ">>" operators to simplify adding/getting data to/from a CAN message.
Dependents: grove_stream_jpa_sd2 grove_stream_jpa_sd2 grove_stream_jpa_sd2-2 grove_stream_jpa_sd2-3
Diff: CANMsg.h
- Revision:
- 3:4e42fdc0459f
- Parent:
- 2:2b8425b12d05
- Child:
- 4:5017a65ff423
--- a/CANMsg.h Thu Mar 29 18:56:19 2018 +0000 +++ b/CANMsg.h Wed Apr 25 11:47:00 2018 +0000 @@ -45,7 +45,8 @@ template<class T> CANMsg &operator<<(const T val) { MBED_ASSERT(len + sizeof(T) <= 8); - *reinterpret_cast<T*>(&data[len]) = val; + //*reinterpret_cast<T*>(&data[len]) = val; // This used to work but now it hangs at run time. + memcpy(&data[len], &val, sizeof(T)); len += sizeof(T); return *this; }