2 This file is part of CanFestival, a library implementing CanOpen
5 Copyright (C): Edouard TISSERANT and Francis DUPIN
7 See COPYING file for copyrights details.
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 ** @author Edouard TISSERANT and Francis DUPIN
29 ** @date Mon Jun 4 17:06:12 2007
31 ** @brief EXEMPLE OF SOMMARY
40 extern UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
41 UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize);
44 static void send_consise_dcf_loop(CO_Data* d,UNS8 nodeId);
46 /* Seek to next NodeID's DCF */
47 #define SEEK_NEXT_DCF() \
48 nodeId=(nodeId+1) % d->dcf_odentry->bSubCount; \
49 if(nodeId==0) nodeId=1; \
58 static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId)
62 if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
64 MSG_ERR(0x1A01, "SDO error in consise DCF", abortCode);
65 MSG_WAR(0x2A02, "server node : ", nodeId);
68 closeSDOtransfer(d, nodeId, SDO_CLIENT);
70 if(abortCode == SDOABT_TIMED_OUT){
71 /* Node may not be ready, try another one */
72 /* Warning, this might leed to endless attempts */
73 /* if node does never answer */
76 send_consise_dcf_loop(d,nodeId);
88 UNS8 send_consise_dcf(CO_Data* d,UNS8 nodeId)
91 /* Fetch DCF OD entry, if not already done */
95 ODCallback_t *Callback;
96 d->dcf_odentry = (*d->scanIndexOD)(0x1F22, &errorCode, &Callback);
97 /* If DCF entry do not exist... Nothing to do.*/
98 if (errorCode != OD_SUCCESSFUL) goto DCF_finish;
101 szData = d->dcf_odentry->pSubindex[nodeId].size;
103 /* if the entry for the nodeId is not empty. */
105 /* if the entry for the nodeId is already been processing, quit.*/
106 if(d->dcf_odentry->pSubindex[nodeId].bAccessType & DCF_TO_SEND) return 1;
108 d->dcf_odentry->pSubindex[nodeId].bAccessType|=DCF_TO_SEND;
110 if(d->dcf_request==1)
111 send_consise_dcf_loop(d,nodeId);
119 static void send_consise_dcf_loop(CO_Data* d,UNS8 nodeId)
121 /* Loop on all DCF subindexes, corresponding to node ID until there is no request*/
122 //while (nodeId < d->dcf_odentry->bSubCount){
123 while (d->dcf_request>0){
124 if(d->dcf_odentry->pSubindex[nodeId].bAccessType & DCF_TO_SEND){
127 UNS8 szData = d->dcf_odentry->pSubindex[nodeId].size;
130 UNS8* dcf = *((UNS8**)d->dcf_odentry->pSubindex[nodeId].pObject);
131 dcfend = dcf + szData;
133 d->dcf_cursor = (UNS8*)dcf + 4;
134 d->dcf_entries_count = 0;
136 nb_entries = UNS32_LE(*((UNS32*)dcf));
139 /* condition on consise DCF string for NodeID, if big enough */
140 if((UNS8*)d->dcf_cursor + 7 < (UNS8*)dcfend && d->dcf_entries_count < nb_entries){
143 UNS8 target_Subindex;
146 /* DCF data may not be 32/16b aligned,
147 * we cannot directly dereference d->dcf_cursor
149 * Do it byte per byte taking care on endianess*/
150 #ifdef CANOPEN_BIG_ENDIAN
151 target_Index = *(d->dcf_cursor++) << 8 |
154 memcpy(&target_Index, d->dcf_cursor,2);
158 target_Subindex = *(d->dcf_cursor++);
160 #ifdef CANOPEN_BIG_ENDIAN
161 target_Size = *(d->dcf_cursor++) << 24 |
162 *(d->dcf_cursor++) << 16 |
163 *(d->dcf_cursor++) << 8 |
166 memcpy(&target_Size, d->dcf_cursor,4);
170 _writeNetworkDict(d, /* CO_Data* d*/
171 nodeId, /* UNS8 nodeId*/
172 target_Index, /* UNS16 index*/
173 target_Subindex, /* UNS8 subindex*/
174 target_Size, /* UNS8 count*/
175 0, /* UNS8 dataType*/
176 d->dcf_cursor,/* void *data*/
177 CheckSDOAndContinue,/* SDOCallback_t
179 0); /* no endianize*/
180 /* Push d->dcf_cursor to the end of data*/
182 d->dcf_cursor += target_Size;
183 d->dcf_entries_count++;
185 /* send_consise_dcf_loop will be called by CheckSDOAndContinue for next DCF entry*/
190 /* We have finished with the dcf entry. Change the flag, decrement the request
191 * and execute the bootup callback. */
192 d->dcf_odentry->pSubindex[nodeId].bAccessType&=~DCF_TO_SEND;
194 (*d->post_SlaveBootup)(d, nodeId);