2 This file is part of CanFestival, a library implementing CanOpen Stack.
4 Copyright (C): Edouard TISSERANT and Francis DUPIN
6 See COPYING file for copyrights details.
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * @brief Responsible for accessing the object dictionary.
26 * This file contains functions for accessing the object dictionary and
27 * variables that are contained by the object dictionary.
28 * Accessing the object dictionary contains setting local variables
29 * as PDOs and accessing (read/write) all entries of the object dictionary
30 * @warning Only the basic entries of an object dictionary are included
34 /** @defgroup od Object Dictionary Management
35 * @brief The Object Dictionary is the heart of each CANopen device containing all communication and application objects.
39 #ifndef __objacces_h__
40 #define __objacces_h__
44 typedef UNS32 (*valueRangeTest_t)(UNS8 typeValue, void *Value);
45 typedef void (* storeODSubIndex_t)(CO_Data* d, UNS16 wIndex, UNS8 bSubindex);
46 void _storeODSubIndex (CO_Data* d, UNS16 wIndex, UNS8 bSubindex);
50 * @brief Print MSG_WAR (s) if error to the access to the object dictionary occurs.
52 * You must uncomment the lines in the file objaccess.c :\n
53 * //#define DEBUG_CAN\n
54 * //#define DEBUG_WAR_CONSOLE_ON\n
55 * //#define DEBUG_ERR_CONSOLE_ON\n\n
56 * Beware that sometimes, we force the sizeDataDict or sizeDataGiven to 0, when we wants to use
57 * this function but we do not have the access to the right value. One example is
58 * getSDOerror(). So do not take attention to these variables if they are null.
61 * @param sizeDataDict Size of the data defined in the dictionary
62 * @param sizeDataGiven Size data given by the user.
63 * @param code error code to print. (SDO abort code. See file def.h)
66 UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex,
67 UNS32 sizeDataDict, UNS32 sizeDataGiven, UNS32 code);
70 /* _getODentry() Reads an entry from the object dictionary.\n
72 * use getODentry() macro to read from object and endianize
73 * use readLocalDict() macro to read from object and not endianize
81 * returnValue = getODentry( (UNS16)0x100B, (UNS8)1,
82 * (void * *)&pbData, (UNS8 *)&length );
83 * if( returnValue != SUCCESSFUL )
88 * @param *d Pointer on a CAN object data structure
89 * @param wIndex The index in the object dictionary where you want to read
91 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
92 * used to tell you how many valid entries you can find
93 * in this index. Look at the canopen standard for further
95 * @param *pDestData Pointer to the pointer which points to the variable where
96 * the value of this object dictionary entry should be copied
97 * @param pExpectedSize This function writes the size of the copied value (in Byte)
99 * @param *pDataType Pointer on the type of the data. See objdictdef.h
100 * @param CheckAccess if other than 0, do not read if the data is Write Only
101 * [Not used today. Put always 0].
102 * @param Endianize When not 0, data is endianized into network byte order
103 * when 0, data is not endianized and copied in machine native
105 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h)
107 UNS32 _getODentry( CO_Data* d,
111 UNS32 * pExpectedSize,
118 * @brief getODentry() to read from object and endianize
119 * @param OD Pointer on a CAN object data structure
120 * @param wIndex The index in the object dictionary where you want to read
122 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
123 * used to tell you how many valid entries you can find
124 * in this index. Look at the canopen standard for further
126 * @param *pDestData Pointer to the pointer which points to the variable where
127 * the value of this object dictionary entry should be copied
128 * @param pExpectedSize This function writes the size of the copied value (in Byte)
129 * into this variable.
130 * @param *pDataType Pointer on the type of the data. See objdictdef.h
131 * @param checkAccess if other than 0, do not read if the data is Write Only
132 * [Not used today. Put always 0].
133 * @param endianize Set to 1 : endianized into network byte order
134 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h)
136 #define getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
137 pDataType, checkAccess) \
138 _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
139 pDataType, checkAccess, 1)
143 * @brief readLocalDict() reads an entry from the object dictionary, but in
144 * contrast to getODentry(), readLocalDict() doesn't endianize entry and reads
145 * entry in machine native endianness.
146 * @param OD Pointer on a CAN object data structure
147 * @param wIndex The index in the object dictionary where you want to read
149 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
150 * used to tell you how many valid entries you can find
151 * in this index. Look at the canopen standard for further
153 * @param *pDestData Pointer to the pointer which points to the variable where
154 * the value of this object dictionary entry should be copied
155 * @param pExpectedSize This function writes the size of the copied value (in Byte)
156 * into this variable.
157 * @param *pDataType Pointer on the type of the data. See objdictdef.h
158 * @param checkAccess if other than 0, do not read if the data is Write Only
159 * [Not used today. Put always 0].
160 * @param endianize Set to 0, data is not endianized and copied in machine native
162 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h)
164 #define readLocalDict( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
165 pDataType, checkAccess) \
166 _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \
167 pDataType, checkAccess, 0)
170 * @brief By this function you can write an entry into the object dictionary
171 * @param *d Pointer on a CAN object data structure
172 * @param wIndex The index in the object dictionary where you want to write
174 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
175 * used to tell you how many valid entries you can find
176 * in this index. Look at the canopen standard for further
178 * @param *pSourceData Pointer to the variable that holds the value that should
179 * be copied into the object dictionary
180 * @param *pExpectedSize The size of the value (in Byte).
181 * @param checkAccess if other than 0, do not read if the data is Read Only or Constant
182 * @param endianize When not 0, data is endianized into network byte order
183 * when 0, data is not endianized and copied in machine native
185 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h)
187 UNS32 _setODentry( CO_Data* d,
191 UNS32 * pExpectedSize,
197 * @brief setODentry converts SourceData from network byte order to machine native
198 * format, and writes that to OD.
202 * B = 0xFF; // set transmission type
204 * retcode = setODentry( (UNS16)0x1800, (UNS8)2, &B, sizeof(UNS8), 1 );
206 * @param d Pointer on a CAN object data structure
207 * @param wIndex The index in the object dictionary where you want to write
209 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
210 * used to tell you how many valid entries you can find
211 * in this index. Look at the canopen standard for further
213 * @param *pSourceData Pointer to the variable that holds the value that should
214 * be copied into the object dictionary
215 * @param *pExpectedSize The size of the value (in Byte).
216 * @param checkAccess if other than 0, do not read if the data is Read Only or Constant
217 * @param endianize Set to 1 : endianized into network byte order
218 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h)
220 #define setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \
221 _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 1)
225 * @brief Writes machine native SourceData to OD.
229 * B = 0xFF; // set transmission type
231 * retcode = writeLocalDict( (UNS16)0x1800, (UNS8)2, &B, sizeof(UNS8), 1 );
233 * @param d Pointer on a CAN object data structure
234 * @param wIndex The index in the object dictionary where you want to write
236 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is
237 * used to tell you how many valid entries you can find
238 * in this index. Look at the canopen standard for further
240 * @param *pSourceData Pointer to the variable that holds the value that should
241 * be copied into the object dictionary
242 * @param *pExpectedSize The size of the value (in Byte).
243 * @param checkAccess if other than 0, do not read if the data is Read Only or Constant
244 * @param endianize Data is not endianized and copied in machine native endianness
245 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h)
247 #define writeLocalDict( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \
248 _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 0)
253 * @brief Scan the index of object dictionary. Used only by setODentry and getODentry.
254 * @param *d Pointer on a CAN object data structure
256 * @param *errorCode : OD_SUCCESSFUL if index foundor SDO abort code. (See file def.h)
258 * @return NULL if index not found. Else : return the table part of the object dictionary.
260 const indextable * scanIndexOD (CO_Data* d, UNS16 wIndex, UNS32 *errorCode, ODCallback_t **Callback);
262 UNS32 RegisterSetODentryCallBack(CO_Data* d, UNS16 wIndex, UNS8 bSubindex, ODCallback_t Callback);
264 #endif /* __objacces_h__ */