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