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