136 *pDataType = ptrTable->pSubindex[bSubindex].bDataType; |
136 *pDataType = ptrTable->pSubindex[bSubindex].bDataType; |
137 szData = ptrTable->pSubindex[bSubindex].size; |
137 szData = ptrTable->pSubindex[bSubindex].size; |
138 |
138 |
139 if(*pExpectedSize == 0 || |
139 if(*pExpectedSize == 0 || |
140 *pExpectedSize == szData || |
140 *pExpectedSize == szData || |
141 (*pDataType == visible_string && *pExpectedSize < szData)) { |
141 /* allow to fetch a shorter string than expected */ |
142 /* We |
142 (*pDataType >= visible_string && *pExpectedSize < szData)) { |
143 allow to fetch a shorter string than expected */ |
|
144 |
143 |
145 # ifdef CANOPEN_BIG_ENDIAN |
144 # ifdef CANOPEN_BIG_ENDIAN |
146 if(endianize && *pDataType > boolean && *pDataType < visible_string) { |
145 if(endianize && dataType > boolean && !( |
|
146 dataType >= visible_string && |
|
147 domain <= dataType)) { |
147 /* data must be transmited with low byte first */ |
148 /* data must be transmited with low byte first */ |
148 UNS8 i, j = 0; |
149 UNS8 i, j = 0; |
149 MSG_WAR(boolean, "data type ", *pDataType); |
150 MSG_WAR(boolean, "data type ", *pDataType); |
150 MSG_WAR(visible_string, "data type ", *pDataType); |
151 MSG_WAR(visible_string, "data type ", *pDataType); |
151 for ( i = szData ; i > 0 ; i--) { |
152 for ( i = szData ; i > 0 ; i--) { |
154 ((UNS8*)ptrTable->pSubindex[bSubindex].pObject)[i-1]; |
155 ((UNS8*)ptrTable->pSubindex[bSubindex].pObject)[i-1]; |
155 } |
156 } |
156 } |
157 } |
157 else /* no endianisation change */ |
158 else /* no endianisation change */ |
158 # endif |
159 # endif |
159 if(*pDataType < visible_string) { |
160 if(*pDataType != visible_string) { |
160 memcpy(pDestData, ptrTable->pSubindex[bSubindex].pObject,szData); |
161 memcpy(pDestData, ptrTable->pSubindex[bSubindex].pObject,szData); |
161 *pExpectedSize = szData; |
162 *pExpectedSize = szData; |
162 }else{ |
163 }else{ |
163 /* TODO : CONFORM TO DS-301 : |
164 /* TODO : CONFORM TO DS-301 : |
164 * - stop using NULL terminated strings |
165 * - stop using NULL terminated strings |
169 UNS8 *ptr_start = ptr; |
170 UNS8 *ptr_start = ptr; |
170 UNS8 *ptr_end = ptr + *pExpectedSize; /* *pExpectedSize IS < szData */ |
171 UNS8 *ptr_end = ptr + *pExpectedSize; /* *pExpectedSize IS < szData */ |
171 while( *ptr && ptr < ptr_end){ |
172 while( *ptr && ptr < ptr_end){ |
172 *((UNS8*)pDestData++) = *(ptr++); |
173 *((UNS8*)pDestData++) = *(ptr++); |
173 } |
174 } |
174 *pExpectedSize = ptr - ptr_start; |
175 |
|
176 *pExpectedSize = ptr - ptr_start; |
|
177 /* terminate string if not maximum length */ |
|
178 if (*pExpectedSize < szData) |
|
179 *(ptr) = 0; |
175 } |
180 } |
176 |
181 |
177 return OD_SUCCESSFUL; |
182 return OD_SUCCESSFUL; |
178 } |
183 } |
179 else { /* Error ! */ |
184 else { /* Error ! */ |
292 dataType = ptrTable->pSubindex[bSubindex].bDataType; |
297 dataType = ptrTable->pSubindex[bSubindex].bDataType; |
293 szData = ptrTable->pSubindex[bSubindex].size; |
298 szData = ptrTable->pSubindex[bSubindex].size; |
294 |
299 |
295 if( *pExpectedSize == 0 || |
300 if( *pExpectedSize == 0 || |
296 *pExpectedSize == szData || |
301 *pExpectedSize == szData || |
297 (dataType == visible_string && *pExpectedSize < szData)) /* We |
302 /* allow to store a shorter string than entry size */ |
298 allow to store a shorter string than entry size */ |
303 (dataType == visible_string && *pExpectedSize < szData)) |
299 { |
304 { |
300 #ifdef CANOPEN_BIG_ENDIAN |
305 #ifdef CANOPEN_BIG_ENDIAN |
301 if(endianize && dataType > boolean && dataType < visible_string) |
306 /* re-endianize do not occur for bool, strings time and domains */ |
|
307 if(endianize && dataType > boolean && !( |
|
308 dataType >= visible_string && |
|
309 domain <= dataType)) |
302 { |
310 { |
303 /* we invert the data source directly. This let us do range |
311 /* we invert the data source directly. This let us do range |
304 testing without */ |
312 testing without */ |
305 /* additional temp variable */ |
313 /* additional temp variable */ |
306 UNS8 i; |
314 UNS8 i; |
316 if (errorCode) { |
324 if (errorCode) { |
317 accessDictionaryError(wIndex, bSubindex, szData, *pExpectedSize, errorCode); |
325 accessDictionaryError(wIndex, bSubindex, szData, *pExpectedSize, errorCode); |
318 return errorCode; |
326 return errorCode; |
319 } |
327 } |
320 memcpy(ptrTable->pSubindex[bSubindex].pObject,pSourceData, *pExpectedSize); |
328 memcpy(ptrTable->pSubindex[bSubindex].pObject,pSourceData, *pExpectedSize); |
|
329 /* TODO : CONFORM TO DS-301 : |
|
330 * - stop using NULL terminated strings |
|
331 * - store string size in td_subindex |
|
332 * */ |
|
333 /* terminate visible_string with '\0' */ |
|
334 if(dataType == visible_string && *pExpectedSize < szData) |
|
335 ((UNS8*)ptrTable->pSubindex[bSubindex].pObject)[*pExpectedSize] = 0; |
|
336 |
321 *pExpectedSize = szData; |
337 *pExpectedSize = szData; |
322 |
338 |
323 /* Callbacks */ |
339 /* Callbacks */ |
324 if(Callback && Callback[bSubindex]){ |
340 if(Callback && Callback[bSubindex]){ |
325 (*Callback[bSubindex])(d, ptrTable, bSubindex); |
341 (*Callback[bSubindex])(d, ptrTable, bSubindex); |