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: ManchesterMsg.h
- Revision:
- 2:de778df5892c
- Parent:
- 0:d5c75b0e5708
- Child:
- 4:f2c392191c74
--- a/ManchesterMsg.h Wed May 17 08:17:13 2017 +0000
+++ b/ManchesterMsg.h Wed May 17 21:02:49 2017 +0000
@@ -2,7 +2,7 @@
******************************************************************************
* @file ManchesterMsg.h
* @author Zoltan Hudak
- * @version
+ * @version
* @date 16-May-2017
* @brief Message container
******************************************************************************
@@ -25,7 +25,6 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
#ifndef MANCHESTERMSG_H
#define MANCHESTERMSG_H
@@ -35,42 +34,36 @@
*/
class ManchesterMsg
{
- unsigned char _max; // Max length (capacity) of data field in bytes
+ size_t _max; // Max length (capacity) of data field in bytes
public:
- char* data; // Data field
- unsigned char len; // Length of data in bytes
+ char* data; // Data field
+ size_t len; // Length of data in bytes
/** Creates empty Manchester message of specified capacity.
*/
- ManchesterMsg(unsigned char max) :
- _max(max),
- data(new char[max]) { len = 0; }
+ ManchesterMsg(size_t max) : _max(max), data(new char[max]) { len = 0; }
- ~ManchesterMsg(void) { delete[] data; }
+ ~ ManchesterMsg(void) { delete[] data; }
- /** Copy constructor.
+ /** Copy constructor.
*/
- ManchesterMsg(const ManchesterMsg& msg) {
- len = msg.len;
- memcpy(data, msg.data, msg.len);
- }
-
-
+ ManchesterMsg(const ManchesterMsg& msg) { len = msg.len; memcpy(data, msg.data, msg.len); }
+
/** Returns message maximum length (capacity)
*/
- unsigned char maxLen(void) { return _max; }
+ size_t maxLen(void) { return _max; }
/** Clears message content
*/
- void clear(void) { len = 0; memset(data, 0, _max); }
+ void clear(void) { len = 0; memset(data, 0, _max); }
/** Inserter operator: Appends data (value) to Manchester message
*/
template<class T>
ManchesterMsg &operator<<(const T val) {
if(len + sizeof(T) <= _max) {
- *reinterpret_cast <T*> (&data[len]) = val;
+ *reinterpret_cast < T * > (&data[len]) = val;
len += sizeof(T);
}
@@ -85,10 +78,10 @@
/** Inserter operator: Appends string of char to Manchester message
*/
ManchesterMsg &operator<<(const char* str) {
- unsigned char strLen = strlen(str);
+ size_t strLen = strlen(str);
if(len + strLen + 1 <= _max) {
memcpy(data + len, (char*)str, strLen);
- len += strLen;
+ len += strLen;
data[len++] = '\0';
}
@@ -105,7 +98,7 @@
template<class T>
ManchesterMsg &operator>>(T& val) {
if(sizeof(T) <= len) {
- val = *reinterpret_cast <T*> (&data[0]);
+ val = *reinterpret_cast < T * > (&data[0]);
len -= sizeof(T);
memcpy(data, data + sizeof(T), len);
}
@@ -117,10 +110,11 @@
#endif
return *this;
}
+
/** Extractor operator: Extracts string of char from CAN message
*/
ManchesterMsg &operator>>(char* str) {
- unsigned char strLen = strlen(data);
+ size_t strLen = strlen(data);
if(strLen <= len) {
memcpy(str, data, strLen + 1);
len -= (strLen + 1);