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