CANMessage is the primitive CAN message object. It supports creation, parsing, formatting of messages. Can be easily integrated with CANPort and CANQueue libraries.
CANMessage.h@0:f0ce97992c5f, 2012-07-15 (annotated)
- Committer:
- WiredHome
- Date:
- Sun Jul 15 15:15:18 2012 +0000
- Revision:
- 0:f0ce97992c5f
- Child:
- 2:4307b498b508
[mbed] converted /A_CANAdapter/CANUtilities/CANMessage
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WiredHome | 0:f0ce97992c5f | 1 | /// @file CANMessage.h |
WiredHome | 0:f0ce97992c5f | 2 | /// CANMessage is the primitive CAN message object. It supports creation, |
WiredHome | 0:f0ce97992c5f | 3 | /// parsing, formatting, of messages. |
WiredHome | 0:f0ce97992c5f | 4 | /// |
WiredHome | 0:f0ce97992c5f | 5 | /// @version 1.0 |
WiredHome | 0:f0ce97992c5f | 6 | /// |
WiredHome | 0:f0ce97992c5f | 7 | /// @note Copyright &copr; 2011 by Smartware Computing, all rights reserved. |
WiredHome | 0:f0ce97992c5f | 8 | /// Individuals may use this application for evaluation or non-commercial |
WiredHome | 0:f0ce97992c5f | 9 | /// purposes. Within this restriction, changes may be made to this application |
WiredHome | 0:f0ce97992c5f | 10 | /// as long as this copyright notice is retained. The user shall make |
WiredHome | 0:f0ce97992c5f | 11 | /// clear that their work is a derived work, and not the original. |
WiredHome | 0:f0ce97992c5f | 12 | /// Users of this application and sources accept this application "as is" and |
WiredHome | 0:f0ce97992c5f | 13 | /// shall hold harmless Smartware Computing, for any undesired results while |
WiredHome | 0:f0ce97992c5f | 14 | /// using this application - whether real or imagined. |
WiredHome | 0:f0ce97992c5f | 15 | /// |
WiredHome | 0:f0ce97992c5f | 16 | /// @author David Smart, Smartware Computing |
WiredHome | 0:f0ce97992c5f | 17 | /// |
WiredHome | 0:f0ce97992c5f | 18 | |
WiredHome | 0:f0ce97992c5f | 19 | #ifndef CANMESSAGE_H |
WiredHome | 0:f0ce97992c5f | 20 | #define CANMESSAGE_H |
WiredHome | 0:f0ce97992c5f | 21 | #include "mbed.h" |
WiredHome | 0:f0ce97992c5f | 22 | |
WiredHome | 0:f0ce97992c5f | 23 | /// CAN direction, in the set {rcv, xmt} |
WiredHome | 0:f0ce97992c5f | 24 | typedef enum { |
WiredHome | 0:f0ce97992c5f | 25 | rcv, |
WiredHome | 0:f0ce97992c5f | 26 | xmt |
WiredHome | 0:f0ce97992c5f | 27 | } CANDIR_T; |
WiredHome | 0:f0ce97992c5f | 28 | |
WiredHome | 0:f0ce97992c5f | 29 | |
WiredHome | 0:f0ce97992c5f | 30 | /// CAN Channel in the set {CH1, CH2} of CANCHANNELS |
WiredHome | 0:f0ce97992c5f | 31 | typedef enum { |
WiredHome | 0:f0ce97992c5f | 32 | CH1, |
WiredHome | 0:f0ce97992c5f | 33 | CH2, |
WiredHome | 0:f0ce97992c5f | 34 | CANCHANNELS |
WiredHome | 0:f0ce97992c5f | 35 | } CANCHANNEL_T; |
WiredHome | 0:f0ce97992c5f | 36 | |
WiredHome | 0:f0ce97992c5f | 37 | |
WiredHome | 0:f0ce97992c5f | 38 | // CAN mode - active(acknowledge) or passive(monitor) |
WiredHome | 0:f0ce97992c5f | 39 | //typedef enum { |
WiredHome | 0:f0ce97992c5f | 40 | // ACTIVE, |
WiredHome | 0:f0ce97992c5f | 41 | // PASSIVE |
WiredHome | 0:f0ce97992c5f | 42 | //} CANMODE_T; |
WiredHome | 0:f0ce97992c5f | 43 | |
WiredHome | 0:f0ce97992c5f | 44 | |
WiredHome | 0:f0ce97992c5f | 45 | /// A super CAN message object, which has additional capabilities |
WiredHome | 0:f0ce97992c5f | 46 | /// |
WiredHome | 0:f0ce97992c5f | 47 | /// This object is derived from CANMessage, however it adds |
WiredHome | 0:f0ce97992c5f | 48 | /// a timestamp and other useful methods. |
WiredHome | 0:f0ce97992c5f | 49 | /// |
WiredHome | 0:f0ce97992c5f | 50 | class CANmsg : public CANMessage |
WiredHome | 0:f0ce97992c5f | 51 | { |
WiredHome | 0:f0ce97992c5f | 52 | public: |
WiredHome | 0:f0ce97992c5f | 53 | /// Constructor for a CANmsg object, which is a superclass of CANMessage |
WiredHome | 0:f0ce97992c5f | 54 | /// |
WiredHome | 0:f0ce97992c5f | 55 | /// The CANmsg object included additional information, including |
WiredHome | 0:f0ce97992c5f | 56 | /// direction, channel number, timestamp, and the ability to format |
WiredHome | 0:f0ce97992c5f | 57 | /// into ASCII |
WiredHome | 0:f0ce97992c5f | 58 | /// |
WiredHome | 0:f0ce97992c5f | 59 | CANmsg(); |
WiredHome | 0:f0ce97992c5f | 60 | |
WiredHome | 0:f0ce97992c5f | 61 | /// Constructor for a CANmsg object, which is a superclass of CANMessage |
WiredHome | 0:f0ce97992c5f | 62 | /// |
WiredHome | 0:f0ce97992c5f | 63 | /// The CANmsg object included additional information, including |
WiredHome | 0:f0ce97992c5f | 64 | /// direction, channel number, timestamp, and the ability to format |
WiredHome | 0:f0ce97992c5f | 65 | /// into ASCII. |
WiredHome | 0:f0ce97992c5f | 66 | /// @param ch is the channel number (CH1, CH2) |
WiredHome | 0:f0ce97992c5f | 67 | /// @param dir is the direction (xmt, rcv) |
WiredHome | 0:f0ce97992c5f | 68 | /// @param msg is a CANMessage object from which to construct this object |
WiredHome | 0:f0ce97992c5f | 69 | /// |
WiredHome | 0:f0ce97992c5f | 70 | CANmsg(CANCHANNEL_T ch, CANDIR_T dir, CANMessage msg); |
WiredHome | 0:f0ce97992c5f | 71 | |
WiredHome | 0:f0ce97992c5f | 72 | /// Constructor for a CANmsg object, which is a superclass of CANMessage |
WiredHome | 0:f0ce97992c5f | 73 | /// |
WiredHome | 0:f0ce97992c5f | 74 | /// The CANmsg object included additional information, including |
WiredHome | 0:f0ce97992c5f | 75 | /// direction, channel number, timestamp, and the ability to format |
WiredHome | 0:f0ce97992c5f | 76 | /// into ASCII. |
WiredHome | 0:f0ce97992c5f | 77 | /// This constructor creates a message from an ascii buffer with |
WiredHome | 0:f0ce97992c5f | 78 | /// the standard message format in it. |
WiredHome | 0:f0ce97992c5f | 79 | /// |
WiredHome | 0:f0ce97992c5f | 80 | /// @todo Improve the parser, it may not handle malformed input well |
WiredHome | 0:f0ce97992c5f | 81 | /// |
WiredHome | 0:f0ce97992c5f | 82 | /// @verbatim |
WiredHome | 0:f0ce97992c5f | 83 | /// t xtd 02 1CF00400 08 11 22 33 44 55 66 77 88 0 0 1234.567890 |
WiredHome | 0:f0ce97992c5f | 84 | /// If the first letter is not 't' or 'r', transmit is assumed |
WiredHome | 0:f0ce97992c5f | 85 | /// xtd 02 1CF00400 08 11 22 33 44 55 66 77 88 0 0 1234.567890 |
WiredHome | 0:f0ce97992c5f | 86 | /// @endverbatim |
WiredHome | 0:f0ce97992c5f | 87 | /// |
WiredHome | 0:f0ce97992c5f | 88 | /// @param p is a pointer to a text string of the message contents, |
WiredHome | 0:f0ce97992c5f | 89 | /// in the same format as what would be output with the |
WiredHome | 0:f0ce97992c5f | 90 | /// FormatCANMessage method. |
WiredHome | 0:f0ce97992c5f | 91 | /// |
WiredHome | 0:f0ce97992c5f | 92 | CANmsg(char *p); |
WiredHome | 0:f0ce97992c5f | 93 | |
WiredHome | 0:f0ce97992c5f | 94 | /// Destructor for the CANmsg object |
WiredHome | 0:f0ce97992c5f | 95 | ~CANmsg(); |
WiredHome | 0:f0ce97992c5f | 96 | |
WiredHome | 0:f0ce97992c5f | 97 | /// Parse a text string into the CANmsg object, which is a superclass of CANMessage |
WiredHome | 0:f0ce97992c5f | 98 | /// |
WiredHome | 0:f0ce97992c5f | 99 | /// The CANmsg object included additional information, including |
WiredHome | 0:f0ce97992c5f | 100 | /// direction, channel number, timestamp, and the ability to format |
WiredHome | 0:f0ce97992c5f | 101 | /// into ASCII. |
WiredHome | 0:f0ce97992c5f | 102 | /// This constructor creates a message from an ascii buffer with |
WiredHome | 0:f0ce97992c5f | 103 | /// the standard message format in it. |
WiredHome | 0:f0ce97992c5f | 104 | /// |
WiredHome | 0:f0ce97992c5f | 105 | /// @todo Improve the parser, it may not handle malformed input well |
WiredHome | 0:f0ce97992c5f | 106 | /// |
WiredHome | 0:f0ce97992c5f | 107 | /// @verbatim |
WiredHome | 0:f0ce97992c5f | 108 | /// t xtd 02 1CF00400 08 11 22 33 44 55 66 77 88 0 0 1234.567890 |
WiredHome | 0:f0ce97992c5f | 109 | /// If the first letter is not 't' or 'r', transmit is assumed |
WiredHome | 0:f0ce97992c5f | 110 | /// xtd 02 1CF00400 08 11 22 33 44 55 66 77 88 0 0 1234.567890 |
WiredHome | 0:f0ce97992c5f | 111 | /// @endverbatim |
WiredHome | 0:f0ce97992c5f | 112 | /// |
WiredHome | 0:f0ce97992c5f | 113 | /// @param p is a pointer to a text string of the message contents, |
WiredHome | 0:f0ce97992c5f | 114 | /// in the same format as what would be output with the |
WiredHome | 0:f0ce97992c5f | 115 | /// FormatCANMessage method. |
WiredHome | 0:f0ce97992c5f | 116 | /// @returns true |
WiredHome | 0:f0ce97992c5f | 117 | /// |
WiredHome | 0:f0ce97992c5f | 118 | bool ParseCANMessage(char *p); |
WiredHome | 0:f0ce97992c5f | 119 | |
WiredHome | 0:f0ce97992c5f | 120 | /// Formats this CAN message into a text buffer - which should be at least 70 |
WiredHome | 0:f0ce97992c5f | 121 | /// |
WiredHome | 0:f0ce97992c5f | 122 | /// @todo buflen is currently ignored, which is unsafe |
WiredHome | 0:f0ce97992c5f | 123 | /// |
WiredHome | 0:f0ce97992c5f | 124 | /// @verbatim |
WiredHome | 0:f0ce97992c5f | 125 | /// t xtd 02 1CF00400 08 11 22 33 44 55 66 77 88 0 0 1234.567890 |
WiredHome | 0:f0ce97992c5f | 126 | /// @endverbatim |
WiredHome | 0:f0ce97992c5f | 127 | /// |
WiredHome | 0:f0ce97992c5f | 128 | /// @param buffer is a pointer to the buffer to fill |
WiredHome | 0:f0ce97992c5f | 129 | /// @param buflen is the size of the buffer (minimum 70 recommended) |
WiredHome | 0:f0ce97992c5f | 130 | /// |
WiredHome | 0:f0ce97992c5f | 131 | /// @returns nothing |
WiredHome | 0:f0ce97992c5f | 132 | void FormatCANMessage(char *buffer, int buflen); |
WiredHome | 0:f0ce97992c5f | 133 | |
WiredHome | 0:f0ce97992c5f | 134 | /// Overrides the timestamp in this message with the current time |
WiredHome | 0:f0ce97992c5f | 135 | void SetTimestamp(); |
WiredHome | 0:f0ce97992c5f | 136 | |
WiredHome | 0:f0ce97992c5f | 137 | /// Gets the timestamp of this message |
WiredHome | 0:f0ce97992c5f | 138 | /// @returns time in microseconds |
WiredHome | 0:f0ce97992c5f | 139 | uint64_t GetTimestamp() { return timestamp; }; |
WiredHome | 0:f0ce97992c5f | 140 | |
WiredHome | 0:f0ce97992c5f | 141 | /// direction of this CAN message - rcv or xmt |
WiredHome | 0:f0ce97992c5f | 142 | CANDIR_T dir; |
WiredHome | 0:f0ce97992c5f | 143 | |
WiredHome | 0:f0ce97992c5f | 144 | /// channel number of this CAN message |
WiredHome | 0:f0ce97992c5f | 145 | CANCHANNEL_T ch; |
WiredHome | 0:f0ce97992c5f | 146 | |
WiredHome | 0:f0ce97992c5f | 147 | private: |
WiredHome | 0:f0ce97992c5f | 148 | /// internally held timestamp |
WiredHome | 0:f0ce97992c5f | 149 | uint64_t timestamp; |
WiredHome | 0:f0ce97992c5f | 150 | |
WiredHome | 0:f0ce97992c5f | 151 | // internally held mode |
WiredHome | 0:f0ce97992c5f | 152 | //CANMODE_T mode; |
WiredHome | 0:f0ce97992c5f | 153 | }; |
WiredHome | 0:f0ce97992c5f | 154 | |
WiredHome | 0:f0ce97992c5f | 155 | #endif // CANMESSAGE_H |