CANMessage is the primitive CAN message object. It supports creation, parsing, formatting of messages. Can be easily integrated with CANPort and CANQueue libraries.
Diff: CANMessage.cpp
- Revision:
- 1:c56577ae52df
- Parent:
- 0:f0ce97992c5f
- Child:
- 2:4307b498b508
--- a/CANMessage.cpp Sun Jul 15 15:15:18 2012 +0000 +++ b/CANMessage.cpp Wed Aug 28 22:02:43 2019 +0000 @@ -20,13 +20,36 @@ /// \li Extending timestamp to 64 bits /// #include <mbed.h> + #include "CANMessage.h" -#include "Utilities.h" // mbed <-> Visual Studio +#include "Utilities.h" // missing functions... + +//#include "FreeRunTimer.h" + +static Timer timer; +static bool timer_on; -#include "FreeRunTimer.h" +static char mytolower(char a) { + if (a >= 'A' && a <= 'Z') + return (a - 'A' + 'a'); + else + return a; +} + +static int mystrnicmp(const char *l, const char *r, size_t n) { + int result = 0; -static FreeRunTimer timer; -static bool timer_on; + if (n != 0) { + do { + result = mytolower(*l++) - mytolower(*r++); + } while ((result == 0) && (*l != '\0') && (--n > 0)); + } + if (result < -1) + result = -1; + else if (result > 1) + result = 1; + return result; +} CANmsg::CANmsg() { if (!timer_on) { @@ -110,7 +133,7 @@ } // 12345678901234567890123456789012345678901234567890123456789012345 -// r xtd 01 1CF00400 08 11 22 33 44 55 66 77 88 0 0 0012.123456 +// r xtd 01 1CF00400 08 11 22 33 44 55 66 77 88 0 0 12.123456 void CANmsg::FormatCANMessage(char *buffer, int buflen) { if (buflen >= 68) { // 63+\r+\n+\0+2spare sprintf(buffer, "%c %s %02d %08X %02X ", @@ -127,7 +150,7 @@ } uint32_t uSec = timestamp % 1000000; // integer math is faster than float uint32_t Sec = timestamp / 1000000; - sprintf(buffer + strlen(buffer), "0 0 %04u.%06u", Sec, uSec); + sprintf(buffer + strlen(buffer), "0 0 %6u.%06u", Sec, uSec); } else { strcpy(buffer,"ERROR, buf too small"); }