author | dejoigny |
Wed, 17 May 2006 15:01:30 +0200 | |
changeset 11 | 64ed038bdc74 |
parent 10 | 0c4d04e5fac0 |
child 12 | 1d3b9ad366c8 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
This file is part of CanFestival, a library implementing CanOpen Stack. |
|
3 |
||
4 |
Copyright (C): Edouard TISSERANT and Francis DUPIN |
|
5 |
||
6 |
See COPYING file for copyrights details. |
|
7 |
||
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. |
|
12 |
||
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. |
|
17 |
||
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 |
|
21 |
*/ |
|
22 |
||
11 | 23 |
//#define DEBUG_WAR_CONSOLE_ON |
24 |
//#define DEBUG_ERR_CONSOLE_ON |
|
25 |
||
26 |
#undef CANOPEN_BIG_ENDIAN |
|
1
b3dc740b4b04
Commit some Fix from Francis on sdo.c and abjacces.c. Fix endianisation problems while accessing OD. Also fix SDO abord handling bug.
etisserant
parents:
0
diff
changeset
|
27 |
|
0 | 28 |
#include "objacces.h" |
29 |
||
8 | 30 |
|
0 | 31 |
#ifdef DEBUG_WAR_CONSOLE_ON |
32 |
UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex, |
|
33 |
UNS8 sizeDataDict, UNS8 sizeDataGiven, UNS32 code) |
|
34 |
{ |
|
35 |
MSG_WAR(0x2B09,"Dictionary index : ", index); |
|
36 |
MSG_WAR(0X2B10," subindex : ", subIndex); |
|
37 |
switch (code) { |
|
38 |
case OD_NO_SUCH_OBJECT: |
|
39 |
MSG_WAR(0x2B11,"Index not found ", index); |
|
40 |
break; |
|
41 |
case OD_NO_SUCH_SUBINDEX : |
|
42 |
MSG_WAR(0x2B12,"SubIndex not found ", subIndex); |
|
43 |
break; |
|
44 |
case OD_WRITE_NOT_ALLOWED : |
|
45 |
MSG_WAR(0x2B13,"Write not allowed, data is read only ", index); |
|
46 |
break; |
|
47 |
case OD_LENGTH_DATA_INVALID : |
|
48 |
MSG_WAR(0x2B14,"Conflict size data. Should be (bytes) : ", sizeDataDict); |
|
49 |
MSG_WAR(0x2B15,"But you have given the size : ", sizeDataGiven); |
|
50 |
break; |
|
51 |
case OD_NOT_MAPPABLE : |
|
52 |
MSG_WAR(0x2B16,"Not mappable data in a PDO at index : ", index); |
|
53 |
break; |
|
54 |
case OD_VALUE_TOO_LOW : |
|
55 |
MSG_WAR(0x2B17,"Value range error : value too low. SDOabort : ", code); |
|
56 |
break; |
|
57 |
case OD_VALUE_TOO_HIGH : |
|
58 |
MSG_WAR(0x2B18,"Value range error : value too high. SDOabort : ", code); |
|
59 |
break; |
|
60 |
default : |
|
61 |
MSG_WAR(0x2B20, "Unknown error code : ", code); |
|
62 |
} |
|
63 |
return 0; |
|
64 |
} |
|
65 |
#endif |
|
66 |
||
67 |
UNS32 getODentry( CO_Data* d, |
|
68 |
UNS16 wIndex, |
|
69 |
UNS8 bSubindex, |
|
70 |
void * pDestData, |
|
71 |
UNS8 * pExpectedSize, |
|
72 |
UNS8 * pDataType, |
|
73 |
UNS8 checkAccess) |
|
74 |
{ // DO NOT USE MSG_ERR because the macro may send a PDO -> infinite loop if it fails. |
|
75 |
UNS32 errorCode; |
|
76 |
UNS8 szData; |
|
77 |
const indextable *ptrTable; |
|
78 |
ODCallback_t *Callback; |
|
79 |
||
80 |
ptrTable = (*d->scanIndexOD)(wIndex, &errorCode, &Callback); |
|
81 |
||
82 |
if (errorCode != OD_SUCCESSFUL) |
|
83 |
return errorCode; |
|
84 |
if( ptrTable->bSubCount <= bSubindex ) { |
|
85 |
// Subindex not found |
|
86 |
accessDictionaryError(wIndex, bSubindex, 0, 0, OD_NO_SUCH_SUBINDEX); |
|
87 |
return OD_NO_SUCH_SUBINDEX; |
|
88 |
} |
|
89 |
||
90 |
if (checkAccess && !(ptrTable->pSubindex[bSubindex].bAccessType & WO)) { |
|
1
b3dc740b4b04
Commit some Fix from Francis on sdo.c and abjacces.c. Fix endianisation problems while accessing OD. Also fix SDO abord handling bug.
etisserant
parents:
0
diff
changeset
|
91 |
MSG_WAR(0x2B30, "Access Type : ", ptrTable->pSubindex[bSubindex].bAccessType); |
0 | 92 |
accessDictionaryError(wIndex, bSubindex, 0, 0, OD_WRITE_NOT_ALLOWED); |
93 |
return OD_READ_NOT_ALLOWED; |
|
94 |
} |
|
95 |
||
96 |
*pDataType = ptrTable->pSubindex[bSubindex].bDataType; |
|
97 |
szData = ptrTable->pSubindex[bSubindex].size; |
|
98 |
||
99 |
if( *pExpectedSize == 0 || |
|
100 |
*pExpectedSize == szData || |
|
101 |
(*pDataType == visible_string && *pExpectedSize > szData)) // We allow to fetch a shorter string than expected |
|
102 |
{ |
|
103 |
#ifdef CANOPEN_BIG_ENDIAN |
|
11 | 104 |
if(*pDataType > boolean && *pDataType < visible_string) { |
0 | 105 |
// data must be transmited with low byte first |
106 |
UNS8 i, j = 0; |
|
1
b3dc740b4b04
Commit some Fix from Francis on sdo.c and abjacces.c. Fix endianisation problems while accessing OD. Also fix SDO abord handling bug.
etisserant
parents:
0
diff
changeset
|
107 |
for ( i = ptrTable->pSubindex[bSubindex].size ; i > 0 ; i--) { |
b3dc740b4b04
Commit some Fix from Francis on sdo.c and abjacces.c. Fix endianisation problems while accessing OD. Also fix SDO abord handling bug.
etisserant
parents:
0
diff
changeset
|
108 |
((char*)pDestData)[j++] = ((char*)ptrTable->pSubindex[bSubindex].pObject)[i-1]; |
0 | 109 |
} |
110 |
} |
|
111 |
#else |
|
112 |
memcpy(pDestData, ptrTable->pSubindex[bSubindex].pObject,*pExpectedSize); |
|
113 |
#endif |
|
114 |
*pExpectedSize = szData; |
|
115 |
return OD_SUCCESSFUL; |
|
116 |
}else{ |
|
117 |
*pExpectedSize = szData; |
|
118 |
accessDictionaryError(wIndex, bSubindex, szData, *pExpectedSize, OD_LENGTH_DATA_INVALID); |
|
119 |
return OD_LENGTH_DATA_INVALID; |
|
120 |
} |
|
121 |
} |
|
122 |
||
123 |
UNS32 setODentry( CO_Data* d, |
|
124 |
UNS16 wIndex, |
|
125 |
UNS8 bSubindex, |
|
126 |
void * pSourceData, |
|
127 |
UNS8 * pExpectedSize, |
|
128 |
UNS8 checkAccess) |
|
129 |
{ |
|
130 |
UNS8 szData; |
|
131 |
UNS8 dataType; |
|
132 |
UNS32 errorCode; |
|
133 |
const indextable *ptrTable; |
|
134 |
ODCallback_t *Callback; |
|
135 |
||
136 |
ptrTable =(*d->scanIndexOD)(wIndex, &errorCode, &Callback); |
|
137 |
if (errorCode != OD_SUCCESSFUL) |
|
138 |
return errorCode; |
|
139 |
||
140 |
if( ptrTable->bSubCount <= bSubindex ) { |
|
141 |
// Subindex not found |
|
142 |
accessDictionaryError(wIndex, bSubindex, 0, *pExpectedSize, OD_NO_SUCH_SUBINDEX); |
|
143 |
return OD_NO_SUCH_SUBINDEX; |
|
144 |
} |
|
1
b3dc740b4b04
Commit some Fix from Francis on sdo.c and abjacces.c. Fix endianisation problems while accessing OD. Also fix SDO abord handling bug.
etisserant
parents:
0
diff
changeset
|
145 |
if (checkAccess && (ptrTable->pSubindex[bSubindex].bAccessType == RO)) { |
b3dc740b4b04
Commit some Fix from Francis on sdo.c and abjacces.c. Fix endianisation problems while accessing OD. Also fix SDO abord handling bug.
etisserant
parents:
0
diff
changeset
|
146 |
MSG_WAR(0x2B25, "Access Type : ", ptrTable->pSubindex[bSubindex].bAccessType); |
0 | 147 |
accessDictionaryError(wIndex, bSubindex, 0, *pExpectedSize, OD_WRITE_NOT_ALLOWED); |
148 |
return OD_WRITE_NOT_ALLOWED; |
|
149 |
} |
|
150 |
||
151 |
||
152 |
dataType = ptrTable->pSubindex[bSubindex].bDataType; |
|
153 |
szData = ptrTable->pSubindex[bSubindex].size; |
|
154 |
||
155 |
if( *pExpectedSize == 0 || |
|
156 |
*pExpectedSize == szData || |
|
157 |
(dataType == visible_string && *pExpectedSize < szData)) // We allow to store a shorter string than entry size |
|
158 |
{ |
|
2
8d4a822f95e4
Fixed Endianisation/ValueRange order in SetODentry
etisserant
parents:
1
diff
changeset
|
159 |
#ifdef CANOPEN_BIG_ENDIAN |
11 | 160 |
if(dataType > boolean && dataType < visible_string) |
161 |
{ |
|
162 |
// we invert the data source directly. This let us do range testing without |
|
163 |
// additional temp variable |
|
164 |
UNS8 tmp, i; |
|
165 |
for ( i = 0 ; i < ( ptrTable->pSubindex[bSubindex].size >> 1) ; i++) |
|
166 |
{ |
|
167 |
UNS8 tmp =((UNS8 *)pSourceData) [(ptrTable->pSubindex[bSubindex].size - 1) - i]; |
|
168 |
((UNS8 *)pSourceData) [(ptrTable->pSubindex[bSubindex].size - 1) - i] = ((UNS8 *)pSourceData)[i]; |
|
169 |
((UNS8 *)pSourceData)[i] = tmp; |
|
170 |
} |
|
171 |
} |
|
2
8d4a822f95e4
Fixed Endianisation/ValueRange order in SetODentry
etisserant
parents:
1
diff
changeset
|
172 |
#endif |
0 | 173 |
errorCode = (*d->valueRangeTest)(dataType, pSourceData); |
174 |
if (errorCode) { |
|
175 |
accessDictionaryError(wIndex, bSubindex, szData, *pExpectedSize, errorCode); |
|
176 |
return errorCode; |
|
177 |
} |
|
2
8d4a822f95e4
Fixed Endianisation/ValueRange order in SetODentry
etisserant
parents:
1
diff
changeset
|
178 |
memcpy(ptrTable->pSubindex[bSubindex].pObject,pSourceData, *pExpectedSize); |
0 | 179 |
*pExpectedSize = szData; |
180 |
||
181 |
// Callbacks |
|
182 |
if(Callback && Callback[bSubindex]){ |
|
183 |
(*Callback[bSubindex])(d, ptrTable, bSubindex); |
|
184 |
} |
|
185 |
||
186 |
// TODO : Store dans NVRAM |
|
187 |
// if (ptrTable->pSubindex[bSubindex].bAccessType & TO_BE_SAVED) |
|
188 |
return OD_SUCCESSFUL; |
|
189 |
}else{ |
|
190 |
*pExpectedSize = szData; |
|
191 |
accessDictionaryError(wIndex, bSubindex, szData, *pExpectedSize, OD_LENGTH_DATA_INVALID); |
|
192 |
return OD_LENGTH_DATA_INVALID; |
|
193 |
} |
|
194 |
} |
|
195 |
||
196 |
||
197 |
const indextable * scanIndexOD (CO_Data* d, UNS16 wIndex, UNS32 *errorCode, ODCallback_t **Callback) |
|
198 |
{ |
|
199 |
return (*d->scanIndexOD)(wIndex, errorCode, Callback); |
|
200 |
} |
|
201 |
||
202 |
UNS32 RegisterSetODentryCallBack(CO_Data* d, UNS16 wIndex, UNS8 bSubindex, ODCallback_t Callback) |
|
203 |
{ |
|
204 |
UNS32 errorCode; |
|
205 |
ODCallback_t *CallbackList; |
|
206 |
||
207 |
scanIndexOD (d, wIndex, &errorCode, &CallbackList); |
|
208 |
if(errorCode == OD_SUCCESSFUL && CallbackList) |
|
209 |
CallbackList[bSubindex] = Callback; |
|
210 |
return errorCode; |
|
211 |
} |
|
212 |
||
1
b3dc740b4b04
Commit some Fix from Francis on sdo.c and abjacces.c. Fix endianisation problems while accessing OD. Also fix SDO abord handling bug.
etisserant
parents:
0
diff
changeset
|
213 |