author | greg |
Wed, 15 Jul 2009 09:36:36 +0200 | |
changeset 556 | 8296acd119a9 |
parent 544 | 7620872e153c |
child 587 | c175351a6994 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2 |
This file is part of CanFestival, a library implementing CanOpen Stack. |
0 | 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 |
*/ |
|
208 | 22 |
/*! |
23 |
** @file sdo.c |
|
24 |
** @author Edouard TISSERANT and Francis DUPIN |
|
25 |
** @date Tue Jun 5 09:32:32 2007 |
|
26 |
** |
|
27 |
** @brief |
|
28 |
** |
|
29 |
** |
|
30 |
*/ |
|
0 | 31 |
|
84 | 32 |
/* #define DEBUG_WAR_CONSOLE_ON */ |
33 |
/* #define DEBUG_ERR_CONSOLE_ON */ |
|
0 | 34 |
|
383 | 35 |
#include "canfestival.h" |
370
6fecf36df407
Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents:
365
diff
changeset
|
36 |
#include "sysdep.h" |
0 | 37 |
|
71 | 38 |
/* Uncomment if your compiler does not support inline functions */ |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
39 |
#define NO_INLINE |
71 | 40 |
|
41 |
#ifdef NO_INLINE |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
42 |
#define INLINE |
71 | 43 |
#else |
86 | 44 |
#define INLINE inline |
71 | 45 |
#endif |
46 |
||
53 | 47 |
/*Internals prototypes*/ |
48 |
||
208 | 49 |
/*! |
50 |
** Called by writeNetworkDict |
|
51 |
** |
|
52 |
** @param d |
|
53 |
** @param nodeId |
|
54 |
** @param index |
|
55 |
** @param subIndex |
|
56 |
** @param count |
|
57 |
** @param dataType |
|
58 |
** @param data |
|
59 |
** @param Callback |
|
60 |
** @param endianize |
|
61 |
** |
|
62 |
** @return |
|
63 |
**/ |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
64 |
INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
65 |
UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize); |
53 | 66 |
|
208 | 67 |
/*! |
68 |
** Called by readNetworkDict |
|
69 |
** |
|
70 |
** @param d |
|
71 |
** @param nodeId |
|
72 |
** @param index |
|
73 |
** @param subIndex |
|
74 |
** @param dataType |
|
75 |
** @param Callback |
|
76 |
** |
|
77 |
** @return |
|
78 |
**/ |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
79 |
INLINE UNS8 _readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, |
53 | 80 |
UNS8 dataType, SDOCallback_t Callback); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
81 |
|
53 | 82 |
|
0 | 83 |
/***************************************************************************/ |
71 | 84 |
/* SDO (un)packing macros */ |
0 | 85 |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
86 |
/** Returns the command specifier (cs, ccs, scs) from the first byte of the SDO |
0 | 87 |
*/ |
88 |
#define getSDOcs(byte) (byte >> 5) |
|
89 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
90 |
/** Returns the number of bytes without data from the first byte of the SDO. Coded in 2 bits |
0 | 91 |
*/ |
92 |
#define getSDOn2(byte) ((byte >> 2) & 3) |
|
93 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
94 |
/** Returns the number of bytes without data from the first byte of the SDO. Coded in 3 bits |
0 | 95 |
*/ |
96 |
#define getSDOn3(byte) ((byte >> 1) & 7) |
|
97 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
98 |
/** Returns the transfer type from the first byte of the SDO |
0 | 99 |
*/ |
100 |
#define getSDOe(byte) ((byte >> 1) & 1) |
|
101 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
102 |
/** Returns the size indicator from the first byte of the SDO |
0 | 103 |
*/ |
104 |
#define getSDOs(byte) (byte & 1) |
|
105 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
106 |
/** Returns the indicator of end transmission from the first byte of the SDO |
0 | 107 |
*/ |
108 |
#define getSDOc(byte) (byte & 1) |
|
109 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
110 |
/** Returns the toggle from the first byte of the SDO |
0 | 111 |
*/ |
112 |
#define getSDOt(byte) ((byte >> 4) & 1) |
|
113 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
114 |
/** Returns the index from the bytes 1 and 2 of the SDO |
0 | 115 |
*/ |
116 |
#define getSDOindex(byte1, byte2) ((byte2 << 8) | (byte1)) |
|
117 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
118 |
/** Returns the subIndex from the byte 3 of the SDO |
0 | 119 |
*/ |
120 |
#define getSDOsubIndex(byte3) (byte3) |
|
121 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
122 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
123 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
124 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
125 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
126 |
** @param id |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
127 |
**/ |
0 | 128 |
void SDOTimeoutAlarm(CO_Data* d, UNS32 id) |
129 |
{ |
|
130 |
MSG_ERR(0x1A01, "SDO timeout. SDO response not received.", 0); |
|
131 |
MSG_WAR(0x2A02, "server node : ", d->transfers[id].nodeId); |
|
132 |
MSG_WAR(0x2A02, " index : ", d->transfers[id].index); |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
133 |
MSG_WAR(0x2A02, " subIndex : ", d->transfers[id].subIndex); |
71 | 134 |
/* Reset timer handler */ |
0 | 135 |
d->transfers[id].timer = TIMER_NONE; |
172
0248c2b148bb
Removed SDOTimeout application callback.Please use SDO callbacks instead.
etisserant
parents:
166
diff
changeset
|
136 |
/*Set aborted state*/ |
0248c2b148bb
Removed SDOTimeout application callback.Please use SDO callbacks instead.
etisserant
parents:
166
diff
changeset
|
137 |
d->transfers[id].state = SDO_ABORTED_INTERNAL; |
71 | 138 |
/* Sending a SDO abort */ |
499
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
139 |
sendSDOabort(d, d->transfers[id].whoami, d->transfers[id].nodeId, |
0 | 140 |
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
|
141 |
d->transfers[id].abortCode = SDOABT_TIMED_OUT; |
0248c2b148bb
Removed SDOTimeout application callback.Please use SDO callbacks instead.
etisserant
parents:
166
diff
changeset
|
142 |
/* Call the user function to inform of the problem.*/ |
0248c2b148bb
Removed SDOTimeout application callback.Please use SDO callbacks instead.
etisserant
parents:
166
diff
changeset
|
143 |
if(d->transfers[id].Callback) |
0248c2b148bb
Removed SDOTimeout application callback.Please use SDO callbacks instead.
etisserant
parents:
166
diff
changeset
|
144 |
/*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
|
145 |
(*d->transfers[id].Callback)(d,d->transfers[id].nodeId); |
0248c2b148bb
Removed SDOTimeout application callback.Please use SDO callbacks instead.
etisserant
parents:
166
diff
changeset
|
146 |
else if(d->transfers[id].whoami == SDO_SERVER) |
0248c2b148bb
Removed SDOTimeout application callback.Please use SDO callbacks instead.
etisserant
parents:
166
diff
changeset
|
147 |
/*Else, if server, reset the line*/ |
0248c2b148bb
Removed SDOTimeout application callback.Please use SDO callbacks instead.
etisserant
parents:
166
diff
changeset
|
148 |
resetSDOline(d, (UNS8)id); |
0 | 149 |
} |
150 |
||
151 |
#define StopSDO_TIMER(id) \ |
|
152 |
MSG_WAR(0x3A05, "StopSDO_TIMER for line : ", line);\ |
|
153 |
d->transfers[id].timer = DelAlarm(d->transfers[id].timer); |
|
154 |
||
155 |
#define StartSDO_TIMER(id) \ |
|
156 |
MSG_WAR(0x3A06, "StartSDO_TIMER for line : ", line);\ |
|
157 |
d->transfers[id].timer = SetAlarm(d,id,&SDOTimeoutAlarm,MS_TO_TIMEVAL(SDO_TIMEOUT_MS),0); |
|
158 |
||
159 |
#define RestartSDO_TIMER(id) \ |
|
160 |
MSG_WAR(0x3A07, "restartSDO_TIMER for line : ", line);\ |
|
161 |
if(d->transfers[id].timer != TIMER_NONE) { StopSDO_TIMER(id) StartSDO_TIMER(id) } |
|
162 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
163 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
164 |
** Reset all sdo buffers |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
165 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
166 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
167 |
**/ |
0 | 168 |
void resetSDO (CO_Data* d) |
169 |
{ |
|
170 |
UNS8 j; |
|
171 |
||
215 | 172 |
/* transfer structure initialization */ |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
173 |
for (j = 0 ; j < SDO_MAX_SIMULTANEOUS_TRANSFERTS ; j++) |
0 | 174 |
resetSDOline(d, j); |
175 |
} |
|
176 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
177 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
178 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
179 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
180 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
181 |
** @param line |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
182 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
183 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
184 |
**/ |
0 | 185 |
UNS32 SDOlineToObjdict (CO_Data* d, UNS8 line) |
186 |
{ |
|
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
187 |
UNS32 size; |
0 | 188 |
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
|
189 |
MSG_WAR(0x3A08, "Enter in SDOlineToObjdict ", line); |
544
7620872e153c
Fixed bugs in SDO caused by UNS8->UNS32 size patch.
etisserant
parents:
539
diff
changeset
|
190 |
/* if SDO initiated with e=0 and s=0 count is null, offset carry effective size*/ |
7620872e153c
Fixed bugs in SDO caused by UNS8->UNS32 size patch.
etisserant
parents:
539
diff
changeset
|
191 |
if( d->transfers[line].count == 0) |
7620872e153c
Fixed bugs in SDO caused by UNS8->UNS32 size patch.
etisserant
parents:
539
diff
changeset
|
192 |
d->transfers[line].count = d->transfers[line].offset; |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
193 |
size = d->transfers[line].count; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
194 |
errorCode = setODentry(d, d->transfers[line].index, d->transfers[line].subIndex, |
0 | 195 |
(void *) d->transfers[line].data, &size, 1); |
196 |
if (errorCode != OD_SUCCESSFUL) |
|
197 |
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
|
198 |
MSG_WAR(0x3A08, "exit of SDOlineToObjdict ", line); |
0 | 199 |
return 0; |
200 |
||
201 |
} |
|
202 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
203 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
204 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
205 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
206 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
207 |
** @param line |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
208 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
209 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
210 |
**/ |
0 | 211 |
UNS32 objdictToSDOline (CO_Data* d, UNS8 line) |
212 |
{ |
|
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
213 |
UNS32 size = 0; |
0 | 214 |
UNS8 dataType; |
215 |
UNS32 errorCode; |
|
216 |
||
12 | 217 |
MSG_WAR(0x3A05, "objdict->line index : ", d->transfers[line].index); |
218 |
MSG_WAR(0x3A06, " subIndex : ", d->transfers[line].subIndex); |
|
0 | 219 |
|
220 |
errorCode = getODentry(d, d->transfers[line].index, |
|
221 |
d->transfers[line].subIndex, |
|
222 |
(void *)d->transfers[line].data, |
|
402
77f875d45250
Fixed faulty read access checking on OD access. Added read acces s checking in SDO (was disabled)
etisserant
parents:
383
diff
changeset
|
223 |
&size, &dataType, 1); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
224 |
|
0 | 225 |
if (errorCode != OD_SUCCESSFUL) |
226 |
return errorCode; |
|
227 |
||
228 |
d->transfers[line].count = size; |
|
229 |
d->transfers[line].offset = 0; |
|
402
77f875d45250
Fixed faulty read access checking on OD access. Added read acces s checking in SDO (was disabled)
etisserant
parents:
383
diff
changeset
|
230 |
|
0 | 231 |
return 0; |
232 |
} |
|
233 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
234 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
235 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
236 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
237 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
238 |
** @param line |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
239 |
** @param nbBytes |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
240 |
** @param data |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
241 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
242 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
243 |
**/ |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
244 |
UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS32 nbBytes, UNS8* data) { |
0 | 245 |
UNS8 i; |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
246 |
UNS32 offset; |
0 | 247 |
|
248 |
if ((d->transfers[line].offset + nbBytes) > SDO_MAX_LENGTH_TRANSFERT) { |
|
249 |
MSG_ERR(0x1A10,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes); |
|
250 |
return 0xFF; |
|
251 |
} |
|
252 |
if ((d->transfers[line].offset + nbBytes) > d->transfers[line].count) { |
|
253 |
MSG_ERR(0x1A11,"SDO Size of data too large. Exceed count", nbBytes); |
|
254 |
return 0xFF; |
|
255 |
} |
|
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
256 |
offset = d->transfers[line].offset; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
257 |
for (i = 0 ; i < nbBytes ; i++) |
0 | 258 |
* (data + i) = d->transfers[line].data[offset + i]; |
259 |
d->transfers[line].offset = d->transfers[line].offset + nbBytes; |
|
260 |
return 0; |
|
261 |
} |
|
262 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
263 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
264 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
265 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
266 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
267 |
** @param line |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
268 |
** @param nbBytes |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
269 |
** @param data |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
270 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
271 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
272 |
**/ |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
273 |
UNS8 SDOtoLine (CO_Data* d, UNS8 line, UNS32 nbBytes, UNS8* data) |
0 | 274 |
{ |
275 |
UNS8 i; |
|
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
276 |
UNS32 offset; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
277 |
|
0 | 278 |
if ((d->transfers[line].offset + nbBytes) > SDO_MAX_LENGTH_TRANSFERT) { |
279 |
MSG_ERR(0x1A15,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes); |
|
280 |
return 0xFF; |
|
281 |
} |
|
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
282 |
offset = d->transfers[line].offset; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
283 |
for (i = 0 ; i < nbBytes ; i++) |
0 | 284 |
d->transfers[line].data[offset + i] = * (data + i); |
285 |
d->transfers[line].offset = d->transfers[line].offset + nbBytes; |
|
286 |
return 0; |
|
287 |
} |
|
288 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
289 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
290 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
291 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
292 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
293 |
** @param nodeId |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
294 |
** @param whoami |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
295 |
** @param index |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
296 |
** @param subIndex |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
297 |
** @param abortCode |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
298 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
299 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
300 |
**/ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
301 |
UNS8 failedSDO (CO_Data* d, UNS8 nodeId, UNS8 whoami, UNS16 index, |
0 | 302 |
UNS8 subIndex, UNS32 abortCode) |
303 |
{ |
|
304 |
UNS8 err; |
|
305 |
UNS8 line; |
|
306 |
err = getSDOlineOnUse( d, nodeId, whoami, &line ); |
|
71 | 307 |
if (!err) /* If a line on use have been found.*/ |
0 | 308 |
MSG_WAR(0x3A20, "FailedSDO : line found : ", line); |
309 |
if ((! err) && (whoami == SDO_SERVER)) { |
|
310 |
resetSDOline( d, line ); |
|
311 |
MSG_WAR(0x3A21, "FailedSDO : line released : ", line); |
|
312 |
} |
|
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
|
313 |
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
|
314 |
StopSDO_TIMER(line); |
0 | 315 |
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
|
316 |
} |
0 | 317 |
MSG_WAR(0x3A22, "Sending SDO abort ", 0); |
499
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
318 |
err = sendSDOabort(d, whoami, nodeId, index, subIndex, abortCode); |
0 | 319 |
if (err) { |
320 |
MSG_WAR(0x3A23, "Unable to send the SDO abort", 0); |
|
321 |
return 0xFF; |
|
322 |
} |
|
323 |
return 0; |
|
324 |
} |
|
325 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
326 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
327 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
328 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
329 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
330 |
** @param line |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
331 |
**/ |
0 | 332 |
void resetSDOline ( CO_Data* d, UNS8 line ) |
333 |
{ |
|
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
334 |
UNS32 i; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
335 |
MSG_WAR(0x3A25, "reset SDO line nb : ", line); |
0 | 336 |
initSDOline(d, line, 0, 0, 0, SDO_RESET); |
337 |
for (i = 0 ; i < SDO_MAX_LENGTH_TRANSFERT ; i++) |
|
338 |
d->transfers[line].data[i] = 0; |
|
501 | 339 |
d->transfers[line].whoami = 0; |
340 |
d->transfers[line].abortCode = 0; |
|
0 | 341 |
} |
342 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
343 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
344 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
345 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
346 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
347 |
** @param line |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
348 |
** @param nodeId |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
349 |
** @param index |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
350 |
** @param subIndex |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
351 |
** @param state |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
352 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
353 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
354 |
**/ |
0 | 355 |
UNS8 initSDOline (CO_Data* d, UNS8 line, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 state) |
356 |
{ |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
357 |
MSG_WAR(0x3A25, "init SDO line nb : ", line); |
0 | 358 |
if (state == SDO_DOWNLOAD_IN_PROGRESS || state == SDO_UPLOAD_IN_PROGRESS){ |
359 |
StartSDO_TIMER(line) |
|
360 |
}else{ |
|
361 |
StopSDO_TIMER(line) |
|
362 |
} |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
363 |
d->transfers[line].nodeId = nodeId; |
0 | 364 |
d->transfers[line].index = index; |
365 |
d->transfers[line].subIndex = subIndex; |
|
366 |
d->transfers[line].state = state; |
|
367 |
d->transfers[line].toggle = 0; |
|
368 |
d->transfers[line].count = 0; |
|
369 |
d->transfers[line].offset = 0; |
|
370 |
d->transfers[line].dataType = 0; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
371 |
d->transfers[line].Callback = NULL; |
0 | 372 |
return 0; |
373 |
} |
|
374 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
375 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
376 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
377 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
378 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
379 |
** @param whoami |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
380 |
** @param line |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
381 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
382 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
383 |
**/ |
0 | 384 |
UNS8 getSDOfreeLine ( CO_Data* d, UNS8 whoami, UNS8 *line ) |
385 |
{ |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
386 |
|
0 | 387 |
UNS8 i; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
388 |
|
0 | 389 |
for (i = 0 ; i < SDO_MAX_SIMULTANEOUS_TRANSFERTS ; i++){ |
390 |
if ( d->transfers[i].state == SDO_RESET ) { |
|
391 |
*line = i; |
|
392 |
d->transfers[i].whoami = whoami; |
|
393 |
return 0; |
|
71 | 394 |
} /* end if */ |
395 |
} /* end for */ |
|
0 | 396 |
MSG_ERR(0x1A25, "Too many SDO in progress. Aborted.", i); |
397 |
return 0xFF; |
|
398 |
} |
|
399 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
400 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
401 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
402 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
403 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
404 |
** @param nodeId |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
405 |
** @param whoami |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
406 |
** @param line |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
407 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
408 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
409 |
**/ |
0 | 410 |
UNS8 getSDOlineOnUse (CO_Data* d, UNS8 nodeId, UNS8 whoami, UNS8 *line) |
411 |
{ |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
412 |
|
0 | 413 |
UNS8 i; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
414 |
|
0 | 415 |
for (i = 0 ; i < SDO_MAX_SIMULTANEOUS_TRANSFERTS ; i++){ |
416 |
if ( (d->transfers[i].state != SDO_RESET) && |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
417 |
(d->transfers[i].nodeId == nodeId) && |
0 | 418 |
(d->transfers[i].whoami == whoami) ) { |
419 |
*line = i; |
|
420 |
return 0; |
|
421 |
} |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
422 |
} |
0 | 423 |
return 0xFF; |
424 |
} |
|
425 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
426 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
427 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
428 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
429 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
430 |
** @param nodeId |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
431 |
** @param whoami |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
432 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
433 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
434 |
**/ |
0 | 435 |
UNS8 closeSDOtransfer (CO_Data* d, UNS8 nodeId, UNS8 whoami) |
436 |
{ |
|
437 |
UNS8 err; |
|
438 |
UNS8 line; |
|
439 |
err = getSDOlineOnUse(d, nodeId, whoami, &line); |
|
440 |
if (err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
441 |
MSG_WAR(0x2A30, "No SDO communication to close for node : ", nodeId); |
0 | 442 |
return 0xFF; |
443 |
} |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
444 |
resetSDOline(d, line); |
0 | 445 |
return 0; |
446 |
} |
|
447 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
448 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
449 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
450 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
451 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
452 |
** @param line |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
453 |
** @param nbBytes |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
454 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
455 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
456 |
**/ |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
457 |
UNS8 getSDOlineRestBytes (CO_Data* d, UNS8 line, UNS32 * nbBytes) |
0 | 458 |
{ |
544
7620872e153c
Fixed bugs in SDO caused by UNS8->UNS32 size patch.
etisserant
parents:
539
diff
changeset
|
459 |
/* SDO initiated with e=0 and s=0 have count set to null */ |
7620872e153c
Fixed bugs in SDO caused by UNS8->UNS32 size patch.
etisserant
parents:
539
diff
changeset
|
460 |
if (d->transfers[line].count == 0) |
0 | 461 |
* nbBytes = 0; |
462 |
else |
|
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
463 |
* nbBytes = d->transfers[line].count - d->transfers[line].offset; |
0 | 464 |
return 0; |
465 |
} |
|
466 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
467 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
468 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
469 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
470 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
471 |
** @param line |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
472 |
** @param nbBytes |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
473 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
474 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
475 |
**/ |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
476 |
UNS8 setSDOlineRestBytes (CO_Data* d, UNS8 line, UNS32 nbBytes) |
0 | 477 |
{ |
478 |
if (nbBytes > SDO_MAX_LENGTH_TRANSFERT) { |
|
479 |
MSG_ERR(0x1A35,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes); |
|
480 |
return 0xFF; |
|
481 |
} |
|
482 |
d->transfers[line].count = nbBytes; |
|
483 |
return 0; |
|
484 |
} |
|
485 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
486 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
487 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
488 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
489 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
490 |
** @param whoami |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
491 |
** @param sdo |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
492 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
493 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
494 |
**/ |
0 | 495 |
UNS8 sendSDO (CO_Data* d, UNS8 whoami, s_SDO sdo) |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
496 |
{ |
0 | 497 |
UNS16 offset; |
498 |
UNS16 lastIndex; |
|
499 |
UNS8 found = 0; |
|
500 |
Message m; |
|
501 |
UNS8 i; |
|
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
435
diff
changeset
|
502 |
UNS32 * pwCobId = NULL; |
306
3586cfa84705
Fixed incoherency with idx 0x1280+n sidx 3 in sdo.c against newly generated objectditcs (UNS32*->UNS8*).
etisserant
parents:
217
diff
changeset
|
503 |
UNS8 * pwNodeId = NULL; |
0 | 504 |
|
505 |
MSG_WAR(0x3A38, "sendSDO",0); |
|
506 |
if( !((d->nodeState == Operational) || (d->nodeState == Pre_operational ))) { |
|
507 |
MSG_WAR(0x2A39, "unable to send the SDO (not in op or pre-op mode", d->nodeState); |
|
508 |
return 0xFF; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
509 |
} |
0 | 510 |
|
215 | 511 |
/*get the server->client cobid*/ |
481 | 512 |
if ( whoami == SDO_SERVER ) {/*case server. only one SDO server*/ |
0 | 513 |
offset = d->firstIndex->SDO_SVR; |
514 |
if (offset == 0) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
515 |
MSG_ERR(0x1A42, "SendSDO : No SDO server found", 0); |
0 | 516 |
return 0xFF; |
517 |
} |
|
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
435
diff
changeset
|
518 |
pwCobId = (UNS32*) d->objdict[offset].pSubindex[2].pObject; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
519 |
MSG_WAR(0x3A41, "I am server. cobId : ", *pwCobId); |
0 | 520 |
} |
215 | 521 |
else { /*case client*/ |
522 |
/* Get the client->server cobid.*/ |
|
0 | 523 |
UNS16 sdoNum = 0; |
524 |
offset = d->firstIndex->SDO_CLT; |
|
525 |
lastIndex = d->lastIndex->SDO_CLT; |
|
526 |
if (offset == 0) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
527 |
MSG_ERR(0x1A42, "SendSDO : No SDO client index found", 0); |
0 | 528 |
return 0xFF; |
529 |
} |
|
481 | 530 |
/* find index for communication server node */ |
0 | 531 |
while (offset <= lastIndex){ |
532 |
MSG_WAR(0x3A43,"Reading index : ", 0x1280 + sdoNum); |
|
533 |
if (d->objdict[offset].bSubCount <= 3) { |
|
534 |
MSG_ERR(0x1A28, "Subindex 3 not found at index ", 0x1280 + sdoNum); |
|
535 |
return 0xFF; |
|
536 |
} |
|
306
3586cfa84705
Fixed incoherency with idx 0x1280+n sidx 3 in sdo.c against newly generated objectditcs (UNS32*->UNS8*).
etisserant
parents:
217
diff
changeset
|
537 |
pwNodeId = (UNS8*) d->objdict[offset].pSubindex[3].pObject; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
538 |
MSG_WAR(0x3A44, "Found nodeId server = ", *pwNodeId); |
0 | 539 |
if(*pwNodeId == sdo.nodeId) { |
540 |
found = 1; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
541 |
break; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
542 |
} |
0 | 543 |
offset ++; |
544 |
sdoNum ++; |
|
545 |
} |
|
546 |
if (! found){ |
|
547 |
MSG_WAR (0x2A45, "No SDO client corresponds to the mesage to send to node ", sdo.nodeId); |
|
548 |
return 0xFF; |
|
549 |
} |
|
481 | 550 |
/* read the client->server cobid */ |
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
435
diff
changeset
|
551 |
pwCobId = (UNS32*) d->objdict[offset].pSubindex[1].pObject; |
0 | 552 |
} |
215 | 553 |
/* message copy for sending */ |
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
435
diff
changeset
|
554 |
m.cob_id = UNS16_LE(*pwCobId); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
555 |
m.rtr = NOT_A_REQUEST; |
215 | 556 |
/* the length of SDO must be 8 */ |
0 | 557 |
m.len = 8; |
558 |
for (i = 0 ; i < 8 ; i++) { |
|
559 |
m.data[i] = sdo.body.data[i]; |
|
560 |
} |
|
149 | 561 |
return canSend(d->canHandle,&m); |
0 | 562 |
} |
563 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
564 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
565 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
566 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
567 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
568 |
** @param whoami |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
569 |
** @param index |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
570 |
** @param subIndex |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
571 |
** @param abortCode |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
572 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
573 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
574 |
**/ |
499
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
575 |
UNS8 sendSDOabort (CO_Data* d, UNS8 whoami, UNS8 nodeID, UNS16 index, UNS8 subIndex, UNS32 abortCode) |
0 | 576 |
{ |
577 |
s_SDO sdo; |
|
578 |
UNS8 ret; |
|
499
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
579 |
UNS8* pNodeIdServer; |
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
580 |
UNS8 nodeIdServer; |
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
581 |
UNS16 offset; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
582 |
|
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
|
583 |
MSG_WAR(0x2A50,"Sending SDO abort ", abortCode); |
499
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
584 |
if(whoami == SDO_SERVER) |
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
585 |
{ |
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
586 |
sdo.nodeId = *d->bDeviceNodeId; |
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
587 |
} |
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
588 |
else |
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
589 |
{ |
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
590 |
sdo.nodeId = nodeID; |
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
591 |
} |
0 | 592 |
sdo.body.data[0] = 0x80; |
71 | 593 |
/* Index */ |
594 |
sdo.body.data[1] = index & 0xFF; /* LSB */ |
|
595 |
sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
596 |
/* Subindex */ |
|
0 | 597 |
sdo.body.data[3] = subIndex; |
71 | 598 |
/* Data */ |
0 | 599 |
sdo.body.data[4] = (UNS8)(abortCode & 0xFF); |
600 |
sdo.body.data[5] = (UNS8)((abortCode >> 8) & 0xFF); |
|
601 |
sdo.body.data[6] = (UNS8)((abortCode >> 16) & 0xFF); |
|
602 |
sdo.body.data[7] = (UNS8)((abortCode >> 24) & 0xFF); |
|
603 |
ret = sendSDO(d, whoami, sdo); |
|
604 |
||
605 |
return ret; |
|
606 |
} |
|
607 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
608 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
609 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
610 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
611 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
612 |
** @param m |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
613 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
614 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
615 |
**/ |
0 | 616 |
UNS8 proceedSDO (CO_Data* d, Message *m) |
617 |
{ |
|
618 |
UNS8 err; |
|
619 |
UNS8 line; |
|
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
620 |
UNS32 nbBytes; /* received or to be transmited. */ |
215 | 621 |
UNS8 nodeId = 0; /* The node from which the SDO is received */ |
311 | 622 |
UNS8 *pNodeId = NULL; |
215 | 623 |
UNS8 whoami = SDO_UNKNOWN; /* SDO_SERVER or SDO_CLIENT.*/ |
624 |
UNS32 errorCode; /* while reading or writing in the local object dictionary.*/ |
|
625 |
s_SDO sdo; /* SDO to transmit */ |
|
0 | 626 |
UNS16 index; |
627 |
UNS8 subIndex; |
|
628 |
UNS32 abortCode; |
|
629 |
UNS8 i,j; |
|
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
435
diff
changeset
|
630 |
UNS32 *pCobId = NULL; |
0 | 631 |
UNS16 offset; |
632 |
UNS16 lastIndex; |
|
633 |
||
634 |
MSG_WAR(0x3A60, "proceedSDO ", 0); |
|
635 |
whoami = SDO_UNKNOWN; |
|
215 | 636 |
/* Looking for the cobId in the object dictionary. */ |
637 |
/* Am-I a server ? */ |
|
0 | 638 |
offset = d->firstIndex->SDO_SVR; |
639 |
lastIndex = d->lastIndex->SDO_SVR; |
|
640 |
j = 0; |
|
641 |
if(offset) while (offset <= lastIndex) { |
|
642 |
if (d->objdict[offset].bSubCount <= 1) { |
|
643 |
MSG_ERR(0x1A61, "Subindex 1 not found at index ", 0x1200 + j); |
|
644 |
return 0xFF; |
|
645 |
} |
|
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
435
diff
changeset
|
646 |
pCobId = (UNS32*) d->objdict[offset].pSubindex[1].pObject; |
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
435
diff
changeset
|
647 |
if ( *pCobId == UNS16_LE(m->cob_id) ) { |
0 | 648 |
whoami = SDO_SERVER; |
649 |
MSG_WAR(0x3A62, "proceedSDO. I am server. index : ", 0x1200 + j); |
|
215 | 650 |
/* In case of server, the node id of the client may be unknown. So we put the index minus offset */ |
651 |
/* 0x1200 where the cobid received is defined. */ |
|
0 | 652 |
nodeId = j; |
653 |
break; |
|
654 |
} |
|
655 |
j++; |
|
656 |
offset++; |
|
215 | 657 |
} /* end while */ |
0 | 658 |
if (whoami == SDO_UNKNOWN) { |
215 | 659 |
/* Am-I client ? */ |
0 | 660 |
offset = d->firstIndex->SDO_CLT; |
661 |
lastIndex = d->lastIndex->SDO_CLT; |
|
662 |
j = 0; |
|
663 |
if(offset) while (offset <= lastIndex) { |
|
664 |
if (d->objdict[offset].bSubCount <= 3) { |
|
665 |
MSG_ERR(0x1A63, "Subindex 3 not found at index ", 0x1280 + j); |
|
666 |
return 0xFF; |
|
667 |
} |
|
215 | 668 |
/* a) Looking for the cobid received. */ |
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
435
diff
changeset
|
669 |
pCobId = (UNS32*) d->objdict[offset].pSubindex[2].pObject; |
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
435
diff
changeset
|
670 |
if (*pCobId == UNS16_LE(m->cob_id) ) { |
215 | 671 |
/* b) cobid found, so reading the node id of the server. */ |
311 | 672 |
pNodeId = (UNS8*) d->objdict[offset].pSubindex[3].pObject; |
0 | 673 |
whoami = SDO_CLIENT; |
311 | 674 |
nodeId = *pNodeId; |
0 | 675 |
MSG_WAR(0x3A64, "proceedSDO. I am server. index : ", 0x1280 + j); |
676 |
MSG_WAR(0x3A65, " Server nodeId : ", nodeId); |
|
677 |
break; |
|
678 |
} |
|
679 |
j++; |
|
680 |
offset++; |
|
71 | 681 |
} /* end while */ |
0 | 682 |
} |
683 |
if (whoami == SDO_UNKNOWN) { |
|
215 | 684 |
return 0xFF;/* This SDO was not for us ! */ |
685 |
} |
|
686 |
||
687 |
/* Test if the size of the SDO is ok */ |
|
0 | 688 |
if ( (*m).len != 8) { |
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
435
diff
changeset
|
689 |
MSG_ERR(0x1A67, "Error size SDO. CobId : ", UNS16_LE(m->cob_id)); |
0 | 690 |
failedSDO(d, nodeId, whoami, 0, 0, SDOABT_GENERAL_ERROR); |
691 |
return 0xFF; |
|
692 |
} |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
693 |
|
0 | 694 |
if (whoami == SDO_CLIENT) { |
695 |
MSG_WAR(0x3A68, "I am CLIENT. Received SDO from nodeId : ", nodeId); |
|
696 |
} |
|
697 |
else { |
|
447
c9d01296d6d9
Endianess patch from Edward Karpicz, Lithuania :-)
etisserant
parents:
435
diff
changeset
|
698 |
MSG_WAR(0x3A69, "I am SERVER. Received SDO cobId : ", UNS16_LE(m->cob_id)); |
0 | 699 |
} |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
700 |
|
215 | 701 |
/* Testing the command specifier */ |
702 |
/* Allowed : cs = 0, 1, 2, 3, 4. (= all except those for block tranfert). */ |
|
703 |
/* cs = other : Not allowed -> abort. */ |
|
0 | 704 |
switch (getSDOcs(m->data[0])) { |
705 |
||
706 |
case 0: |
|
215 | 707 |
/* I am SERVER */ |
0 | 708 |
if (whoami == SDO_SERVER) { |
215 | 709 |
/* Receiving a download segment data. */ |
710 |
/* A SDO transfert should have been yet initiated. */ |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
711 |
err = getSDOlineOnUse( d, nodeId, whoami, &line ); |
0 | 712 |
if (!err) |
713 |
err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS; |
|
714 |
if (err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
715 |
MSG_ERR(0x1A70, "SDO error : Received download segment for unstarted trans. index 0x1200 + ", |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
716 |
nodeId); |
0 | 717 |
failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
718 |
return 0xFF; |
|
719 |
} |
|
215 | 720 |
/* Reset the wathdog */ |
0 | 721 |
RestartSDO_TIMER(line) |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
722 |
MSG_WAR(0x3A71, "Received SDO download segment defined at index 0x1200 + ", nodeId); |
0 | 723 |
index = d->transfers[line].index; |
724 |
subIndex = d->transfers[line].subIndex; |
|
215 | 725 |
/* Toggle test. */ |
0 | 726 |
if (d->transfers[line].toggle != getSDOt(m->data[0])) { |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
727 |
MSG_ERR(0x1A72, "SDO error : Toggle error : ", getSDOt(m->data[0])); |
0 | 728 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED); |
729 |
return 0xFF; |
|
730 |
} |
|
215 | 731 |
/* Nb of data to be downloaded */ |
0 | 732 |
nbBytes = 7 - getSDOn3(m->data[0]); |
215 | 733 |
/* Store the data in the transfert structure. */ |
0 | 734 |
err = SDOtoLine(d, line, nbBytes, (*m).data + 1); |
735 |
if (err) { |
|
736 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
737 |
return 0xFF; |
|
738 |
} |
|
215 | 739 |
/* Sending the SDO response, CS = 1 */ |
740 |
sdo.nodeId = *d->bDeviceNodeId; /* The node id of the server, (here it is the sender). */ |
|
0 | 741 |
sdo.body.data[0] = (1 << 5) | (d->transfers[line].toggle << 4); |
742 |
for (i = 1 ; i < 8 ; i++) |
|
743 |
sdo.body.data[i] = 0; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
744 |
MSG_WAR(0x3A73, "SDO. Send response to download request defined at index 0x1200 + ", nodeId); |
0 | 745 |
sendSDO(d, whoami, sdo); |
215 | 746 |
/* Inverting the toggle for the next segment. */ |
0 | 747 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
215 | 748 |
/* If it was the last segment, */ |
0 | 749 |
if (getSDOc(m->data[0])) { |
215 | 750 |
/* Transfering line data to object dictionary. */ |
751 |
/* The code does not use the "d" of initiate frame. So it is safe if e=s=0 */ |
|
0 | 752 |
errorCode = SDOlineToObjdict(d, line); |
753 |
if (errorCode) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
754 |
MSG_ERR(0x1A54, "SDO error : Unable to copy the data in the object dictionary", 0); |
0 | 755 |
failedSDO(d, nodeId, whoami, index, subIndex, errorCode); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
756 |
return 0xFF; |
0 | 757 |
} |
215 | 758 |
/* Release of the line */ |
0 | 759 |
resetSDOline(d, line); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
760 |
MSG_WAR(0x3A74, "SDO. End of download defined at index 0x1200 + ", nodeId); |
0 | 761 |
} |
71 | 762 |
} /* end if SERVER */ |
763 |
else { /* if CLIENT */ |
|
215 | 764 |
/* I am CLIENT */ |
765 |
/* It is a request for a previous upload segment. We should find a line opened for this.*/ |
|
0 | 766 |
err = getSDOlineOnUse( d, nodeId, whoami, &line); |
767 |
if (!err) |
|
768 |
err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS; |
|
769 |
if (err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
770 |
MSG_ERR(0x1A75, "SDO error : Received segment response for unknown trans. from nodeId", nodeId); |
0 | 771 |
failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
772 |
return 0xFF; |
|
773 |
} |
|
215 | 774 |
/* Reset the wathdog */ |
0 | 775 |
RestartSDO_TIMER(line) |
776 |
index = d->transfers[line].index; |
|
777 |
subIndex = d->transfers[line].subIndex; |
|
215 | 778 |
/* test of the toggle; */ |
0 | 779 |
if (d->transfers[line].toggle != getSDOt(m->data[0])) { |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
780 |
MSG_ERR(0x1A76, "SDO error : Received segment response Toggle error. from nodeId", nodeId); |
0 | 781 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED); |
782 |
return 0xFF; |
|
783 |
} |
|
215 | 784 |
/* nb of data to be uploaded */ |
0 | 785 |
nbBytes = 7 - getSDOn3(m->data[0]); |
215 | 786 |
/* Storing the data in the line structure. */ |
0 | 787 |
err = SDOtoLine(d, line, nbBytes, (*m).data + 1); |
788 |
if (err) { |
|
789 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
790 |
return 0xFF; |
|
791 |
} |
|
215 | 792 |
/* Inverting the toggle for the next segment. */ |
0 | 793 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
215 | 794 |
/* If it was the last segment,*/ |
0 | 795 |
if ( getSDOc(m->data[0])) { |
215 | 796 |
/* Put in state finished */ |
797 |
/* The code is safe for the case e=s=0 in initiate frame. */ |
|
0 | 798 |
StopSDO_TIMER(line) |
799 |
d->transfers[line].state = SDO_FINISHED; |
|
32 | 800 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
801 |
|
0 | 802 |
MSG_WAR(0x3A77, "SDO. End of upload from node : ", nodeId); |
803 |
} |
|
215 | 804 |
else { /* more segments to receive */ |
805 |
/* Sending the request for the next segment. */ |
|
0 | 806 |
sdo.nodeId = nodeId; |
807 |
sdo.body.data[0] = (3 << 5) | (d->transfers[line].toggle << 4); |
|
808 |
for (i = 1 ; i < 8 ; i++) |
|
809 |
sdo.body.data[i] = 0; |
|
810 |
sendSDO(d, whoami, sdo); |
|
811 |
MSG_WAR(0x3A78, "SDO send upload segment request to nodeId", nodeId); |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
812 |
} |
71 | 813 |
} /* End if CLIENT */ |
0 | 814 |
break; |
815 |
||
816 |
case 1: |
|
215 | 817 |
/* I am SERVER */ |
818 |
/* Receive of an initiate download */ |
|
0 | 819 |
if (whoami == SDO_SERVER) { |
820 |
index = getSDOindex(m->data[1],m->data[2]); |
|
821 |
subIndex = getSDOsubIndex(m->data[3]); |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
822 |
MSG_WAR(0x3A79, "Received SDO Initiate Download (to store data) defined at index 0x1200 + ", |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
823 |
nodeId); |
0 | 824 |
MSG_WAR(0x3A80, "Writing at index : ", index); |
825 |
MSG_WAR(0x3A80, "Writing at subIndex : ", subIndex); |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
826 |
|
215 | 827 |
/* Search if a SDO transfert have been yet initiated */ |
0 | 828 |
err = getSDOlineOnUse( d, nodeId, whoami, &line ); |
829 |
if (! err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
830 |
MSG_ERR(0x1A81, "SDO error : Transmission yet started.", 0); |
0 | 831 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
832 |
return 0xFF; |
|
833 |
} |
|
215 | 834 |
/* No line on use. Great ! */ |
835 |
/* Try to open a new line. */ |
|
0 | 836 |
err = getSDOfreeLine( d, whoami, &line ); |
837 |
if (err) { |
|
838 |
MSG_ERR(0x1A82, "SDO error : No line free, too many SDO in progress. Aborted.", 0); |
|
839 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
|
840 |
return 0xFF; |
|
841 |
} |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
842 |
initSDOline(d, line, nodeId, index, subIndex, SDO_DOWNLOAD_IN_PROGRESS); |
0 | 843 |
|
215 | 844 |
if (getSDOe(m->data[0])) { /* If SDO expedited */ |
845 |
/* nb of data to be downloaded */ |
|
0 | 846 |
nbBytes = 4 - getSDOn2(m->data[0]); |
215 | 847 |
/* Storing the data in the line structure. */ |
0 | 848 |
d->transfers[line].count = nbBytes; |
849 |
err = SDOtoLine(d, line, nbBytes, (*m).data + 4); |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
850 |
|
0 | 851 |
if (err) { |
852 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
853 |
return 0xFF; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
854 |
} |
0 | 855 |
|
215 | 856 |
/* SDO expedited -> transfert finished. Data can be stored in the dictionary. */ |
857 |
/*The line will be reseted when it is downloading in the dictionary. */ |
|
0 | 858 |
MSG_WAR(0x3A83, "SDO Initiate Download is an expedited transfert. Finished.: ", nodeId); |
215 | 859 |
/* Transfering line data to object dictionary. */ |
0 | 860 |
errorCode = SDOlineToObjdict(d, line); |
861 |
if (errorCode) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
862 |
MSG_ERR(0x1A84, "SDO error : Unable to copy the data in the object dictionary", 0); |
0 | 863 |
failedSDO(d, nodeId, whoami, index, subIndex, errorCode); |
864 |
return 0xFF; |
|
865 |
} |
|
215 | 866 |
/* Release of the line. */ |
0 | 867 |
resetSDOline(d, line); |
868 |
} |
|
215 | 869 |
else {/* So, if it is not an expedited transfert */ |
0 | 870 |
if (getSDOs(m->data[0])) { |
544
7620872e153c
Fixed bugs in SDO caused by UNS8->UNS32 size patch.
etisserant
parents:
539
diff
changeset
|
871 |
nbBytes = m->data[4] + m->data[5]<<8 + m->data[6]<<16 + m->data[7]<<24; |
0 | 872 |
err = setSDOlineRestBytes(d, nodeId, nbBytes); |
873 |
if (err) { |
|
874 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
875 |
return 0xFF; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
876 |
} |
0 | 877 |
} |
878 |
} |
|
215 | 879 |
/*Sending a SDO, cs=3*/ |
880 |
sdo.nodeId = *d->bDeviceNodeId; /* The node id of the server, (here it is the sender).*/ |
|
0 | 881 |
sdo.body.data[0] = 3 << 5; |
71 | 882 |
sdo.body.data[1] = index & 0xFF; /* LSB */ |
883 |
sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
0 | 884 |
sdo.body.data[3] = subIndex; |
885 |
for (i = 4 ; i < 8 ; i++) |
|
886 |
sdo.body.data[i] = 0; |
|
887 |
sendSDO(d, whoami, sdo); |
|
71 | 888 |
} /* end if I am SERVER */ |
0 | 889 |
else { |
215 | 890 |
/* I am CLIENT */ |
891 |
/* It is a response for a previous download segment. We should find a line opened for this. */ |
|
0 | 892 |
err = getSDOlineOnUse( d, nodeId, whoami, &line); |
893 |
if (!err) |
|
894 |
err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS; |
|
895 |
if (err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
896 |
MSG_ERR(0x1A85, "SDO error : Received segment response for unknown trans. from nodeId", nodeId); |
0 | 897 |
failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
898 |
return 0xFF; |
|
899 |
} |
|
215 | 900 |
/* Reset the wathdog */ |
0 | 901 |
RestartSDO_TIMER(line) |
902 |
index = d->transfers[line].index; |
|
903 |
subIndex = d->transfers[line].subIndex; |
|
215 | 904 |
/* test of the toggle; */ |
0 | 905 |
if (d->transfers[line].toggle != getSDOt(m->data[0])) { |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
906 |
MSG_ERR(0x1A86, "SDO error : Received segment response Toggle error. from nodeId", nodeId); |
0 | 907 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED); |
908 |
return 0xFF; |
|
909 |
} |
|
910 |
||
215 | 911 |
/* End transmission or downloading next segment. We need to know if it will be the last one. */ |
0 | 912 |
getSDOlineRestBytes(d, line, &nbBytes); |
913 |
if (nbBytes == 0) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
914 |
MSG_WAR(0x3A87, "SDO End download. segment response received. OK. from nodeId", nodeId); |
0 | 915 |
StopSDO_TIMER(line) |
916 |
d->transfers[line].state = SDO_FINISHED; |
|
32 | 917 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
0 | 918 |
return 0x00; |
919 |
} |
|
215 | 920 |
/* At least one transfer to send. */ |
0 | 921 |
if (nbBytes > 7) { |
215 | 922 |
/* several segments to download.*/ |
923 |
/* code to send the next segment. (cs = 0; c = 0) */ |
|
0 | 924 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
71 | 925 |
sdo.nodeId = nodeId; /* The server node Id; */ |
0 | 926 |
sdo.body.data[0] = (d->transfers[line].toggle << 4); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
927 |
err = lineToSDO(d, line, 7, sdo.body.data + 1); |
0 | 928 |
if (err) { |
929 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
930 |
return 0xFF; |
|
931 |
} |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
932 |
} |
0 | 933 |
else { |
215 | 934 |
/* Last segment. */ |
935 |
/* code to send the last segment. (cs = 0; c = 1)*/ |
|
0 | 936 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
71 | 937 |
sdo.nodeId = nodeId; /* The server node Id; */ |
0 | 938 |
sdo.body.data[0] = (d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
939 |
err = lineToSDO(d, line, nbBytes, sdo.body.data + 1); |
0 | 940 |
if (err) { |
941 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
942 |
return 0xFF; |
|
943 |
} |
|
944 |
for (i = nbBytes + 1 ; i < 8 ; i++) |
|
945 |
sdo.body.data[i] = 0; |
|
946 |
} |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
947 |
MSG_WAR(0x3A88, "SDO sending download segment to nodeId", nodeId); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
948 |
sendSDO(d, whoami, sdo); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
949 |
} /* end if I am a CLIENT */ |
0 | 950 |
break; |
951 |
||
952 |
case 2: |
|
215 | 953 |
/* I am SERVER */ |
954 |
/* Receive of an initiate upload.*/ |
|
0 | 955 |
if (whoami == SDO_SERVER) { |
956 |
index = getSDOindex(m->data[1],m->data[2]); |
|
957 |
subIndex = getSDOsubIndex(m->data[3]); |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
958 |
MSG_WAR(0x3A89, "Received SDO Initiate upload (to send data) defined at index 0x1200 + ", |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
959 |
nodeId); |
0 | 960 |
MSG_WAR(0x3A90, "Reading at index : ", index); |
961 |
MSG_WAR(0x3A91, "Reading at subIndex : ", subIndex); |
|
215 | 962 |
/* Search if a SDO transfert have been yet initiated*/ |
0 | 963 |
err = getSDOlineOnUse( d, nodeId, whoami, &line ); |
964 |
if (! err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
965 |
MSG_ERR(0x1A92, "SDO error : Transmission yet started at line : ", line); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
966 |
MSG_WAR(0x3A93, "nodeId = ", nodeId); |
12 | 967 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
968 |
return 0xFF; |
|
0 | 969 |
} |
215 | 970 |
/* No line on use. Great !*/ |
971 |
/* Try to open a new line.*/ |
|
0 | 972 |
err = getSDOfreeLine( d, whoami, &line ); |
973 |
if (err) { |
|
974 |
MSG_ERR(0x1A71, "SDO error : No line free, too many SDO in progress. Aborted.", 0); |
|
975 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
|
976 |
return 0xFF; |
|
977 |
} |
|
978 |
initSDOline(d, line, nodeId, index, subIndex, SDO_UPLOAD_IN_PROGRESS); |
|
215 | 979 |
/* Transfer data from dictionary to the line structure. */ |
0 | 980 |
errorCode = objdictToSDOline(d, line); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
981 |
|
0 | 982 |
if (errorCode) { |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
983 |
MSG_ERR(0x1A94, "SDO error : Unable to copy the data from object dictionary. Err code : ", |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
984 |
errorCode); |
0 | 985 |
failedSDO(d, nodeId, whoami, index, subIndex, errorCode); |
986 |
return 0xFF; |
|
987 |
} |
|
215 | 988 |
/* Preparing the response.*/ |
989 |
getSDOlineRestBytes(d, line, &nbBytes); /* Nb bytes to transfer ? */ |
|
990 |
sdo.nodeId = nodeId; /* The server node Id; */ |
|
0 | 991 |
if (nbBytes > 4) { |
215 | 992 |
/* normal transfert. (segmented). */ |
993 |
/* code to send the initiate upload response. (cs = 2) */ |
|
0 | 994 |
sdo.body.data[0] = (2 << 5) | 1; |
71 | 995 |
sdo.body.data[1] = index & 0xFF; /* LSB */ |
996 |
sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
0 | 997 |
sdo.body.data[3] = subIndex; |
71 | 998 |
sdo.body.data[4] = nbBytes; /* Limitation of canfestival2 : Max tranfert is 256 bytes.*/ |
215 | 999 |
/* It takes too much memory to upgrate to 2^32 because the size of data is also coded */ |
1000 |
/* in the object dictionary, at every index and subindex. */ |
|
0 | 1001 |
for (i = 5 ; i < 8 ; i++) |
1002 |
sdo.body.data[i] = 0; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1003 |
MSG_WAR(0x3A95, "SDO. Sending normal upload initiate response defined at index 0x1200 + ", nodeId); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1004 |
sendSDO(d, whoami, sdo); |
0 | 1005 |
} |
1006 |
else { |
|
215 | 1007 |
/* Expedited upload. (cs = 2 ; e = 1) */ |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1008 |
sdo.body.data[0] = (2 << 5) | ((4 - nbBytes) << 2) | 3; |
71 | 1009 |
sdo.body.data[1] = index & 0xFF; /* LSB */ |
1010 |
sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
0 | 1011 |
sdo.body.data[3] = subIndex; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1012 |
err = lineToSDO(d, line, nbBytes, sdo.body.data + 4); |
0 | 1013 |
if (err) { |
1014 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1015 |
return 0xFF; |
|
1016 |
} |
|
1017 |
for (i = 4 + nbBytes ; i < 8 ; i++) |
|
1018 |
sdo.body.data[i] = 0; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1019 |
MSG_WAR(0x3A96, "SDO. Sending expedited upload initiate response defined at index 0x1200 + ", |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1020 |
nodeId); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1021 |
sendSDO(d, whoami, sdo); |
215 | 1022 |
/* Release the line.*/ |
0 | 1023 |
resetSDOline(d, line); |
1024 |
} |
|
215 | 1025 |
} /* end if I am SERVER*/ |
0 | 1026 |
else { |
215 | 1027 |
/* I am CLIENT */ |
1028 |
/* It is the response for the previous initiate upload request.*/ |
|
1029 |
/* We should find a line opened for this. */ |
|
0 | 1030 |
err = getSDOlineOnUse( d, nodeId, whoami, &line); |
1031 |
if (!err) |
|
1032 |
err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS; |
|
1033 |
if (err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1034 |
MSG_ERR(0x1A97, "SDO error : Received response for unknown upload request from nodeId", nodeId); |
0 | 1035 |
failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
1036 |
return 0xFF; |
|
1037 |
} |
|
215 | 1038 |
/* Reset the wathdog */ |
0 | 1039 |
RestartSDO_TIMER(line) |
1040 |
index = d->transfers[line].index; |
|
1041 |
subIndex = d->transfers[line].subIndex; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1042 |
|
71 | 1043 |
if (getSDOe(m->data[0])) { /* If SDO expedited */ |
215 | 1044 |
/* nb of data to be uploaded */ |
0 | 1045 |
nbBytes = 4 - getSDOn2(m->data[0]); |
215 | 1046 |
/* Storing the data in the line structure. */ |
0 | 1047 |
err = SDOtoLine(d, line, nbBytes, (*m).data + 4); |
1048 |
if (err) { |
|
1049 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1050 |
return 0xFF; |
|
1051 |
} |
|
215 | 1052 |
/* SDO expedited -> transfert finished. data are available via getReadResultNetworkDict(). */ |
0 | 1053 |
MSG_WAR(0x3A98, "SDO expedited upload finished. Response received from node : ", nodeId); |
1054 |
StopSDO_TIMER(line) |
|
1055 |
d->transfers[line].count = nbBytes; |
|
1056 |
d->transfers[line].state = SDO_FINISHED; |
|
32 | 1057 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
0 | 1058 |
return 0; |
1059 |
} |
|
215 | 1060 |
else { /* So, if it is not an expedited transfert */ |
1061 |
/* Storing the nb of data to receive. */ |
|
0 | 1062 |
if (getSDOs(m->data[0])) { |
544
7620872e153c
Fixed bugs in SDO caused by UNS8->UNS32 size patch.
etisserant
parents:
539
diff
changeset
|
1063 |
nbBytes = m->data[4] + m->data[5]<<8 + m->data[6]<<16 + m->data[7]<<24; |
0 | 1064 |
err = setSDOlineRestBytes(d, line, nbBytes); |
1065 |
if (err) { |
|
1066 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1067 |
return 0xFF; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1068 |
} |
0 | 1069 |
} |
215 | 1070 |
/* Requesting next segment. (cs = 3) */ |
0 | 1071 |
sdo.nodeId = nodeId; |
1072 |
sdo.body.data[0] = 3 << 5; |
|
1073 |
for (i = 1 ; i < 8 ; i++) |
|
1074 |
sdo.body.data[i] = 0; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1075 |
MSG_WAR(0x3A99, "SDO. Sending upload segment request to node : ", nodeId); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1076 |
sendSDO(d, whoami, sdo); |
0 | 1077 |
} |
215 | 1078 |
} /* End if CLIENT */ |
0 | 1079 |
break; |
1080 |
||
1081 |
case 3: |
|
215 | 1082 |
/* I am SERVER */ |
0 | 1083 |
if (whoami == SDO_SERVER) { |
215 | 1084 |
/* Receiving a upload segment. */ |
1085 |
/* A SDO transfert should have been yet initiated. */ |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1086 |
err = getSDOlineOnUse( d, nodeId, whoami, &line ); |
0 | 1087 |
if (!err) |
1088 |
err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS; |
|
1089 |
if (err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1090 |
MSG_ERR(0x1AA0, "SDO error : Received upload segment for unstarted trans. index 0x1200 + ", |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1091 |
nodeId); |
0 | 1092 |
failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
1093 |
return 0xFF; |
|
1094 |
} |
|
215 | 1095 |
/* Reset the wathdog */ |
0 | 1096 |
RestartSDO_TIMER(line) |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1097 |
MSG_WAR(0x3AA1, "Received SDO upload segment defined at index 0x1200 + ", nodeId); |
0 | 1098 |
index = d->transfers[line].index; |
1099 |
subIndex = d->transfers[line].subIndex; |
|
215 | 1100 |
/* Toggle test.*/ |
0 | 1101 |
if (d->transfers[line].toggle != getSDOt(m->data[0])) { |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1102 |
MSG_ERR(0x1AA2, "SDO error : Toggle error : ", getSDOt(m->data[0])); |
0 | 1103 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED); |
1104 |
return 0xFF; |
|
1105 |
} |
|
215 | 1106 |
/* Uploading next segment. We need to know if it will be the last one. */ |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1107 |
getSDOlineRestBytes(d, line, &nbBytes); |
0 | 1108 |
if (nbBytes > 7) { |
215 | 1109 |
/* The segment to transfer is not the last one.*/ |
1110 |
/* code to send the next segment. (cs = 0; c = 0) */ |
|
71 | 1111 |
sdo.nodeId = nodeId; /* The server node Id; */ |
0 | 1112 |
sdo.body.data[0] = (d->transfers[line].toggle << 4); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1113 |
err = lineToSDO(d, line, 7, sdo.body.data + 1); |
0 | 1114 |
if (err) { |
1115 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1116 |
return 0xFF; |
|
1117 |
} |
|
215 | 1118 |
/* Inverting the toggle for the next tranfert. */ |
0 | 1119 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1120 |
MSG_WAR(0x3AA3, "SDO. Sending upload segment defined at index 0x1200 + ", nodeId); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1121 |
sendSDO(d, whoami, sdo); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1122 |
} |
0 | 1123 |
else { |
215 | 1124 |
/* Last segment. */ |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1125 |
/* code to send the last segment. (cs = 0; c = 1) */ |
208 | 1126 |
sdo.nodeId = nodeId; /** The server node Id; */ |
0 | 1127 |
sdo.body.data[0] = (d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1128 |
err = lineToSDO(d, line, nbBytes, sdo.body.data + 1); |
0 | 1129 |
if (err) { |
1130 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1131 |
return 0xFF; |
|
1132 |
} |
|
1133 |
for (i = nbBytes + 1 ; i < 8 ; i++) |
|
1134 |
sdo.body.data[i] = 0; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1135 |
MSG_WAR(0x3AA4, "SDO. Sending last upload segment defined at index 0x1200 + ", nodeId); |
0 | 1136 |
sendSDO(d, whoami, sdo); |
215 | 1137 |
/* Release the line */ |
0 | 1138 |
resetSDOline(d, line); |
1139 |
} |
|
71 | 1140 |
} /* end if SERVER*/ |
0 | 1141 |
else { |
215 | 1142 |
/* I am CLIENT */ |
1143 |
/* It is the response for the previous initiate download request. */ |
|
1144 |
/* We should find a line opened for this. */ |
|
0 | 1145 |
err = getSDOlineOnUse( d, nodeId, whoami, &line); |
1146 |
if (!err) |
|
1147 |
err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS; |
|
1148 |
if (err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1149 |
MSG_ERR(0x1AA5, "SDO error : Received response for unknown download request from nodeId", nodeId); |
0 | 1150 |
failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
1151 |
return 0xFF; |
|
1152 |
} |
|
215 | 1153 |
/* Reset the watchdog */ |
0 | 1154 |
RestartSDO_TIMER(line) |
1155 |
index = d->transfers[line].index; |
|
1156 |
subIndex = d->transfers[line].subIndex; |
|
71 | 1157 |
/* End transmission or requesting next segment. */ |
0 | 1158 |
getSDOlineRestBytes(d, line, &nbBytes); |
1159 |
if (nbBytes == 0) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1160 |
MSG_WAR(0x3AA6, "SDO End download expedited. Response received. from nodeId", nodeId); |
0 | 1161 |
StopSDO_TIMER(line) |
1162 |
d->transfers[line].state = SDO_FINISHED; |
|
32 | 1163 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
0 | 1164 |
return 0x00; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1165 |
} |
0 | 1166 |
if (nbBytes > 7) { |
215 | 1167 |
/* more than one request to send */ |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1168 |
/* code to send the next segment. (cs = 0; c = 0) */ |
208 | 1169 |
sdo.nodeId = nodeId; /** The server node Id; */ |
0 | 1170 |
sdo.body.data[0] = (d->transfers[line].toggle << 4); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1171 |
err = lineToSDO(d, line, 7, sdo.body.data + 1); |
0 | 1172 |
if (err) { |
1173 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1174 |
return 0xFF; |
|
1175 |
} |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1176 |
} |
0 | 1177 |
else { |
215 | 1178 |
/* Last segment.*/ |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1179 |
/* code to send the last segment. (cs = 0; c = 1) */ |
215 | 1180 |
sdo.nodeId = nodeId; /* The server node Id; */ |
0 | 1181 |
sdo.body.data[0] = (d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1182 |
err = lineToSDO(d, line, nbBytes, sdo.body.data + 1); |
0 | 1183 |
if (err) { |
1184 |
failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1185 |
return 0xFF; |
|
1186 |
} |
|
1187 |
for (i = nbBytes + 1 ; i < 8 ; i++) |
|
1188 |
sdo.body.data[i] = 0; |
|
1189 |
} |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1190 |
MSG_WAR(0x3AA7, "SDO sending download segment to nodeId", nodeId); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1191 |
sendSDO(d, whoami, sdo); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1192 |
|
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1193 |
} /* end if I am a CLIENT */ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1194 |
break; |
0 | 1195 |
|
82 | 1196 |
case 4: |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1197 |
abortCode = |
435 | 1198 |
(UNS32)m->data[4] | |
82 | 1199 |
((UNS32)m->data[5] << 8) | |
1200 |
((UNS32)m->data[6] << 16) | |
|
1201 |
((UNS32)m->data[7] << 24); |
|
215 | 1202 |
/* Received SDO abort. */ |
1203 |
/* Looking for the line concerned. */ |
|
0 | 1204 |
if (whoami == SDO_SERVER) { |
1205 |
err = getSDOlineOnUse( d, nodeId, whoami, &line ); |
|
1206 |
if (!err) { |
|
1207 |
resetSDOline( d, line ); |
|
1208 |
MSG_WAR(0x3AA8, "SD0. Received SDO abort. Line released. Code : ", abortCode); |
|
1209 |
} |
|
1210 |
else |
|
1211 |
MSG_WAR(0x3AA9, "SD0. Received SDO abort. No line found. Code : ", abortCode); |
|
215 | 1212 |
/* Tips : The end user has no way to know that the server node has received an abort SDO. */ |
1213 |
/* Its is ok, I think.*/ |
|
0 | 1214 |
} |
215 | 1215 |
else { /* If I am CLIENT */ |
0 | 1216 |
err = getSDOlineOnUse( d, nodeId, whoami, &line ); |
1217 |
if (!err) { |
|
215 | 1218 |
/* The line *must* be released by the core program. */ |
0 | 1219 |
StopSDO_TIMER(line) |
1220 |
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
|
1221 |
d->transfers[line].abortCode = abortCode; |
0 | 1222 |
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
|
1223 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
0 | 1224 |
} |
1225 |
else |
|
1226 |
MSG_WAR(0x3AB1, "SD0. Received SDO abort. No line found. Code : ", abortCode); |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1227 |
} |
0 | 1228 |
break; |
1229 |
default: |
|
215 | 1230 |
/* Error : Unknown cs */ |
0 | 1231 |
MSG_ERR(0x1AB2, "SDO. Received unknown command specifier : ", getSDOcs(m->data[0])); |
1232 |
return 0xFF; |
|
1233 |
||
71 | 1234 |
} /* End switch */ |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1235 |
return 0; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1236 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1237 |
|
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1238 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1239 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1240 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1241 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1242 |
** @param nodeId |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1243 |
** @param index |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1244 |
** @param subIndex |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1245 |
** @param count |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1246 |
** @param dataType |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1247 |
** @param data |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1248 |
** @param Callback |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1249 |
** @param endianize |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1250 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1251 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1252 |
**/ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1253 |
INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
1254 |
UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize) |
0 | 1255 |
{ |
1256 |
UNS8 err; |
|
1257 |
UNS8 SDOfound = 0; |
|
1258 |
UNS8 line; |
|
71 | 1259 |
s_SDO sdo; /* SDO to transmit */ |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
1260 |
UNS8 i; |
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
1261 |
UNS32 j; |
0 | 1262 |
UNS16 lastIndex; |
1263 |
UNS16 offset; |
|
311 | 1264 |
UNS8 *pNodeIdServer; |
1265 |
UNS8 nodeIdServer; |
|
0 | 1266 |
|
1267 |
MSG_WAR(0x3AC0, "Send SDO to write in the dictionary of node : ", nodeId); |
|
1268 |
MSG_WAR(0x3AC1, " At index : ", index); |
|
1269 |
MSG_WAR(0x3AC2, " subIndex : ", subIndex); |
|
1270 |
MSG_WAR(0x3AC3, " nb bytes : ", count); |
|
1271 |
||
215 | 1272 |
/* Verify that there is no SDO communication yet. */ |
0 | 1273 |
err = getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line); |
1274 |
if (!err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1275 |
MSG_ERR(0x1AC4, "SDO error : Communication yet established. with node : ", nodeId); |
0 | 1276 |
return 0xFF; |
1277 |
} |
|
215 | 1278 |
/* Taking the line ... */ |
0 | 1279 |
err = getSDOfreeLine( d, SDO_CLIENT, &line ); |
1280 |
if (err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1281 |
MSG_ERR(0x1AC5, "SDO error : No line free, too many SDO in progress. Aborted for node : ", nodeId); |
0 | 1282 |
return (0xFF); |
1283 |
} |
|
215 | 1284 |
/* Check which SDO to use to communicate with the node */ |
0 | 1285 |
offset = d->firstIndex->SDO_CLT; |
1286 |
lastIndex = d->lastIndex->SDO_CLT; |
|
1287 |
if (offset == 0) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1288 |
MSG_ERR(0x1AC6, "writeNetworkDict : No SDO client index found", 0); |
0 | 1289 |
return 0xFF; |
1290 |
} |
|
1291 |
i = 0; |
|
1292 |
while (offset <= lastIndex) { |
|
1293 |
if (d->objdict[offset].bSubCount <= 3) { |
|
1294 |
MSG_ERR(0x1AC8, "Subindex 3 not found at index ", 0x1280 + i); |
|
1295 |
return 0xFF; |
|
1296 |
} |
|
215 | 1297 |
/* looking for the nodeId server */ |
311 | 1298 |
pNodeIdServer = (UNS8*) d->objdict[offset].pSubindex[3].pObject; |
0 | 1299 |
nodeIdServer = *pNodeIdServer; |
1300 |
MSG_WAR(0x1AD2, "index : ", 0x1280 + i); |
|
1301 |
MSG_WAR(0x1AD3, "nodeIdServer : ", nodeIdServer); |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1302 |
|
311 | 1303 |
if(nodeIdServer == nodeId) { |
0 | 1304 |
SDOfound = 1; |
1305 |
break; |
|
1306 |
} |
|
1307 |
offset++; |
|
1308 |
i++; |
|
71 | 1309 |
} /* end while */ |
0 | 1310 |
if (!SDOfound) { |
1311 |
MSG_ERR(0x1AC9, "SDO. Error. No client found to communicate with node : ", nodeId); |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1312 |
return 0xFE; |
0 | 1313 |
} |
1314 |
MSG_WAR(0x3AD0," SDO client defined at index : ", 0x1280 + i); |
|
1315 |
initSDOline(d, line, nodeId, index, subIndex, SDO_DOWNLOAD_IN_PROGRESS); |
|
1316 |
d->transfers[line].count = count; |
|
1317 |
d->transfers[line].dataType = dataType; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1318 |
|
215 | 1319 |
/* Copy data to transfers structure. */ |
0 | 1320 |
for (j = 0 ; j < count ; j++) { |
1321 |
# ifdef CANOPEN_BIG_ENDIAN |
|
174
cd1638bc0cb0
Added _writenetworkdictionary option to avoir endianiation
etisserant
parents:
172
diff
changeset
|
1322 |
if (dataType == 0 && endianize) |
0 | 1323 |
d->transfers[line].data[count - 1 - j] = ((char *)data)[j]; |
71 | 1324 |
else /* String of bytes. */ |
0 | 1325 |
d->transfers[line].data[j] = ((char *)data)[j]; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1326 |
# else |
0 | 1327 |
d->transfers[line].data[j] = ((char *)data)[j]; |
1328 |
# endif |
|
1329 |
} |
|
215 | 1330 |
/* Send the SDO to the server. Initiate download, cs=1. */ |
0 | 1331 |
sdo.nodeId = nodeId; |
215 | 1332 |
if (count <= 4) { /* Expedited transfert */ |
0 | 1333 |
sdo.body.data[0] = (1 << 5) | ((4 - count) << 2) | 3; |
1334 |
for (i = 4 ; i < 8 ; i++) |
|
1335 |
sdo.body.data[i] = d->transfers[line].data[i - 4]; |
|
1336 |
d->transfers[line].offset = count; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1337 |
} |
208 | 1338 |
else { /** Normal transfert */ |
0 | 1339 |
sdo.body.data[0] = (1 << 5) | 1; |
544
7620872e153c
Fixed bugs in SDO caused by UNS8->UNS32 size patch.
etisserant
parents:
539
diff
changeset
|
1340 |
for (i = 0 ; i < 4 ; i++) |
7620872e153c
Fixed bugs in SDO caused by UNS8->UNS32 size patch.
etisserant
parents:
539
diff
changeset
|
1341 |
sdo.body.data[i+4] = count << (i<<3); /* i*8 */ |
0 | 1342 |
} |
71 | 1343 |
sdo.body.data[1] = index & 0xFF; /* LSB */ |
1344 |
sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
0 | 1345 |
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
|
1346 |
|
1b3165f2d17d
Implemented writeNetworkDictCallBack test in TestMasterSlave example. Fixed callback assignement race condition in sdo.c.
etisserant
parents:
149
diff
changeset
|
1347 |
d->transfers[line].Callback = Callback; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1348 |
|
0 | 1349 |
err = sendSDO(d, SDO_CLIENT, sdo); |
1350 |
if (err) { |
|
1351 |
MSG_ERR(0x1AD1, "SDO. Error while sending SDO to node : ", nodeId); |
|
215 | 1352 |
/* release the line */ |
0 | 1353 |
resetSDOline(d, line); |
1354 |
return 0xFF; |
|
32 | 1355 |
} |
154
1b3165f2d17d
Implemented writeNetworkDictCallBack test in TestMasterSlave example. Fixed callback assignement race condition in sdo.c.
etisserant
parents:
149
diff
changeset
|
1356 |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1357 |
|
0 | 1358 |
return 0; |
1359 |
} |
|
53 | 1360 |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1361 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1362 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1363 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1364 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1365 |
** @param nodeId |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1366 |
** @param index |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1367 |
** @param subIndex |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1368 |
** @param count |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1369 |
** @param dataType |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1370 |
** @param data |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1371 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1372 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1373 |
**/ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1374 |
UNS8 writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
1375 |
UNS8 subIndex, UNS32 count, UNS8 dataType, void *data) |
32 | 1376 |
{ |
174
cd1638bc0cb0
Added _writenetworkdictionary option to avoir endianiation
etisserant
parents:
172
diff
changeset
|
1377 |
return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, NULL, 1); |
32 | 1378 |
} |
1379 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1380 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1381 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1382 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1383 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1384 |
** @param nodeId |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1385 |
** @param index |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1386 |
** @param subIndex |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1387 |
** @param count |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1388 |
** @param dataType |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1389 |
** @param data |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1390 |
** @param Callback |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1391 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1392 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1393 |
**/ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1394 |
UNS8 writeNetworkDictCallBack (CO_Data* d, UNS8 nodeId, UNS16 index, |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
1395 |
UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback) |
32 | 1396 |
{ |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1397 |
return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, Callback, 1); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1398 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1399 |
|
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1400 |
UNS8 writeNetworkDictCallBackAI (CO_Data* d, UNS8 nodeId, UNS16 index, |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
1401 |
UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize) |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1402 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1403 |
UNS8 ret; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1404 |
UNS16 lastIndex; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1405 |
UNS16 offset; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1406 |
UNS8 nodeIdServer; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1407 |
UNS8 i; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1408 |
|
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1409 |
ret = _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, Callback, endianize); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1410 |
if(ret == 0xFE) |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1411 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1412 |
offset = d->firstIndex->SDO_CLT; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1413 |
lastIndex = d->lastIndex->SDO_CLT; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1414 |
if (offset == 0) |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1415 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1416 |
MSG_ERR(0x1AC6, "writeNetworkDict : No SDO client index found", 0); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1417 |
return 0xFF; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1418 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1419 |
i = 0; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1420 |
while (offset <= lastIndex) |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1421 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1422 |
if (d->objdict[offset].bSubCount <= 3) |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1423 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1424 |
MSG_ERR(0x1AC8, "Subindex 3 not found at index ", 0x1280 + i); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1425 |
return 0xFF; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1426 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1427 |
nodeIdServer = *(UNS8*) d->objdict[offset].pSubindex[3].pObject; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1428 |
if(nodeIdServer == 0) |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1429 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1430 |
*(UNS32*)d->objdict[offset].pSubindex[1].pObject = (UNS32)(0x600 + nodeId); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1431 |
*(UNS32*)d->objdict[offset].pSubindex[2].pObject = (UNS32)(0x580 + nodeId); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1432 |
*(UNS8*) d->objdict[offset].pSubindex[3].pObject = nodeId; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1433 |
return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, Callback, 1); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1434 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1435 |
offset++; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1436 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1437 |
return 0xFF; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1438 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1439 |
else if(ret == 0) |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1440 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1441 |
return 0; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1442 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1443 |
else |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1444 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1445 |
return 0xFF; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1446 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1447 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1448 |
|
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1449 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1450 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1451 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1452 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1453 |
** @param nodeId |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1454 |
** @param index |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1455 |
** @param subIndex |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1456 |
** @param dataType |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1457 |
** @param Callback |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1458 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1459 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1460 |
**/ |
71 | 1461 |
INLINE UNS8 _readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback) |
0 | 1462 |
{ |
1463 |
UNS8 err; |
|
1464 |
UNS8 SDOfound = 0; |
|
1465 |
UNS8 i; |
|
1466 |
UNS8 line; |
|
71 | 1467 |
s_SDO sdo; /* SDO to transmit */ |
311 | 1468 |
UNS8 *pNodeIdServer; |
1469 |
UNS8 nodeIdServer; |
|
0 | 1470 |
UNS16 offset; |
1471 |
UNS16 lastIndex; |
|
1472 |
MSG_WAR(0x3AD5, "Send SDO to read in the dictionary of node : ", nodeId); |
|
1473 |
MSG_WAR(0x3AD6, " At index : ", index); |
|
1474 |
MSG_WAR(0x3AD7, " subIndex : ", subIndex); |
|
1475 |
||
1476 |
||
215 | 1477 |
/* Verify that there is no SDO communication yet. */ |
0 | 1478 |
err = getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line); |
1479 |
if (!err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1480 |
MSG_ERR(0x1AD8, "SDO error : Communication yet established. with node : ", nodeId); |
0 | 1481 |
return 0xFF; |
1482 |
} |
|
215 | 1483 |
/* Taking the line ... */ |
0 | 1484 |
err = getSDOfreeLine( d, SDO_CLIENT, &line ); |
1485 |
if (err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1486 |
MSG_ERR(0x1AD9, "SDO error : No line free, too many SDO in progress. Aborted for node : ", nodeId); |
0 | 1487 |
return (0xFF); |
1488 |
} |
|
1489 |
else |
|
1490 |
MSG_WAR(0x3AE0, "Transmission on line : ", line); |
|
1491 |
||
215 | 1492 |
/* Check which SDO to use to communicate with the node */ |
0 | 1493 |
offset = d->firstIndex->SDO_CLT; |
1494 |
lastIndex = d->lastIndex->SDO_CLT; |
|
1495 |
if (offset == 0) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1496 |
MSG_ERR(0x1AE1, "writeNetworkDict : No SDO client index found", 0); |
0 | 1497 |
return 0xFF; |
1498 |
} |
|
1499 |
i = 0; |
|
1500 |
while (offset <= lastIndex) { |
|
1501 |
if (d->objdict[offset].bSubCount <= 3) { |
|
1502 |
MSG_ERR(0x1AE2, "Subindex 3 not found at index ", 0x1280 + i); |
|
1503 |
return 0xFF; |
|
1504 |
} |
|
215 | 1505 |
/* looking for the nodeId server */ |
311 | 1506 |
pNodeIdServer = (UNS8*) d->objdict[offset].pSubindex[3].pObject; |
0 | 1507 |
nodeIdServer = *pNodeIdServer; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1508 |
|
311 | 1509 |
if(nodeIdServer == nodeId) { |
0 | 1510 |
SDOfound = 1; |
1511 |
break; |
|
1512 |
} |
|
1513 |
offset++; |
|
1514 |
i++; |
|
71 | 1515 |
} /* end while */ |
0 | 1516 |
if (!SDOfound) { |
1517 |
MSG_ERR(0x1AE3, "SDO. Error. No client found to communicate with node : ", nodeId); |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1518 |
return 0xFE; |
0 | 1519 |
} |
1520 |
MSG_WAR(0x3AE4," SDO client defined at index : ", 0x1280 + i); |
|
1521 |
initSDOline(d, line, nodeId, index, subIndex, SDO_UPLOAD_IN_PROGRESS); |
|
1522 |
getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line); |
|
1523 |
sdo.nodeId = nodeId; |
|
215 | 1524 |
/* Send the SDO to the server. Initiate upload, cs=2. */ |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1525 |
d->transfers[line].dataType = dataType; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1526 |
sdo.body.data[0] = (2 << 5); |
71 | 1527 |
sdo.body.data[1] = index & 0xFF; /* LSB */ |
1528 |
sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
0 | 1529 |
sdo.body.data[3] = subIndex; |
1530 |
for (i = 4 ; i < 8 ; i++) |
|
1531 |
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
|
1532 |
d->transfers[line].Callback = Callback; |
0 | 1533 |
err = sendSDO(d, SDO_CLIENT, sdo); |
1534 |
if (err) { |
|
1535 |
MSG_ERR(0x1AE5, "SDO. Error while sending SDO to node : ", nodeId); |
|
71 | 1536 |
/* release the line */ |
0 | 1537 |
resetSDOline(d, line); |
1538 |
return 0xFF; |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1539 |
} |
0 | 1540 |
return 0; |
1541 |
} |
|
1542 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1543 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1544 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1545 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1546 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1547 |
** @param nodeId |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1548 |
** @param index |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1549 |
** @param subIndex |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1550 |
** @param dataType |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1551 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1552 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1553 |
**/ |
32 | 1554 |
UNS8 readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType) |
1555 |
{ |
|
1556 |
return _readNetworkDict (d, nodeId, index, subIndex, dataType, NULL); |
|
1557 |
} |
|
1558 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1559 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1560 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1561 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1562 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1563 |
** @param nodeId |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1564 |
** @param index |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1565 |
** @param subIndex |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1566 |
** @param dataType |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1567 |
** @param Callback |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1568 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1569 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1570 |
**/ |
32 | 1571 |
UNS8 readNetworkDictCallback (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback) |
1572 |
{ |
|
1573 |
return _readNetworkDict (d, nodeId, index, subIndex, dataType, Callback); |
|
1574 |
} |
|
53 | 1575 |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1576 |
UNS8 readNetworkDictCallbackAI (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback) |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1577 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1578 |
UNS8 ret; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1579 |
UNS16 lastIndex; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1580 |
UNS16 offset; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1581 |
UNS8 nodeIdServer; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1582 |
UNS8 i; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1583 |
|
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1584 |
ret = _readNetworkDict (d, nodeId, index, subIndex, dataType, Callback); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1585 |
if(ret == 0xFE) |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1586 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1587 |
offset = d->firstIndex->SDO_CLT; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1588 |
lastIndex = d->lastIndex->SDO_CLT; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1589 |
if (offset == 0) |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1590 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1591 |
MSG_ERR(0x1AC6, "writeNetworkDict : No SDO client index found", 0); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1592 |
return 0xFF; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1593 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1594 |
i = 0; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1595 |
while (offset <= lastIndex) |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1596 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1597 |
if (d->objdict[offset].bSubCount <= 3) |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1598 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1599 |
MSG_ERR(0x1AC8, "Subindex 3 not found at index ", 0x1280 + i); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1600 |
return 0xFF; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1601 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1602 |
nodeIdServer = *(UNS8*) d->objdict[offset].pSubindex[3].pObject; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1603 |
if(nodeIdServer == 0) |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1604 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1605 |
*(UNS32*)d->objdict[offset].pSubindex[1].pObject = (UNS32)(0x600 + nodeId); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1606 |
*(UNS32*)d->objdict[offset].pSubindex[2].pObject = (UNS32)(0x580 + nodeId); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1607 |
*(UNS8*) d->objdict[offset].pSubindex[3].pObject = nodeId; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1608 |
return _readNetworkDict (d, nodeId, index, subIndex, dataType, Callback); |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1609 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1610 |
offset++; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1611 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1612 |
return 0xFF; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1613 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1614 |
else if(ret == 0) |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1615 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1616 |
return 0; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1617 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1618 |
else |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1619 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1620 |
return 0xFF; |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1621 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1622 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1623 |
|
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1624 |
/*! |
495
b2d6307a89fa
Changed getReadResultNetworkDict behaviour about size. Do not copy more data than pointet by Size arg.
etisserant
parents:
481
diff
changeset
|
1625 |
** |
b2d6307a89fa
Changed getReadResultNetworkDict behaviour about size. Do not copy more data than pointet by Size arg.
etisserant
parents:
481
diff
changeset
|
1626 |
** |
b2d6307a89fa
Changed getReadResultNetworkDict behaviour about size. Do not copy more data than pointet by Size arg.
etisserant
parents:
481
diff
changeset
|
1627 |
** @param d |
b2d6307a89fa
Changed getReadResultNetworkDict behaviour about size. Do not copy more data than pointet by Size arg.
etisserant
parents:
481
diff
changeset
|
1628 |
** @param nodeId |
b2d6307a89fa
Changed getReadResultNetworkDict behaviour about size. Do not copy more data than pointet by Size arg.
etisserant
parents:
481
diff
changeset
|
1629 |
** @param data |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1630 |
** @param size pointer to expected size, changed into returned size. Expected size will be truncated to transfered data size |
495
b2d6307a89fa
Changed getReadResultNetworkDict behaviour about size. Do not copy more data than pointet by Size arg.
etisserant
parents:
481
diff
changeset
|
1631 |
** @param abortCode |
b2d6307a89fa
Changed getReadResultNetworkDict behaviour about size. Do not copy more data than pointet by Size arg.
etisserant
parents:
481
diff
changeset
|
1632 |
** |
b2d6307a89fa
Changed getReadResultNetworkDict behaviour about size. Do not copy more data than pointet by Size arg.
etisserant
parents:
481
diff
changeset
|
1633 |
** @return |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1634 |
**/ |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
1635 |
UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, UNS32 *size, |
0 | 1636 |
UNS32 * abortCode) |
1637 |
{ |
|
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
1638 |
UNS32 i; |
0 | 1639 |
UNS8 err; |
1640 |
UNS8 line; |
|
499
061f12bd838b
getReadResultNetworkDict now returns abortcode. Now, abort message should be sent correctly from client.
etisserant
parents:
495
diff
changeset
|
1641 |
* abortCode = 0; |
0 | 1642 |
|
215 | 1643 |
/* Looking for the line tranfert. */ |
0 | 1644 |
err = getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line); |
1645 |
if (err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1646 |
MSG_ERR(0x1AF0, "SDO error : No line found for communication with node : ", nodeId); |
0 | 1647 |
return SDO_ABORTED_INTERNAL; |
1648 |
} |
|
503
8435a9ee54f8
Fixed (again) return of abortcode value in SDO's getReadResultNetworkDict
etisserant
parents:
501
diff
changeset
|
1649 |
* abortCode = d->transfers[line].abortCode; |
0 | 1650 |
if (d->transfers[line].state != SDO_FINISHED) |
1651 |
return d->transfers[line].state; |
|
1652 |
||
544
7620872e153c
Fixed bugs in SDO caused by UNS8->UNS32 size patch.
etisserant
parents:
539
diff
changeset
|
1653 |
/* if SDO initiated with e=0 and s=0 count is null, offset carry effective size*/ |
7620872e153c
Fixed bugs in SDO caused by UNS8->UNS32 size patch.
etisserant
parents:
539
diff
changeset
|
1654 |
if( d->transfers[line].count == 0) |
7620872e153c
Fixed bugs in SDO caused by UNS8->UNS32 size patch.
etisserant
parents:
539
diff
changeset
|
1655 |
d->transfers[line].count = d->transfers[line].offset; |
495
b2d6307a89fa
Changed getReadResultNetworkDict behaviour about size. Do not copy more data than pointet by Size arg.
etisserant
parents:
481
diff
changeset
|
1656 |
/* use transfers[line].count as max size */ |
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
1657 |
if( d->transfers[line].count < *size ) |
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
1658 |
*size = d->transfers[line].count; |
544
7620872e153c
Fixed bugs in SDO caused by UNS8->UNS32 size patch.
etisserant
parents:
539
diff
changeset
|
1659 |
/* Copy payload to data pointer */ |
0 | 1660 |
for ( i = 0 ; i < *size ; i++) { |
1661 |
# ifdef CANOPEN_BIG_ENDIAN |
|
1662 |
if (d->transfers[line].dataType != visible_string) |
|
1663 |
( (char *) data)[*size - 1 - i] = d->transfers[line].data[i]; |
|
215 | 1664 |
else /* String of bytes. */ |
0 | 1665 |
( (char *) data)[i] = d->transfers[line].data[i]; |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1666 |
# else |
0 | 1667 |
( (char *) data)[i] = d->transfers[line].data[i]; |
1668 |
# endif |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1669 |
} |
0 | 1670 |
return SDO_FINISHED; |
1671 |
} |
|
1672 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1673 |
/*! |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1674 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1675 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1676 |
** @param d |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1677 |
** @param nodeId |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1678 |
** @param abortCode |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1679 |
** |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1680 |
** @return |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1681 |
**/ |
0 | 1682 |
UNS8 getWriteResultNetworkDict (CO_Data* d, UNS8 nodeId, UNS32 * abortCode) |
1683 |
{ |
|
1684 |
UNS8 line = 0; |
|
1685 |
UNS8 err; |
|
1686 |
||
1687 |
* abortCode = 0; |
|
215 | 1688 |
/* Looking for the line tranfert. */ |
0 | 1689 |
err = getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line); |
1690 |
if (err) { |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1691 |
MSG_ERR(0x1AF1, "SDO error : No line found for communication with node : ", nodeId); |
0 | 1692 |
return SDO_ABORTED_INTERNAL; |
1693 |
} |
|
1694 |
* abortCode = d->transfers[line].abortCode; |
|
1695 |
return d->transfers[line].state; |
|
1696 |
} |