author | Laurent Bessard |
Mon, 01 Oct 2012 19:18:35 +0200 | |
changeset 748 | 18ed0f3b030a |
parent 719 | 438a979fda5d |
permissions | -rw-r--r-- |
0 | 1 |
/* |
663 | 2 |
This file is part of CanFestival, a library implementing CanOpen Stack. |
3 |
||
4 |
Copyright (C): Edouard TISSERANT and Francis DUPIN |
|
5 |
||
6 |
See COPYING file for copyrights details. |
|
7 |
||
8 |
This library is free software; you can redistribute it and/or |
|
9 |
modify it under the terms of the GNU Lesser General Public |
|
10 |
License as published by the Free Software Foundation; either |
|
11 |
version 2.1 of the License, or (at your option) any later version. |
|
12 |
||
13 |
This library is distributed in the hope that it will be useful, |
|
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 |
Lesser General Public License for more details. |
|
17 |
||
18 |
You should have received a copy of the GNU Lesser General Public |
|
19 |
License along with this library; if not, write to the Free Software |
|
20 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21 |
*/ |
|
22 |
/*! |
|
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 |
|
667
f48424ce2a5e
Added include stdlib.h for malloc functions in sdo.c
fbeaulier
parents:
666
diff
changeset
|
35 |
#include <stdlib.h> |
f48424ce2a5e
Added include stdlib.h for malloc functions in sdo.c
fbeaulier
parents:
666
diff
changeset
|
36 |
|
383 | 37 |
#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
|
38 |
#include "sysdep.h" |
0 | 39 |
|
71 | 40 |
/* 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
|
41 |
#define NO_INLINE |
71 | 42 |
|
43 |
#ifdef NO_INLINE |
|
663 | 44 |
#define INLINE |
71 | 45 |
#else |
663 | 46 |
#define INLINE inline |
71 | 47 |
#endif |
48 |
||
53 | 49 |
/*Internals prototypes*/ |
50 |
||
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
667
diff
changeset
|
51 |
UNS8 GetSDOClientFromNodeId( CO_Data* d, UNS8 nodeId ); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
667
diff
changeset
|
52 |
|
208 | 53 |
/*! |
663 | 54 |
** Called by writeNetworkDict |
55 |
** |
|
56 |
** @param d |
|
57 |
** @param nodeId |
|
58 |
** @param index |
|
59 |
** @param subIndex |
|
60 |
** @param count |
|
61 |
** @param dataType |
|
62 |
** @param data |
|
63 |
** @param Callback |
|
64 |
** @param endianize |
|
65 |
** |
|
66 |
** @return |
|
67 |
**/ |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
68 |
INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
69 |
UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize, UNS8 useBlockMode); |
663 | 70 |
|
71 |
/*! |
|
72 |
** Called by readNetworkDict |
|
73 |
** |
|
74 |
** @param d |
|
75 |
** @param nodeId |
|
76 |
** @param index |
|
77 |
** @param subIndex |
|
78 |
** @param dataType |
|
79 |
** @param Callback |
|
80 |
** |
|
81 |
** @return |
|
82 |
**/ |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
83 |
INLINE UNS8 _readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
84 |
UNS8 dataType, SDOCallback_t Callback, UNS8 useBlockMode); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
85 |
|
53 | 86 |
|
0 | 87 |
/***************************************************************************/ |
71 | 88 |
/* SDO (un)packing macros */ |
0 | 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 command specifier (cs, ccs, scs) from the first byte of the SDO |
663 | 91 |
*/ |
0 | 92 |
#define getSDOcs(byte) (byte >> 5) |
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 2 bits |
663 | 95 |
*/ |
0 | 96 |
#define getSDOn2(byte) ((byte >> 2) & 3) |
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 number of bytes without data from the first byte of the SDO. Coded in 3 bits |
663 | 99 |
*/ |
0 | 100 |
#define getSDOn3(byte) ((byte >> 1) & 7) |
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 transfer type from the first byte of the SDO |
663 | 103 |
*/ |
0 | 104 |
#define getSDOe(byte) ((byte >> 1) & 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 size indicator from the first byte of the SDO |
663 | 107 |
*/ |
0 | 108 |
#define getSDOs(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 indicator of end transmission from the first byte of the SDO |
663 | 111 |
*/ |
0 | 112 |
#define getSDOc(byte) (byte & 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 toggle from the first byte of the SDO |
663 | 115 |
*/ |
0 | 116 |
#define getSDOt(byte) ((byte >> 4) & 1) |
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 index from the bytes 1 and 2 of the SDO |
663 | 119 |
*/ |
604 | 120 |
#define getSDOindex(byte1, byte2) (((UNS16)byte2 << 8) | ((UNS16)byte1)) |
0 | 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 |
/** Returns the subIndex from the byte 3 of the SDO |
663 | 123 |
*/ |
0 | 124 |
#define getSDOsubIndex(byte3) (byte3) |
125 |
||
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
126 |
/** Returns the subcommand in SDO block transfer |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
127 |
*/ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
128 |
#define getSDOblockSC(byte) (byte & 3) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
129 |
|
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
130 |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
131 |
/*! |
663 | 132 |
** |
133 |
** |
|
134 |
** @param d |
|
135 |
** @param id |
|
136 |
**/ |
|
0 | 137 |
void SDOTimeoutAlarm(CO_Data* d, UNS32 id) |
138 |
{ |
|
663 | 139 |
UNS16 offset; |
140 |
UNS8 nodeId; |
|
141 |
/* Get the client->server cobid.*/ |
|
142 |
offset = d->firstIndex->SDO_CLT; |
|
143 |
if ((offset == 0) || ((offset+d->transfers[id].CliServNbr) > d->lastIndex->SDO_CLT)) { |
|
144 |
return ; |
|
145 |
} |
|
700 | 146 |
nodeId = (UNS8) *((UNS32*) d->objdict[offset+d->transfers[id].CliServNbr].pSubindex[3].pObject); |
663 | 147 |
MSG_ERR(0x1A01, "SDO timeout. SDO response not received.", 0); |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
148 |
MSG_WAR(0x2A02, "server node id : ", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
149 |
MSG_WAR(0x2A02, " index : ", d->transfers[id].index); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
150 |
MSG_WAR(0x2A02, " subIndex : ", d->transfers[id].subIndex); |
663 | 151 |
/* Reset timer handler */ |
152 |
d->transfers[id].timer = TIMER_NONE; |
|
153 |
/*Set aborted state*/ |
|
154 |
d->transfers[id].state = SDO_ABORTED_INTERNAL; |
|
155 |
/* Sending a SDO abort */ |
|
156 |
sendSDOabort(d, d->transfers[id].whoami, d->transfers[id].CliServNbr, |
|
157 |
d->transfers[id].index, d->transfers[id].subIndex, SDOABT_TIMED_OUT); |
|
158 |
d->transfers[id].abortCode = SDOABT_TIMED_OUT; |
|
159 |
/* Call the user function to inform of the problem.*/ |
|
160 |
if(d->transfers[id].Callback) |
|
161 |
/*If ther is a callback, it is responsible to close SDO transfer (client)*/ |
|
162 |
(*d->transfers[id].Callback)(d, nodeId); |
|
163 |
/*Reset the line if (whoami == SDO_SERVER) or the callback did not close the line. |
|
164 |
Otherwise this sdo transfer would never be closed. */ |
|
665
90e6cf84a0d7
patch from Christian Taedcke <hacking@taedcke.com> : fix-wrong-resetSDOline-for-sdo-timeout.patch
fbeaulier
parents:
664
diff
changeset
|
165 |
if(d->transfers[id].abortCode == SDOABT_TIMED_OUT) |
90e6cf84a0d7
patch from Christian Taedcke <hacking@taedcke.com> : fix-wrong-resetSDOline-for-sdo-timeout.patch
fbeaulier
parents:
664
diff
changeset
|
166 |
resetSDOline(d, (UNS8)id); |
0 | 167 |
} |
168 |
||
169 |
#define StopSDO_TIMER(id) \ |
|
663 | 170 |
MSG_WAR(0x3A05, "StopSDO_TIMER for line : ", line);\ |
0 | 171 |
d->transfers[id].timer = DelAlarm(d->transfers[id].timer); |
172 |
||
173 |
#define StartSDO_TIMER(id) \ |
|
663 | 174 |
MSG_WAR(0x3A06, "StartSDO_TIMER for line : ", line);\ |
0 | 175 |
d->transfers[id].timer = SetAlarm(d,id,&SDOTimeoutAlarm,MS_TO_TIMEVAL(SDO_TIMEOUT_MS),0); |
176 |
||
177 |
#define RestartSDO_TIMER(id) \ |
|
663 | 178 |
MSG_WAR(0x3A07, "restartSDO_TIMER for line : ", line);\ |
0 | 179 |
if(d->transfers[id].timer != TIMER_NONE) { StopSDO_TIMER(id) StartSDO_TIMER(id) } |
180 |
||
506
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 |
/*! |
663 | 182 |
** Reset all sdo buffers |
183 |
** |
|
184 |
** @param d |
|
185 |
**/ |
|
0 | 186 |
void resetSDO (CO_Data* d) |
187 |
{ |
|
663 | 188 |
UNS8 j; |
189 |
||
190 |
/* transfer structure initialization */ |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
191 |
for (j = 0 ; j < SDO_MAX_SIMULTANEOUS_TRANSFERS ; j++) |
663 | 192 |
resetSDOline(d, j); |
193 |
} |
|
194 |
||
195 |
/*! |
|
196 |
** |
|
197 |
** |
|
198 |
** @param d |
|
199 |
** @param line |
|
200 |
** |
|
201 |
** @return |
|
202 |
**/ |
|
0 | 203 |
UNS32 SDOlineToObjdict (CO_Data* d, UNS8 line) |
204 |
{ |
|
663 | 205 |
UNS32 size; |
206 |
UNS32 errorCode; |
|
207 |
MSG_WAR(0x3A08, "Enter in SDOlineToObjdict ", line); |
|
208 |
/* if SDO initiated with e=0 and s=0 count is null, offset carry effective size*/ |
|
209 |
if( d->transfers[line].count == 0) |
|
210 |
d->transfers[line].count = d->transfers[line].offset; |
|
211 |
size = d->transfers[line].count; |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
212 |
|
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
213 |
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
214 |
if (size > SDO_MAX_LENGTH_TRANSFER) |
663 | 215 |
{ |
216 |
errorCode = setODentry(d, d->transfers[line].index, d->transfers[line].subIndex, |
|
217 |
(void *) d->transfers[line].dynamicData, &size, 1); |
|
218 |
} |
|
219 |
else |
|
220 |
{ |
|
221 |
errorCode = setODentry(d, d->transfers[line].index, d->transfers[line].subIndex, |
|
222 |
(void *) d->transfers[line].data, &size, 1); |
|
223 |
} |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
224 |
#else //SDO_DYNAMIC_BUFFER_ALLOCATION |
663 | 225 |
errorCode = setODentry(d, d->transfers[line].index, d->transfers[line].subIndex, |
226 |
(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
|
227 |
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION |
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
228 |
|
663 | 229 |
if (errorCode != OD_SUCCESSFUL) |
230 |
return errorCode; |
|
231 |
MSG_WAR(0x3A08, "exit of SDOlineToObjdict ", line); |
|
232 |
return 0; |
|
233 |
||
234 |
} |
|
235 |
||
236 |
/*! |
|
237 |
** |
|
238 |
** |
|
239 |
** @param d |
|
240 |
** @param line |
|
241 |
** |
|
242 |
** @return |
|
243 |
**/ |
|
0 | 244 |
UNS32 objdictToSDOline (CO_Data* d, UNS8 line) |
245 |
{ |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
246 |
UNS32 size = SDO_MAX_LENGTH_TRANSFER; |
663 | 247 |
UNS8 dataType; |
248 |
UNS32 errorCode; |
|
249 |
||
250 |
MSG_WAR(0x3A05, "objdict->line index : ", d->transfers[line].index); |
|
251 |
MSG_WAR(0x3A06, " subIndex : ", d->transfers[line].subIndex); |
|
0 | 252 |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
253 |
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION |
666
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
254 |
/* Try to use the static buffer. */ |
663 | 255 |
errorCode = getODentry(d, d->transfers[line].index, |
256 |
d->transfers[line].subIndex, |
|
257 |
(void *)d->transfers[line].data, |
|
258 |
&size, &dataType, 1); |
|
666
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
259 |
if (errorCode == SDOABT_OUT_OF_MEMORY) { |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
260 |
/* The static buffer is too small, try again using a dynamic buffer. * |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
261 |
* 'size' now contains the real size of the requested object. */ |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
262 |
if (size <= SDO_DYNAMIC_BUFFER_ALLOCATION_SIZE) { |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
263 |
d->transfers[line].dynamicData = (UNS8 *) malloc(size * sizeof(UNS8)); |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
264 |
if (d->transfers[line].dynamicData != NULL) { |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
265 |
d->transfers[line].dynamicDataSize = size; |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
266 |
errorCode = getODentry(d, |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
267 |
d->transfers[line].index, |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
268 |
d->transfers[line].subIndex, |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
269 |
(void *) d->transfers[line].dynamicData, |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
270 |
&d->transfers[line].dynamicDataSize, |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
271 |
&dataType, |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
272 |
1); |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
273 |
} |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
274 |
} |
9febdd6fdc71
patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents:
665
diff
changeset
|
275 |
} |
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
276 |
#else //SDO_DYNAMIC_BUFFER_ALLOCATION |
663 | 277 |
errorCode = getODentry(d, d->transfers[line].index, |
278 |
d->transfers[line].subIndex, |
|
279 |
(void *)d->transfers[line].data, |
|
280 |
&size, &dataType, 1); |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
281 |
#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
|
282 |
|
663 | 283 |
if (errorCode != OD_SUCCESSFUL) |
284 |
return errorCode; |
|
285 |
||
286 |
d->transfers[line].count = size; |
|
287 |
d->transfers[line].offset = 0; |
|
288 |
||
289 |
return 0; |
|
290 |
} |
|
291 |
||
292 |
/*! |
|
293 |
** |
|
294 |
** |
|
295 |
** @param d |
|
296 |
** @param line |
|
297 |
** @param nbBytes |
|
298 |
** @param data |
|
299 |
** |
|
300 |
** @return |
|
301 |
**/ |
|
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
|
302 |
UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS32 nbBytes, UNS8* data) { |
663 | 303 |
UNS8 i; |
304 |
UNS32 offset; |
|
0 | 305 |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
306 |
#ifndef SDO_DYNAMIC_BUFFER_ALLOCATION |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
307 |
if ((d->transfers[line].offset + nbBytes) > SDO_MAX_LENGTH_TRANSFER) { |
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
308 |
MSG_ERR(0x1A10,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFER", nbBytes); |
663 | 309 |
return 0xFF; |
310 |
} |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
311 |
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION |
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
312 |
|
663 | 313 |
if ((d->transfers[line].offset + nbBytes) > d->transfers[line].count) { |
314 |
MSG_ERR(0x1A11,"SDO Size of data too large. Exceed count", nbBytes); |
|
315 |
return 0xFF; |
|
316 |
} |
|
317 |
offset = d->transfers[line].offset; |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
318 |
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
319 |
if (d->transfers[line].count <= SDO_MAX_LENGTH_TRANSFER) |
663 | 320 |
{ |
321 |
for (i = 0 ; i < nbBytes ; i++) |
|
322 |
* (data + i) = d->transfers[line].data[offset + i]; |
|
323 |
} |
|
324 |
else |
|
325 |
{ |
|
326 |
if (d->transfers[line].dynamicData == NULL) |
|
327 |
{ |
|
328 |
MSG_ERR(0x1A11,"SDO's dynamic buffer not allocated. Line", line); |
|
329 |
return 0xFF; |
|
330 |
} |
|
331 |
for (i = 0 ; i < nbBytes ; i++) |
|
332 |
* (data + i) = d->transfers[line].dynamicData[offset + i]; |
|
333 |
} |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
334 |
#else //SDO_DYNAMIC_BUFFER_ALLOCATION |
663 | 335 |
for (i = 0 ; i < nbBytes ; i++) |
336 |
* (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
|
337 |
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION |
663 | 338 |
d->transfers[line].offset = d->transfers[line].offset + nbBytes; |
339 |
return 0; |
|
340 |
} |
|
341 |
||
342 |
/*! |
|
343 |
** |
|
344 |
** |
|
345 |
** @param d |
|
346 |
** @param line |
|
347 |
** @param nbBytes |
|
348 |
** @param data |
|
349 |
** |
|
350 |
** @return |
|
351 |
**/ |
|
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
|
352 |
UNS8 SDOtoLine (CO_Data* d, UNS8 line, UNS32 nbBytes, UNS8* data) |
0 | 353 |
{ |
663 | 354 |
UNS8 i; |
355 |
UNS32 offset; |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
356 |
#ifndef SDO_DYNAMIC_BUFFER_ALLOCATION |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
357 |
if ((d->transfers[line].offset + nbBytes) > SDO_MAX_LENGTH_TRANSFER) { |
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
358 |
MSG_ERR(0x1A15,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFER", nbBytes); |
663 | 359 |
return 0xFF; |
360 |
} |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
361 |
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION |
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
362 |
|
663 | 363 |
offset = d->transfers[line].offset; |
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
364 |
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION |
663 | 365 |
{ |
366 |
UNS8* lineData = d->transfers[line].data; |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
367 |
if ((d->transfers[line].offset + nbBytes) > SDO_MAX_LENGTH_TRANSFER) { |
663 | 368 |
if (d->transfers[line].dynamicData == NULL) { |
369 |
d->transfers[line].dynamicData = (UNS8*) malloc(SDO_DYNAMIC_BUFFER_ALLOCATION_SIZE); |
|
370 |
d->transfers[line].dynamicDataSize = SDO_DYNAMIC_BUFFER_ALLOCATION_SIZE; |
|
371 |
||
372 |
if (d->transfers[line].dynamicData == NULL) { |
|
373 |
MSG_ERR(0x1A15,"SDO allocating dynamic buffer failed, size", SDO_DYNAMIC_BUFFER_ALLOCATION_SIZE); |
|
374 |
return 0xFF; |
|
375 |
} |
|
376 |
//Copy present data |
|
377 |
memcpy(d->transfers[line].dynamicData, d->transfers[line].data, offset); |
|
378 |
} |
|
379 |
else if ((d->transfers[line].offset + nbBytes) > d->transfers[line].dynamicDataSize) |
|
380 |
{ |
|
381 |
UNS8* newDynamicBuffer = (UNS8*) realloc(d->transfers[line].dynamicData, d->transfers[line].dynamicDataSize + SDO_DYNAMIC_BUFFER_ALLOCATION_SIZE); |
|
382 |
if (newDynamicBuffer == NULL) { |
|
383 |
MSG_ERR(0x1A15,"SDO reallocating dynamic buffer failed, size", d->transfers[line].dynamicDataSize + SDO_DYNAMIC_BUFFER_ALLOCATION_SIZE); |
|
384 |
return 0xFF; |
|
385 |
} |
|
386 |
d->transfers[line].dynamicData = newDynamicBuffer; |
|
387 |
d->transfers[line].dynamicDataSize += SDO_DYNAMIC_BUFFER_ALLOCATION_SIZE; |
|
388 |
} |
|
389 |
lineData = d->transfers[line].dynamicData; |
|
390 |
} |
|
391 |
||
392 |
for (i = 0 ; i < nbBytes ; i++) |
|
393 |
lineData[offset + i] = * (data + i); |
|
394 |
} |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
395 |
#else //SDO_DYNAMIC_BUFFER_ALLOCATION |
663 | 396 |
for (i = 0 ; i < nbBytes ; i++) |
397 |
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
|
398 |
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION |
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
399 |
|
663 | 400 |
d->transfers[line].offset = d->transfers[line].offset + nbBytes; |
401 |
return 0; |
|
402 |
} |
|
403 |
||
404 |
/*! |
|
405 |
** |
|
406 |
** |
|
407 |
** @param d |
|
408 |
** @param CliServNbr |
|
409 |
** @param whoami |
|
410 |
** @param index |
|
411 |
** @param subIndex |
|
412 |
** @param abortCode |
|
413 |
** |
|
414 |
** @return |
|
415 |
**/ |
|
416 |
UNS8 failedSDO (CO_Data* d, UNS8 CliServNbr, UNS8 whoami, UNS16 index, |
|
0 | 417 |
UNS8 subIndex, UNS32 abortCode) |
418 |
{ |
|
663 | 419 |
UNS8 err; |
420 |
UNS8 line; |
|
421 |
err = getSDOlineOnUse( d, CliServNbr, whoami, &line ); |
|
422 |
if (!err) /* If a line on use have been found.*/ |
|
423 |
MSG_WAR(0x3A20, "FailedSDO : line found : ", line); |
|
424 |
if ((! err) && (whoami == SDO_SERVER)) { |
|
425 |
resetSDOline( d, line ); |
|
426 |
MSG_WAR(0x3A21, "FailedSDO : line released : ", line); |
|
427 |
} |
|
428 |
if ((! err) && (whoami == SDO_CLIENT)) { |
|
429 |
StopSDO_TIMER(line); |
|
430 |
d->transfers[line].state = SDO_ABORTED_INTERNAL; |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
431 |
d->transfers[line].abortCode = abortCode; |
663 | 432 |
} |
433 |
MSG_WAR(0x3A22, "Sending SDO abort ", 0); |
|
434 |
err = sendSDOabort(d, whoami, CliServNbr, index, subIndex, abortCode); |
|
435 |
if (err) { |
|
436 |
MSG_WAR(0x3A23, "Unable to send the SDO abort", 0); |
|
437 |
return 0xFF; |
|
438 |
} |
|
439 |
return 0; |
|
440 |
} |
|
441 |
||
442 |
/*! |
|
443 |
** |
|
444 |
** |
|
445 |
** @param d |
|
446 |
** @param line |
|
447 |
**/ |
|
0 | 448 |
void resetSDOline ( CO_Data* d, UNS8 line ) |
449 |
{ |
|
663 | 450 |
UNS32 i; |
451 |
MSG_WAR(0x3A25, "reset SDO line nb : ", line); |
|
452 |
initSDOline(d, line, 0, 0, 0, SDO_RESET); |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
453 |
for (i = 0 ; i < SDO_MAX_LENGTH_TRANSFER ; i++) |
663 | 454 |
d->transfers[line].data[i] = 0; |
455 |
d->transfers[line].whoami = 0; |
|
456 |
d->transfers[line].abortCode = 0; |
|
0 | 457 |
} |
458 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
459 |
/*! |
663 | 460 |
** |
461 |
** |
|
462 |
** @param d |
|
463 |
** @param line |
|
464 |
** @param CliServNbr |
|
465 |
** @param index |
|
466 |
** @param subIndex |
|
467 |
** @param state |
|
468 |
** |
|
469 |
** @return |
|
470 |
**/ |
|
471 |
UNS8 initSDOline (CO_Data* d, UNS8 line, UNS8 CliServNbr, UNS16 index, UNS8 subIndex, UNS8 state) |
|
472 |
{ |
|
473 |
MSG_WAR(0x3A25, "init SDO line nb : ", line); |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
474 |
if (state == SDO_DOWNLOAD_IN_PROGRESS || state == SDO_UPLOAD_IN_PROGRESS || |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
475 |
state == SDO_BLOCK_DOWNLOAD_IN_PROGRESS || state == SDO_BLOCK_UPLOAD_IN_PROGRESS){ |
663 | 476 |
StartSDO_TIMER(line) |
477 |
}else{ |
|
478 |
StopSDO_TIMER(line) |
|
479 |
} |
|
480 |
d->transfers[line].CliServNbr = CliServNbr; |
|
481 |
d->transfers[line].index = index; |
|
482 |
d->transfers[line].subIndex = subIndex; |
|
483 |
d->transfers[line].state = state; |
|
484 |
d->transfers[line].toggle = 0; |
|
485 |
d->transfers[line].count = 0; |
|
486 |
d->transfers[line].offset = 0; |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
487 |
d->transfers[line].peerCRCsupport = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
488 |
d->transfers[line].blksize = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
489 |
d->transfers[line].ackseq = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
490 |
d->transfers[line].objsize = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
491 |
d->transfers[line].lastblockoffset = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
492 |
d->transfers[line].seqno = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
493 |
d->transfers[line].endfield = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
494 |
d->transfers[line].rxstep = RXSTEP_INIT; |
663 | 495 |
d->transfers[line].dataType = 0; |
496 |
d->transfers[line].Callback = NULL; |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
497 |
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION |
663 | 498 |
free(d->transfers[line].dynamicData); |
499 |
d->transfers[line].dynamicData = 0; |
|
500 |
d->transfers[line].dynamicDataSize = 0; |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
501 |
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION |
663 | 502 |
return 0; |
503 |
} |
|
504 |
||
505 |
/*! |
|
506 |
** |
|
507 |
** |
|
508 |
** @param d |
|
509 |
** @param whoami |
|
510 |
** @param line |
|
511 |
** |
|
512 |
** @return |
|
513 |
**/ |
|
0 | 514 |
UNS8 getSDOfreeLine ( CO_Data* d, UNS8 whoami, UNS8 *line ) |
515 |
{ |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
516 |
|
663 | 517 |
UNS8 i; |
518 |
||
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
519 |
for (i = 0 ; i < SDO_MAX_SIMULTANEOUS_TRANSFERS ; i++){ |
663 | 520 |
if ( d->transfers[i].state == SDO_RESET ) { |
521 |
*line = i; |
|
522 |
d->transfers[i].whoami = whoami; |
|
523 |
return 0; |
|
524 |
} /* end if */ |
|
525 |
} /* end for */ |
|
526 |
MSG_ERR(0x1A25, "Too many SDO in progress. Aborted.", i); |
|
527 |
return 0xFF; |
|
528 |
} |
|
529 |
||
530 |
/*! |
|
531 |
** |
|
532 |
** |
|
533 |
** @param d |
|
534 |
** @param CliServNbr |
|
535 |
** @param whoami |
|
536 |
** @param line |
|
537 |
** |
|
538 |
** @return |
|
539 |
**/ |
|
540 |
UNS8 getSDOlineOnUse (CO_Data* d, UNS8 CliServNbr, UNS8 whoami, UNS8 *line) |
|
541 |
{ |
|
542 |
||
543 |
UNS8 i; |
|
544 |
||
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
545 |
for (i = 0 ; i < SDO_MAX_SIMULTANEOUS_TRANSFERS ; i++){ |
663 | 546 |
if ( (d->transfers[i].state != SDO_RESET) && |
547 |
(d->transfers[i].state != SDO_ABORTED_INTERNAL) && |
|
548 |
(d->transfers[i].CliServNbr == CliServNbr) && |
|
549 |
(d->transfers[i].whoami == whoami) ) { |
|
550 |
if (line) *line = i; |
|
551 |
return 0; |
|
552 |
} |
|
553 |
} |
|
554 |
return 0xFF; |
|
555 |
} |
|
556 |
||
557 |
/*! |
|
558 |
** |
|
559 |
** |
|
560 |
** @param d |
|
561 |
** @param CliServNbr |
|
562 |
** @param whoami |
|
563 |
** @param line |
|
564 |
** |
|
565 |
** @return |
|
566 |
**/ |
|
567 |
UNS8 getSDOlineToClose (CO_Data* d, UNS8 CliServNbr, UNS8 whoami, UNS8 *line) |
|
568 |
{ |
|
569 |
||
570 |
UNS8 i; |
|
571 |
||
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
572 |
for (i = 0 ; i < SDO_MAX_SIMULTANEOUS_TRANSFERS ; i++){ |
663 | 573 |
if ( (d->transfers[i].state != SDO_RESET) && |
574 |
(d->transfers[i].CliServNbr == CliServNbr) && |
|
575 |
(d->transfers[i].whoami == whoami) ) { |
|
576 |
if (line) *line = i; |
|
577 |
return 0; |
|
578 |
} |
|
579 |
} |
|
580 |
return 0xFF; |
|
581 |
} |
|
582 |
||
583 |
||
584 |
/*! |
|
585 |
** |
|
586 |
** |
|
587 |
** @param d |
|
588 |
** @param CliServNbr |
|
589 |
** @param whoami |
|
590 |
** |
|
591 |
** @return |
|
592 |
**/ |
|
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
667
diff
changeset
|
593 |
UNS8 closeSDOtransfer (CO_Data* d, UNS8 nodeId, UNS8 whoami) |
663 | 594 |
{ |
595 |
UNS8 err; |
|
596 |
UNS8 line; |
|
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
667
diff
changeset
|
597 |
UNS8 CliNbr; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
667
diff
changeset
|
598 |
/* First let's find the corresponding SDO client in our OD */ |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
667
diff
changeset
|
599 |
CliNbr = GetSDOClientFromNodeId(d, nodeId); |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
667
diff
changeset
|
600 |
if(CliNbr >= 0xFE) |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
667
diff
changeset
|
601 |
return SDO_ABORTED_INTERNAL; |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
667
diff
changeset
|
602 |
err = getSDOlineToClose(d, CliNbr, whoami, &line); |
663 | 603 |
if (err) { |
604 |
MSG_WAR(0x2A30, "No SDO communication to close", 0); |
|
605 |
return 0xFF; |
|
606 |
} |
|
607 |
resetSDOline(d, line); |
|
608 |
return 0; |
|
609 |
} |
|
610 |
||
611 |
/*! |
|
612 |
** |
|
613 |
** |
|
614 |
** @param d |
|
615 |
** @param line |
|
616 |
** @param nbBytes |
|
617 |
** |
|
618 |
** @return |
|
619 |
**/ |
|
539
187058b4a4b8
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents:
538
diff
changeset
|
620 |
UNS8 getSDOlineRestBytes (CO_Data* d, UNS8 line, UNS32 * nbBytes) |
0 | 621 |
{ |
663 | 622 |
/* SDO initiated with e=0 and s=0 have count set to null */ |
623 |
if (d->transfers[line].count == 0) |
|
624 |
* nbBytes = 0; |
|
625 |
else |
|
626 |
* nbBytes = d->transfers[line].count - d->transfers[line].offset; |
|
627 |
return 0; |
|
628 |
} |
|
629 |
||
630 |
/*! |
|
631 |
** |
|
632 |
** |
|
633 |
** @param d |
|
634 |
** @param line |
|
635 |
** @param nbBytes |
|
636 |
** |
|
637 |
** @return |
|
638 |
**/ |
|
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
|
639 |
UNS8 setSDOlineRestBytes (CO_Data* d, UNS8 line, UNS32 nbBytes) |
0 | 640 |
{ |
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
641 |
#ifndef SDO_DYNAMIC_BUFFER_ALLOCATION |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
642 |
if (nbBytes > SDO_MAX_LENGTH_TRANSFER) { |
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
643 |
MSG_ERR(0x1A35,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFER", nbBytes); |
663 | 644 |
return 0xFF; |
645 |
} |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
646 |
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION |
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
647 |
|
663 | 648 |
d->transfers[line].count = nbBytes; |
649 |
return 0; |
|
650 |
} |
|
651 |
||
652 |
/*! |
|
653 |
** |
|
654 |
** |
|
655 |
** @param d |
|
656 |
** @param whoami |
|
657 |
** @param CliServNbr |
|
658 |
** @param pData |
|
659 |
** |
|
660 |
** @return |
|
661 |
**/ |
|
662 |
UNS8 sendSDO (CO_Data* d, UNS8 whoami, UNS8 CliServNbr, UNS8 *pData) |
|
663 |
{ |
|
664 |
UNS16 offset; |
|
665 |
UNS8 i; |
|
666 |
Message m; |
|
667 |
||
668 |
MSG_WAR(0x3A38, "sendSDO",0); |
|
669 |
if( !((d->nodeState == Operational) || (d->nodeState == Pre_operational ))) { |
|
670 |
MSG_WAR(0x2A39, "unable to send the SDO (not in op or pre-op mode", d->nodeState); |
|
671 |
return 0xFF; |
|
672 |
} |
|
673 |
||
674 |
/*get the server->client cobid*/ |
|
675 |
if ( whoami == SDO_SERVER ) { |
|
676 |
offset = d->firstIndex->SDO_SVR; |
|
677 |
if ((offset == 0) || ((offset+CliServNbr) > d->lastIndex->SDO_SVR)) { |
|
678 |
MSG_ERR(0x1A42, "SendSDO : SDO server not found", 0); |
|
679 |
return 0xFF; |
|
680 |
} |
|
700 | 681 |
m.cob_id = (UNS16) *((UNS32*) d->objdict[offset+CliServNbr].pSubindex[2].pObject); |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
682 |
MSG_WAR(0x3A41, "I am server Tx cobId : ", m.cob_id); |
663 | 683 |
} |
684 |
else { /*case client*/ |
|
685 |
/* Get the client->server cobid.*/ |
|
686 |
offset = d->firstIndex->SDO_CLT; |
|
687 |
if ((offset == 0) || ((offset+CliServNbr) > d->lastIndex->SDO_CLT)) { |
|
688 |
MSG_ERR(0x1A42, "SendSDO : SDO client not found", 0); |
|
689 |
return 0xFF; |
|
690 |
} |
|
700 | 691 |
m.cob_id = (UNS16) *((UNS32*) d->objdict[offset+CliServNbr].pSubindex[1].pObject); |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
692 |
MSG_WAR(0x3A41, "I am client Tx cobId : ", m.cob_id); |
663 | 693 |
} |
694 |
/* message copy for sending */ |
|
695 |
m.rtr = NOT_A_REQUEST; |
|
696 |
/* the length of SDO must be 8 */ |
|
697 |
m.len = 8; |
|
698 |
for (i = 0 ; i < 8 ; i++) { |
|
699 |
m.data[i] = pData[i]; |
|
700 |
} |
|
701 |
return canSend(d->canHandle,&m); |
|
702 |
} |
|
703 |
||
704 |
/*! |
|
705 |
** |
|
706 |
** |
|
707 |
** @param d |
|
708 |
** @param whoami |
|
709 |
** @param index |
|
710 |
** @param subIndex |
|
711 |
** @param abortCode |
|
712 |
** |
|
713 |
** @return |
|
714 |
**/ |
|
715 |
UNS8 sendSDOabort (CO_Data* d, UNS8 whoami, UNS8 CliServNbr, UNS16 index, UNS8 subIndex, UNS32 abortCode) |
|
716 |
{ |
|
717 |
UNS8 data[8]; |
|
718 |
UNS8 ret; |
|
719 |
||
720 |
MSG_WAR(0x2A50,"Sending SDO abort ", abortCode); |
|
721 |
data[0] = 0x80; |
|
722 |
/* Index */ |
|
723 |
data[1] = index & 0xFF; /* LSB */ |
|
724 |
data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
725 |
/* Subindex */ |
|
726 |
data[3] = subIndex; |
|
727 |
/* Data */ |
|
728 |
data[4] = (UNS8)(abortCode & 0xFF); |
|
729 |
data[5] = (UNS8)((abortCode >> 8) & 0xFF); |
|
730 |
data[6] = (UNS8)((abortCode >> 16) & 0xFF); |
|
731 |
data[7] = (UNS8)((abortCode >> 24) & 0xFF); |
|
732 |
ret = sendSDO(d, whoami, CliServNbr, data); |
|
733 |
||
734 |
return ret; |
|
735 |
} |
|
736 |
||
737 |
/*! |
|
738 |
** |
|
739 |
** |
|
740 |
** @param d |
|
741 |
** @param m |
|
742 |
** |
|
743 |
** @return |
|
744 |
**/ |
|
0 | 745 |
UNS8 proceedSDO (CO_Data* d, Message *m) |
746 |
{ |
|
663 | 747 |
UNS8 err; |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
748 |
UNS8 cs; |
663 | 749 |
UNS8 line; |
750 |
UNS32 nbBytes; /* received or to be transmited. */ |
|
751 |
UNS8 nodeId = 0; /* The node Id of the server if client otherwise unused */ |
|
752 |
UNS8 CliServNbr; |
|
753 |
UNS8 whoami = SDO_UNKNOWN; /* SDO_SERVER or SDO_CLIENT.*/ |
|
754 |
UNS32 errorCode; /* while reading or writing in the local object dictionary.*/ |
|
755 |
UNS8 data[8]; /* data for SDO to transmit */ |
|
756 |
UNS16 index; |
|
757 |
UNS8 subIndex; |
|
758 |
UNS32 abortCode; |
|
759 |
UNS32 i; |
|
760 |
UNS8 j; |
|
761 |
UNS32 *pCobId = NULL; |
|
762 |
UNS16 offset; |
|
763 |
UNS16 lastIndex; |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
764 |
UNS8 SubCommand; /* Block transfer only */ |
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
765 |
UNS8 SeqNo; /* Sequence number in block transfer */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
766 |
UNS8 AckSeq; /* Sequence number of last segment that was received successfully */ |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
767 |
UNS8 NbBytesNoData; /* Number of bytes that do not contain data in last segment of block transfer */ |
663 | 768 |
|
769 |
MSG_WAR(0x3A60, "proceedSDO ", 0); |
|
770 |
whoami = SDO_UNKNOWN; |
|
771 |
/* Looking for the cobId in the object dictionary. */ |
|
772 |
/* Am-I a server ? */ |
|
773 |
offset = d->firstIndex->SDO_SVR; |
|
774 |
lastIndex = d->lastIndex->SDO_SVR; |
|
775 |
j = 0; |
|
776 |
if(offset) while (offset <= lastIndex) { |
|
777 |
if (d->objdict[offset].bSubCount <= 1) { |
|
778 |
MSG_ERR(0x1A61, "Subindex 1 not found at index ", 0x1200 + j); |
|
779 |
return 0xFF; |
|
780 |
} |
|
781 |
/* Looking for the cobid received. */ |
|
782 |
pCobId = (UNS32*) d->objdict[offset].pSubindex[1].pObject; |
|
783 |
if ( *pCobId == UNS16_LE(m->cob_id) ) { |
|
784 |
whoami = SDO_SERVER; |
|
785 |
MSG_WAR(0x3A62, "proceedSDO. I am server. index : ", 0x1200 + j); |
|
786 |
/* Defining Server number = index minus 0x1200 where the cobid received is defined. */ |
|
787 |
CliServNbr = j; |
|
788 |
break; |
|
789 |
} |
|
790 |
j++; |
|
791 |
offset++; |
|
792 |
} /* end while */ |
|
793 |
if (whoami == SDO_UNKNOWN) { |
|
794 |
/* Am-I client ? */ |
|
795 |
offset = d->firstIndex->SDO_CLT; |
|
796 |
lastIndex = d->lastIndex->SDO_CLT; |
|
797 |
j = 0; |
|
798 |
if(offset) while (offset <= lastIndex) { |
|
799 |
if (d->objdict[offset].bSubCount <= 3) { |
|
800 |
MSG_ERR(0x1A63, "Subindex 3 not found at index ", 0x1280 + j); |
|
801 |
return 0xFF; |
|
802 |
} |
|
803 |
/* Looking for the cobid received. */ |
|
804 |
pCobId = (UNS32*) d->objdict[offset].pSubindex[2].pObject; |
|
805 |
if (*pCobId == UNS16_LE(m->cob_id) ) { |
|
806 |
whoami = SDO_CLIENT; |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
807 |
MSG_WAR(0x3A64, "proceedSDO. I am client index : ", 0x1280 + j); |
663 | 808 |
/* Defining Client number = index minus 0x1280 where the cobid received is defined. */ |
809 |
CliServNbr = j; |
|
810 |
/* Reading the server node ID, if client it is mandatory in the OD */ |
|
811 |
nodeId = *((UNS8*) d->objdict[offset].pSubindex[3].pObject); |
|
812 |
break; |
|
813 |
} |
|
814 |
j++; |
|
815 |
offset++; |
|
816 |
} /* end while */ |
|
817 |
} |
|
818 |
if (whoami == SDO_UNKNOWN) { |
|
819 |
return 0xFF;/* This SDO was not for us ! */ |
|
820 |
} |
|
821 |
||
822 |
/* Test if the size of the SDO is ok */ |
|
823 |
if ( (*m).len != 8) { |
|
824 |
MSG_ERR(0x1A67, "Error size SDO", 0); |
|
825 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_GENERAL_ERROR); |
|
826 |
return 0xFF; |
|
827 |
} |
|
828 |
||
829 |
if (whoami == SDO_CLIENT) { |
|
830 |
MSG_WAR(0x3A68, "I am CLIENT number ", CliServNbr); |
|
831 |
} |
|
832 |
else { |
|
833 |
MSG_WAR(0x3A69, "I am SERVER number ", CliServNbr); |
|
834 |
} |
|
835 |
||
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
836 |
/* Look for an SDO transfer already initiated. */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
837 |
err = getSDOlineOnUse( d, CliServNbr, whoami, &line ); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
838 |
|
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
839 |
/* Let's find cs value, first it is set as "not valid" */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
840 |
cs = 0xFF; |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
841 |
/* Special cases for block transfer : in frames with segment data cs is not spécified */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
842 |
if (!err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
843 |
if ((whoami == SDO_SERVER) && (d->transfers[line].state == SDO_BLOCK_DOWNLOAD_IN_PROGRESS) || |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
844 |
(whoami == SDO_CLIENT) && (d->transfers[line].state == SDO_BLOCK_UPLOAD_IN_PROGRESS)) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
845 |
if(m->data[0] == 0x80) /* If first byte is 0x80 it is an abort frame (seqno = 0 not allowed) */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
846 |
cs = 4; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
847 |
else |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
848 |
cs = 6; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
849 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
850 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
851 |
/* Other cases : cs is specified */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
852 |
if (cs == 0xFF) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
853 |
cs = getSDOcs(m->data[0]); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
854 |
|
663 | 855 |
/* Testing the command specifier */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
856 |
/* Allowed : cs = 0, 1, 2, 3, 4, 5, 6 */ |
663 | 857 |
/* cs = other : Not allowed -> abort. */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
858 |
switch (cs) { |
663 | 859 |
|
860 |
case 0: |
|
861 |
/* I am SERVER */ |
|
862 |
if (whoami == SDO_SERVER) { |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
863 |
/* Receiving a download segment data : an SDO transfer should have been yet initiated. */ |
663 | 864 |
if (!err) |
865 |
err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS; |
|
866 |
if (err) { |
|
867 |
MSG_ERR(0x1A70, "SDO error : Received download segment for unstarted trans. index 0x1200 + ", |
|
868 |
CliServNbr); |
|
869 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
|
870 |
return 0xFF; |
|
871 |
} |
|
872 |
/* Reset the wathdog */ |
|
873 |
RestartSDO_TIMER(line) |
|
874 |
MSG_WAR(0x3A71, "Received SDO download segment defined at index 0x1200 + ", CliServNbr); |
|
875 |
index = d->transfers[line].index; |
|
876 |
subIndex = d->transfers[line].subIndex; |
|
877 |
/* Toggle test. */ |
|
878 |
if (d->transfers[line].toggle != getSDOt(m->data[0])) { |
|
879 |
MSG_ERR(0x1A72, "SDO error : Toggle error : ", getSDOt(m->data[0])); |
|
880 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED); |
|
881 |
return 0xFF; |
|
882 |
} |
|
883 |
/* Nb of data to be downloaded */ |
|
884 |
nbBytes = 7 - getSDOn3(m->data[0]); |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
885 |
/* Store the data in the transfer structure. */ |
663 | 886 |
err = SDOtoLine(d, line, nbBytes, (*m).data + 1); |
887 |
if (err) { |
|
888 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
889 |
return 0xFF; |
|
890 |
} |
|
891 |
/* Sending the SDO response, CS = 1 */ |
|
892 |
data[0] = (1 << 5) | (d->transfers[line].toggle << 4); |
|
893 |
for (i = 1 ; i < 8 ; i++) |
|
894 |
data[i] = 0; |
|
895 |
MSG_WAR(0x3A73, "SDO. Send response to download request defined at index 0x1200 + ", CliServNbr); |
|
896 |
sendSDO(d, whoami, CliServNbr, data); |
|
897 |
/* Inverting the toggle for the next segment. */ |
|
898 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
|
899 |
/* If it was the last segment, */ |
|
900 |
if (getSDOc(m->data[0])) { |
|
901 |
/* Transfering line data to object dictionary. */ |
|
902 |
/* The code does not use the "d" of initiate frame. So it is safe if e=s=0 */ |
|
903 |
errorCode = SDOlineToObjdict(d, line); |
|
904 |
if (errorCode) { |
|
905 |
MSG_ERR(0x1A54, "SDO error : Unable to copy the data in the object dictionary", 0); |
|
906 |
failedSDO(d, CliServNbr, whoami, index, subIndex, errorCode); |
|
907 |
return 0xFF; |
|
908 |
} |
|
909 |
/* Release of the line */ |
|
910 |
resetSDOline(d, line); |
|
911 |
MSG_WAR(0x3A74, "SDO. End of download defined at index 0x1200 + ", CliServNbr); |
|
912 |
} |
|
913 |
} /* end if SERVER */ |
|
914 |
else { /* if CLIENT */ |
|
915 |
/* I am CLIENT */ |
|
916 |
/* It is a request for a previous upload segment. We should find a line opened for this.*/ |
|
917 |
if (!err) |
|
918 |
err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS; |
|
919 |
if (err) { |
|
920 |
MSG_ERR(0x1A75, "SDO error : Received segment response for unknown trans. from nodeId", nodeId); |
|
921 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
|
922 |
return 0xFF; |
|
923 |
} |
|
924 |
/* Reset the wathdog */ |
|
925 |
RestartSDO_TIMER(line) |
|
926 |
index = d->transfers[line].index; |
|
927 |
subIndex = d->transfers[line].subIndex; |
|
928 |
/* test of the toggle; */ |
|
929 |
if (d->transfers[line].toggle != getSDOt(m->data[0])) { |
|
930 |
MSG_ERR(0x1A76, "SDO error : Received segment response Toggle error. from nodeId", nodeId); |
|
931 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED); |
|
932 |
return 0xFF; |
|
933 |
} |
|
934 |
/* nb of data to be uploaded */ |
|
935 |
nbBytes = 7 - getSDOn3(m->data[0]); |
|
936 |
/* Storing the data in the line structure. */ |
|
937 |
err = SDOtoLine(d, line, nbBytes, (*m).data + 1); |
|
938 |
if (err) { |
|
939 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
940 |
return 0xFF; |
|
941 |
} |
|
942 |
/* Inverting the toggle for the next segment. */ |
|
943 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
|
944 |
/* If it was the last segment,*/ |
|
945 |
if ( getSDOc(m->data[0])) { |
|
946 |
/* Put in state finished */ |
|
947 |
/* The code is safe for the case e=s=0 in initiate frame. */ |
|
948 |
StopSDO_TIMER(line) |
|
949 |
d->transfers[line].state = SDO_FINISHED; |
|
950 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
|
951 |
||
952 |
MSG_WAR(0x3A77, "SDO. End of upload from node : ", nodeId); |
|
953 |
} |
|
954 |
else { /* more segments to receive */ |
|
955 |
/* Sending the request for the next segment. */ |
|
956 |
data[0] = (3 << 5) | (d->transfers[line].toggle << 4); |
|
957 |
for (i = 1 ; i < 8 ; i++) |
|
958 |
data[i] = 0; |
|
959 |
sendSDO(d, whoami, CliServNbr, data); |
|
960 |
MSG_WAR(0x3A78, "SDO send upload segment request to nodeId", nodeId); |
|
961 |
} |
|
962 |
} /* End if CLIENT */ |
|
963 |
break; |
|
964 |
||
965 |
case 1: |
|
966 |
/* I am SERVER */ |
|
967 |
/* Receive of an initiate download */ |
|
968 |
if (whoami == SDO_SERVER) { |
|
969 |
index = getSDOindex(m->data[1],m->data[2]); |
|
970 |
subIndex = getSDOsubIndex(m->data[3]); |
|
971 |
MSG_WAR(0x3A79, "Received SDO Initiate Download (to store data) defined at index 0x1200 + ", |
|
972 |
CliServNbr); |
|
973 |
MSG_WAR(0x3A80, "Writing at index : ", index); |
|
974 |
MSG_WAR(0x3A80, "Writing at subIndex : ", subIndex); |
|
975 |
||
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
976 |
/* Search if a SDO transfer have been yet initiated */ |
663 | 977 |
if (! err) { |
978 |
MSG_ERR(0x1A81, "SDO error : Transmission yet started.", 0); |
|
979 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
|
980 |
return 0xFF; |
|
981 |
} |
|
982 |
/* No line on use. Great ! */ |
|
983 |
/* Try to open a new line. */ |
|
984 |
err = getSDOfreeLine( d, whoami, &line ); |
|
985 |
if (err) { |
|
986 |
MSG_ERR(0x1A82, "SDO error : No line free, too many SDO in progress. Aborted.", 0); |
|
987 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
|
988 |
return 0xFF; |
|
989 |
} |
|
990 |
initSDOline(d, line, CliServNbr, index, subIndex, SDO_DOWNLOAD_IN_PROGRESS); |
|
991 |
||
992 |
if (getSDOe(m->data[0])) { /* If SDO expedited */ |
|
993 |
/* nb of data to be downloaded */ |
|
994 |
nbBytes = 4 - getSDOn2(m->data[0]); |
|
995 |
/* Storing the data in the line structure. */ |
|
996 |
d->transfers[line].count = nbBytes; |
|
997 |
err = SDOtoLine(d, line, nbBytes, (*m).data + 4); |
|
998 |
||
999 |
if (err) { |
|
1000 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1001 |
return 0xFF; |
|
1002 |
} |
|
1003 |
||
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1004 |
/* SDO expedited -> transfer finished. Data can be stored in the dictionary. */ |
663 | 1005 |
/*The line will be reseted when it is downloading in the dictionary. */ |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1006 |
MSG_WAR(0x3A83, "SDO Initiate Download is an expedited transfer. Finished. ", 0); |
663 | 1007 |
/* Transfering line data to object dictionary. */ |
1008 |
errorCode = SDOlineToObjdict(d, line); |
|
1009 |
if (errorCode) { |
|
1010 |
MSG_ERR(0x1A84, "SDO error : Unable to copy the data in the object dictionary", 0); |
|
1011 |
failedSDO(d, CliServNbr, whoami, index, subIndex, errorCode); |
|
1012 |
return 0xFF; |
|
1013 |
} |
|
1014 |
/* Release of the line. */ |
|
1015 |
resetSDOline(d, line); |
|
1016 |
} |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1017 |
else {/* So, if it is not an expedited transfer */ |
663 | 1018 |
if (getSDOs(m->data[0])) { |
1019 |
nbBytes = (m->data[4]) + ((UNS32)(m->data[5])<<8) + ((UNS32)(m->data[6])<<16) + ((UNS32)(m->data[7])<<24); |
|
682 | 1020 |
err = setSDOlineRestBytes(d, line, nbBytes); |
663 | 1021 |
if (err) { |
1022 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1023 |
return 0xFF; |
|
1024 |
} |
|
1025 |
} |
|
1026 |
} |
|
1027 |
/*Sending a SDO, cs=3*/ |
|
1028 |
data[0] = 3 << 5; |
|
1029 |
data[1] = index & 0xFF; /* LSB */ |
|
1030 |
data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
1031 |
data[3] = subIndex; |
|
1032 |
for (i = 4 ; i < 8 ; i++) |
|
1033 |
data[i] = 0; |
|
1034 |
sendSDO(d, whoami, CliServNbr, data); |
|
1035 |
} /* end if I am SERVER */ |
|
1036 |
else { |
|
1037 |
/* I am CLIENT */ |
|
1038 |
/* It is a response for a previous download segment. We should find a line opened for this. */ |
|
1039 |
if (!err) |
|
1040 |
err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS; |
|
1041 |
if (err) { |
|
1042 |
MSG_ERR(0x1A85, "SDO error : Received segment response for unknown trans. from nodeId", nodeId); |
|
1043 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
|
1044 |
return 0xFF; |
|
1045 |
} |
|
1046 |
/* Reset the wathdog */ |
|
1047 |
RestartSDO_TIMER(line) |
|
1048 |
index = d->transfers[line].index; |
|
1049 |
subIndex = d->transfers[line].subIndex; |
|
1050 |
/* test of the toggle; */ |
|
1051 |
if (d->transfers[line].toggle != getSDOt(m->data[0])) { |
|
1052 |
MSG_ERR(0x1A86, "SDO error : Received segment response Toggle error. from nodeId", nodeId); |
|
1053 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED); |
|
1054 |
return 0xFF; |
|
1055 |
} |
|
1056 |
||
1057 |
/* End transmission or downloading next segment. We need to know if it will be the last one. */ |
|
1058 |
getSDOlineRestBytes(d, line, &nbBytes); |
|
1059 |
if (nbBytes == 0) { |
|
1060 |
MSG_WAR(0x3A87, "SDO End download. segment response received. OK. from nodeId", nodeId); |
|
1061 |
StopSDO_TIMER(line) |
|
1062 |
d->transfers[line].state = SDO_FINISHED; |
|
1063 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
|
1064 |
return 0x00; |
|
1065 |
} |
|
1066 |
/* At least one transfer to send. */ |
|
1067 |
if (nbBytes > 7) { |
|
1068 |
/* several segments to download.*/ |
|
1069 |
/* code to send the next segment. (cs = 0; c = 0) */ |
|
1070 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
|
1071 |
data[0] = (d->transfers[line].toggle << 4); |
|
1072 |
err = lineToSDO(d, line, 7, data + 1); |
|
1073 |
if (err) { |
|
1074 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1075 |
return 0xFF; |
|
1076 |
} |
|
1077 |
} |
|
1078 |
else { |
|
1079 |
/* Last segment. */ |
|
1080 |
/* code to send the last segment. (cs = 0; c = 1)*/ |
|
1081 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
|
1082 |
data[0] = (UNS8)((d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1); |
|
1083 |
err = lineToSDO(d, line, nbBytes, data + 1); |
|
1084 |
if (err) { |
|
1085 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1086 |
return 0xFF; |
|
1087 |
} |
|
1088 |
for (i = nbBytes + 1 ; i < 8 ; i++) |
|
1089 |
data[i] = 0; |
|
1090 |
} |
|
1091 |
MSG_WAR(0x3A88, "SDO sending download segment to nodeId", nodeId); |
|
1092 |
sendSDO(d, whoami, CliServNbr, data); |
|
1093 |
} /* end if I am a CLIENT */ |
|
1094 |
break; |
|
1095 |
||
1096 |
case 2: |
|
1097 |
/* I am SERVER */ |
|
1098 |
/* Receive of an initiate upload.*/ |
|
1099 |
if (whoami == SDO_SERVER) { |
|
1100 |
index = getSDOindex(m->data[1],m->data[2]); |
|
1101 |
subIndex = getSDOsubIndex(m->data[3]); |
|
1102 |
MSG_WAR(0x3A89, "Received SDO Initiate upload (to send data) defined at index 0x1200 + ", |
|
1103 |
CliServNbr); |
|
1104 |
MSG_WAR(0x3A90, "Reading at index : ", index); |
|
1105 |
MSG_WAR(0x3A91, "Reading at subIndex : ", subIndex); |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1106 |
/* Search if a SDO transfer have been yet initiated*/ |
663 | 1107 |
if (! err) { |
1108 |
MSG_ERR(0x1A92, "SDO error : Transmission yet started at line : ", line); |
|
1109 |
MSG_WAR(0x3A93, "Server Nbr = ", CliServNbr); |
|
1110 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
|
1111 |
return 0xFF; |
|
1112 |
} |
|
1113 |
/* No line on use. Great !*/ |
|
1114 |
/* Try to open a new line.*/ |
|
1115 |
err = getSDOfreeLine( d, whoami, &line ); |
|
1116 |
if (err) { |
|
1117 |
MSG_ERR(0x1A71, "SDO error : No line free, too many SDO in progress. Aborted.", 0); |
|
1118 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
|
1119 |
return 0xFF; |
|
1120 |
} |
|
1121 |
initSDOline(d, line, CliServNbr, index, subIndex, SDO_UPLOAD_IN_PROGRESS); |
|
1122 |
/* Transfer data from dictionary to the line structure. */ |
|
1123 |
errorCode = objdictToSDOline(d, line); |
|
1124 |
||
1125 |
if (errorCode) { |
|
1126 |
MSG_ERR(0x1A94, "SDO error : Unable to copy the data from object dictionary. Err code : ", |
|
1127 |
errorCode); |
|
1128 |
failedSDO(d, CliServNbr, whoami, index, subIndex, errorCode); |
|
1129 |
return 0xFF; |
|
1130 |
} |
|
1131 |
/* Preparing the response.*/ |
|
1132 |
getSDOlineRestBytes(d, line, &nbBytes); /* Nb bytes to transfer ? */ |
|
1133 |
if (nbBytes > 4) { |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1134 |
/* normal transfer. (segmented). */ |
663 | 1135 |
/* code to send the initiate upload response. (cs = 2) */ |
1136 |
data[0] = (2 << 5) | 1; |
|
1137 |
data[1] = index & 0xFF; /* LSB */ |
|
1138 |
data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
1139 |
data[3] = subIndex; |
|
700 | 1140 |
data[4] = (UNS8) nbBytes; |
1141 |
data[5] = (UNS8) (nbBytes >> 8); |
|
1142 |
data[6] = (UNS8) (nbBytes >> 16); |
|
1143 |
data[7] = (UNS8) (nbBytes >> 24); |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1144 |
MSG_WAR(0x3A95, "SDO. Sending normal upload initiate response defined at index 0x1200 + ", nodeId); |
663 | 1145 |
sendSDO(d, whoami, CliServNbr, data); |
1146 |
} |
|
1147 |
else { |
|
1148 |
/* Expedited upload. (cs = 2 ; e = 1) */ |
|
1149 |
data[0] = (UNS8)((2 << 5) | ((4 - nbBytes) << 2) | 3); |
|
1150 |
data[1] = index & 0xFF; /* LSB */ |
|
1151 |
data[2] = (index >> 8) & 0xFF; /* MSB */ |
|
1152 |
data[3] = subIndex; |
|
1153 |
err = lineToSDO(d, line, nbBytes, data + 4); |
|
1154 |
if (err) { |
|
1155 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1156 |
return 0xFF; |
|
1157 |
} |
|
1158 |
for (i = 4 + nbBytes ; i < 8 ; i++) |
|
1159 |
data[i] = 0; |
|
1160 |
MSG_WAR(0x3A96, "SDO. Sending expedited upload initiate response defined at index 0x1200 + ", |
|
1161 |
CliServNbr); |
|
1162 |
sendSDO(d, whoami, CliServNbr, data); |
|
1163 |
/* Release the line.*/ |
|
1164 |
resetSDOline(d, line); |
|
1165 |
} |
|
1166 |
} /* end if I am SERVER*/ |
|
1167 |
else { |
|
1168 |
/* I am CLIENT */ |
|
1169 |
/* It is the response for the previous initiate upload request.*/ |
|
1170 |
/* We should find a line opened for this. */ |
|
1171 |
if (!err) |
|
1172 |
err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS; |
|
1173 |
if (err) { |
|
1174 |
MSG_ERR(0x1A97, "SDO error : Received response for unknown upload request from nodeId", nodeId); |
|
1175 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
|
1176 |
return 0xFF; |
|
1177 |
} |
|
1178 |
/* Reset the wathdog */ |
|
1179 |
RestartSDO_TIMER(line) |
|
1180 |
index = d->transfers[line].index; |
|
1181 |
subIndex = d->transfers[line].subIndex; |
|
1182 |
||
1183 |
if (getSDOe(m->data[0])) { /* If SDO expedited */ |
|
1184 |
/* nb of data to be uploaded */ |
|
1185 |
nbBytes = 4 - getSDOn2(m->data[0]); |
|
1186 |
/* Storing the data in the line structure. */ |
|
1187 |
err = SDOtoLine(d, line, nbBytes, (*m).data + 4); |
|
1188 |
if (err) { |
|
1189 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1190 |
return 0xFF; |
|
1191 |
} |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1192 |
/* SDO expedited -> transfer finished. data are available via getReadResultNetworkDict(). */ |
663 | 1193 |
MSG_WAR(0x3A98, "SDO expedited upload finished. Response received from node : ", nodeId); |
1194 |
StopSDO_TIMER(line) |
|
1195 |
d->transfers[line].count = nbBytes; |
|
1196 |
d->transfers[line].state = SDO_FINISHED; |
|
1197 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
|
1198 |
return 0; |
|
1199 |
} |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1200 |
else { /* So, if it is not an expedited transfer */ |
663 | 1201 |
/* Storing the nb of data to receive. */ |
1202 |
if (getSDOs(m->data[0])) { |
|
1203 |
nbBytes = m->data[4] + ((UNS32)(m->data[5])<<8) + ((UNS32)(m->data[6])<<16) + ((UNS32)(m->data[7])<<24); |
|
1204 |
err = setSDOlineRestBytes(d, line, nbBytes); |
|
1205 |
if (err) { |
|
1206 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1207 |
return 0xFF; |
|
1208 |
} |
|
1209 |
} |
|
1210 |
/* Requesting next segment. (cs = 3) */ |
|
1211 |
data[0] = 3 << 5; |
|
1212 |
for (i = 1 ; i < 8 ; i++) |
|
1213 |
data[i] = 0; |
|
1214 |
MSG_WAR(0x3A99, "SDO. Sending upload segment request to node : ", nodeId); |
|
1215 |
sendSDO(d, whoami, CliServNbr, data); |
|
1216 |
} |
|
1217 |
} /* End if CLIENT */ |
|
1218 |
break; |
|
1219 |
||
1220 |
case 3: |
|
1221 |
/* I am SERVER */ |
|
1222 |
if (whoami == SDO_SERVER) { |
|
1223 |
/* Receiving a upload segment. */ |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1224 |
/* A SDO transfer should have been yet initiated. */ |
663 | 1225 |
if (!err) |
1226 |
err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS; |
|
1227 |
if (err) { |
|
1228 |
MSG_ERR(0x1AA0, "SDO error : Received upload segment for unstarted trans. index 0x1200 + ", |
|
1229 |
CliServNbr); |
|
1230 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
|
1231 |
return 0xFF; |
|
1232 |
} |
|
1233 |
/* Reset the wathdog */ |
|
1234 |
RestartSDO_TIMER(line) |
|
1235 |
MSG_WAR(0x3AA1, "Received SDO upload segment defined at index 0x1200 + ", CliServNbr); |
|
1236 |
index = d->transfers[line].index; |
|
1237 |
subIndex = d->transfers[line].subIndex; |
|
1238 |
/* Toggle test.*/ |
|
1239 |
if (d->transfers[line].toggle != getSDOt(m->data[0])) { |
|
1240 |
MSG_ERR(0x1AA2, "SDO error : Toggle error : ", getSDOt(m->data[0])); |
|
1241 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED); |
|
1242 |
return 0xFF; |
|
1243 |
} |
|
1244 |
/* Uploading next segment. We need to know if it will be the last one. */ |
|
1245 |
getSDOlineRestBytes(d, line, &nbBytes); |
|
1246 |
if (nbBytes > 7) { |
|
1247 |
/* The segment to transfer is not the last one.*/ |
|
1248 |
/* code to send the next segment. (cs = 0; c = 0) */ |
|
1249 |
data[0] = (d->transfers[line].toggle << 4); |
|
1250 |
err = lineToSDO(d, line, 7, data + 1); |
|
1251 |
if (err) { |
|
1252 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1253 |
return 0xFF; |
|
1254 |
} |
|
1255 |
/* Inverting the toggle for the next tranfert. */ |
|
1256 |
d->transfers[line].toggle = ! d->transfers[line].toggle & 1; |
|
1257 |
MSG_WAR(0x3AA3, "SDO. Sending upload segment defined at index 0x1200 + ", CliServNbr); |
|
1258 |
sendSDO(d, whoami, CliServNbr, data); |
|
1259 |
} |
|
1260 |
else { |
|
1261 |
/* Last segment. */ |
|
1262 |
/* code to send the last segment. (cs = 0; c = 1) */ |
|
1263 |
data[0] = (UNS8)((d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1); |
|
1264 |
err = lineToSDO(d, line, nbBytes, data + 1); |
|
1265 |
if (err) { |
|
1266 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1267 |
return 0xFF; |
|
1268 |
} |
|
1269 |
for (i = nbBytes + 1 ; i < 8 ; i++) |
|
1270 |
data[i] = 0; |
|
1271 |
MSG_WAR(0x3AA4, "SDO. Sending last upload segment defined at index 0x1200 + ", CliServNbr); |
|
1272 |
sendSDO(d, whoami, CliServNbr, data); |
|
1273 |
/* Release the line */ |
|
1274 |
resetSDOline(d, line); |
|
1275 |
} |
|
1276 |
} /* end if SERVER*/ |
|
1277 |
else { |
|
1278 |
/* I am CLIENT */ |
|
1279 |
/* It is the response for the previous initiate download request. */ |
|
1280 |
/* We should find a line opened for this. */ |
|
1281 |
if (!err) |
|
1282 |
err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS; |
|
1283 |
if (err) { |
|
1284 |
MSG_ERR(0x1AA5, "SDO error : Received response for unknown download request from nodeId", nodeId); |
|
1285 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
|
1286 |
return 0xFF; |
|
1287 |
} |
|
1288 |
/* Reset the watchdog */ |
|
1289 |
RestartSDO_TIMER(line) |
|
1290 |
index = d->transfers[line].index; |
|
1291 |
subIndex = d->transfers[line].subIndex; |
|
1292 |
/* End transmission or requesting next segment. */ |
|
1293 |
getSDOlineRestBytes(d, line, &nbBytes); |
|
1294 |
if (nbBytes == 0) { |
|
1295 |
MSG_WAR(0x3AA6, "SDO End download expedited. Response received. from nodeId", nodeId); |
|
1296 |
StopSDO_TIMER(line) |
|
1297 |
d->transfers[line].state = SDO_FINISHED; |
|
1298 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
|
1299 |
return 0x00; |
|
1300 |
} |
|
1301 |
if (nbBytes > 7) { |
|
1302 |
/* more than one request to send */ |
|
1303 |
/* code to send the next segment. (cs = 0; c = 0) */ |
|
1304 |
data[0] = (d->transfers[line].toggle << 4); |
|
1305 |
err = lineToSDO(d, line, 7, data + 1); |
|
1306 |
if (err) { |
|
1307 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1308 |
return 0xFF; |
|
1309 |
} |
|
1310 |
} |
|
1311 |
else { |
|
1312 |
/* Last segment.*/ |
|
1313 |
/* code to send the last segment. (cs = 0; c = 1) */ |
|
1314 |
data[0] = (UNS8)((d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1); |
|
1315 |
err = lineToSDO(d, line, nbBytes, data + 1); |
|
1316 |
if (err) { |
|
1317 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
|
1318 |
return 0xFF; |
|
1319 |
} |
|
1320 |
for (i = nbBytes + 1 ; i < 8 ; i++) |
|
1321 |
data[i] = 0; |
|
1322 |
} |
|
1323 |
MSG_WAR(0x3AA7, "SDO sending download segment to nodeId", nodeId); |
|
1324 |
sendSDO(d, whoami, CliServNbr, data); |
|
1325 |
||
1326 |
} /* end if I am a CLIENT */ |
|
1327 |
break; |
|
1328 |
||
1329 |
case 4: |
|
1330 |
abortCode = |
|
1331 |
(UNS32)m->data[4] | |
|
1332 |
((UNS32)m->data[5] << 8) | |
|
1333 |
((UNS32)m->data[6] << 16) | |
|
1334 |
((UNS32)m->data[7] << 24); |
|
1335 |
/* Received SDO abort. */ |
|
1336 |
if (whoami == SDO_SERVER) { |
|
1337 |
if (!err) { |
|
1338 |
resetSDOline( d, line ); |
|
1339 |
MSG_WAR(0x3AA8, "SD0. Received SDO abort. Line released. Code : ", abortCode); |
|
1340 |
} |
|
1341 |
else |
|
1342 |
MSG_WAR(0x3AA9, "SD0. Received SDO abort. No line found. Code : ", abortCode); |
|
1343 |
/* Tips : The end user has no way to know that the server node has received an abort SDO. */ |
|
1344 |
/* Its is ok, I think.*/ |
|
1345 |
} |
|
1346 |
else { /* If I am CLIENT */ |
|
1347 |
if (!err) { |
|
1348 |
/* The line *must* be released by the core program. */ |
|
1349 |
StopSDO_TIMER(line) |
|
1350 |
d->transfers[line].state = SDO_ABORTED_RCV; |
|
1351 |
d->transfers[line].abortCode = abortCode; |
|
1352 |
MSG_WAR(0x3AB0, "SD0. Received SDO abort. Line state ABORTED. Code : ", abortCode); |
|
1353 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
|
1354 |
} |
|
1355 |
else |
|
1356 |
MSG_WAR(0x3AB1, "SD0. Received SDO abort. No line found. Code : ", abortCode); |
|
1357 |
} |
|
1358 |
break; |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1359 |
case 5: /* Command specifier for data transmission - the client or server is the data producer */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1360 |
SubCommand = getSDOblockSC(m->data[0]); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1361 |
if (whoami == SDO_SERVER) { /* Server block upload */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1362 |
if (SubCommand == SDO_BCS_INITIATE_UPLOAD_REQUEST) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1363 |
index = getSDOindex(m->data[1],m->data[2]); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1364 |
subIndex = getSDOsubIndex(m->data[3]); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1365 |
MSG_WAR(0x3AB2, "Received SDO Initiate block upload defined at index 0x1200 + ", |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1366 |
CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1367 |
MSG_WAR(0x3AB3, "Reading at index : ", index); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1368 |
MSG_WAR(0x3AB4, "Reading at subIndex : ", subIndex); |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1369 |
/* Search if a SDO transfer have been yet initiated */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1370 |
if (! err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1371 |
MSG_ERR(0x1A93, "SDO error : Transmission yet started at line : ", line); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1372 |
MSG_WAR(0x3AB5, "Server Nbr = ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1373 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1374 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1375 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1376 |
/* No line on use. Great !*/ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1377 |
/* Try to open a new line.*/ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1378 |
err = getSDOfreeLine( d, whoami, &line ); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1379 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1380 |
MSG_ERR(0x1A73, "SDO error : No line free, too many SDO in progress. Aborted.", 0); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1381 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1382 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1383 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1384 |
initSDOline(d, line, CliServNbr, index, subIndex, SDO_BLOCK_UPLOAD_IN_PROGRESS); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1385 |
d->transfers[line].peerCRCsupport = ((m->data[0])>>2) & 1; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1386 |
d->transfers[line].blksize = m->data[4]; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1387 |
/* Transfer data from dictionary to the line structure. */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1388 |
errorCode = objdictToSDOline(d, line); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1389 |
if (errorCode) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1390 |
MSG_ERR(0x1A95, "SDO error : Unable to copy the data from object dictionary. Err code : ", |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1391 |
errorCode); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1392 |
failedSDO(d, CliServNbr, whoami, index, subIndex, errorCode); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1393 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1394 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1395 |
/* Preparing the response.*/ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1396 |
getSDOlineRestBytes(d, line, &nbBytes); /* get Nb bytes to transfer */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1397 |
d->transfers[line].objsize = nbBytes; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1398 |
data[0] = (6 << 5) | (1 << 1) | SDO_BSS_INITIATE_UPLOAD_RESPONSE; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1399 |
data[1] = index & 0xFF; /* LSB */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1400 |
data[2] = (index >> 8) & 0xFF; /* MSB */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1401 |
data[3] = subIndex; |
700 | 1402 |
data[4] = (UNS8) nbBytes; |
1403 |
data[5] = (UNS8) (nbBytes >> 8); |
|
1404 |
data[6] = (UNS8) (nbBytes >> 16); |
|
1405 |
data[7] = (UNS8) (nbBytes >> 24); |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1406 |
MSG_WAR(0x3A9A, "SDO. Sending normal block upload initiate response defined at index 0x1200 + ", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1407 |
sendSDO(d, whoami, CliServNbr, data); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1408 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1409 |
else if (SubCommand == SDO_BCS_END_UPLOAD_REQUEST) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1410 |
MSG_WAR(0x3AA2, "Received SDO block END upload request defined at index 0x1200 + ", CliServNbr); |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1411 |
/* A SDO transfer should have been yet initiated. */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1412 |
if (!err) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1413 |
err = d->transfers[line].state != SDO_BLOCK_UPLOAD_IN_PROGRESS; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1414 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1415 |
MSG_ERR(0x1AA1, "SDO error : Received block upload request for unstarted trans. index 0x1200 + ", |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1416 |
CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1417 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1418 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1419 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1420 |
/* Release the line */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1421 |
resetSDOline(d, line); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1422 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1423 |
else if ((SubCommand == SDO_BCS_UPLOAD_RESPONSE) || (SubCommand == SDO_BCS_START_UPLOAD)) { |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1424 |
/* A SDO transfer should have been yet initiated. */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1425 |
if (!err) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1426 |
err = d->transfers[line].state != SDO_BLOCK_UPLOAD_IN_PROGRESS; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1427 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1428 |
MSG_ERR(0x1AA1, "SDO error : Received block upload response for unstarted trans. index 0x1200 + ", |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1429 |
CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1430 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1431 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1432 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1433 |
/* Reset the wathdog */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1434 |
RestartSDO_TIMER(line); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1435 |
/* Uploading first or next block */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1436 |
index = d->transfers[line].index; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1437 |
subIndex = d->transfers[line].subIndex; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1438 |
if (SubCommand == SDO_BCS_UPLOAD_RESPONSE) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1439 |
MSG_WAR(0x3AA2, "Received SDO block upload response defined at index 0x1200 + ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1440 |
d->transfers[line].blksize = m->data[2]; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1441 |
AckSeq = (m->data[1]) & 0x7f; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1442 |
getSDOlineRestBytes(d, line, &nbBytes); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1443 |
if((nbBytes == 0) && (AckSeq == d->transfers[line].seqno)){ /* Si tout est envoyé et confirmé reçu on envoi un block end upload response */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1444 |
data[0] = (6 << 5) | ((d->transfers[line].endfield) << 2) | SDO_BSS_END_UPLOAD_RESPONSE; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1445 |
for (i = 1 ; i < 8 ; i++) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1446 |
data[i] = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1447 |
MSG_WAR(0x3AA5, "SDO. Sending block END upload response defined at index 0x1200 + ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1448 |
sendSDO(d, whoami, CliServNbr, data); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1449 |
break; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1450 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1451 |
else |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1452 |
d->transfers[line].offset = d->transfers[line].lastblockoffset + 7 * AckSeq; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1453 |
if(d->transfers[line].offset > d->transfers[line].count) { /* Bad AckSeq reveived (too high) */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1454 |
MSG_ERR(0x1AA1, "SDO error : Received upload response with bad ackseq index 0x1200 + ", |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1455 |
CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1456 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1457 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1458 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1459 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1460 |
else |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1461 |
MSG_WAR(0x3AA2, "Received SDO block START upload defined at index 0x1200 + ", CliServNbr); |
700 | 1462 |
d->transfers[line].lastblockoffset = (UNS8) d->transfers[line].offset; |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1463 |
for(SeqNo = 1 ; SeqNo <= d->transfers[line].blksize ; SeqNo++) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1464 |
d->transfers[line].seqno = SeqNo; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1465 |
getSDOlineRestBytes(d, line, &nbBytes); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1466 |
if (nbBytes > 7) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1467 |
/* The segment to transfer is not the last one.*/ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1468 |
data[0] = SeqNo; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1469 |
err = lineToSDO(d, line, 7, data + 1); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1470 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1471 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1472 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1473 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1474 |
MSG_WAR(0x3AA5, "SDO. Sending upload segment defined at index 0x1200 + ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1475 |
sendSDO(d, whoami, CliServNbr, data); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1476 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1477 |
else { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1478 |
/* Last segment is in this block */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1479 |
data[0] = 0x80 | SeqNo; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1480 |
err = lineToSDO(d, line, nbBytes, data + 1); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1481 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1482 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1483 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1484 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1485 |
for (i = nbBytes + 1 ; i < 8 ; i++) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1486 |
data[i] = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1487 |
MSG_WAR(0x3AA5, "SDO. Sending last upload segment defined at index 0x1200 + ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1488 |
sendSDO(d, whoami, CliServNbr, data); |
700 | 1489 |
d->transfers[line].endfield = (UNS8) (7 - nbBytes); |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1490 |
break; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1491 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1492 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1493 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1494 |
} /* end if SERVER */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1495 |
else { /* if CLIENT (block download) */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1496 |
if ((SubCommand == SDO_BSS_INITIATE_DOWNLOAD_RESPONSE) || (SubCommand == SDO_BSS_DOWNLOAD_RESPONSE)) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1497 |
/* We should find a line opened for this. */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1498 |
if (!err) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1499 |
err = d->transfers[line].state != SDO_BLOCK_DOWNLOAD_IN_PROGRESS; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1500 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1501 |
MSG_ERR(0x1AAA, "SDO error : Received response for unknown block download request from node id", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1502 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1503 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1504 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1505 |
/* Reset the watchdog */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1506 |
RestartSDO_TIMER(line) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1507 |
if (SubCommand == SDO_BSS_INITIATE_DOWNLOAD_RESPONSE) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1508 |
index = d->transfers[line].index; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1509 |
subIndex = d->transfers[line].subIndex; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1510 |
d->transfers[line].peerCRCsupport = ((m->data[0])>>2) & 1; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1511 |
d->transfers[line].blksize = m->data[4]; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1512 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1513 |
else { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1514 |
d->transfers[line].blksize = m->data[2]; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1515 |
AckSeq = (m->data[1]) & 0x7f; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1516 |
getSDOlineRestBytes(d, line, &nbBytes); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1517 |
if((nbBytes == 0) && (AckSeq == d->transfers[line].seqno)){ /* Si tout est envoyé et confirmé reçu on envoi un block end download request */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1518 |
data[0] = (6 << 5) | ((d->transfers[line].endfield) << 2) | SDO_BCS_END_DOWNLOAD_REQUEST; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1519 |
for (i = 1 ; i < 8 ; i++) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1520 |
data[i] = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1521 |
MSG_WAR(0x3AA5, "SDO. Sending block END download request defined at index 0x1200 + ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1522 |
sendSDO(d, whoami, CliServNbr, data); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1523 |
break; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1524 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1525 |
else |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1526 |
d->transfers[line].offset = d->transfers[line].lastblockoffset + 7 * AckSeq; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1527 |
if(d->transfers[line].offset > d->transfers[line].count) { /* Bad AckSeq reveived (too high) */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1528 |
MSG_ERR(0x1AA1, "SDO error : Received upload segment with bad ackseq index 0x1200 + ", |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1529 |
CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1530 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1531 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1532 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1533 |
} |
700 | 1534 |
d->transfers[line].lastblockoffset = (UNS8) d->transfers[line].offset; |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1535 |
for(SeqNo = 1 ; SeqNo <= d->transfers[line].blksize ; SeqNo++) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1536 |
d->transfers[line].seqno = SeqNo; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1537 |
getSDOlineRestBytes(d, line, &nbBytes); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1538 |
if (nbBytes > 7) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1539 |
/* The segment to transfer is not the last one.*/ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1540 |
data[0] = SeqNo; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1541 |
err = lineToSDO(d, line, 7, data + 1); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1542 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1543 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1544 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1545 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1546 |
MSG_WAR(0x3AAB, "SDO. Sending download segment to node id ", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1547 |
sendSDO(d, whoami, CliServNbr, data); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1548 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1549 |
else { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1550 |
/* Last segment is in this block */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1551 |
data[0] = 0x80 | SeqNo; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1552 |
err = lineToSDO(d, line, nbBytes, data + 1); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1553 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1554 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1555 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1556 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1557 |
for (i = nbBytes + 1 ; i < 8 ; i++) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1558 |
data[i] = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1559 |
MSG_WAR(0x3AAB, "SDO. Sending last download segment to node id ", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1560 |
sendSDO(d, whoami, CliServNbr, data); |
700 | 1561 |
d->transfers[line].endfield = (UNS8) (7 - nbBytes); |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1562 |
break; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1563 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1564 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1565 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1566 |
else if (SubCommand == SDO_BSS_END_DOWNLOAD_RESPONSE) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1567 |
MSG_WAR(0x3AAC, "SDO End block download response from nodeId", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1568 |
StopSDO_TIMER(line) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1569 |
d->transfers[line].state = SDO_FINISHED; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1570 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1571 |
return 0x00; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1572 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1573 |
else { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1574 |
MSG_ERR(0x1AAB, "SDO error block download : Received wrong subcommand from nodeId", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1575 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1576 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1577 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1578 |
} /* end if CLIENT */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1579 |
break; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1580 |
case 6: /* Command specifier for data reception - the client or server is the data consumer */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1581 |
if (whoami == SDO_SERVER) { /* Server block download */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1582 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1583 |
/* Nothing already started */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1584 |
SubCommand = (m->data[0]) & 1; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1585 |
if (SubCommand != SDO_BCS_INITIATE_DOWNLOAD_REQUEST) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1586 |
MSG_ERR(0x1AAC, "SDO error block download : Received wrong subcommand from node id", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1587 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1588 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1589 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1590 |
index = getSDOindex(m->data[1],m->data[2]); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1591 |
subIndex = getSDOsubIndex(m->data[3]); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1592 |
MSG_WAR(0x3A9B, "Received SDO block download initiate defined at index 0x1200 + ", |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1593 |
CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1594 |
MSG_WAR(0x3A9B, "Writing at index : ", index); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1595 |
MSG_WAR(0x3A9B, "Writing at subIndex : ", subIndex); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1596 |
/* Try to open a new line. */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1597 |
err = getSDOfreeLine( d, whoami, &line ); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1598 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1599 |
MSG_ERR(0x1A89, "SDO error : No line free, too many SDO in progress. Aborted.", 0); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1600 |
failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1601 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1602 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1603 |
initSDOline(d, line, CliServNbr, index, subIndex, SDO_BLOCK_DOWNLOAD_IN_PROGRESS); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1604 |
d->transfers[line].rxstep = RXSTEP_STARTED; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1605 |
d->transfers[line].peerCRCsupport = ((m->data[0])>>2) & 1; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1606 |
if ((m->data[0]) & 2) /* if data set size is indicated */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1607 |
d->transfers[line].objsize = (UNS32)m->data[4] + (UNS32)m->data[5]*256 + (UNS32)m->data[6]*256*256 + (UNS32)m->data[7]*256*256*256; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1608 |
data[0] = (5 << 5) | SDO_BSS_INITIATE_DOWNLOAD_RESPONSE; |
700 | 1609 |
data[1] = (UNS8) index; /* LSB */ |
1610 |
data[2] = (UNS8) (index >> 8); /* MSB */ |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1611 |
data[3] = subIndex; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1612 |
data[4] = SDO_BLOCK_SIZE; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1613 |
data[5] = data[6] = data[7] = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1614 |
MSG_WAR(0x3AAD, "SDO. Sending block download initiate response - index 0x1200 + ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1615 |
sendSDO(d, whoami, CliServNbr, data); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1616 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1617 |
else if (d->transfers[line].rxstep == RXSTEP_STARTED) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1618 |
MSG_WAR(0x3A9B, "Received SDO block download data segment - index 0x1200 + ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1619 |
RestartSDO_TIMER(line) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1620 |
SeqNo = m->data[0] & 0x7F; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1621 |
if (m->data[0] & 0x80) { /* Last segment ? */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1622 |
if(SeqNo == (d->transfers[line].seqno + 1)) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1623 |
d->transfers[line].rxstep = RXSTEP_END; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1624 |
d->transfers[line].seqno = SeqNo; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1625 |
/* Store the data temporary because we don't know yet how many bytes do not contain data */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1626 |
memcpy(d->transfers[line].tmpData, m->data, 8); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1627 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1628 |
data[0] = (5 << 5) | SDO_BSS_DOWNLOAD_RESPONSE; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1629 |
data[1] = d->transfers[line].seqno; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1630 |
data[2] = SDO_BLOCK_SIZE; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1631 |
data[3] = data[4] = data[5] = data[6] = data[7] = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1632 |
MSG_WAR(0x3AAE, "SDO. Sending block download response - index 0x1200 + ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1633 |
sendSDO(d, whoami, CliServNbr, data); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1634 |
d->transfers[line].seqno = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1635 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1636 |
else { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1637 |
if (SeqNo == (d->transfers[line].seqno + 1)) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1638 |
d->transfers[line].seqno = SeqNo; |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1639 |
/* Store the data in the transfer structure. */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1640 |
err = SDOtoLine(d, line, 7, (*m).data + 1); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1641 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1642 |
failedSDO(d, CliServNbr, whoami, d->transfers[line].index, d->transfers[line].subIndex, SDOABT_GENERAL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1643 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1644 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1645 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1646 |
if (SeqNo == SDO_BLOCK_SIZE) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1647 |
data[0] = (5 << 5) | SDO_BSS_DOWNLOAD_RESPONSE; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1648 |
data[1] = d->transfers[line].seqno; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1649 |
data[2] = SDO_BLOCK_SIZE; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1650 |
data[3] = data[4] = data[5] = data[6] = data[7] = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1651 |
MSG_WAR(0x3AAE, "SDO. Sending block download response - index 0x1200 + ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1652 |
sendSDO(d, whoami, CliServNbr, data); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1653 |
d->transfers[line].seqno = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1654 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1655 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1656 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1657 |
else if (d->transfers[line].rxstep == RXSTEP_END) { /* endphase */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1658 |
MSG_WAR(0x3A9B, "Received SDO block download end request - index 0x1200 + ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1659 |
/* here store remaining bytes in tmpData to line, check size and confirm or abort */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1660 |
if ((m->data[0] & 1) != SDO_BCS_END_DOWNLOAD_REQUEST) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1661 |
MSG_ERR(0x1AAD, "SDO error block download : Received wrong subcommand - index 0x1200 + ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1662 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1663 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1664 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1665 |
RestartSDO_TIMER(line) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1666 |
NbBytesNoData = (m->data[0]>>2) & 0x07; |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1667 |
/* Store the data in the transfer structure. */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1668 |
err = SDOtoLine(d, line, 7-NbBytesNoData, d->transfers[line].tmpData + 1); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1669 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1670 |
failedSDO(d, CliServNbr, whoami, d->transfers[line].index, d->transfers[line].subIndex, SDOABT_GENERAL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1671 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1672 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1673 |
if(d->transfers[line].objsize){ /* If size was indicated in the initiate request */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1674 |
if (d->transfers[line].objsize != d->transfers[line].offset){ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1675 |
MSG_ERR(0x1AAE, "SDO error block download : sizes do not match - index 0x1200 + ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1676 |
failedSDO(d, CliServNbr, whoami, d->transfers[line].index, d->transfers[line].subIndex, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1677 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1678 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1679 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1680 |
data[0] = (5 << 5) | SDO_BSS_END_DOWNLOAD_RESPONSE; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1681 |
for (i = 1 ; i < 8 ; i++) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1682 |
data[i] = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1683 |
MSG_WAR(0x3AAF, "SDO. Sending block download end response - index 0x1200 + ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1684 |
sendSDO(d, whoami, CliServNbr, data); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1685 |
/* Transfering line data to object dictionary. */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1686 |
errorCode = SDOlineToObjdict(d, line); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1687 |
if (errorCode) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1688 |
MSG_ERR(0x1AAF, "SDO error : Unable to copy the data in the object dictionary", 0); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1689 |
failedSDO(d, CliServNbr, whoami, d->transfers[line].index, d->transfers[line].subIndex, errorCode); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1690 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1691 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1692 |
/* Release of the line */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1693 |
resetSDOline(d, line); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1694 |
MSG_WAR(0x3AAF, "SDO. End of block download defined at index 0x1200 + ", CliServNbr); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1695 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1696 |
} /* end if SERVER */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1697 |
else { /* if CLIENT (block upload) */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1698 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1699 |
/* Nothing already started */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1700 |
MSG_ERR(0x1AAD, "SDO error block upload : no transmission started", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1701 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1702 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1703 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1704 |
RestartSDO_TIMER(line) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1705 |
if (d->transfers[line].rxstep == RXSTEP_INIT) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1706 |
if ((m->data[0] & 1) == SDO_BSS_INITIATE_UPLOAD_RESPONSE) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1707 |
MSG_WAR(0x3A9C, "Received SDO block upload response from node id ", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1708 |
d->transfers[line].rxstep = RXSTEP_STARTED; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1709 |
d->transfers[line].peerCRCsupport = ((m->data[0])>>2) & 1; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1710 |
if ((m->data[0]) & 2) /* if data set size is indicated */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1711 |
d->transfers[line].objsize = (UNS32)m->data[4] + (UNS32)m->data[5]*256 + (UNS32)m->data[6]*256*256 + (UNS32)m->data[7]*256*256*256; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1712 |
data[0] = (5 << 5) | SDO_BCS_START_UPLOAD; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1713 |
for (i = 1 ; i < 8 ; i++) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1714 |
data[i] = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1715 |
MSG_WAR(0x3AB6, "SDO. Sending block upload start to node id ", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1716 |
sendSDO(d, whoami, CliServNbr, data); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1717 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1718 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1719 |
else if (d->transfers[line].rxstep == RXSTEP_STARTED) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1720 |
SeqNo = m->data[0] & 0x7F; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1721 |
if (m->data[0] & 0x80) { /* Last segment ? */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1722 |
if(SeqNo == (d->transfers[line].seqno + 1)) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1723 |
d->transfers[line].rxstep = RXSTEP_END; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1724 |
d->transfers[line].seqno = SeqNo; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1725 |
/* Store the data temporary because we don't know yet how many bytes do not contain data */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1726 |
memcpy(d->transfers[line].tmpData, m->data, 8); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1727 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1728 |
data[0] = (5 << 5) | SDO_BCS_UPLOAD_RESPONSE; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1729 |
data[1] = d->transfers[line].seqno; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1730 |
data[2] = SDO_BLOCK_SIZE; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1731 |
data[3] = data[4] = data[5] = data[6] = data[7] = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1732 |
MSG_WAR(0x3AB7, "SDO. Sending block upload response to node id ", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1733 |
sendSDO(d, whoami, CliServNbr, data); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1734 |
d->transfers[line].seqno = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1735 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1736 |
else { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1737 |
if (SeqNo == (d->transfers[line].seqno + 1)) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1738 |
d->transfers[line].seqno = SeqNo; |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1739 |
/* Store the data in the transfer structure. */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1740 |
err = SDOtoLine(d, line, 7, (*m).data + 1); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1741 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1742 |
failedSDO(d, CliServNbr, whoami, d->transfers[line].index, d->transfers[line].subIndex, SDOABT_GENERAL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1743 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1744 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1745 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1746 |
if (SeqNo == SDO_BLOCK_SIZE) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1747 |
data[0] = (5 << 5) | SDO_BCS_UPLOAD_RESPONSE; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1748 |
data[1] = d->transfers[line].seqno; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1749 |
data[2] = SDO_BLOCK_SIZE; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1750 |
data[3] = data[4] = data[5] = data[6] = data[7] = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1751 |
MSG_WAR(0x3AAE, "SDO. Sending block upload response to node id ", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1752 |
sendSDO(d, whoami, CliServNbr, data); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1753 |
d->transfers[line].seqno = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1754 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1755 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1756 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1757 |
else if (d->transfers[line].rxstep == RXSTEP_END) { /* endphase */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1758 |
/* here store remaining bytes in tmpData to line, check size and confirm or abort */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1759 |
if ((m->data[0] & 1) != SDO_BSS_END_UPLOAD_RESPONSE) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1760 |
MSG_ERR(0x1AAD, "SDO error block upload : Received wrong subcommand from node id ", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1761 |
failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1762 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1763 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1764 |
NbBytesNoData = (m->data[0]>>2) & 0x07; |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1765 |
/* Store the data in the transfer structure. */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1766 |
err = SDOtoLine(d, line, 7-NbBytesNoData, d->transfers[line].tmpData + 1); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1767 |
if (err) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1768 |
failedSDO(d, CliServNbr, whoami, d->transfers[line].index, d->transfers[line].subIndex, SDOABT_GENERAL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1769 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1770 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1771 |
if(d->transfers[line].objsize){ /* If size was indicated in the initiate request */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1772 |
if (d->transfers[line].objsize != d->transfers[line].offset){ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1773 |
MSG_ERR(0x1AAE, "SDO error block download : sizes do not match - from node id ", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1774 |
failedSDO(d, CliServNbr, whoami, d->transfers[line].index, d->transfers[line].subIndex, SDOABT_LOCAL_CTRL_ERROR); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1775 |
return 0xFF; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1776 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1777 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1778 |
data[0] = (5 << 5) | SDO_BCS_END_UPLOAD_REQUEST; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1779 |
for (i = 1 ; i < 8 ; i++) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1780 |
data[i] = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1781 |
MSG_WAR(0x3AAF, "SDO. Sending block upload end request to node id ", nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1782 |
sendSDO(d, whoami, CliServNbr, data); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1783 |
MSG_WAR(0x3AAF, "SDO. End of block upload request", 0); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1784 |
StopSDO_TIMER(line) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1785 |
d->transfers[line].state = SDO_FINISHED; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1786 |
if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1787 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1788 |
} /* end if CLIENT */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1789 |
break; |
663 | 1790 |
default: |
1791 |
/* Error : Unknown cs */ |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1792 |
MSG_ERR(0x1AB2, "SDO. Received unknown command specifier : ", cs); |
663 | 1793 |
return 0xFF; |
1794 |
||
1795 |
} /* End switch */ |
|
1796 |
return 0; |
|
1797 |
} |
|
1798 |
||
1799 |
||
1800 |
/*! |
|
1801 |
** |
|
1802 |
** |
|
1803 |
** @param d |
|
1804 |
** @param nodeId |
|
1805 |
** |
|
1806 |
** @return |
|
1807 |
** 0xFF : No SDO client available |
|
1808 |
** 0xFE : Not found |
|
1809 |
** otherwise : SDO client number |
|
1810 |
**/ |
|
1811 |
UNS8 GetSDOClientFromNodeId( CO_Data* d, UNS8 nodeId ) |
|
1812 |
{ |
|
1813 |
UNS8 SDOfound = 0; |
|
1814 |
UNS8 CliNbr; |
|
1815 |
UNS16 lastIndex; |
|
1816 |
UNS16 offset; |
|
1817 |
UNS8 nodeIdServer; |
|
1818 |
||
1819 |
offset = d->firstIndex->SDO_CLT; |
|
1820 |
lastIndex = d->lastIndex->SDO_CLT; |
|
1821 |
if (offset == 0) { |
|
1822 |
MSG_ERR(0x1AC6, "No SDO client index found for nodeId ", nodeId); |
|
1823 |
return 0xFF; |
|
1824 |
} |
|
1825 |
CliNbr = 0; |
|
1826 |
while (offset <= lastIndex) { |
|
1827 |
if (d->objdict[offset].bSubCount <= 3) { |
|
1828 |
MSG_ERR(0x1AC8, "Subindex 3 not found at index ", 0x1280 + CliNbr); |
|
1829 |
return 0xFF; |
|
1830 |
} |
|
1831 |
/* looking for the server nodeId */ |
|
1832 |
nodeIdServer = *((UNS8*) d->objdict[offset].pSubindex[3].pObject); |
|
1833 |
MSG_WAR(0x1AD2, "index : ", 0x1280 + CliNbr); |
|
1834 |
MSG_WAR(0x1AD3, "nodeIdServer : ", nodeIdServer); |
|
1835 |
||
1836 |
if(nodeIdServer == nodeId) { |
|
1837 |
SDOfound = 1; |
|
1838 |
break; |
|
1839 |
} |
|
1840 |
offset++; |
|
1841 |
CliNbr++; |
|
1842 |
} /* end while */ |
|
1843 |
if (!SDOfound) { |
|
711 | 1844 |
MSG_WAR(0x1AC9, "SDO No preset client found to communicate with node : ", nodeId); |
663 | 1845 |
return 0xFE; |
1846 |
} |
|
1847 |
MSG_WAR(0x3AD0," SDO client defined at index : ", 0x1280 + CliNbr); |
|
1848 |
||
1849 |
return CliNbr; |
|
1850 |
} |
|
1851 |
||
1852 |
||
1853 |
/*! |
|
1854 |
** |
|
1855 |
** |
|
1856 |
** @param d |
|
1857 |
** @param nodeId |
|
1858 |
** @param index |
|
1859 |
** @param subIndex |
|
1860 |
** @param count |
|
1861 |
** @param dataType |
|
1862 |
** @param data |
|
1863 |
** @param Callback |
|
1864 |
** @param endianize |
|
1865 |
** |
|
1866 |
** @return |
|
1867 |
**/ |
|
1868 |
INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1869 |
UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize, UNS8 useBlockMode) |
663 | 1870 |
{ |
1871 |
UNS8 err; |
|
1872 |
UNS8 line; |
|
1873 |
UNS8 CliNbr; |
|
1874 |
UNS32 j; |
|
1875 |
UNS8 i; |
|
1876 |
UNS8 buf[8]; |
|
1877 |
||
1878 |
MSG_WAR(0x3AC0, "Send SDO to write in the dictionary of node : ", nodeId); |
|
1879 |
MSG_WAR(0x3AC1, " At index : ", index); |
|
1880 |
MSG_WAR(0x3AC2, " subIndex : ", subIndex); |
|
1881 |
MSG_WAR(0x3AC3, " nb bytes : ", count); |
|
1882 |
||
1883 |
/* First let's find the corresponding SDO client in our OD */ |
|
1884 |
CliNbr = GetSDOClientFromNodeId( d, nodeId); |
|
1885 |
if(CliNbr >= 0xFE) |
|
1886 |
return CliNbr; |
|
1887 |
/* Verify that there is no SDO communication yet. */ |
|
1888 |
err = getSDOlineOnUse(d, CliNbr, SDO_CLIENT, &line); |
|
1889 |
if (!err) { |
|
1890 |
MSG_ERR(0x1AC4, "SDO error : Communication yet established. with node : ", nodeId); |
|
1891 |
return 0xFF; |
|
1892 |
} |
|
1893 |
/* Taking the line ... */ |
|
1894 |
err = getSDOfreeLine( d, SDO_CLIENT, &line ); |
|
0 | 1895 |
if (err) { |
663 | 1896 |
MSG_ERR(0x1AC5, "SDO error : No line free, too many SDO in progress. Aborted for node : ", nodeId); |
1897 |
return (0xFF); |
|
1898 |
} |
|
669
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
667
diff
changeset
|
1899 |
else |
50da44ebaf00
Configuration manager with DCF in object 0x1F22 rewritten almost from scratch.
Mongo
parents:
667
diff
changeset
|
1900 |
MSG_WAR(0x3AE1, "Transmission on line : ", line); |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1901 |
if(useBlockMode) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1902 |
initSDOline(d, line, CliNbr, index, subIndex, SDO_BLOCK_DOWNLOAD_IN_PROGRESS); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1903 |
d->transfers[line].objsize = count; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1904 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1905 |
else |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1906 |
initSDOline(d, line, CliNbr, index, subIndex, SDO_DOWNLOAD_IN_PROGRESS); |
663 | 1907 |
d->transfers[line].count = count; |
1908 |
d->transfers[line].dataType = dataType; |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
1909 |
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION |
663 | 1910 |
{ |
1911 |
UNS8* lineData = d->transfers[line].data; |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1912 |
if (count > SDO_MAX_LENGTH_TRANSFER) |
663 | 1913 |
{ |
1914 |
d->transfers[line].dynamicData = (UNS8*) malloc(count); |
|
1915 |
d->transfers[line].dynamicDataSize = count; |
|
1916 |
if (d->transfers[line].dynamicData == NULL) |
|
1917 |
{ |
|
1918 |
MSG_ERR(0x1AC9, "SDO. Error. Could not allocate enough bytes : ", count); |
|
1919 |
return 0xFE; |
|
1920 |
} |
|
1921 |
lineData = d->transfers[line].dynamicData; |
|
1922 |
} |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
1923 |
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION |
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
1924 |
|
663 | 1925 |
/* Copy data to transfers structure. */ |
1926 |
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
|
1927 |
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION |
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
1928 |
# ifdef CANOPEN_BIG_ENDIAN |
663 | 1929 |
if (dataType == 0 && endianize) |
1930 |
lineData[count - 1 - j] = ((char *)data)[j]; |
|
1931 |
else /* String of bytes. */ |
|
1932 |
lineData[j] = ((char *)data)[j]; |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
1933 |
# else |
663 | 1934 |
lineData[j] = ((char *)data)[j]; |
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
1935 |
# endif |
663 | 1936 |
} |
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
1937 |
#else //SDO_DYNAMIC_BUFFER_ALLOCATION |
0 | 1938 |
# ifdef CANOPEN_BIG_ENDIAN |
663 | 1939 |
if (dataType == 0 && endianize) |
1940 |
d->transfers[line].data[count - 1 - j] = ((char *)data)[j]; |
|
1941 |
else /* String of bytes. */ |
|
1942 |
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
|
1943 |
# else |
663 | 1944 |
d->transfers[line].data[j] = ((char *)data)[j]; |
0 | 1945 |
# endif |
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
1946 |
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION |
663 | 1947 |
} |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1948 |
if(useBlockMode) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1949 |
buf[0] = (6 << 5) | (1 << 1 ); /* CCS = 6 , CC = 0 , S = 1 , CS = 0 */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1950 |
for (i = 0 ; i < 4 ; i++) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1951 |
buf[i+4] = (UNS8)((count >> (i<<3))); /* i*8 */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1952 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1953 |
else { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1954 |
/* Send the SDO to the server. Initiate download, cs=1. */ |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1955 |
if (count <= 4) { /* Expedited transfer */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1956 |
buf[0] = (UNS8)((1 << 5) | ((4 - count) << 2) | 3); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1957 |
for (i = 4 ; i < 8 ; i++) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1958 |
buf[i] = d->transfers[line].data[i - 4]; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1959 |
d->transfers[line].offset = count; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1960 |
} |
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
1961 |
else { /** Normal transfer */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1962 |
buf[0] = (1 << 5) | 1; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1963 |
for (i = 0 ; i < 4 ; i++) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1964 |
buf[i+4] = (UNS8)((count >> (i<<3))); /* i*8 */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1965 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
1966 |
} |
663 | 1967 |
buf[1] = index & 0xFF; /* LSB */ |
1968 |
buf[2] = (index >> 8) & 0xFF; /* MSB */ |
|
1969 |
buf[3] = subIndex; |
|
1970 |
||
1971 |
d->transfers[line].Callback = Callback; |
|
1972 |
||
1973 |
err = sendSDO(d, SDO_CLIENT, CliNbr, buf); |
|
1974 |
if (err) { |
|
1975 |
MSG_ERR(0x1AD1, "SDO. Error while sending SDO to node : ", nodeId); |
|
1976 |
/* release the line */ |
|
1977 |
resetSDOline(d, line); |
|
1978 |
return 0xFF; |
|
1979 |
} |
|
1980 |
||
1981 |
||
1982 |
return 0; |
|
1983 |
} |
|
1984 |
||
1985 |
/*! |
|
1986 |
** |
|
1987 |
** |
|
1988 |
** @param d |
|
1989 |
** @param nodeId |
|
1990 |
** @param index |
|
1991 |
** @param subIndex |
|
1992 |
** @param count |
|
1993 |
** @param dataType |
|
1994 |
** @param data |
|
717
cfb4f62f35af
Fixed example TestMasterSlaveLSS in Master.c missing argument in writeNetworkDictCallBack
Mongo
parents:
711
diff
changeset
|
1995 |
** @param useBlockMode |
663 | 1996 |
** |
1997 |
** @return |
|
1998 |
**/ |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
1999 |
UNS8 writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2000 |
UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, UNS8 useBlockMode) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2001 |
{ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2002 |
return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, NULL, 1, useBlockMode); |
32 | 2003 |
} |
2004 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2005 |
/*! |
663 | 2006 |
** |
2007 |
** |
|
2008 |
** @param d |
|
2009 |
** @param nodeId |
|
2010 |
** @param index |
|
2011 |
** @param subIndex |
|
2012 |
** @param count |
|
2013 |
** @param dataType |
|
2014 |
** @param data |
|
2015 |
** @param Callback |
|
717
cfb4f62f35af
Fixed example TestMasterSlaveLSS in Master.c missing argument in writeNetworkDictCallBack
Mongo
parents:
711
diff
changeset
|
2016 |
** @param useBlockMode |
663 | 2017 |
** |
2018 |
** @return |
|
2019 |
**/ |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2020 |
UNS8 writeNetworkDictCallBack (CO_Data* d, UNS8 nodeId, UNS16 index, |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2021 |
UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 useBlockMode) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2022 |
{ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2023 |
return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, Callback, 1, useBlockMode); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2024 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2025 |
|
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2026 |
UNS8 writeNetworkDictCallBackAI (CO_Data* d, UNS8 nodeId, UNS16 index, |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2027 |
UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize, UNS8 useBlockMode) |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2028 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2029 |
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
|
2030 |
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
|
2031 |
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
|
2032 |
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
|
2033 |
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
|
2034 |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2035 |
ret = _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, Callback, endianize, useBlockMode); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2036 |
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
|
2037 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2038 |
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
|
2039 |
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
|
2040 |
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
|
2041 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2042 |
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
|
2043 |
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
|
2044 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2045 |
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
|
2046 |
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
|
2047 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2048 |
if (d->objdict[offset].bSubCount <= 3) |
663 | 2049 |
{ |
2050 |
MSG_ERR(0x1AC8, "Subindex 3 not found at index ", 0x1280 + i); |
|
2051 |
return 0xFF; |
|
2052 |
} |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2053 |
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
|
2054 |
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
|
2055 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2056 |
*(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
|
2057 |
*(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
|
2058 |
*(UNS8*) d->objdict[offset].pSubindex[3].pObject = nodeId; |
672
3bbc9aeba925
bug correction in sdo.c, in writeNetworkDictCallBackAI a call to _writeNetworkDict had endianize forced to 1
Mongo
parents:
669
diff
changeset
|
2059 |
return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, Callback, endianize, useBlockMode); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2060 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2061 |
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
|
2062 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2063 |
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
|
2064 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2065 |
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
|
2066 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2067 |
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
|
2068 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2069 |
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
|
2070 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2071 |
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
|
2072 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2073 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2074 |
|
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2075 |
/*! |
663 | 2076 |
** |
2077 |
** |
|
2078 |
** @param d |
|
2079 |
** @param nodeId |
|
2080 |
** @param index |
|
2081 |
** @param subIndex |
|
2082 |
** @param dataType |
|
2083 |
** @param Callback |
|
717
cfb4f62f35af
Fixed example TestMasterSlaveLSS in Master.c missing argument in writeNetworkDictCallBack
Mongo
parents:
711
diff
changeset
|
2084 |
** @param useBlockMode |
663 | 2085 |
** |
2086 |
** @return |
|
2087 |
**/ |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2088 |
INLINE UNS8 _readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback, UNS8 useBlockMode) |
0 | 2089 |
{ |
663 | 2090 |
UNS8 err; |
2091 |
UNS8 i; |
|
2092 |
UNS8 CliNbr; |
|
2093 |
UNS8 line; |
|
2094 |
UNS8 data[8]; |
|
2095 |
||
2096 |
MSG_WAR(0x3AD5, "Send SDO to read in the dictionary of node : ", nodeId); |
|
2097 |
MSG_WAR(0x3AD6, " At index : ", index); |
|
2098 |
MSG_WAR(0x3AD7, " subIndex : ", subIndex); |
|
2099 |
||
2100 |
/* First let's find the corresponding SDO client in our OD */ |
|
2101 |
CliNbr = GetSDOClientFromNodeId( d, nodeId); |
|
2102 |
if(CliNbr >= 0xFE) |
|
2103 |
return CliNbr; |
|
2104 |
||
2105 |
/* Verify that there is no SDO communication yet. */ |
|
2106 |
err = getSDOlineOnUse(d, CliNbr, SDO_CLIENT, &line); |
|
2107 |
if (!err) { |
|
2108 |
MSG_ERR(0x1AD8, "SDO error : Communication yet established. with node : ", nodeId); |
|
2109 |
return 0xFF; |
|
2110 |
} |
|
2111 |
/* Taking the line ... */ |
|
2112 |
err = getSDOfreeLine( d, SDO_CLIENT, &line ); |
|
2113 |
if (err) { |
|
2114 |
MSG_ERR(0x1AD9, "SDO error : No line free, too many SDO in progress. Aborted for node : ", nodeId); |
|
2115 |
return (0xFF); |
|
2116 |
} |
|
2117 |
else |
|
2118 |
MSG_WAR(0x3AE0, "Transmission on line : ", line); |
|
2119 |
||
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2120 |
if(useBlockMode) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2121 |
initSDOline(d, line, CliNbr, index, subIndex, SDO_BLOCK_UPLOAD_IN_PROGRESS); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2122 |
/* Send the SDO to the server. Initiate block upload, cs=0. */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2123 |
d->transfers[line].dataType = dataType; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2124 |
data[0] = (5 << 5) | SDO_BCS_INITIATE_UPLOAD_REQUEST; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2125 |
data[1] = index & 0xFF; /* LSB */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2126 |
data[2] = (index >> 8) & 0xFF; /* MSB */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2127 |
data[3] = subIndex; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2128 |
data[4] = SDO_BLOCK_SIZE; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2129 |
for (i = 5 ; i < 8 ; i++) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2130 |
data[i] = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2131 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2132 |
else { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2133 |
initSDOline(d, line, CliNbr, index, subIndex, SDO_UPLOAD_IN_PROGRESS); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2134 |
/* Send the SDO to the server. Initiate upload, cs=2. */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2135 |
d->transfers[line].dataType = dataType; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2136 |
data[0] = (2 << 5); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2137 |
data[1] = index & 0xFF; /* LSB */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2138 |
data[2] = (index >> 8) & 0xFF; /* MSB */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2139 |
data[3] = subIndex; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2140 |
for (i = 4 ; i < 8 ; i++) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2141 |
data[i] = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2142 |
} |
663 | 2143 |
d->transfers[line].Callback = Callback; |
2144 |
err = sendSDO(d, SDO_CLIENT, CliNbr, data); |
|
2145 |
if (err) { |
|
2146 |
MSG_ERR(0x1AE5, "SDO. Error while sending SDO to node : ", nodeId); |
|
2147 |
/* release the line */ |
|
2148 |
resetSDOline(d, line); |
|
2149 |
return 0xFF; |
|
2150 |
} |
|
2151 |
return 0; |
|
2152 |
} |
|
2153 |
||
2154 |
/*! |
|
2155 |
** |
|
2156 |
** |
|
2157 |
** @param d |
|
2158 |
** @param nodeId |
|
2159 |
** @param index |
|
2160 |
** @param subIndex |
|
2161 |
** @param dataType |
|
717
cfb4f62f35af
Fixed example TestMasterSlaveLSS in Master.c missing argument in writeNetworkDictCallBack
Mongo
parents:
711
diff
changeset
|
2162 |
** @param useBlockMode |
663 | 2163 |
** |
2164 |
** @return |
|
2165 |
**/ |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2166 |
UNS8 readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, UNS8 useBlockMode) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2167 |
{ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2168 |
return _readNetworkDict (d, nodeId, index, subIndex, dataType, NULL, useBlockMode); |
32 | 2169 |
} |
2170 |
||
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2171 |
/*! |
663 | 2172 |
** |
2173 |
** |
|
2174 |
** @param d |
|
2175 |
** @param nodeId |
|
2176 |
** @param index |
|
2177 |
** @param subIndex |
|
2178 |
** @param dataType |
|
2179 |
** @param Callback |
|
717
cfb4f62f35af
Fixed example TestMasterSlaveLSS in Master.c missing argument in writeNetworkDictCallBack
Mongo
parents:
711
diff
changeset
|
2180 |
** @param useBlockMode |
663 | 2181 |
** |
2182 |
** @return |
|
2183 |
**/ |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2184 |
UNS8 readNetworkDictCallback (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback, UNS8 useBlockMode) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2185 |
{ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2186 |
return _readNetworkDict (d, nodeId, index, subIndex, dataType, Callback, useBlockMode); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2187 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2188 |
|
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2189 |
UNS8 readNetworkDictCallbackAI (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback, UNS8 useBlockMode) |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2190 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2191 |
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
|
2192 |
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
|
2193 |
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
|
2194 |
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
|
2195 |
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
|
2196 |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2197 |
ret = _readNetworkDict (d, nodeId, index, subIndex, dataType, Callback, useBlockMode); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2198 |
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
|
2199 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2200 |
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
|
2201 |
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
|
2202 |
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
|
2203 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2204 |
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
|
2205 |
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
|
2206 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2207 |
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
|
2208 |
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
|
2209 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2210 |
if (d->objdict[offset].bSubCount <= 3) |
663 | 2211 |
{ |
2212 |
MSG_ERR(0x1AC8, "Subindex 3 not found at index ", 0x1280 + i); |
|
2213 |
return 0xFF; |
|
2214 |
} |
|
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2215 |
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
|
2216 |
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
|
2217 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2218 |
*(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
|
2219 |
*(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
|
2220 |
*(UNS8*) d->objdict[offset].pSubindex[3].pObject = nodeId; |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2221 |
return _readNetworkDict (d, nodeId, index, subIndex, dataType, Callback, useBlockMode); |
506
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2222 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2223 |
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
|
2224 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2225 |
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
|
2226 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2227 |
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
|
2228 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2229 |
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
|
2230 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2231 |
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
|
2232 |
{ |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2233 |
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
|
2234 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2235 |
} |
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2236 |
|
c17e2e17aca8
Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents:
503
diff
changeset
|
2237 |
/*! |
663 | 2238 |
** |
2239 |
** |
|
2240 |
** @param d |
|
2241 |
** @param nodeId |
|
2242 |
** @param data |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2243 |
** @param size : *size MUST contain the size of *data buffer before calling |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2244 |
** The function set it to the actual number of written bytes |
663 | 2245 |
** @param abortCode |
2246 |
** |
|
2247 |
** @return |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2248 |
** SDO_PROVIDED_BUFFER_TOO_SMALL if *data is not big enough |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2249 |
** or any transmission status value. |
663 | 2250 |
**/ |
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
|
2251 |
UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, UNS32 *size, |
663 | 2252 |
UNS32 * abortCode) |
2253 |
{ |
|
2254 |
UNS32 i; |
|
2255 |
UNS8 err; |
|
2256 |
UNS8 CliNbr; |
|
2257 |
UNS8 line; |
|
2258 |
* abortCode = 0; |
|
2259 |
||
2260 |
/* First let's find the corresponding SDO client in our OD */ |
|
2261 |
CliNbr = GetSDOClientFromNodeId(d, nodeId); |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2262 |
if(CliNbr >= 0xFE) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2263 |
*size = 0; |
663 | 2264 |
return SDO_ABORTED_INTERNAL; |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2265 |
} |
663 | 2266 |
|
2267 |
/* Looking for the line tranfert. */ |
|
2268 |
err = getSDOlineOnUse(d, CliNbr, SDO_CLIENT, &line); |
|
2269 |
if (err) { |
|
2270 |
MSG_ERR(0x1AF0, "SDO error : No line found for communication with node : ", nodeId); |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2271 |
*size = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2272 |
return SDO_ABORTED_INTERNAL; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2273 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2274 |
|
694
8dd1e58b3815
There is no English word "transfert". Fix all the typos.
JaFojtik
parents:
682
diff
changeset
|
2275 |
/* If transfer not finished just return, but if aborted set abort code and size to 0 */ |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2276 |
if (d->transfers[line].state != SDO_FINISHED) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2277 |
if((d->transfers[line].state == SDO_ABORTED_RCV) || (d->transfers[line].state == SDO_ABORTED_INTERNAL)) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2278 |
*abortCode = d->transfers[line].abortCode; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2279 |
*size = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2280 |
} |
663 | 2281 |
return d->transfers[line].state; |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2282 |
} |
663 | 2283 |
|
2284 |
/* if SDO initiated with e=0 and s=0 count is null, offset carry effective size*/ |
|
2285 |
if( d->transfers[line].count == 0) |
|
2286 |
d->transfers[line].count = d->transfers[line].offset; |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2287 |
|
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2288 |
/* Check if the provided buffer is big enough */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2289 |
if(*size < d->transfers[line].count) { |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2290 |
*size = 0; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2291 |
return SDO_PROVIDED_BUFFER_TOO_SMALL; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2292 |
} |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2293 |
|
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2294 |
/* Give back actual size */ |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2295 |
*size = d->transfers[line].count; |
663 | 2296 |
|
2297 |
/* Copy payload to data pointer */ |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
2298 |
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION |
663 | 2299 |
{ |
2300 |
UNS8 *lineData = d->transfers[line].data; |
|
2301 |
||
2302 |
if (d->transfers[line].dynamicData && d->transfers[line].dynamicDataSize) |
|
2303 |
{ |
|
2304 |
lineData = d->transfers[line].dynamicData; |
|
2305 |
} |
|
2306 |
for ( i = 0 ; i < *size ; i++) { |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
2307 |
# ifdef CANOPEN_BIG_ENDIAN |
663 | 2308 |
if (d->transfers[line].dataType != visible_string) |
2309 |
( (char *) data)[*size - 1 - i] = lineData[i]; |
|
2310 |
else /* String of bytes. */ |
|
2311 |
( (char *) data)[i] = lineData[i]; |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
2312 |
# else |
663 | 2313 |
( (char *) data)[i] = lineData[i]; |
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
2314 |
# endif |
663 | 2315 |
} |
2316 |
} |
|
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
2317 |
#else //SDO_DYNAMIC_BUFFER_ALLOCATION |
663 | 2318 |
for ( i = 0 ; i < *size ; i++) { |
0 | 2319 |
# ifdef CANOPEN_BIG_ENDIAN |
663 | 2320 |
if (d->transfers[line].dataType != visible_string) |
2321 |
( (char *) data)[*size - 1 - i] = d->transfers[line].data[i]; |
|
2322 |
else /* String of bytes. */ |
|
2323 |
( (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
|
2324 |
# else |
663 | 2325 |
( (char *) data)[i] = d->transfers[line].data[i]; |
0 | 2326 |
# endif |
663 | 2327 |
} |
636
033fe6f1ec3c
ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents:
627
diff
changeset
|
2328 |
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION |
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2329 |
resetSDOline(d, line); |
663 | 2330 |
return SDO_FINISHED; |
2331 |
} |
|
2332 |
||
2333 |
/*! |
|
2334 |
** |
|
2335 |
** |
|
2336 |
** @param d |
|
2337 |
** @param nodeId |
|
2338 |
** @param abortCode |
|
2339 |
** |
|
2340 |
** @return |
|
2341 |
**/ |
|
0 | 2342 |
UNS8 getWriteResultNetworkDict (CO_Data* d, UNS8 nodeId, UNS32 * abortCode) |
2343 |
{ |
|
663 | 2344 |
UNS8 line = 0; |
2345 |
UNS8 err; |
|
2346 |
UNS8 CliNbr; |
|
2347 |
* abortCode = 0; |
|
2348 |
||
2349 |
/* First let's find the corresponding SDO client in our OD */ |
|
2350 |
CliNbr = GetSDOClientFromNodeId(d, nodeId); |
|
2351 |
if(CliNbr >= 0xFE) |
|
2352 |
return SDO_ABORTED_INTERNAL; |
|
2353 |
||
2354 |
/* Looking for the line tranfert. */ |
|
2355 |
err = getSDOlineOnUse(d, CliNbr, SDO_CLIENT, &line); |
|
2356 |
if (err) { |
|
2357 |
MSG_ERR(0x1AF1, "SDO error : No line found for communication with node : ", nodeId); |
|
2358 |
return SDO_ABORTED_INTERNAL; |
|
2359 |
} |
|
2360 |
* abortCode = d->transfers[line].abortCode; |
|
664
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2361 |
if (d->transfers[line].state != SDO_FINISHED) |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2362 |
return d->transfers[line].state; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2363 |
resetSDOline(d, line); |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2364 |
return SDO_FINISHED; |
a03f0aa7d219
CHANGE: SDO block mode added, without CRC support
fbeaulier
parents:
663
diff
changeset
|
2365 |
} |