MIRA
CANOpenUtil.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_CANOPENUTIL_H_
44 #define _MLAB_CANOPENUTIL_H_
45 
46 #include <string>
47 
48 #include <can/CANDefs.h>
49 #include <can/CANOpenDefs.h>
50 
51 namespace mira { namespace can {
52 
54 
58 namespace CANOpenUtil
59 {
60 
62 
64 MLAB_CAN_EXPORT std::string getErrorMsg(CANOpenError pError);
65 
67 MLAB_CAN_EXPORT std::string getTypeString(CANOpenType pType);
68 
71 
74 
77 
79 
81 template<typename T>
82 T read(const CANMessage& message, std::size_t offset)
83 {
84  static_assert(sizeof(T) == 0, "Not implemented for this type.");
85 }
86 
88 template<> MLAB_CAN_EXPORT int8 read<int8>(const CANMessage& message,
89  std::size_t offset);
90 
92 template<> MLAB_CAN_EXPORT int16 read<int16>(const CANMessage& message,
93  std::size_t offset);
94 
96 template<> MLAB_CAN_EXPORT int32 read<int32>(const CANMessage& message,
97  std::size_t offset);
98 
100 template<> MLAB_CAN_EXPORT int64 read<int64>(const CANMessage& message,
101  std::size_t offset);
102 
104 template<> MLAB_CAN_EXPORT uint8 read<uint8>(const CANMessage& message,
105  std::size_t offset);
106 
108 template<> MLAB_CAN_EXPORT uint16 read<uint16>(const CANMessage& message,
109  std::size_t offset);
110 
112 template<> MLAB_CAN_EXPORT uint32 read<uint32>(const CANMessage& message,
113  std::size_t offset);
114 
116 template<> MLAB_CAN_EXPORT uint64 read<uint64>(const CANMessage& message,
117  std::size_t offset);
118 
120 template<> MLAB_CAN_EXPORT float read<float>(const CANMessage& message,
121  std::size_t offsete);
122 
124 template<> MLAB_CAN_EXPORT double read<double>(const CANMessage& message,
125  std::size_t offset);
126 
128 
130 template<typename T>
131 std::size_t write(CANMessage& ioMmessage, std::size_t offset, T value)
132 {
133  static_assert(sizeof(T) == 0, "Not implemented for this type.");
134  return(0);
135 }
136 
138 template<> MLAB_CAN_EXPORT std::size_t write<int8>(CANMessage& ioMmessage,
139  std::size_t offset,
140  int8 value);
141 
143 template<> MLAB_CAN_EXPORT std::size_t write<int16>(CANMessage& ioMmessage,
144  std::size_t offset,
145  int16 value);
146 
148 template<> MLAB_CAN_EXPORT std::size_t write<int32>(CANMessage& ioMmessage,
149  std::size_t offset,
150  int32 value);
151 
153 template<> MLAB_CAN_EXPORT std::size_t write<int64>(CANMessage& ioMmessage,
154  std::size_t offset,
155  int64 value);
156 
158 template<> MLAB_CAN_EXPORT std::size_t write<uint8>(CANMessage& ioMmessage,
159  std::size_t offset,
160  uint8 value);
161 
163 template<> MLAB_CAN_EXPORT std::size_t write<uint16>(CANMessage& ioMmessage,
164  std::size_t offset,
165  uint16 value);
166 
168 template<> MLAB_CAN_EXPORT std::size_t write<uint32>(CANMessage& ioMmessage,
169  std::size_t offset,
170  uint32 value);
171 
173 template<> MLAB_CAN_EXPORT std::size_t write<uint64>(CANMessage& ioMmessage,
174  std::size_t offset,
175  uint64 value);
176 
178 template<> MLAB_CAN_EXPORT std::size_t write<float>(CANMessage& ioMmessage,
179  std::size_t offset,
180  float value);
181 
183 template<> MLAB_CAN_EXPORT std::size_t write<double>(CANMessage& ioMmessage,
184  std::size_t offset,
185  double value);
186 
188 
189 } // namespace CANOpenUtil
190 
192 
193 }} // namespaces
194 
195 #endif
MLAB_CAN_EXPORT uint8 read< uint8 >(const CANMessage &message, std::size_t offset)
CANopen read for uint8.
MLAB_CAN_EXPORT std::size_t write< int8 >(CANMessage &ioMmessage, std::size_t offset, int8 value)
CANopen write for int8.
MLAB_CAN_EXPORT std::size_t write< uint32 >(CANMessage &ioMmessage, std::size_t offset, uint32 value)
CANopen write for uint32.
MLAB_CAN_EXPORT std::string getNodeStatusString(CANOpenNodeStatus pStatus)
Get a textual description of a CANopen node status.
MLAB_CAN_EXPORT int16 read< int16 >(const CANMessage &message, std::size_t offset)
CANopen read for int16.
CANOpenError
CANopen error definitions.
Definition: CANOpenDefs.h:53
MLAB_CAN_EXPORT std::size_t write< uint64 >(CANMessage &ioMmessage, std::size_t offset, uint64 value)
CANopen write for uint64.
MLAB_CAN_EXPORT std::size_t write< float >(CANMessage &ioMmessage, std::size_t offset, float value)
CANopen write for float.
MLAB_CAN_EXPORT std::string getErrorMsg(CANOpenError pError)
Get a textual description of a CANopen error.
MLAB_CAN_EXPORT std::string getAccessModeString(CANOpenAccessMode pMode)
Get a textual description of a CANopen access mode.
T read(const CANMessage &message, std::size_t offset)
A template based read operation of CANopen data types.
Definition: CANOpenUtil.h:82
Global definitions of the CANopen standard.
CANOpenAccessMode
The different access rights of a CANopen SDO.
Definition: CANOpenDefs.h:143
MLAB_CAN_EXPORT std::size_t write< int16 >(CANMessage &ioMmessage, std::size_t offset, int16 value)
CANopen write for int16.
MLAB_CAN_EXPORT std::size_t write< uint16 >(CANMessage &ioMmessage, std::size_t offset, uint16 value)
CANopen write for uint16.
MLAB_CAN_EXPORT std::size_t write< double >(CANMessage &ioMmessage, std::size_t offset, double value)
CANopen write for double.
MLAB_CAN_EXPORT float read< float >(const CANMessage &message, std::size_t offsete)
CANopen read for float.
CANOpenType
CANopen type definitions.
Definition: CANOpenDefs.h:92
MLAB_CAN_EXPORT double read< double >(const CANMessage &message, std::size_t offset)
CANopen read for double.
MLAB_CAN_EXPORT std::size_t write< uint8 >(CANMessage &ioMmessage, std::size_t offset, uint8 value)
CANopen write for uint8.
CANOpenNodeStatus
The different CANopen node states.
Definition: CANOpenDefs.h:154
MLAB_CAN_EXPORT std::string getTypeString(CANOpenType pType)
Get a textual description of a CANopen type.
std::size_t write(CANMessage &ioMmessage, std::size_t offset, T value)
A template based write operation of CANopen data types.
Definition: CANOpenUtil.h:131
MLAB_CAN_EXPORT uint32 read< uint32 >(const CANMessage &message, std::size_t offset)
CANopen read for uint32.
#define MLAB_CAN_EXPORT
Definition: CANExports.h:57
MLAB_CAN_EXPORT int32 read< int32 >(const CANMessage &message, std::size_t offset)
CANopen read for int32.
MLAB_CAN_EXPORT std::size_t write< int64 >(CANMessage &ioMmessage, std::size_t offset, int64 value)
CANopen write for int64.
MLAB_CAN_EXPORT std::size_t write< int32 >(CANMessage &ioMmessage, std::size_t offset, int32 value)
CANopen write for int32.
MLAB_CAN_EXPORT int8 read< int8 >(const CANMessage &message, std::size_t offset)
CANopen read for int8.
A definition of a CAN message.
Definition: CANDefs.h:105
Common CANbus definitions.
MLAB_CAN_EXPORT int64 read< int64 >(const CANMessage &message, std::size_t offset)
CANopen read for int64.
MLAB_CAN_EXPORT uint64 read< uint64 >(const CANMessage &message, std::size_t offset)
CANopen read for uint64.
MLAB_CAN_EXPORT uint16 read< uint16 >(const CANMessage &message, std::size_t offset)
CANopen read for uint16.
CANOpenSDOKind
The different SDO kinds.
Definition: CANOpenDefs.h:130
MLAB_CAN_EXPORT std::string getSDOKindString(CANOpenSDOKind pKind)
Get a textual description of a CANopen SDO kind.