nana
Revision 5:d037e8c6ce88, committed 2021-09-01
- Comitter:
- kurobikari
- Date:
- Wed Sep 01 02:43:33 2021 +0000
- Parent:
- 4:5017a65ff423
- Commit message:
- CAN
Changed in this revision
CANMsg.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/CANMsg.h Tue Feb 05 14:50:19 2019 +0000 +++ b/CANMsg.h Wed Sep 01 02:43:33 2021 +0000 @@ -1,14 +1,3 @@ -#ifndef CANMSG_H -#define CANMSG_H - -/* CAN message container. - * Provides "<<" (append) and ">>" (extract) operators to simplyfy - * adding/getting data items to/from a CAN message. - * Usage is similar to the C++ io-stream operators. - * Data length of CAN message is automatically updated when using "<<" or ">>" operators. - * - * See Wiki page <https://developer.mbed.org/users/hudakz/code/CAN_Hello/> for demo. - */ #include "CAN.h" @@ -39,33 +28,6 @@ id = 0; memset(data, 0, 8); }; - - /** Append operator: Appends data (value) to CAN message - */ - template<class T> - CANMsg &operator<<(const T val) { - MBED_ASSERT(len + sizeof(T) <= 8); - memcpy(&data[len], &val, sizeof(T)); - len += sizeof(T); - return *this; - } - - /** Extract operator: Extracts data (value) from CAN message - */ - template<class T> - CANMsg &operator>>(T& val) { - MBED_ASSERT(sizeof(T) <= len); - if (sizeof(T) > len) { - memcpy(&val, data, len); - len = 0; - } - else { - memcpy(&val, data, sizeof(T)); - len -= sizeof(T); - } - memcpy(data, data + sizeof(T), len); - return *this; - } }; -#endif // CANMSG_H +