18 You should have received a copy of the GNU Lesser General Public |
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 |
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 |
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 */ |
21 */ |
22 |
22 |
23 /** \file |
23 /** @file |
24 * \brief Responsible for accessing the object dictionary. |
24 * @brief Responsible for accessing the object dictionary. |
25 * |
25 * |
26 * This file contains functions for accessing the object dictionary and |
26 * This file contains functions for accessing the object dictionary and |
27 * variables that are contained by the object dictionary. |
27 * variables that are contained by the object dictionary. |
28 * Accessing the object dictionary contains setting local variables |
28 * Accessing the object dictionary contains setting local variables |
29 * as PDOs and accessing (read/write) all entries of the object dictionary |
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 |
30 * @warning Only the basic entries of an object dictionary are included |
31 * at the moment. |
31 * at the moment. |
32 */ |
32 */ |
33 |
33 |
|
34 /** @defgroup od Object Dictionary Management |
|
35 * @ingroup userapi |
|
36 */ |
|
37 |
34 #ifndef __objacces_h__ |
38 #ifndef __objacces_h__ |
35 #define __objacces_h__ |
39 #define __objacces_h__ |
36 |
40 |
37 #include <applicfg.h> |
41 #include <applicfg.h> |
38 |
42 |
39 typedef UNS32 (*valueRangeTest_t)(UNS8 typeValue, void *Value); |
43 typedef UNS32 (*valueRangeTest_t)(UNS8 typeValue, void *Value); |
40 typedef void (* storeODSubIndex_t)(CO_Data* d, UNS16 wIndex, UNS8 bSubindex); |
44 typedef void (* storeODSubIndex_t)(CO_Data* d, UNS16 wIndex, UNS8 bSubindex); |
41 void _storeODSubIndex (CO_Data* d, UNS16 wIndex, UNS8 bSubindex); |
45 void _storeODSubIndex (CO_Data* d, UNS16 wIndex, UNS8 bSubindex); |
42 |
46 |
43 /* |
47 /** |
44 Print MSG_WAR (s) if error to the access to the object dictionary occurs. |
48 * @ingroup od |
45 You must uncomment the lines |
49 * @brief Print MSG_WAR (s) if error to the access to the object dictionary occurs. |
46 //#define DEBUG_CAN |
50 * |
47 //#define DEBUG_WAR_CONSOLE_ON |
51 * You must uncomment the lines in the file objaccess.c :\n |
48 //#define DEBUG_ERR_CONSOLE_ON |
52 * //#define DEBUG_CAN\n |
49 in the file objaccess.c |
53 * //#define DEBUG_WAR_CONSOLE_ON\n |
50 sizeDataDict : Size of the data defined in the dictionary |
54 * //#define DEBUG_ERR_CONSOLE_ON\n\n |
51 sizeDataGiven : Size data given by the user. |
55 * Beware that sometimes, we force the sizeDataDict or sizeDataGiven to 0, when we wants to use |
52 code : error code to print. (SDO abort code. See file def.h) |
56 * this function but we do not have the access to the right value. One example is |
53 Beware that sometimes, we force the sizeDataDict or sizeDataGiven to 0, when we wants to use |
57 * getSDOerror(). So do not take attention to these variables if they are null. |
54 this function but we do not have the access to the right value. One example is |
58 * @param index |
55 getSDOerror(). So do not take attention to these variables if they are null. |
59 * @param subIndex |
56 */ |
60 * @param sizeDataDict Size of the data defined in the dictionary |
57 |
61 * @param sizeDataGiven Size data given by the user. |
|
62 * @param code error code to print. (SDO abort code. See file def.h) |
|
63 * @return |
|
64 */ |
58 UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex, |
65 UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex, |
59 UNS8 sizeDataDict, UNS8 sizeDataGiven, UNS32 code); |
66 UNS8 sizeDataDict, UNS8 sizeDataGiven, UNS32 code); |
60 |
67 |
61 |
68 |
62 /* _getODentry() Reads an entry from the object dictionary.\n |
69 /* _getODentry() Reads an entry from the object dictionary.\n |
63 * |
70 * |
64 * use getODentry() macro to read from object and endianize |
71 * use getODentry() macro to read from object and endianize |
65 * use readLocalDict() macro to read from object and not endianize |
72 * use readLocalDict() macro to read from object and not endianize |
66 * |
73 * |
67 * \code |
74 * @code |
68 * // Example usage: |
75 * // Example usage: |
69 * UNS8 *pbData; |
76 * UNS8 *pbData; |
70 * UNS8 length; |
77 * UNS8 length; |
71 * UNS32 returnValue; |
78 * UNS32 returnValue; |
72 * |
79 * |
73 * returnValue = getODentry( (UNS16)0x100B, (UNS8)1, |
80 * returnValue = getODentry( (UNS16)0x100B, (UNS8)1, |
74 * (void * *)&pbData, (UNS8 *)&length ); |
81 * (void * *)&pbData, (UNS8 *)&length ); |
75 * if( returnValue != SUCCESSFUL ) |
82 * if( returnValue != SUCCESSFUL ) |
76 * { |
83 * { |
77 * // error handling |
84 * // error handling |
78 * } |
85 * } |
79 * \endcode |
86 * @endcode |
80 * \param wIndex The index in the object dictionary where you want to read |
87 * @param *d Pointer on a CAN object data structure |
81 * an entry |
88 * @param wIndex The index in the object dictionary where you want to read |
82 * \param bSubindex The subindex of the Index. e.g. mostly subindex 0 is |
89 * an entry |
83 * used to tell you how many valid entries you can find |
90 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is |
84 * in this index. Look at the canopen standard for further |
91 * used to tell you how many valid entries you can find |
85 * information |
92 * in this index. Look at the canopen standard for further |
86 * \param ppbData Pointer to the pointer which points to the variable where |
93 * information |
87 * the value of this object dictionary entry should be copied |
94 * @param *pDestData Pointer to the pointer which points to the variable where |
88 * \param pdwSize This function writes the size of the copied value (in Byte) |
95 * the value of this object dictionary entry should be copied |
89 * into this variable. |
96 * @param pExpectedSize This function writes the size of the copied value (in Byte) |
90 * \param pDataType : The type of the data. See objdictdef.h |
97 * into this variable. |
91 * \param CheckAccess if other than 0, do not read if the data is Write Only |
98 * @param *pDataType Pointer on the type of the data. See objdictdef.h |
92 * [Not used today. Put always 0]. |
99 * @param CheckAccess if other than 0, do not read if the data is Write Only |
93 * \param Endianize when not 0, data is endianized into network byte order |
100 * [Not used today. Put always 0]. |
94 * when 0, data is not endianized and copied in machine native |
101 * @param Endianize When not 0, data is endianized into network byte order |
95 * endianness |
102 * when 0, data is not endianized and copied in machine native |
96 * \return OD_SUCCESSFUL or SDO abort code. (See file def.h) |
103 * endianness |
|
104 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h) |
97 */ |
105 */ |
98 UNS32 _getODentry( CO_Data* d, |
106 UNS32 _getODentry( CO_Data* d, |
99 UNS16 wIndex, |
107 UNS16 wIndex, |
100 UNS8 bSubindex, |
108 UNS8 bSubindex, |
101 void * pDestData, |
109 void * pDestData, |
102 UNS8 * pExpectedSize, |
110 UNS8 * pExpectedSize, |
103 UNS8 * pDataType, |
111 UNS8 * pDataType, |
104 UNS8 checkAccess, |
112 UNS8 checkAccess, |
105 UNS8 endianize); |
113 UNS8 endianize); |
106 |
114 |
|
115 /** |
|
116 * @ingroup od |
|
117 * @brief getODentry() to read from object and endianize |
|
118 * @param OD Pointer on a CAN object data structure |
|
119 * @param wIndex The index in the object dictionary where you want to read |
|
120 * an entry |
|
121 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is |
|
122 * used to tell you how many valid entries you can find |
|
123 * in this index. Look at the canopen standard for further |
|
124 * information |
|
125 * @param *pDestData Pointer to the pointer which points to the variable where |
|
126 * the value of this object dictionary entry should be copied |
|
127 * @param pExpectedSize This function writes the size of the copied value (in Byte) |
|
128 * into this variable. |
|
129 * @param *pDataType Pointer on the type of the data. See objdictdef.h |
|
130 * @param checkAccess if other than 0, do not read if the data is Write Only |
|
131 * [Not used today. Put always 0]. |
|
132 * @param endianize Set to 1 : endianized into network byte order |
|
133 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h) |
|
134 */ |
107 #define getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ |
135 #define getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ |
108 pDataType, checkAccess) \ |
136 pDataType, checkAccess) \ |
109 _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ |
137 _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ |
110 pDataType, checkAccess, 1) |
138 pDataType, checkAccess, 1) |
111 |
139 |
112 /* |
140 /** |
113 * readLocalDict() reads an entry from the object dictionary, but in |
141 * @ingroup od |
|
142 * @brief readLocalDict() reads an entry from the object dictionary, but in |
114 * contrast to getODentry(), readLocalDict() doesn't endianize entry and reads |
143 * contrast to getODentry(), readLocalDict() doesn't endianize entry and reads |
115 * entry in machine native endianness. |
144 * entry in machine native endianness. |
|
145 * @param OD Pointer on a CAN object data structure |
|
146 * @param wIndex The index in the object dictionary where you want to read |
|
147 * an entry |
|
148 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is |
|
149 * used to tell you how many valid entries you can find |
|
150 * in this index. Look at the canopen standard for further |
|
151 * information |
|
152 * @param *pDestData Pointer to the pointer which points to the variable where |
|
153 * the value of this object dictionary entry should be copied |
|
154 * @param pExpectedSize This function writes the size of the copied value (in Byte) |
|
155 * into this variable. |
|
156 * @param *pDataType Pointer on the type of the data. See objdictdef.h |
|
157 * @param checkAccess if other than 0, do not read if the data is Write Only |
|
158 * [Not used today. Put always 0]. |
|
159 * @param endianize Set to 0, data is not endianized and copied in machine native |
|
160 * endianness |
|
161 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h) |
116 */ |
162 */ |
117 #define readLocalDict( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ |
163 #define readLocalDict( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ |
118 pDataType, checkAccess) \ |
164 pDataType, checkAccess) \ |
119 _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ |
165 _getODentry( OD, wIndex, bSubindex, pDestData, pExpectedSize, \ |
120 pDataType, checkAccess, 0) |
166 pDataType, checkAccess, 0) |
121 |
167 |
122 /* By this function you can write an entry into the object dictionary\n |
168 /** |
123 * \code |
169 * @brief By this function you can write an entry into the object dictionary |
124 * // Example usage: |
170 * @param *d Pointer on a CAN object data structure |
125 * UNS8 B; |
171 * @param wIndex The index in the object dictionary where you want to write |
126 * B = 0xFF; // set transmission type |
172 * an entry |
127 * |
173 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is |
128 * retcode = setODentry( (UNS16)0x1800, (UNS8)2, &B, sizeof(UNS8), 1 ); |
174 * used to tell you how many valid entries you can find |
129 * \endocde |
175 * in this index. Look at the canopen standard for further |
130 * \param wIndex The index in the object dictionary where you want to write |
176 * information |
131 * an entry |
177 * @param *pSourceData Pointer to the variable that holds the value that should |
132 * \param bSubindex The subindex of the Index. e.g. mostly subindex 0 is |
178 * be copied into the object dictionary |
133 * used to tell you how many valid entries you can find |
179 * @param *pExpectedSize The size of the value (in Byte). |
134 * in this index. Look at the canopen standard for further |
180 * @param checkAccess if other than 0, do not read if the data is Read Only or Constant |
135 * information |
181 * @param endianize When not 0, data is endianized into network byte order |
136 * \param pbData Pointer to the variable that holds the value that should |
182 * when 0, data is not endianized and copied in machine native |
137 * be copied into the object dictionary |
183 * endianness |
138 * \param dwSize The size of the value (in Byte). |
184 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h) |
139 * \param CheckAccess if other than 0, do not read if the data is Read Only or Constant |
|
140 * \return OD_SUCCESSFUL or SDO abort code. (See file def.h) |
|
141 */ |
185 */ |
142 UNS32 _setODentry( CO_Data* d, |
186 UNS32 _setODentry( CO_Data* d, |
143 UNS16 wIndex, |
187 UNS16 wIndex, |
144 UNS8 bSubindex, |
188 UNS8 bSubindex, |
145 void * pSourceData, |
189 void * pSourceData, |
146 UNS8 * pExpectedSize, |
190 UNS8 * pExpectedSize, |
147 UNS8 checkAccess, |
191 UNS8 checkAccess, |
148 UNS8 endianize); |
192 UNS8 endianize); |
149 |
193 |
150 /* |
194 /** |
151 * setODentry converts SourceData from network byte order to machine native |
195 * @ingroup od |
152 * format, and writes that to OD. |
196 * @brief setODentry converts SourceData from network byte order to machine native |
|
197 * format, and writes that to OD. |
|
198 * @code |
|
199 * // Example usage: |
|
200 * UNS8 B; |
|
201 * B = 0xFF; // set transmission type |
|
202 * |
|
203 * retcode = setODentry( (UNS16)0x1800, (UNS8)2, &B, sizeof(UNS8), 1 ); |
|
204 * @endcode |
|
205 * @param d Pointer on a CAN object data structure |
|
206 * @param wIndex The index in the object dictionary where you want to write |
|
207 * an entry |
|
208 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is |
|
209 * used to tell you how many valid entries you can find |
|
210 * in this index. Look at the canopen standard for further |
|
211 * information |
|
212 * @param *pSourceData Pointer to the variable that holds the value that should |
|
213 * be copied into the object dictionary |
|
214 * @param *pExpectedSize The size of the value (in Byte). |
|
215 * @param checkAccess if other than 0, do not read if the data is Read Only or Constant |
|
216 * @param endianize Set to 1 : endianized into network byte order |
|
217 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h) |
153 */ |
218 */ |
154 #define setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \ |
219 #define setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \ |
155 _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 1) |
220 _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 1) |
156 |
221 |
157 /* |
222 /** |
158 * writeLocalDict writes machine native SourceData to OD. |
223 * @ingroup od |
|
224 * @brief Writes machine native SourceData to OD. |
|
225 * @code |
|
226 * // Example usage: |
|
227 * UNS8 B; |
|
228 * B = 0xFF; // set transmission type |
|
229 * |
|
230 * retcode = writeLocalDict( (UNS16)0x1800, (UNS8)2, &B, sizeof(UNS8), 1 ); |
|
231 * @endcode |
|
232 * @param d Pointer on a CAN object data structure |
|
233 * @param wIndex The index in the object dictionary where you want to write |
|
234 * an entry |
|
235 * @param bSubindex The subindex of the Index. e.g. mostly subindex 0 is |
|
236 * used to tell you how many valid entries you can find |
|
237 * in this index. Look at the canopen standard for further |
|
238 * information |
|
239 * @param *pSourceData Pointer to the variable that holds the value that should |
|
240 * be copied into the object dictionary |
|
241 * @param *pExpectedSize The size of the value (in Byte). |
|
242 * @param checkAccess if other than 0, do not read if the data is Read Only or Constant |
|
243 * @param endianize Data is not endianized and copied in machine native endianness |
|
244 * @return OD_SUCCESSFUL or SDO abort code. (See file def.h) |
159 */ |
245 */ |
160 #define writeLocalDict( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \ |
246 #define writeLocalDict( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess) \ |
161 _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 0) |
247 _setODentry( d, wIndex, bSubindex, pSourceData, pExpectedSize, checkAccess, 0) |
162 |
248 |
163 |
249 |
164 |
250 |
165 /* Scan the index of object dictionary. Used only by setODentry and getODentry. |
251 /** |
166 * *errorCode : OD_SUCCESSFUL if index foundor SDO abort code. (See file def.h) |
252 * @brief Scan the index of object dictionary. Used only by setODentry and getODentry. |
167 * Return NULL if index not found. Else : return the table part of the object dictionary. |
253 * @param *d Pointer on a CAN object data structure |
|
254 * @param wIndex |
|
255 * @param *errorCode : OD_SUCCESSFUL if index foundor SDO abort code. (See file def.h) |
|
256 * @param **Callback |
|
257 * @return NULL if index not found. Else : return the table part of the object dictionary. |
168 */ |
258 */ |
169 const indextable * scanIndexOD (CO_Data* d, UNS16 wIndex, UNS32 *errorCode, ODCallback_t **Callback); |
259 const indextable * scanIndexOD (CO_Data* d, UNS16 wIndex, UNS32 *errorCode, ODCallback_t **Callback); |
170 |
260 |
171 UNS32 RegisterSetODentryCallBack(CO_Data* d, UNS16 wIndex, UNS8 bSubindex, ODCallback_t Callback); |
261 UNS32 RegisterSetODentryCallBack(CO_Data* d, UNS16 wIndex, UNS8 bSubindex, ODCallback_t Callback); |
172 |
262 |