94 } |
93 } |
95 |
94 |
96 *pDataType = ptrTable->pSubindex[bSubindex].bDataType; |
95 *pDataType = ptrTable->pSubindex[bSubindex].bDataType; |
97 szData = ptrTable->pSubindex[bSubindex].size; |
96 szData = ptrTable->pSubindex[bSubindex].size; |
98 |
97 |
99 if( *pExpectedSize == 0 || |
98 if( *pExpectedSize == 0 || |
100 *pExpectedSize == szData || |
99 *pExpectedSize == szData || |
101 (*pDataType == visible_string && *pExpectedSize > szData)) // We allow to fetch a shorter string than expected |
100 (*pDataType == visible_string && *pExpectedSize < szData)) {// We allow to fetch a shorter string than expected |
102 { |
101 |
103 #ifdef CANOPEN_BIG_ENDIAN |
102 # ifdef CANOPEN_BIG_ENDIAN |
104 if(*pDataType > boolean && *pDataType < visible_string) { |
103 if(*pDataType > boolean && *pDataType < visible_string) { |
105 // data must be transmited with low byte first |
104 // data must be transmited with low byte first |
106 UNS8 i, j = 0; |
105 UNS8 i, j = 0; |
107 for ( i = ptrTable->pSubindex[bSubindex].size ; i > 0 ; i--) { |
106 MSG_WAR(boolean, "data type ", *pDataType); |
108 ((char*)pDestData)[j++] = ((char*)ptrTable->pSubindex[bSubindex].pObject)[i-1]; |
107 MSG_WAR(visible_string, "data type ", *pDataType); |
109 } |
108 for ( i = szData ; i > 0 ; i--) { |
110 } |
109 MSG_WAR(i," ", j); |
111 #else |
110 ((UNS8*)pDestData)[j++] = |
112 memcpy(pDestData, ptrTable->pSubindex[bSubindex].pObject,*pExpectedSize); |
111 ((UNS8*)ptrTable->pSubindex[bSubindex].pObject)[i-1]; |
113 #endif |
112 } |
114 *pExpectedSize = szData; |
113 } |
115 return OD_SUCCESSFUL; |
114 else // It it is a visible string no endianisation to perform |
116 }else{ |
115 memcpy(pDestData, ptrTable->pSubindex[bSubindex].pObject,szData); |
117 *pExpectedSize = szData; |
116 # else |
118 accessDictionaryError(wIndex, bSubindex, szData, *pExpectedSize, OD_LENGTH_DATA_INVALID); |
117 memcpy(pDestData, ptrTable->pSubindex[bSubindex].pObject,szData); |
119 return OD_LENGTH_DATA_INVALID; |
118 # endif |
120 } |
119 |
|
120 *pExpectedSize = szData; |
|
121 #if 0 |
|
122 // Me laisser ça, please ! (FD) |
|
123 { |
|
124 UNS8 i; |
|
125 for (i = 0 ; i < 10 ; i++) { |
|
126 MSG_WAR(*pExpectedSize, "dic data= ", |
|
127 *(UNS8 *)(ptrTable->pSubindex[bSubindex].pObject + i)); |
|
128 } |
|
129 |
|
130 } |
|
131 #endif |
|
132 return OD_SUCCESSFUL; |
|
133 } |
|
134 else { // Error ! |
|
135 *pExpectedSize = szData; |
|
136 accessDictionaryError(wIndex, bSubindex, szData, |
|
137 *pExpectedSize, OD_LENGTH_DATA_INVALID); |
|
138 return OD_LENGTH_DATA_INVALID; |
|
139 } |
121 } |
140 } |
122 |
141 |
123 UNS32 setODentry( CO_Data* d, |
142 UNS32 setODentry( CO_Data* d, |
124 UNS16 wIndex, |
143 UNS16 wIndex, |
125 UNS8 bSubindex, |
144 UNS8 bSubindex, |