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