Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: CANMsg.h
- Revision:
- 4:5017a65ff423
- Parent:
- 3:4e42fdc0459f
- Child:
- 5:db8883da4778
diff -r 4e42fdc0459f -r 5017a65ff423 CANMsg.h
--- a/CANMsg.h Wed Apr 25 11:47:00 2018 +0000
+++ b/CANMsg.h Tue Feb 05 14:50:19 2019 +0000
@@ -12,7 +12,7 @@
#include "CAN.h"
-class CANMsg : public CANMessage
+class CANMsg : public mbed::CANMessage
{
public:
/** Creates empty CAN message.
@@ -45,7 +45,6 @@
template<class T>
CANMsg &operator<<(const T val) {
MBED_ASSERT(len + sizeof(T) <= 8);
- //*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;
@@ -56,8 +55,14 @@
template<class T>
CANMsg &operator>>(T& val) {
MBED_ASSERT(sizeof(T) <= len);
- val = *reinterpret_cast<T*>(&data[0]);
- len -= sizeof(T);
+ 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;
}