author | frdupin |
Mon, 29 Jan 2007 14:36:42 +0100 | |
changeset 79 | 9d8959095936 |
parent 71 | 95cd3376cc9f |
child 82 | 81505425b1e5 |
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 |
||
71 | 23 |
/* #define DEBUG_WAR_CONSOLE_ON */ |
24 |
/* #define DEBUG_ERR_CONSOLE_ON */ |
|
0 | 25 |
|
26 |
#include "objacces.h" |
|
27 |
#include "sdo.h" |
|
28 |
||
71 | 29 |
/* Uncomment if your compiler does not support inline functions */ |
30 |
#define NO_INLINE |
|
31 |
||
32 |
#ifdef NO_INLINE |
|
33 |
#define INLINE |
|
34 |
#else |
|
35 |
#define INLINE inline |
|
36 |
#endif |
|
37 |
||
53 | 38 |
/*Internals prototypes*/ |
39 |
||
40 |
/** Called by writeNetworkDict */ |
|
71 | 41 |
INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
53 | 42 |
UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback); |
43 |
||
44 |
/** Called by readNetworkDict */ |
|
71 | 45 |
INLINE UNS8 _readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, |
53 | 46 |
UNS8 dataType, SDOCallback_t Callback); |
47 |
||
48 |
||
0 | 49 |
/***************************************************************************/ |
71 | 50 |
/* SDO (un)packing macros */ |
0 | 51 |
|
52 |
/** Returns the command specifier (cs, ccs, scs) from the first byte of the SDO |
|
53 |
*/ |
|
54 |
#define getSDOcs(byte) (byte >> 5) |
|
55 |
||
56 |
/** Returns the number of bytes without data from the first byte of the SDO. Coded in 2 bits |
|
57 |
*/ |
|
58 |
#define getSDOn2(byte) ((byte >> 2) & 3) |
|
59 |
||
60 |
/** Returns the number of bytes without data from the first byte of the SDO. Coded in 3 bits |
|
61 |
*/ |
|
62 |
#define getSDOn3(byte) ((byte >> 1) & 7) |
|
63 |
||
64 |
/** Returns the transfer type from the first byte of the SDO |
|
65 |
*/ |
|
66 |
#define getSDOe(byte) ((byte >> 1) & 1) |
|
67 |
||
68 |
/** Returns the size indicator from the first byte of the SDO |
|
69 |
*/ |
|
70 |
#define getSDOs(byte) (byte & 1) |
|
71 |
||
72 |
/** Returns the indicator of end transmission from the first byte of the SDO |
|
73 |
*/ |
|
74 |
#define getSDOc(byte) (byte & 1) |
|
75 |
||
76 |
/** Returns the toggle from the first byte of the SDO |
|
77 |
*/ |
|
78 |
#define getSDOt(byte) ((byte >> 4) & 1) |
|
79 |
||
80 |
/** Returns the index from the bytes 1 and 2 of the SDO |
|
81 |
*/ |
|
82 |
#define getSDOindex(byte1, byte2) ((byte2 << 8) | (byte1)) |
|
83 |
||
84 |
/** Returns the subIndex from the byte 3 of the SDO |
|
85 |
*/ |
|
71 | 86 |
|
0 | 87 |
#define getSDOsubIndex(byte3) (byte3) |
88 |
||
89 |
/*************************************************************************** |
|
90 |
** |
|
91 |
*/ |
|
92 |
void SDOTimeoutAlarm(CO_Data* d, UNS32 id) |
|
93 |
{ |
|
94 |
MSG_ERR(0x1A01, "SDO timeout. SDO response not received.", 0); |
|
95 |
MSG_WAR(0x2A02, "server node : ", d->transfers[id].nodeId); |
|
96 |
MSG_WAR(0x2A02, " index : ", d->transfers[id].index); |
|
97 |
MSG_WAR(0x2A02, " subIndex : ", d->transfers[id].subIndex); |
|
71 | 98 |
/* Reset timer handler */ |
0 | 99 |
d->transfers[id].timer = TIMER_NONE; |
71 | 100 |
/* Call the user function to inform of the problem.*/ |
0 | 101 |
(*d->SDOtimeoutError)(id); |
71 | 102 |
/* Sending a SDO abort */ |
0 | 103 |
sendSDOabort(d, d->transfers[id].whoami, |
104 |
d->transfers[id].index, d->transfers[id].subIndex, SDOABT_TIMED_OUT); |
|
71 | 105 |
/* Reset the line*/ |
0 | 106 |
resetSDOline(d, id); |
107 |
} |
|
108 |
||
109 |
#define StopSDO_TIMER(id) \ |
|
110 |
MSG_WAR(0x3A05, "StopSDO_TIMER for line : ", line);\ |
|
111 |
d->transfers[id].timer = DelAlarm(d->transfers[id].timer); |
|
112 |
||
113 |
#define StartSDO_TIMER(id) \ |
|
114 |
MSG_WAR(0x3A06, "StartSDO_TIMER for line : ", line);\ |
|
115 |
d->transfers[id].timer = SetAlarm(d,id,&SDOTimeoutAlarm,MS_TO_TIMEVAL(SDO_TIMEOUT_MS),0); |
|
116 |
||
117 |
#define RestartSDO_TIMER(id) \ |
|
118 |
MSG_WAR(0x3A07, "restartSDO_TIMER for line : ", line);\ |
|
119 |
if(d->transfers[id].timer != TIMER_NONE) { StopSDO_TIMER(id) StartSDO_TIMER(id) } |
|
120 |
||
121 |
/***************************************************************************/ |
|
122 |
/** Reset all sdo buffers |
|
123 |
*/ |
|
124 |
void resetSDO (CO_Data* d) |
|
125 |
{ |
|
126 |
UNS8 j; |
|
127 |
||
128 |
/* transfer structure initialization */ |
|
129 |
for (j = 0 ; j < SDO_MAX_SIMULTANEOUS_TRANSFERTS ; j++) |
|
130 |
resetSDOline(d, j); |
|
131 |
} |
|
132 |
||
133 |
/***************************************************************************/ |
|
134 |
UNS32 SDOlineToObjdict (CO_Data* d, UNS8 line) |
|
135 |
{ |
|
136 |
UNS8 size; |
|
137 |
UNS32 errorCode; |
|
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
|
138 |
MSG_WAR(0x3A08, "Enter in SDOlineToObjdict ", line); |
0 | 139 |
size = d->transfers[line].count; |
140 |
errorCode = setODentry(d, d->transfers[line].index, d->transfers[line].subIndex, |
|
141 |
(void *) d->transfers[line].data, &size, 1); |
|
142 |
if (errorCode != OD_SUCCESSFUL) |
|
143 |
return errorCode; |
|
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
|
144 |
MSG_WAR(0x3A08, "exit of SDOlineToObjdict ", line); |
0 | 145 |
return 0; |
146 |
||
147 |
} |
|
148 |
||
149 |
/***************************************************************************/ |
|
150 |
UNS32 objdictToSDOline (CO_Data* d, UNS8 line) |
|
151 |
{ |
|
152 |
UNS8 size = 0; |
|
153 |
UNS8 dataType; |
|
154 |
UNS32 errorCode; |
|
155 |
||
12 | 156 |
MSG_WAR(0x3A05, "objdict->line index : ", d->transfers[line].index); |
157 |
MSG_WAR(0x3A06, " subIndex : ", d->transfers[line].subIndex); |
|
0 | 158 |
|
159 |
errorCode = getODentry(d, d->transfers[line].index, |
|
160 |
d->transfers[line].subIndex, |
|
161 |
(void *)d->transfers[line].data, |
|
162 |
&size, &dataType, 0); |
|
163 |
||
164 |
if (errorCode != OD_SUCCESSFUL) |
|
165 |
return errorCode; |
|
166 |
||
167 |
d->transfers[line].count = size; |
|
168 |
d->transfers[line].offset = 0; |
|
12 | 169 |
#if 0 |
71 | 170 |
/*Me laisser ça, please ! (FD)*/ |
12 | 171 |
{ |
172 |
UNS8 i; |
|
173 |
for (i = 0 ; i < 10 ; i++) { |
|
174 |
MSG_WAR(i, "data= ", d->transfers[line].data[i]); |
|
175 |
} |
|
176 |
} |
|
177 |
#endif |
|
0 | 178 |
return 0; |
179 |
} |
|
180 |
||
181 |
/***************************************************************************/ |
|
182 |
UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8* data) { |
|
183 |
UNS8 i; |
|
184 |
UNS8 offset; |
|
185 |
||
186 |
if ((d->transfers[line].offset + nbBytes) > SDO_MAX_LENGTH_TRANSFERT) { |
|
187 |
MSG_ERR(0x1A10,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes); |
|
188 |
return 0xFF; |
|
189 |
} |
|
190 |
if ((d->transfers[line].offset + nbBytes) > d->transfers[line].count) { |
|
191 |
MSG_ERR(0x1A11,"SDO Size of data too large. Exceed count", nbBytes); |
|
192 |
return 0xFF; |
|
193 |
} |
|
194 |
offset = d->transfers[line].offset; |
|
195 |
for (i = 0 ; i < nbBytes ; i++) |
|
196 |
* (data + i) = d->transfers[line].data[offset + i]; |
|
197 |
d->transfers[line].offset = d->transfers[line].offset + nbBytes; |
|
198 |
return 0; |
|
199 |
} |
|
200 |
||
201 |
||
202 |
/***************************************************************************/ |
|
203 |
UNS8 SDOtoLine (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8* data) |
|
204 |
{ |
|
205 |
UNS8 i; |
|
206 |
UNS8 offset; |
|
207 |
||
208 |
if ((d->transfers[line].offset + nbBytes) > SDO_MAX_LENGTH_TRANSFERT) { |
|
209 |
MSG_ERR(0x1A15,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes); |
|
210 |
return 0xFF; |
|
211 |
} |
|
212 |
offset = d->transfers[line].offset; |
|
213 |
for (i = 0 ; i < nbBytes ; i++) |
|
214 |
d->transfers[line].data[offset + i] = * (data + i); |
|
215 |
d->transfers[line].offset = d->transfers[line].offset + nbBytes; |
|
216 |
return 0; |
|
217 |
} |
|
218 |
||
219 |
/***************************************************************************/ |
|
220 |
UNS8 failedSDO (CO_Data* d, UNS8 nodeId, UNS8 whoami, UNS16 index, |
|
221 |
UNS8 subIndex, UNS32 abortCode) |
|
222 |
{ |
|
223 |
UNS8 err; |
|
224 |
UNS8 line; |
|
225 |
err = getSDOlineOnUse( d, nodeId, whoami, &line ); |
|
71 | 226 |
if (!err) /* If a line on use have been found.*/ |
0 | 227 |
MSG_WAR(0x3A20, "FailedSDO : line found : ", line); |
228 |
if ((! err) && (whoami == SDO_SERVER)) { |
|
229 |
resetSDOline( d, line ); |
|
230 |
MSG_WAR(0x3A21, "FailedSDO : line released : ", line); |
|
231 |
} |
|
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
|
232 |
if ((! err) && (whoami == SDO_CLIENT)) { |
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
|
233 |
StopSDO_TIMER(line); |
0 | 234 |
d->transfers[line].state = SDO_ABORTED_INTERNAL; |
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
|
235 |
} |
0 | 236 |
MSG_WAR(0x3A22, "Sending SDO abort ", 0); |
237 |
err = sendSDOabort(d, whoami, index, subIndex, abortCode); |
|
238 |
if (err) { |
|
239 |
MSG_WAR(0x3A23, "Unable to send the SDO abort", 0); |
|
240 |
return 0xFF; |
|
241 |
} |
|
242 |
return 0; |
|
243 |
} |
|
244 |
||
245 |
/***************************************************************************/ |
|
246 |
void resetSDOline ( CO_Data* d, UNS8 line ) |
|
247 |
{ |
|
248 |
UNS8 i; |
|
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
|
249 |
MSG_WAR(0x3A25, "reset SDO line nb : ", line); |
0 | 250 |
initSDOline(d, line, 0, 0, 0, SDO_RESET); |
251 |
for (i = 0 ; i < SDO_MAX_LENGTH_TRANSFERT ; i++) |
|
252 |
d->transfers[line].data[i] = 0; |
|
253 |
} |
|
254 |
||
255 |
/***************************************************************************/ |
|
256 |
UNS8 initSDOline (CO_Data* d, UNS8 line, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 state) |
|
257 |
{ |
|
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
|
258 |
MSG_WAR(0x3A25, "init SDO line nb : ", line); |
0 | 259 |
if (state == SDO_DOWNLOAD_IN_PROGRESS || state == SDO_UPLOAD_IN_PROGRESS){ |
260 |
StartSDO_TIMER(line) |
|
261 |
}else{ |
|
262 |
StopSDO_TIMER(line) |
|
263 |
} |
|
264 |
d->transfers[line].nodeId = nodeId; |
|
265 |
d->transfers[line].index = index; |
|
266 |
d->transfers[line].subIndex = subIndex; |
|
267 |
d->transfers[line].state = state; |
|
268 |
d->transfers[line].toggle = 0; |
|
269 |
d->transfers[line].count = 0; |
|
270 |
d->transfers[line].offset = 0; |
|
271 |
d->transfers[line].dataType = 0; |
|
32 | 272 |
d->transfers[line].Callback = NULL; |
0 | 273 |
return 0; |
274 |
} |
|
275 |
||
276 |
/***************************************************************************/ |
|
277 |
UNS8 getSDOfreeLine ( CO_Data* d, UNS8 whoami, UNS8 *line ) |
|
278 |
{ |
|
279 |
||
280 |
UNS8 i; |
|
281 |
||
282 |
for (i = 0 ; i < SDO_MAX_SIMULTANEOUS_TRANSFERTS ; i++){ |
|
283 |
if ( d->transfers[i].state == SDO_RESET ) { |
|
284 |
*line = i; |
|
285 |
d->transfers[i].whoami = whoami; |
|
286 |
return 0; |
|
71 | 287 |
} /* end if */ |
288 |
} /* end for */ |
|
0 | 289 |
MSG_ERR(0x1A25, "Too many SDO in progress. Aborted.", i); |
290 |
return 0xFF; |
|
291 |
} |
|
292 |
||
293 |
/***************************************************************************/ |
|
294 |
UNS8 getSDOlineOnUse (CO_Data* d, UNS8 nodeId, UNS8 whoami, UNS8 *line) |
|
295 |
{ |
|
296 |
||
297 |
UNS8 i; |
|
298 |
||
299 |
for (i = 0 ; i < SDO_MAX_SIMULTANEOUS_TRANSFERTS ; i++){ |
|
300 |
if ( (d->transfers[i].state != SDO_RESET) && |
|
301 |
(d->transfers[i].nodeId == nodeId) && |
|
302 |
(d->transfers[i].whoami == whoami) ) { |
|
303 |
*line = i; |
|
304 |
return 0; |
|
305 |
} |
|
306 |
} |
|
307 |
return 0xFF; |
|
308 |
} |
|
309 |
||
310 |
/***************************************************************************/ |
|
311 |
UNS8 closeSDOtransfer (CO_Data* d, UNS8 nodeId, UNS8 whoami) |
|
312 |
{ |
|
313 |
UNS8 err; |
|
314 |
UNS8 line; |
|
315 |
err = getSDOlineOnUse(d, nodeId, whoami, &line); |
|
316 |
if (err) { |
|
317 |
MSG_WAR(0x2A30, "No SDO communication to close for node : ", nodeId); |
|
318 |
return 0xFF; |
|
319 |
} |
|
320 |
resetSDOline(d, line); |
|
321 |
return 0; |
|
322 |
} |
|
323 |
||
324 |
/***************************************************************************/ |
|
325 |
UNS8 getSDOlineRestBytes (CO_Data* d, UNS8 line, UNS8 * nbBytes) |
|
326 |
{ |
|
71 | 327 |
if (d->transfers[line].count == 0) /* if received initiate SDO protocol with e=0 and s=0 */ |
0 | 328 |
* nbBytes = 0; |
329 |
else |
|
330 |
* nbBytes = d->transfers[line].count - d->transfers[line].offset; |
|
331 |
return 0; |
|
332 |
} |
|
333 |
||
334 |
/***************************************************************************/ |
|
335 |
UNS8 setSDOlineRestBytes (CO_Data* d, UNS8 line, UNS8 nbBytes) |
|
336 |
{ |
|
337 |
if (nbBytes > SDO_MAX_LENGTH_TRANSFERT) { |
|
338 |
MSG_ERR(0x1A35,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes); |
|
339 |
return 0xFF; |
|
340 |
} |
|
341 |
d->transfers[line].count = nbBytes; |
|
342 |
return 0; |
|
343 |
} |
|
344 |
||
345 |
||
346 |
/***************************************************************************/ |
|
347 |
UNS8 sendSDO (CO_Data* d, UNS8 whoami, s_SDO sdo) |
|
348 |
{ |
|
349 |
UNS16 offset; |
|
350 |
UNS16 lastIndex; |
|
351 |
UNS8 found = 0; |
|
352 |
Message m; |
|
353 |
UNS8 i; |
|
354 |
UNS32 * pwCobId = NULL; |
|
355 |
UNS8 * pwNodeId = NULL; |
|
356 |
UNS8 * pSize; |
|
357 |
UNS8 size; |
|
358 |
pSize = &size; |
|
359 |
||
360 |
MSG_WAR(0x3A38, "sendSDO",0); |
|
361 |
if( !((d->nodeState == Operational) || (d->nodeState == Pre_operational ))) { |
|
362 |
MSG_WAR(0x2A39, "unable to send the SDO (not in op or pre-op mode", d->nodeState); |
|
363 |
return 0xFF; |
|
364 |
} |
|
365 |
||
366 |
/*get the server->client cobid*/ |
|
367 |
if ( whoami == SDO_SERVER ) {/*case server. Easy because today only one server SDO is authorized in CanFestival*/ |
|
368 |
offset = d->firstIndex->SDO_SVR; |
|
369 |
if (offset == 0) { |
|
370 |
MSG_ERR(0x1A42, "SendSDO : No SDO server found", 0); |
|
371 |
return 0xFF; |
|
372 |
} |
|
373 |
pwCobId = d->objdict[offset].pSubindex[2].pObject; |
|
374 |
MSG_WAR(0x3A41, "I am server. cobId : ", *pwCobId); |
|
375 |
} |
|
376 |
else { /*case client*/ |
|
377 |
/* Get the client->server cobid.*/ |
|
378 |
UNS16 sdoNum = 0; |
|
379 |
offset = d->firstIndex->SDO_CLT; |
|
380 |
lastIndex = d->lastIndex->SDO_CLT; |
|
381 |
if (offset == 0) { |
|
382 |
MSG_ERR(0x1A42, "SendSDO : No SDO client index found", 0); |
|
383 |
return 0xFF; |
|
384 |
} |
|
385 |
/* First, have to find at the index where is defined the communication with the server node */ |
|
386 |
while (offset <= lastIndex){ |
|
387 |
MSG_WAR(0x3A43,"Reading index : ", 0x1280 + sdoNum); |
|
388 |
if (d->objdict[offset].bSubCount <= 3) { |
|
389 |
MSG_ERR(0x1A28, "Subindex 3 not found at index ", 0x1280 + sdoNum); |
|
390 |
return 0xFF; |
|
391 |
} |
|
392 |
pwNodeId = d->objdict[offset].pSubindex[3].pObject; |
|
393 |
MSG_WAR(0x3A44, "Found nodeId server = ", *pwNodeId); |
|
394 |
if(*pwNodeId == sdo.nodeId) { |
|
395 |
found = 1; |
|
396 |
break; |
|
397 |
} |
|
398 |
offset ++; |
|
399 |
sdoNum ++; |
|
400 |
} |
|
401 |
if (! found){ |
|
402 |
MSG_WAR (0x2A45, "No SDO client corresponds to the mesage to send to node ", sdo.nodeId); |
|
403 |
return 0xFF; |
|
404 |
} |
|
405 |
/* Second, read the cobid client->server */ |
|
406 |
pwCobId = d->objdict[offset].pSubindex[1].pObject; |
|
407 |
} |
|
408 |
/* message copy for sending */ |
|
409 |
m.cob_id.w = *pwCobId; |
|
410 |
m.rtr = NOT_A_REQUEST; |
|
71 | 411 |
/* the length of SDO must be 8 */ |
0 | 412 |
m.len = 8; |
413 |
for (i = 0 ; i < 8 ; i++) { |
|
414 |
m.data[i] = sdo.body.data[i]; |
|
415 |
} |
|
416 |
return (*d->canSend)(&m); |
|
417 |
} |
|
418 |
||
419 |
/***************************************************************************/ |
|
420 |
UNS8 sendSDOabort (CO_Data* d, UNS8 whoami, UNS16 index, UNS8 subIndex, UNS32 abortCode) |
|
421 |
{ |
|
422 |
s_SDO sdo; |
|
423 |
UNS8 ret; |
|
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
|
424 |
MSG_WAR(0x2A50,"Sending SDO abort ", abortCode); |
0 | 425 |
sdo.nodeId = *d->bDeviceNodeId; |
426 |
sdo.body.data[0] = 0x80; |
|
71 | 427 |
/* Index */ |
428 |
sdo.body.data[1] = index & 0xFF; /* LSB */ |
|
429 |
sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
430 |
/* Subindex */ |
|
0 | 431 |
sdo.body.data[3] = subIndex; |
71 | 432 |
/* Data */ |
0 | 433 |
sdo.body.data[4] = (UNS8)(abortCode & 0xFF); |
434 |
sdo.body.data[5] = (UNS8)((abortCode >> 8) & 0xFF); |
|
435 |
sdo.body.data[6] = (UNS8)((abortCode >> 16) & 0xFF); |
|
436 |
sdo.body.data[7] = (UNS8)((abortCode >> 24) & 0xFF); |
|
437 |
ret = sendSDO(d, whoami, sdo); |
|
438 |
||
439 |
return ret; |
|
440 |
} |
|
441 |
||
442 |
/***************************************************************************/ |
|
443 |
UNS8 proceedSDO (CO_Data* d, Message *m) |
|
444 |
{ |
|
445 |
UNS8 err; |
|
446 |
UNS8 line; |
|
71 | 447 |
UNS8 nbBytes; /* received or to be transmited. */ |
448 |
UNS8 nodeId = 0; /* The node from which the SDO is received */ |
|
0 | 449 |
UNS8 *pNodeId = NULL; |
71 | 450 |
UNS8 whoami = SDO_UNKNOWN; /* SDO_SERVER or SDO_CLIENT.*/ |
451 |
UNS32 errorCode; /* while reading or writing in the local object dictionary.*/ |
|
452 |
s_SDO sdo; /* SDO to transmit */ |
|
0 | 453 |
UNS16 index; |
454 |
UNS8 subIndex; |
|
455 |
UNS32 abortCode; |
|
456 |
UNS8 i,j; |
|
457 |
UNS32 * pCobId = NULL; |
|
458 |
UNS8 * pSize; |
|
459 |
UNS8 size; |
|
460 |
UNS16 offset; |
|
461 |
UNS16 lastIndex; |
|
462 |
||
463 |
pSize = &size; |
|
464 |
||
465 |
MSG_WAR(0x3A60, "proceedSDO ", 0); |
|
466 |
whoami = SDO_UNKNOWN; |
|
71 | 467 |
/* Looking for the cobId in the object dictionary. */ |
468 |
/* Am-I a server ? */ |
|
0 | 469 |
offset = d->firstIndex->SDO_SVR; |
470 |
lastIndex = d->lastIndex->SDO_SVR; |
|
471 |
j = 0; |
|
472 |
if(offset) while (offset <= lastIndex) { |
|
473 |
if (d->objdict[offset].bSubCount <= 1) { |
|
474 |
MSG_ERR(0x1A61, "Subindex 1 not found at index ", 0x1200 + j); |
|
475 |
return 0xFF; |
|
476 |
} |
|
477 |
pCobId = d->objdict[offset].pSubindex[1].pObject; |
|
478 |
if ( *pCobId == (*m).cob_id.w ) { |
|
479 |
whoami = SDO_SERVER; |
|
480 |
MSG_WAR(0x3A62, "proceedSDO. I am server. index : ", 0x1200 + j); |
|
71 | 481 |
/* In case of server, the node id of the client may be unknown. So we put the index minus offset */ |
482 |
/* 0x1200 where the cobid received is defined. */ |
|
0 | 483 |
nodeId = j; |
484 |
break; |
|
485 |
} |
|
486 |
j++; |
|
487 |
offset++; |
|
71 | 488 |
} /* end while */ |
0 | 489 |
if (whoami == SDO_UNKNOWN) { |
71 | 490 |
/* Am-I client ? */ |
0 | 491 |
offset = d->firstIndex->SDO_CLT; |
492 |
lastIndex = d->lastIndex->SDO_CLT; |
|
493 |
j = 0; |
|
494 |
if(offset) while (offset <= lastIndex) { |
|
495 |
if (d->objdict[offset].bSubCount <= 3) { |
|
496 |
MSG_ERR(0x1A63, "Subindex 3 not found at index ", 0x1280 + j); |
|
497 |
return 0xFF; |
|
498 |
} |
|
71 | 499 |
/* a) Looking for the cobid received. */ |
0 | 500 |
pCobId = d->objdict[offset].pSubindex[2].pObject; |
501 |
if (*pCobId == (*m).cob_id.w ) { |
|
71 | 502 |
/* b) cobid found, so reading the node id of the server. */ |
0 | 503 |
pNodeId = d->objdict[offset].pSubindex[3].pObject; |
504 |
whoami = SDO_CLIENT; |
|
505 |
nodeId = *pNodeId; |
|
506 |
MSG_WAR(0x3A64, "proceedSDO. I am server. index : ", 0x1280 + j); |
|
507 |
MSG_WAR(0x3A65, " Server nodeId : ", nodeId); |
|
508 |
break; |
|
509 |
} |
|
510 |
j++; |
|
511 |
offset++; |
|
71 | 512 |
} /* end while */ |
0 | 513 |
} |
514 |
if (whoami == SDO_UNKNOWN) { |
|
71 | 515 |
return 0xFF;/* This SDO was not for us ! */ |
516 |
} |
|
517 |
||
518 |
/* Test if the size of the SDO is ok */ |
|
0 | 519 |
if ( (*m).len != 8) { |
520 |
MSG_ERR(0x1A67, "Error size SDO. CobId : ", (*m).cob_id.w); |
|
521 |
failedSDO(d, nodeId, whoami, 0, 0, SDOABT_GENERAL_ERROR); |
|
522 |
return 0xFF; |
|
523 |
} |
|
524 |
||
525 |
if (whoami == SDO_CLIENT) { |
|
526 |
MSG_WAR(0x3A68, "I am CLIENT. Received SDO from nodeId : ", nodeId); |
|
527 |
} |
|
528 |
else { |
|
529 |
MSG_WAR(0x3A69, "I am SERVER. Received SDO cobId : ", (*m).cob_id.w); |
|
530 |
} |
|
531 |
||
71 | 532 |
/* Testing the command specifier */ |
533 |
/* Allowed : cs = 0, 1, 2, 3, 4. (= all except those for block tranfert). */ |
|
534 |
/* cs = other : Not allowed -> abort. */ |
|
0 | 535 |
switch (getSDOcs(m->data[0])) { |
536 |
||
537 |
case 0: |
|
71 | 538 |
/* I am SERVER */ |
0 | 539 |
if (whoami == SDO_SERVER) { |
71 | 540 |
/* Receiving a download segment data. */ |
541 |
/* A SDO transfert should have been yet initiated. */ |
|
0 | 542 |
err = getSDOlineOnUse( d, nodeId, whoami, &line ); |
543 |
if (!err) |
|
544 |
err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS; |
|
545 |
if (err) { |
|
546 |
MSG_ERR(0x1A70, "SDO error : Received download segment for unstarted trans. index 0x1200 + ", |
|
547 |
nodeId); |
|
548 |
failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
|
549 |
return 0xFF; |
|
550 |
} |
|
71 | 551 |
/* Reset the wathdog */ |
0 | 552 |
RestartSDO_TIMER(line) |
553 |
MSG_WAR(0x3A71, "Received SDO download segment defined at index 0x1200 + ", nodeId); |
|
554 |
index = d->transfers[line].index; |
|
555 |
subIndex = d->transfers[line].subIndex; |
|
71 | 556 |
/* Toggle test. */ |
0 | 557 |
if (d->transfers[line].toggle != getSDOt(m->data[0])) { |
558 |
MSG_ERR(0x1A72, "SDO error : Toggle error : ", getSDOt(m->data[0])); |
|
559 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED); |
|
560 |
return 0xFF; |
|
561 |
} |
|
71 | 562 |
/* Nb of data to be downloaded */ |
0 | 563 |
nbBytes = 7 - getSDOn3(m->data[0]); |
71 | 564 |
/* Store the data in the transfert structure. */ |
0 | 565 |
err = SDOtoLine(d, line, nbBytes, (*m).data + 1); |
566 |
if (err) { |
|
567 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
568 |
return 0xFF; |
|
569 |
} |
|
71 | 570 |
/* Sending the SDO response, CS = 1 */ |
571 |
sdo.nodeId = *d->bDeviceNodeId; /* The node id of the server, (here it is the sender). */ |
|
0 | 572 |
sdo.body.data[0] = (1 << 5) | (d->transfers[line].toggle << 4); |
573 |
for (i = 1 ; i < 8 ; i++) |
|
574 |
sdo.body.data[i] = 0; |
|
575 |
MSG_WAR(0x3A73, "SDO. Send response to download request defined at index 0x1200 + ", nodeId); |
|
576 |
sendSDO(d, whoami, sdo); |
|
71 | 577 |
/* Inverting the toggle for the next segment. */ |
0 | 578 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
71 | 579 |
/* If it was the last segment, */ |
0 | 580 |
if (getSDOc(m->data[0])) { |
71 | 581 |
/* Transfering line data to object dictionary. */ |
582 |
/* The code does not use the "d" of initiate frame. So it is safe if e=s=0 */ |
|
0 | 583 |
errorCode = SDOlineToObjdict(d, line); |
584 |
if (errorCode) { |
|
585 |
MSG_ERR(0x1A54, "SDO error : Unable to copy the data in the object dictionary", 0); |
|
586 |
failedSDO(d, nodeId, whoami, index, subIndex, errorCode); |
|
587 |
return 0xFF; |
|
588 |
} |
|
71 | 589 |
/* Release of the line */ |
0 | 590 |
resetSDOline(d, line); |
591 |
MSG_WAR(0x3A74, "SDO. End of download defined at index 0x1200 + ", nodeId); |
|
592 |
} |
|
71 | 593 |
} /* end if SERVER */ |
594 |
else { /* if CLIENT */ |
|
595 |
/* I am CLIENT */ |
|
596 |
/* It is a request for a previous upload segment. We should find a line opened for this.*/ |
|
0 | 597 |
err = getSDOlineOnUse( d, nodeId, whoami, &line); |
598 |
if (!err) |
|
599 |
err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS; |
|
600 |
if (err) { |
|
601 |
MSG_ERR(0x1A75, "SDO error : Received segment response for unknown trans. from nodeId", nodeId); |
|
602 |
failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
|
603 |
return 0xFF; |
|
604 |
} |
|
71 | 605 |
/* Reset the wathdog */ |
0 | 606 |
RestartSDO_TIMER(line) |
607 |
index = d->transfers[line].index; |
|
608 |
subIndex = d->transfers[line].subIndex; |
|
71 | 609 |
/* test of the toggle; */ |
0 | 610 |
if (d->transfers[line].toggle != getSDOt(m->data[0])) { |
611 |
MSG_ERR(0x1A76, "SDO error : Received segment response Toggle error. from nodeId", nodeId); |
|
612 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED); |
|
613 |
return 0xFF; |
|
614 |
} |
|
71 | 615 |
/* nb of data to be uploaded */ |
0 | 616 |
nbBytes = 7 - getSDOn3(m->data[0]); |
71 | 617 |
/* Storing the data in the line structure. */ |
0 | 618 |
err = SDOtoLine(d, line, nbBytes, (*m).data + 1); |
619 |
if (err) { |
|
620 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
621 |
return 0xFF; |
|
622 |
} |
|
71 | 623 |
/* Inverting the toggle for the next segment. */ |
0 | 624 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
71 | 625 |
/* If it was the last segment,*/ |
0 | 626 |
if ( getSDOc(m->data[0])) { |
71 | 627 |
/* Put in state finished */ |
628 |
/* The code is safe for the case e=s=0 in initiate frame. */ |
|
0 | 629 |
StopSDO_TIMER(line) |
630 |
d->transfers[line].state = SDO_FINISHED; |
|
32 | 631 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
632 |
||
0 | 633 |
MSG_WAR(0x3A77, "SDO. End of upload from node : ", nodeId); |
634 |
} |
|
71 | 635 |
else { /* more segments to receive */ |
636 |
/* Sending the request for the next segment. */ |
|
0 | 637 |
sdo.nodeId = nodeId; |
638 |
sdo.body.data[0] = (3 << 5) | (d->transfers[line].toggle << 4); |
|
639 |
for (i = 1 ; i < 8 ; i++) |
|
640 |
sdo.body.data[i] = 0; |
|
641 |
sendSDO(d, whoami, sdo); |
|
642 |
MSG_WAR(0x3A78, "SDO send upload segment request to nodeId", nodeId); |
|
643 |
} |
|
71 | 644 |
} /* End if CLIENT */ |
0 | 645 |
break; |
646 |
||
647 |
case 1: |
|
71 | 648 |
/* I am SERVER */ |
649 |
/* Receive of an initiate download */ |
|
0 | 650 |
if (whoami == SDO_SERVER) { |
651 |
index = getSDOindex(m->data[1],m->data[2]); |
|
652 |
subIndex = getSDOsubIndex(m->data[3]); |
|
653 |
MSG_WAR(0x3A79, "Received SDO Initiate Download (to store data) defined at index 0x1200 + ", |
|
654 |
nodeId); |
|
655 |
MSG_WAR(0x3A80, "Writing at index : ", index); |
|
656 |
MSG_WAR(0x3A80, "Writing at subIndex : ", subIndex); |
|
657 |
||
71 | 658 |
/* Search if a SDO transfert have been yet initiated */ |
0 | 659 |
err = getSDOlineOnUse( d, nodeId, whoami, &line ); |
660 |
if (! err) { |
|
661 |
MSG_ERR(0x1A81, "SDO error : Transmission yet started.", 0); |
|
662 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
|
663 |
return 0xFF; |
|
664 |
} |
|
71 | 665 |
/* No line on use. Great ! */ |
666 |
/* Try to open a new line. */ |
|
0 | 667 |
err = getSDOfreeLine( d, whoami, &line ); |
668 |
if (err) { |
|
669 |
MSG_ERR(0x1A82, "SDO error : No line free, too many SDO in progress. Aborted.", 0); |
|
670 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
|
671 |
return 0xFF; |
|
672 |
} |
|
673 |
initSDOline(d, line, nodeId, index, subIndex, SDO_DOWNLOAD_IN_PROGRESS); |
|
674 |
||
71 | 675 |
if (getSDOe(m->data[0])) { /* If SDO expedited */ |
676 |
/* nb of data to be downloaded */ |
|
0 | 677 |
nbBytes = 4 - getSDOn2(m->data[0]); |
71 | 678 |
/* Storing the data in the line structure. */ |
0 | 679 |
d->transfers[line].count = nbBytes; |
680 |
err = SDOtoLine(d, line, nbBytes, (*m).data + 4); |
|
681 |
||
682 |
if (err) { |
|
683 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
684 |
return 0xFF; |
|
685 |
} |
|
686 |
||
71 | 687 |
/* SDO expedited -> transfert finished. Data can be stored in the dictionary. */ |
688 |
/* The line will be reseted when it is downloading in the dictionary. */ |
|
0 | 689 |
MSG_WAR(0x3A83, "SDO Initiate Download is an expedited transfert. Finished.: ", nodeId); |
71 | 690 |
/* Transfering line data to object dictionary. */ |
0 | 691 |
errorCode = SDOlineToObjdict(d, line); |
692 |
if (errorCode) { |
|
693 |
MSG_ERR(0x1A84, "SDO error : Unable to copy the data in the object dictionary", 0); |
|
694 |
failedSDO(d, nodeId, whoami, index, subIndex, errorCode); |
|
695 |
return 0xFF; |
|
696 |
} |
|
71 | 697 |
/* Release of the line. */ |
0 | 698 |
resetSDOline(d, line); |
699 |
} |
|
71 | 700 |
else {/* So, if it is not an expedited transfert */ |
0 | 701 |
if (getSDOs(m->data[0])) { |
71 | 702 |
/* TODO : if e and s = 0, not reading m->data[4] but put nbBytes = 0 */ |
703 |
nbBytes = m->data[4]; /* Transfert limited to 255 bytes. */ |
|
0 | 704 |
err = setSDOlineRestBytes(d, nodeId, nbBytes); |
705 |
if (err) { |
|
706 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
707 |
return 0xFF; |
|
708 |
} |
|
709 |
} |
|
710 |
} |
|
71 | 711 |
/*Sending a SDO, cs=3*/ |
712 |
sdo.nodeId = *d->bDeviceNodeId; /* The node id of the server, (here it is the sender).*/ |
|
0 | 713 |
sdo.body.data[0] = 3 << 5; |
71 | 714 |
sdo.body.data[1] = index & 0xFF; /* LSB */ |
715 |
sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
0 | 716 |
sdo.body.data[3] = subIndex; |
717 |
for (i = 4 ; i < 8 ; i++) |
|
718 |
sdo.body.data[i] = 0; |
|
719 |
sendSDO(d, whoami, sdo); |
|
71 | 720 |
} /* end if I am SERVER */ |
0 | 721 |
else { |
71 | 722 |
/* I am CLIENT */ |
723 |
/* It is a response for a previous download segment. We should find a line opened for this. */ |
|
0 | 724 |
err = getSDOlineOnUse( d, nodeId, whoami, &line); |
725 |
if (!err) |
|
726 |
err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS; |
|
727 |
if (err) { |
|
728 |
MSG_ERR(0x1A85, "SDO error : Received segment response for unknown trans. from nodeId", nodeId); |
|
729 |
failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
|
730 |
return 0xFF; |
|
731 |
} |
|
71 | 732 |
/* Reset the wathdog */ |
0 | 733 |
RestartSDO_TIMER(line) |
734 |
index = d->transfers[line].index; |
|
735 |
subIndex = d->transfers[line].subIndex; |
|
71 | 736 |
/* test of the toggle; */ |
0 | 737 |
if (d->transfers[line].toggle != getSDOt(m->data[0])) { |
738 |
MSG_ERR(0x1A86, "SDO error : Received segment response Toggle error. from nodeId", nodeId); |
|
739 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED); |
|
740 |
return 0xFF; |
|
741 |
} |
|
742 |
||
71 | 743 |
/* End transmission or downloading next segment. We need to know if it will be the last one. */ |
0 | 744 |
getSDOlineRestBytes(d, line, &nbBytes); |
745 |
if (nbBytes == 0) { |
|
746 |
MSG_WAR(0x3A87, "SDO End download. segment response received. OK. from nodeId", nodeId); |
|
747 |
StopSDO_TIMER(line) |
|
748 |
d->transfers[line].state = SDO_FINISHED; |
|
32 | 749 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
0 | 750 |
return 0x00; |
751 |
} |
|
71 | 752 |
/* At least one transfer to send. */ |
0 | 753 |
if (nbBytes > 7) { |
71 | 754 |
/* several segments to download.*/ |
755 |
/* code to send the next segment. (cs = 0; c = 0) */ |
|
0 | 756 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
71 | 757 |
sdo.nodeId = nodeId; /* The server node Id; */ |
0 | 758 |
sdo.body.data[0] = (d->transfers[line].toggle << 4); |
759 |
err = lineToSDO(d, line, 7, sdo.body.data + 1); |
|
760 |
if (err) { |
|
761 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
762 |
return 0xFF; |
|
763 |
} |
|
764 |
} |
|
765 |
else { |
|
71 | 766 |
/* Last segment. */ |
767 |
/* code to send the last segment. (cs = 0; c = 1)*/ |
|
0 | 768 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
71 | 769 |
sdo.nodeId = nodeId; /* The server node Id; */ |
0 | 770 |
sdo.body.data[0] = (d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1; |
771 |
err = lineToSDO(d, line, nbBytes, sdo.body.data + 1); |
|
772 |
if (err) { |
|
773 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
774 |
return 0xFF; |
|
775 |
} |
|
776 |
for (i = nbBytes + 1 ; i < 8 ; i++) |
|
777 |
sdo.body.data[i] = 0; |
|
778 |
} |
|
779 |
MSG_WAR(0x3A88, "SDO sending download segment to nodeId", nodeId); |
|
780 |
sendSDO(d, whoami, sdo); |
|
71 | 781 |
} /* end if I am a CLIENT */ |
0 | 782 |
break; |
783 |
||
784 |
case 2: |
|
71 | 785 |
/* I am SERVER */ |
786 |
/* Receive of an initiate upload.*/ |
|
0 | 787 |
if (whoami == SDO_SERVER) { |
788 |
index = getSDOindex(m->data[1],m->data[2]); |
|
789 |
subIndex = getSDOsubIndex(m->data[3]); |
|
790 |
MSG_WAR(0x3A89, "Received SDO Initiate upload (to send data) defined at index 0x1200 + ", |
|
791 |
nodeId); |
|
792 |
MSG_WAR(0x3A90, "Reading at index : ", index); |
|
793 |
MSG_WAR(0x3A91, "Reading at subIndex : ", subIndex); |
|
71 | 794 |
/* Search if a SDO transfert have been yet initiated*/ |
0 | 795 |
err = getSDOlineOnUse( d, nodeId, whoami, &line ); |
796 |
if (! err) { |
|
12 | 797 |
MSG_ERR(0x1A92, "SDO error : Transmission yet started at line : ", line); |
0 | 798 |
MSG_WAR(0x3A93, "nodeId = ", nodeId); |
12 | 799 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
800 |
return 0xFF; |
|
0 | 801 |
} |
71 | 802 |
/* No line on use. Great !*/ |
803 |
/* Try to open a new line.*/ |
|
0 | 804 |
err = getSDOfreeLine( d, whoami, &line ); |
805 |
if (err) { |
|
806 |
MSG_ERR(0x1A71, "SDO error : No line free, too many SDO in progress. Aborted.", 0); |
|
807 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
|
808 |
return 0xFF; |
|
809 |
} |
|
810 |
initSDOline(d, line, nodeId, index, subIndex, SDO_UPLOAD_IN_PROGRESS); |
|
71 | 811 |
/* Transfer data from dictionary to the line structure. */ |
0 | 812 |
errorCode = objdictToSDOline(d, line); |
813 |
||
814 |
if (errorCode) { |
|
815 |
MSG_ERR(0x1A94, "SDO error : Unable to copy the data from object dictionary. Err code : ", |
|
816 |
errorCode); |
|
817 |
failedSDO(d, nodeId, whoami, index, subIndex, errorCode); |
|
818 |
return 0xFF; |
|
819 |
} |
|
71 | 820 |
/* Preparing the response.*/ |
821 |
getSDOlineRestBytes(d, line, &nbBytes); /* Nb bytes to transfer ? */ |
|
822 |
sdo.nodeId = nodeId; /* The server node Id; */ |
|
0 | 823 |
if (nbBytes > 4) { |
71 | 824 |
/* normal transfert. (segmented). */ |
825 |
/* code to send the initiate upload response. (cs = 2) */ |
|
0 | 826 |
sdo.body.data[0] = (2 << 5) | 1; |
71 | 827 |
sdo.body.data[1] = index & 0xFF; /* LSB */ |
828 |
sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
0 | 829 |
sdo.body.data[3] = subIndex; |
71 | 830 |
sdo.body.data[4] = nbBytes; /* Limitation of canfestival2 : Max tranfert is 256 bytes.*/ |
831 |
/* It takes too much memory to upgrate to 2^32 because the size of data is also coded */ |
|
832 |
/* in the object dictionary, at every index and subindex. */ |
|
0 | 833 |
for (i = 5 ; i < 8 ; i++) |
834 |
sdo.body.data[i] = 0; |
|
835 |
MSG_WAR(0x3A95, "SDO. Sending normal upload initiate response defined at index 0x1200 + ", nodeId); |
|
836 |
sendSDO(d, whoami, sdo); |
|
837 |
} |
|
838 |
else { |
|
71 | 839 |
/* Expedited upload. (cs = 2 ; e = 1) */ |
0 | 840 |
sdo.body.data[0] = (2 << 5) | ((4 - nbBytes) << 2) | 3; |
71 | 841 |
sdo.body.data[1] = index & 0xFF; /* LSB */ |
842 |
sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
0 | 843 |
sdo.body.data[3] = subIndex; |
844 |
err = lineToSDO(d, line, nbBytes, sdo.body.data + 4); |
|
845 |
if (err) { |
|
846 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
847 |
return 0xFF; |
|
848 |
} |
|
849 |
for (i = 4 + nbBytes ; i < 8 ; i++) |
|
850 |
sdo.body.data[i] = 0; |
|
851 |
MSG_WAR(0x3A96, "SDO. Sending expedited upload initiate response defined at index 0x1200 + ", |
|
852 |
nodeId); |
|
853 |
sendSDO(d, whoami, sdo); |
|
71 | 854 |
/* Release the line.*/ |
0 | 855 |
resetSDOline(d, line); |
856 |
} |
|
71 | 857 |
} /* end if I am SERVER*/ |
0 | 858 |
else { |
71 | 859 |
/* I am CLIENT */ |
860 |
/* It is the response for the previous initiate upload request.*/ |
|
861 |
/* We should find a line opened for this. */ |
|
0 | 862 |
err = getSDOlineOnUse( d, nodeId, whoami, &line); |
863 |
if (!err) |
|
864 |
err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS; |
|
865 |
if (err) { |
|
866 |
MSG_ERR(0x1A97, "SDO error : Received response for unknown upload request from nodeId", nodeId); |
|
867 |
failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
|
868 |
return 0xFF; |
|
869 |
} |
|
71 | 870 |
/* Reset the wathdog */ |
0 | 871 |
RestartSDO_TIMER(line) |
872 |
index = d->transfers[line].index; |
|
873 |
subIndex = d->transfers[line].subIndex; |
|
874 |
||
71 | 875 |
if (getSDOe(m->data[0])) { /* If SDO expedited */ |
876 |
/* nb of data to be uploaded */ |
|
0 | 877 |
nbBytes = 4 - getSDOn2(m->data[0]); |
71 | 878 |
/* Storing the data in the line structure. */ |
0 | 879 |
err = SDOtoLine(d, line, nbBytes, (*m).data + 4); |
880 |
if (err) { |
|
881 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
882 |
return 0xFF; |
|
883 |
} |
|
71 | 884 |
/* SDO expedited -> transfert finished. data are available via getReadResultNetworkDict(). */ |
0 | 885 |
MSG_WAR(0x3A98, "SDO expedited upload finished. Response received from node : ", nodeId); |
886 |
StopSDO_TIMER(line) |
|
887 |
d->transfers[line].count = nbBytes; |
|
888 |
d->transfers[line].state = SDO_FINISHED; |
|
32 | 889 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
0 | 890 |
return 0; |
891 |
} |
|
71 | 892 |
else { /* So, if it is not an expedited transfert */ |
893 |
/* Storing the nb of data to receive. */ |
|
0 | 894 |
if (getSDOs(m->data[0])) { |
71 | 895 |
nbBytes = m->data[4]; /* Remember the limitation to 255 bytes to transfert */ |
0 | 896 |
err = setSDOlineRestBytes(d, line, nbBytes); |
897 |
if (err) { |
|
898 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
899 |
return 0xFF; |
|
900 |
} |
|
901 |
} |
|
71 | 902 |
/* Requesting next segment. (cs = 3) */ |
0 | 903 |
sdo.nodeId = nodeId; |
904 |
sdo.body.data[0] = 3 << 5; |
|
905 |
for (i = 1 ; i < 8 ; i++) |
|
906 |
sdo.body.data[i] = 0; |
|
907 |
MSG_WAR(0x3A99, "SDO. Sending upload segment request to node : ", nodeId); |
|
908 |
sendSDO(d, whoami, sdo); |
|
909 |
} |
|
71 | 910 |
} /* End if CLIENT */ |
0 | 911 |
break; |
912 |
||
913 |
case 3: |
|
71 | 914 |
/* I am SERVER */ |
0 | 915 |
if (whoami == SDO_SERVER) { |
71 | 916 |
/* Receiving a upload segment. */ |
917 |
/* A SDO transfert should have been yet initiated. */ |
|
0 | 918 |
err = getSDOlineOnUse( d, nodeId, whoami, &line ); |
919 |
if (!err) |
|
920 |
err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS; |
|
921 |
if (err) { |
|
922 |
MSG_ERR(0x1AA0, "SDO error : Received upload segment for unstarted trans. index 0x1200 + ", |
|
923 |
nodeId); |
|
924 |
failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
|
925 |
return 0xFF; |
|
926 |
} |
|
71 | 927 |
/* Reset the wathdog */ |
0 | 928 |
RestartSDO_TIMER(line) |
929 |
MSG_WAR(0x3AA1, "Received SDO upload segment defined at index 0x1200 + ", nodeId); |
|
930 |
index = d->transfers[line].index; |
|
931 |
subIndex = d->transfers[line].subIndex; |
|
71 | 932 |
/* Toggle test.*/ |
0 | 933 |
if (d->transfers[line].toggle != getSDOt(m->data[0])) { |
934 |
MSG_ERR(0x1AA2, "SDO error : Toggle error : ", getSDOt(m->data[0])); |
|
935 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED); |
|
936 |
return 0xFF; |
|
937 |
} |
|
71 | 938 |
/* Uploading next segment. We need to know if it will be the last one. */ |
0 | 939 |
getSDOlineRestBytes(d, line, &nbBytes); |
940 |
if (nbBytes > 7) { |
|
71 | 941 |
/* The segment to transfer is not the last one.*/ |
942 |
/* code to send the next segment. (cs = 0; c = 0) */ |
|
943 |
sdo.nodeId = nodeId; /* The server node Id; */ |
|
0 | 944 |
sdo.body.data[0] = (d->transfers[line].toggle << 4); |
945 |
err = lineToSDO(d, line, 7, sdo.body.data + 1); |
|
946 |
if (err) { |
|
947 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
948 |
return 0xFF; |
|
949 |
} |
|
71 | 950 |
/* Inverting the toggle for the next tranfert. */ |
0 | 951 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
952 |
MSG_WAR(0x3AA3, "SDO. Sending upload segment defined at index 0x1200 + ", nodeId); |
|
953 |
sendSDO(d, whoami, sdo); |
|
954 |
} |
|
955 |
else { |
|
71 | 956 |
/* Last segment. */ |
957 |
/* code to send the last segment. (cs = 0; c = 1) */ |
|
958 |
sdo.nodeId = nodeId; /* The server node Id; */ |
|
0 | 959 |
sdo.body.data[0] = (d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1; |
960 |
err = lineToSDO(d, line, nbBytes, sdo.body.data + 1); |
|
961 |
if (err) { |
|
962 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
963 |
return 0xFF; |
|
964 |
} |
|
965 |
for (i = nbBytes + 1 ; i < 8 ; i++) |
|
966 |
sdo.body.data[i] = 0; |
|
967 |
MSG_WAR(0x3AA4, "SDO. Sending last upload segment defined at index 0x1200 + ", nodeId); |
|
968 |
sendSDO(d, whoami, sdo); |
|
71 | 969 |
/* Release the line */ |
0 | 970 |
resetSDOline(d, line); |
971 |
} |
|
71 | 972 |
} /* end if SERVER*/ |
0 | 973 |
else { |
71 | 974 |
/* I am CLIENT */ |
975 |
/* It is the response for the previous initiate download request. */ |
|
976 |
/* We should find a line opened for this. */ |
|
0 | 977 |
err = getSDOlineOnUse( d, nodeId, whoami, &line); |
978 |
if (!err) |
|
979 |
err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS; |
|
980 |
if (err) { |
|
981 |
MSG_ERR(0x1AA5, "SDO error : Received response for unknown download request from nodeId", nodeId); |
|
982 |
failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
|
983 |
return 0xFF; |
|
984 |
} |
|
71 | 985 |
/* Reset the wathdog */ |
0 | 986 |
RestartSDO_TIMER(line) |
987 |
index = d->transfers[line].index; |
|
988 |
subIndex = d->transfers[line].subIndex; |
|
71 | 989 |
/* End transmission or requesting next segment. */ |
0 | 990 |
getSDOlineRestBytes(d, line, &nbBytes); |
991 |
if (nbBytes == 0) { |
|
992 |
MSG_WAR(0x3AA6, "SDO End download expedited. Response received. from nodeId", nodeId); |
|
993 |
StopSDO_TIMER(line) |
|
994 |
d->transfers[line].state = SDO_FINISHED; |
|
32 | 995 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
0 | 996 |
return 0x00; |
997 |
} |
|
998 |
if (nbBytes > 7) { |
|
71 | 999 |
/* more than one request to send */ |
1000 |
/* code to send the next segment. (cs = 0; c = 0) */ |
|
1001 |
sdo.nodeId = nodeId; /* The server node Id; */ |
|
0 | 1002 |
sdo.body.data[0] = (d->transfers[line].toggle << 4); |
1003 |
err = lineToSDO(d, line, 7, sdo.body.data + 1); |
|
1004 |
if (err) { |
|
1005 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1006 |
return 0xFF; |
|
1007 |
} |
|
1008 |
} |
|
1009 |
else { |
|
71 | 1010 |
/* Last segment.*/ |
1011 |
/* code to send the last segment. (cs = 0; c = 1) */ |
|
1012 |
sdo.nodeId = nodeId; /* The server node Id; */ |
|
0 | 1013 |
sdo.body.data[0] = (d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1; |
1014 |
err = lineToSDO(d, line, nbBytes, sdo.body.data + 1); |
|
1015 |
if (err) { |
|
1016 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1017 |
return 0xFF; |
|
1018 |
} |
|
1019 |
for (i = nbBytes + 1 ; i < 8 ; i++) |
|
1020 |
sdo.body.data[i] = 0; |
|
1021 |
} |
|
1022 |
MSG_WAR(0x3AA7, "SDO sending download segment to nodeId", nodeId); |
|
1023 |
sendSDO(d, whoami, sdo); |
|
1024 |
||
71 | 1025 |
} /* end if I am a CLIENT */ |
0 | 1026 |
break; |
1027 |
||
1028 |
case 4: |
|
1029 |
abortCode = (*m).data[3] | |
|
1030 |
(m->data[5] << 8) | |
|
1031 |
(m->data[6] << 16) | |
|
1032 |
(m->data[7] << 24); |
|
71 | 1033 |
/* Received SDO abort. */ |
1034 |
/* Looking for the line concerned. */ |
|
0 | 1035 |
if (whoami == SDO_SERVER) { |
1036 |
err = getSDOlineOnUse( d, nodeId, whoami, &line ); |
|
1037 |
if (!err) { |
|
1038 |
resetSDOline( d, line ); |
|
1039 |
MSG_WAR(0x3AA8, "SD0. Received SDO abort. Line released. Code : ", abortCode); |
|
1040 |
} |
|
1041 |
else |
|
1042 |
MSG_WAR(0x3AA9, "SD0. Received SDO abort. No line found. Code : ", abortCode); |
|
71 | 1043 |
/* Tips : The end user has no way to know that the server node has received an abort SDO. */ |
1044 |
/* Its is ok, I think.*/ |
|
0 | 1045 |
} |
71 | 1046 |
else { /* If I am CLIENT */ |
0 | 1047 |
err = getSDOlineOnUse( d, nodeId, whoami, &line ); |
1048 |
if (!err) { |
|
71 | 1049 |
/* The line *must* be released by the core program. */ |
0 | 1050 |
StopSDO_TIMER(line) |
1051 |
d->transfers[line].state = SDO_ABORTED_RCV; |
|
1052 |
MSG_WAR(0x3AB0, "SD0. Received SDO abort. Line state ABORTED. Code : ", abortCode); |
|
1053 |
} |
|
1054 |
else |
|
1055 |
MSG_WAR(0x3AB1, "SD0. Received SDO abort. No line found. Code : ", abortCode); |
|
1056 |
} |
|
1057 |
break; |
|
1058 |
default: |
|
71 | 1059 |
/* Error : Unknown cs */ |
0 | 1060 |
MSG_ERR(0x1AB2, "SDO. Received unknown command specifier : ", getSDOcs(m->data[0])); |
1061 |
return 0xFF; |
|
1062 |
||
71 | 1063 |
} /* End switch */ |
0 | 1064 |
return 0; |
1065 |
} |
|
1066 |
||
1067 |
/*******************************************************************)******/ |
|
71 | 1068 |
INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
32 | 1069 |
UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback) |
0 | 1070 |
{ |
1071 |
UNS8 err; |
|
1072 |
UNS8 SDOfound = 0; |
|
1073 |
UNS8 line; |
|
71 | 1074 |
s_SDO sdo; /* SDO to transmit */ |
0 | 1075 |
UNS8 i, j; |
1076 |
UNS8 * pSize; |
|
1077 |
UNS8 size; |
|
1078 |
UNS16 lastIndex; |
|
1079 |
UNS16 offset; |
|
1080 |
UNS8 *pNodeIdServer; |
|
1081 |
UNS8 nodeIdServer; |
|
1082 |
pSize = &size; |
|
1083 |
||
1084 |
MSG_WAR(0x3AC0, "Send SDO to write in the dictionary of node : ", nodeId); |
|
1085 |
MSG_WAR(0x3AC1, " At index : ", index); |
|
1086 |
MSG_WAR(0x3AC2, " subIndex : ", subIndex); |
|
1087 |
MSG_WAR(0x3AC3, " nb bytes : ", count); |
|
1088 |
||
71 | 1089 |
/* Verify that there is no SDO communication yet. */ |
0 | 1090 |
err = getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line); |
1091 |
if (!err) { |
|
1092 |
MSG_ERR(0x1AC4, "SDO error : Communication yet established. with node : ", nodeId); |
|
1093 |
return 0xFF; |
|
1094 |
} |
|
71 | 1095 |
/* Taking the line ... */ |
0 | 1096 |
err = getSDOfreeLine( d, SDO_CLIENT, &line ); |
1097 |
if (err) { |
|
1098 |
MSG_ERR(0x1AC5, "SDO error : No line free, too many SDO in progress. Aborted for node : ", nodeId); |
|
1099 |
return (0xFF); |
|
1100 |
} |
|
71 | 1101 |
/* Check which SDO to use to communicate with the node */ |
0 | 1102 |
offset = d->firstIndex->SDO_CLT; |
1103 |
lastIndex = d->lastIndex->SDO_CLT; |
|
1104 |
if (offset == 0) { |
|
1105 |
MSG_ERR(0x1AC6, "writeNetworkDict : No SDO client index found", 0); |
|
1106 |
return 0xFF; |
|
1107 |
} |
|
1108 |
i = 0; |
|
1109 |
while (offset <= lastIndex) { |
|
1110 |
if (d->objdict[offset].bSubCount <= 3) { |
|
1111 |
MSG_ERR(0x1AC8, "Subindex 3 not found at index ", 0x1280 + i); |
|
1112 |
return 0xFF; |
|
1113 |
} |
|
71 | 1114 |
/* looking for the nodeId server */ |
0 | 1115 |
pNodeIdServer = d->objdict[offset].pSubindex[3].pObject; |
1116 |
nodeIdServer = *pNodeIdServer; |
|
1117 |
MSG_WAR(0x1AD2, "index : ", 0x1280 + i); |
|
1118 |
MSG_WAR(0x1AD3, "nodeIdServer : ", nodeIdServer); |
|
1119 |
||
1120 |
if(nodeIdServer == nodeId) { |
|
1121 |
SDOfound = 1; |
|
1122 |
break; |
|
1123 |
} |
|
1124 |
offset++; |
|
1125 |
i++; |
|
71 | 1126 |
} /* end while */ |
0 | 1127 |
if (!SDOfound) { |
1128 |
MSG_ERR(0x1AC9, "SDO. Error. No client found to communicate with node : ", nodeId); |
|
1129 |
return 0xFF; |
|
1130 |
} |
|
1131 |
MSG_WAR(0x3AD0," SDO client defined at index : ", 0x1280 + i); |
|
1132 |
initSDOline(d, line, nodeId, index, subIndex, SDO_DOWNLOAD_IN_PROGRESS); |
|
1133 |
d->transfers[line].count = count; |
|
1134 |
d->transfers[line].dataType = dataType; |
|
1135 |
||
71 | 1136 |
/* Copy data to transfers structure. */ |
0 | 1137 |
for (j = 0 ; j < count ; j++) { |
1138 |
# ifdef CANOPEN_BIG_ENDIAN |
|
1139 |
if (dataType == 0) |
|
1140 |
d->transfers[line].data[count - 1 - j] = ((char *)data)[j]; |
|
71 | 1141 |
else /* String of bytes. */ |
0 | 1142 |
d->transfers[line].data[j] = ((char *)data)[j]; |
1143 |
# else |
|
1144 |
d->transfers[line].data[j] = ((char *)data)[j]; |
|
1145 |
# endif |
|
1146 |
} |
|
71 | 1147 |
/* Send the SDO to the server. Initiate download, cs=1. */ |
0 | 1148 |
sdo.nodeId = nodeId; |
71 | 1149 |
if (count <= 4) { /* Expedited transfert */ |
0 | 1150 |
sdo.body.data[0] = (1 << 5) | ((4 - count) << 2) | 3; |
1151 |
for (i = 4 ; i < 8 ; i++) |
|
1152 |
sdo.body.data[i] = d->transfers[line].data[i - 4]; |
|
1153 |
d->transfers[line].offset = count; |
|
1154 |
} |
|
71 | 1155 |
else { /* Normal transfert */ |
0 | 1156 |
sdo.body.data[0] = (1 << 5) | 1; |
71 | 1157 |
sdo.body.data[4] = count; /* nb of byte to transmit. Max = 255. (canfestival2 limitation). */ |
0 | 1158 |
for (i = 5 ; i < 8 ; i++) |
1159 |
sdo.body.data[i] = 0; |
|
1160 |
} |
|
71 | 1161 |
sdo.body.data[1] = index & 0xFF; /* LSB */ |
1162 |
sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
0 | 1163 |
sdo.body.data[3] = subIndex; |
1164 |
||
1165 |
err = sendSDO(d, SDO_CLIENT, sdo); |
|
1166 |
if (err) { |
|
1167 |
MSG_ERR(0x1AD1, "SDO. Error while sending SDO to node : ", nodeId); |
|
71 | 1168 |
/* release the line */ |
0 | 1169 |
resetSDOline(d, line); |
1170 |
return 0xFF; |
|
32 | 1171 |
} |
1172 |
d->transfers[line].Callback = Callback; |
|
0 | 1173 |
return 0; |
1174 |
} |
|
53 | 1175 |
|
1176 |
/*--------------------------------------------------------------------------*/ |
|
1177 |
||
32 | 1178 |
UNS8 writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
1179 |
UNS8 subIndex, UNS8 count, UNS8 dataType, void *data) |
|
1180 |
{ |
|
1181 |
return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, NULL); |
|
1182 |
} |
|
1183 |
||
53 | 1184 |
/*--------------------------------------------------------------------------*/ |
1185 |
||
32 | 1186 |
UNS8 writeNetworkDictCallBack (CO_Data* d, UNS8 nodeId, UNS16 index, |
1187 |
UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback) |
|
1188 |
{ |
|
1189 |
return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, Callback); |
|
1190 |
} |
|
1191 |
||
1192 |
||
1193 |
/***************************************************************************/ |
|
71 | 1194 |
INLINE UNS8 _readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback) |
0 | 1195 |
{ |
1196 |
UNS8 err; |
|
1197 |
UNS8 SDOfound = 0; |
|
1198 |
UNS8 i; |
|
1199 |
UNS8 line; |
|
1200 |
UNS8 * pSize; |
|
1201 |
UNS8 size; |
|
71 | 1202 |
s_SDO sdo; /* SDO to transmit */ |
0 | 1203 |
UNS8 *pNodeIdServer; |
1204 |
UNS8 nodeIdServer; |
|
1205 |
UNS16 offset; |
|
1206 |
UNS16 lastIndex; |
|
1207 |
pSize = &size; |
|
1208 |
MSG_WAR(0x3AD5, "Send SDO to read in the dictionary of node : ", nodeId); |
|
1209 |
MSG_WAR(0x3AD6, " At index : ", index); |
|
1210 |
MSG_WAR(0x3AD7, " subIndex : ", subIndex); |
|
1211 |
||
1212 |
||
71 | 1213 |
/* Verify that there is no SDO communication yet. */ |
0 | 1214 |
err = getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line); |
1215 |
if (!err) { |
|
1216 |
MSG_ERR(0x1AD8, "SDO error : Communication yet established. with node : ", nodeId); |
|
1217 |
return 0xFF; |
|
1218 |
} |
|
71 | 1219 |
/* Taking the line ... */ |
0 | 1220 |
err = getSDOfreeLine( d, SDO_CLIENT, &line ); |
1221 |
if (err) { |
|
1222 |
MSG_ERR(0x1AD9, "SDO error : No line free, too many SDO in progress. Aborted for node : ", nodeId); |
|
1223 |
return (0xFF); |
|
1224 |
} |
|
1225 |
else |
|
1226 |
MSG_WAR(0x3AE0, "Transmission on line : ", line); |
|
1227 |
||
71 | 1228 |
/* Check which SDO to use to communicate with the node */ |
0 | 1229 |
offset = d->firstIndex->SDO_CLT; |
1230 |
lastIndex = d->lastIndex->SDO_CLT; |
|
1231 |
if (offset == 0) { |
|
1232 |
MSG_ERR(0x1AE1, "writeNetworkDict : No SDO client index found", 0); |
|
1233 |
return 0xFF; |
|
1234 |
} |
|
1235 |
i = 0; |
|
1236 |
while (offset <= lastIndex) { |
|
1237 |
if (d->objdict[offset].bSubCount <= 3) { |
|
1238 |
MSG_ERR(0x1AE2, "Subindex 3 not found at index ", 0x1280 + i); |
|
1239 |
return 0xFF; |
|
1240 |
} |
|
71 | 1241 |
/* looking for the nodeId server */ |
0 | 1242 |
pNodeIdServer = d->objdict[offset].pSubindex[3].pObject; |
1243 |
nodeIdServer = *pNodeIdServer; |
|
1244 |
||
1245 |
if(nodeIdServer == nodeId) { |
|
1246 |
SDOfound = 1; |
|
1247 |
break; |
|
1248 |
} |
|
1249 |
offset++; |
|
1250 |
i++; |
|
71 | 1251 |
} /* end while */ |
0 | 1252 |
if (!SDOfound) { |
1253 |
MSG_ERR(0x1AE3, "SDO. Error. No client found to communicate with node : ", nodeId); |
|
1254 |
return 0xFF; |
|
1255 |
} |
|
1256 |
MSG_WAR(0x3AE4," SDO client defined at index : ", 0x1280 + i); |
|
1257 |
initSDOline(d, line, nodeId, index, subIndex, SDO_UPLOAD_IN_PROGRESS); |
|
1258 |
getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line); |
|
1259 |
sdo.nodeId = nodeId; |
|
71 | 1260 |
/* Send the SDO to the server. Initiate upload, cs=2. */ |
0 | 1261 |
d->transfers[line].dataType = dataType; |
1262 |
sdo.body.data[0] = (2 << 5); |
|
71 | 1263 |
sdo.body.data[1] = index & 0xFF; /* LSB */ |
1264 |
sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
0 | 1265 |
sdo.body.data[3] = subIndex; |
1266 |
for (i = 4 ; i < 8 ; i++) |
|
1267 |
sdo.body.data[i] = 0; |
|
1268 |
err = sendSDO(d, SDO_CLIENT, sdo); |
|
1269 |
if (err) { |
|
1270 |
MSG_ERR(0x1AE5, "SDO. Error while sending SDO to node : ", nodeId); |
|
71 | 1271 |
/* release the line */ |
0 | 1272 |
resetSDOline(d, line); |
1273 |
return 0xFF; |
|
1274 |
} |
|
32 | 1275 |
d->transfers[line].Callback = Callback; |
0 | 1276 |
return 0; |
1277 |
} |
|
1278 |
||
53 | 1279 |
/*--------------------------------------------------------------------------*/ |
1280 |
||
32 | 1281 |
UNS8 readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType) |
1282 |
{ |
|
1283 |
return _readNetworkDict (d, nodeId, index, subIndex, dataType, NULL); |
|
1284 |
} |
|
1285 |
||
53 | 1286 |
/*--------------------------------------------------------------------------*/ |
32 | 1287 |
UNS8 readNetworkDictCallback (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback) |
1288 |
{ |
|
1289 |
return _readNetworkDict (d, nodeId, index, subIndex, dataType, Callback); |
|
1290 |
} |
|
53 | 1291 |
|
0 | 1292 |
/***************************************************************************/ |
1293 |
||
1294 |
UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, UNS8 *size, |
|
1295 |
UNS32 * abortCode) |
|
1296 |
{ |
|
1297 |
UNS8 i; |
|
1298 |
UNS8 err; |
|
1299 |
UNS8 line; |
|
1300 |
* size = 0; |
|
1301 |
||
71 | 1302 |
/* Looking for the line tranfert. */ |
0 | 1303 |
err = getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line); |
1304 |
if (err) { |
|
1305 |
MSG_ERR(0x1AF0, "SDO error : No line found for communication with node : ", nodeId); |
|
1306 |
return SDO_ABORTED_INTERNAL; |
|
1307 |
} |
|
1308 |
if (d->transfers[line].state != SDO_FINISHED) |
|
1309 |
return d->transfers[line].state; |
|
1310 |
||
71 | 1311 |
/* Transfert is finished. Put the value in the data. */ |
0 | 1312 |
* size = d->transfers[line].count; |
1313 |
for ( i = 0 ; i < *size ; i++) { |
|
1314 |
# ifdef CANOPEN_BIG_ENDIAN |
|
1315 |
if (d->transfers[line].dataType != visible_string) |
|
1316 |
( (char *) data)[*size - 1 - i] = d->transfers[line].data[i]; |
|
71 | 1317 |
else /* String of bytes. */ |
0 | 1318 |
( (char *) data)[i] = d->transfers[line].data[i]; |
1319 |
# else |
|
1320 |
( (char *) data)[i] = d->transfers[line].data[i]; |
|
1321 |
# endif |
|
1322 |
} |
|
1323 |
return SDO_FINISHED; |
|
1324 |
} |
|
1325 |
||
1326 |
/***************************************************************************/ |
|
1327 |
||
1328 |
UNS8 getWriteResultNetworkDict (CO_Data* d, UNS8 nodeId, UNS32 * abortCode) |
|
1329 |
{ |
|
1330 |
UNS8 line = 0; |
|
1331 |
UNS8 err; |
|
1332 |
||
1333 |
* abortCode = 0; |
|
71 | 1334 |
/* Looking for the line tranfert. */ |
0 | 1335 |
err = getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line); |
1336 |
if (err) { |
|
1337 |
MSG_ERR(0x1AF1, "SDO error : No line found for communication with node : ", nodeId); |
|
1338 |
return SDO_ABORTED_INTERNAL; |
|
1339 |
} |
|
1340 |
* abortCode = d->transfers[line].abortCode; |
|
1341 |
return d->transfers[line].state; |
|
1342 |
} |
|
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
|
1343 |