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