MIRA
CANDefs.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 MetraLabs GmbH (MLAB), GERMANY.
3  * All rights reserved.
4  * Contact: info@MetraLabs.com
5  *
6  * Commercial Usage:
7  * Licensees holding valid commercial licenses may use this file in
8  * accordance with the commercial license agreement provided with the
9  * software or, alternatively, in accordance with the terms contained in
10  * a written agreement between you and MetraLabs.
11  *
12  * GNU General Public License Usage:
13  * Alternatively, this file may be used under the terms of the GNU
14  * General Public License version 3.0 as published by the Free Software
15  * Foundation and appearing in the file LICENSE.GPL3 included in the
16  * packaging of this file. Please review the following information to
17  * ensure the GNU General Public License version 3.0 requirements will be
18  * met: http://www.gnu.org/copyleft/gpl.html.
19  * Alternatively you may (at your option) use any later version of the GNU
20  * General Public License if such license has been publicly approved by
21  * MetraLabs (or its successors, if any).
22  *
23  * IN NO EVENT SHALL "MLAB" BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
24  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE
25  * OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLABS" HAS BEEN
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * "MLAB" SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
31  * "AS IS" BASIS, AND "MLAB" HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
32  * SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
33  */
34 
43 #ifndef _MLAB_CANDEFS_H_
44 #define _MLAB_CANDEFS_H_
45 
46 #include <platform/Types.h>
47 #include <utils/EnumToFlags.h>
48 #include <utils/Time.h>
49 
50 #include <can/CANExports.h>
51 
52 namespace mira { namespace can {
53 
55 
60  CAN_BAUDRATE_1M = 1000000,
61  CAN_BAUDRATE_500K = 500000,
62  CAN_BAUDRATE_250K = 250000,
63  CAN_BAUDRATE_125K = 125000,
64  CAN_BAUDRATE_100K = 100000,
65  CAN_BAUDRATE_50K = 50000,
66  CAN_BAUDRATE_20K = 20000,
67  CAN_BAUDRATE_10K = 10000,
69 };
70 
72 
77  CAN_STATUS_OK = 0x0000,
84  CAN_STATUS_BUS_OFF = 0x0040,
86 };
87 
89 
92 
94 
95 #define CAN_MAX_STANDARD_ID 0x7ff // 11 bits
96 #define CAN_MAX_EXTENDED_ID 0x1fffffff // 29 bits
97 
98 #define CAN_MSG_TYPE_STANDARD 0x00 // a standard frame
99 #define CAN_MSG_TYPE_RTR 0x01 // a remote frame
100 #define CAN_MSG_TYPE_EXTENDED 0x02 // an extended frame
101 
105 struct CANMessage {
106  uint32 id;
107  uint8 type;
108  uint8 len;
109  uint8 data[8];
111  template<typename Reflector>
112  void reflect(Reflector& r)
113  {
114  r.member("ID", id, "11/29 bit identifier");
115  r.member("Type", type, "CAN message type");
116  r.member("Length", len, "Number of data bytes (0..8)");
117  r.member("Data", data, "Data - Up to 8 data bytes");
118  }
119 
122  id(0xFFFFFFFF), type(CAN_MSG_TYPE_STANDARD), len(0)
123  {
124  memset(&data, 0x00, 8);
125  };
126 };
127 
137  uint16 errorCode;
138  uint8 specific[5];
139 
140  template<typename Reflector>
141  void reflect(Reflector& r)
142  {
143  r.member("ErrorRegister", errorRegister, "One byte error register");
144  r.member("ErrorCode", errorCode, "16 bit error code");
145  r.member("Specific", specific,
146  "Up to 5 data bytes manufacturer specific error information");
147  }
148 
150  errorRegister(0),
151  errorCode(0)
152  {
153  memset(&specific, 0x00, 5);
154  }
155 };
156 
158 
159 }} // namespaces
160 
161 #endif
CANBaudRate
An enum of the different CAN baud rates.
Definition: CANDefs.h:59
Overrun in receive buffer.
Definition: CANDefs.h:80
busoff
Definition: CANDefs.h:84
The receive queue is overrun.
Definition: CANDefs.h:81
No error.
Definition: CANDefs.h:77
An unknown error.
Definition: CANDefs.h:85
The transmit buffer is full.
Definition: CANDefs.h:78
void reflect(Reflector &r)
Definition: CANDefs.h:112
buslight
Definition: CANDefs.h:82
CANEmergencyMessage()
Definition: CANDefs.h:149
20 kBit/s
Definition: CANDefs.h:66
busheavy
Definition: CANDefs.h:83
50 kBit/s
Definition: CANDefs.h:65
A definition of a CAN emergency message.
Definition: CANDefs.h:135
uint8 len
number of data bytes (0...8)
Definition: CANDefs.h:108
The transmit queue is full.
Definition: CANDefs.h:79
5 kBit/s
Definition: CANDefs.h:68
uint8 specific[5]
Up to 5 data bytes manufacturer specific error information.
Definition: CANDefs.h:138
#define MLAB_CAN_EXPORT
Definition: CANExports.h:57
CANStatusFlags
CAN status enum definitions.
Definition: CANDefs.h:76
uint8 type
CAN_MSG_TYPE_*.
Definition: CANDefs.h:107
CAN export macro declaration.
#define CAN_MSG_TYPE_STANDARD
Definition: CANDefs.h:98
uint8 data[8]
up to 8 data bytes
Definition: CANDefs.h:109
100 kBit/s
Definition: CANDefs.h:64
10 kBit/s
Definition: CANDefs.h:67
125 kBit/s
Definition: CANDefs.h:63
MLAB_CAN_EXPORT std::string convertCANStatus2String(CANStatusFlags)
Convert a CANStatusFlag into a human-readable message.
void reflect(Reflector &r)
Definition: CANDefs.h:141
uint16 errorCode
16 bit emergency error code
Definition: CANDefs.h:137
A definition of a CAN message.
Definition: CANDefs.h:105
CANMessage()
The constructor for this struct.
Definition: CANDefs.h:121
MIRA_ENUM_TO_FLAGS(CANStatusFlags)
1 MBit/s
Definition: CANDefs.h:60
500 kBit/s
Definition: CANDefs.h:61
250 kBit/s
Definition: CANDefs.h:62
uint8 errorRegister
One byte error register (Object 1001h of the local object dictionary)
Definition: CANDefs.h:136
uint32 id
11/29 bit identifier
Definition: CANDefs.h:106