greg@178: /*
nico@207:   This file is part of CanFestival, a library implementing CanOpen
nico@207:   Stack.
greg@178: 
nico@207:   Copyright (C): Edouard TISSERANT and Francis DUPIN
greg@178: 
nico@207:   See COPYING file for copyrights details.
greg@178: 
nico@207:   This library is free software; you can redistribute it and/or
nico@207:   modify it under the terms of the GNU Lesser General Public
nico@207:   License as published by the Free Software Foundation; either
nico@207:   version 2.1 of the License, or (at your option) any later version.
greg@178: 
nico@207:   This library is distributed in the hope that it will be useful,
nico@207:   but WITHOUT ANY WARRANTY; without even the implied warranty of
nico@207:   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
nico@207:   Lesser General Public License for more details.
greg@178: 
nico@207:   You should have received a copy of the GNU Lesser General Public
nico@207:   License along with this library; if not, write to the Free Software
nico@207:   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
nico@207:   USA
greg@178: */
greg@178: 
nico@210: 
nico@208: /**
nico@207: ** @file   dcf.c
nico@207: ** @author Edouard TISSERANT and Francis DUPIN
nico@207: ** @date   Mon Jun  4 17:06:12 2007
nico@207: **
nico@208: ** @brief EXEMPLE OF SOMMARY
nico@207: **
nico@207: **
nico@207: */
nico@215: 
nico@215: 
greg@178: #include "objacces.h"
greg@178: #include "sdo.h"
greg@178: #include "dcf.h"
etisserant@200: #include "sysdep.h"
greg@178: 
nico@207: extern UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
nico@207:                                UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize);
etisserant@204: 
greg@178: const indextable *ptrTable;
greg@178: 
nico@208: /**
nico@207: **
nico@207: **
nico@207: ** @param d
nico@207: ** @param nodeId
nico@208: */
greg@178: static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId)
greg@178: {
nico@207:   UNS32 abortCode;
etisserant@191: 
nico@207:   if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
nico@207:     {
nico@207:       MSG_ERR(0x1A01, "SDO error in consise DCF", abortCode);
nico@207:       MSG_WAR(0x2A02, "server node : ", nodeId);
nico@207:     }
nico@207: 
nico@207:   closeSDOtransfer(d, nodeId, SDO_CLIENT);
nico@207:   decompo_dcf(d,nodeId);
greg@178: }
greg@178: 
nico@208: /**
nico@207: **
nico@207: **
nico@207: ** @param d
nico@207: ** @param nodeId
nico@207: **
nico@207: ** @return
nico@208: */
greg@178: UNS32 decompo_dcf(CO_Data* d,UNS8 nodeId)
greg@178: {
nico@207:   UNS32 errorCode;
nico@207:   UNS16 target_Index;
nico@207:   UNS8 target_Subindex;
nico@207:   UNS32 target_Size;
nico@207:   UNS32 res;
nico@207:   ODCallback_t *Callback;
greg@178: 
nico@207:   ptrTable = (*d->scanIndexOD)(0x1F22, &errorCode, &Callback);
nico@207:   if (errorCode != OD_SUCCESSFUL)
nico@207:     {
nico@207:       return errorCode;
nico@207:     }
greg@178: 
nico@215:   /* Loop on all Nodes supported in DCF subindexes*/
nico@207:   while (nodeId < ptrTable->bSubCount){
nico@207:     UNS32 nb_targets;
nico@207: 
nico@207:     UNS8 szData = ptrTable->pSubindex[nodeId].size;
nico@207:     UNS8* dcfend;
nico@207: 
nico@207:     {
nico@207:       UNS8* dcf = *((UNS8**)ptrTable->pSubindex[nodeId].pObject);
nico@207:       dcfend = dcf + szData;
nico@207:       if (!d->dcf_cursor){
nico@207:         d->dcf_cursor = (UNS8*)dcf + 4;
nico@207:         d->dcf_count_targets = 0;
nico@207:       }
nico@207:       nb_targets = UNS32_LE(*((UNS32*)dcf));
nico@207:     }
nico@207: 
nico@215:     /* condition on consise DCF string for NodeID, if big enough */
nico@207:     if((UNS8*)d->dcf_cursor + 7 < (UNS8*)dcfend && d->dcf_count_targets < nb_targets)
nico@207:       {
nico@215:         /* pointer to the DCF string for NodeID */
nico@207:         target_Index = UNS16_LE(*((UNS16*)(d->dcf_cursor))); d->dcf_cursor += 2;
nico@207:         target_Subindex = *((UNS8*)(((UNS8*)d->dcf_cursor)++));
nico@207:         target_Size = UNS32_LE(*((UNS32*)(d->dcf_cursor))); d->dcf_cursor += 4;
nico@207: 
nico@208:         /* printf("Master : ConfigureSlaveNode %2.2x (Concise
nico@207:           DCF)\n",nodeId);*/
nico@215:         res = _writeNetworkDict(d, /* CO_Data* d*/
nico@215:                                 nodeId, /* UNS8 nodeId*/
nico@215:                                 target_Index, /* UNS16 index*/
nico@215:                                 target_Subindex, /* UNS8 subindex*/
nico@215:                                 target_Size, /* UNS8 count*/
nico@215:                                 0, /* UNS8 dataType*/
nico@215:                                 d->dcf_cursor,/* void *data*/
nico@215:                                 CheckSDOAndContinue,/* SDOCallback_t
nico@207:                                                       Callback*/
nico@215:                                 0); /* no endianize*/
nico@215:         /* Push d->dcf_cursor to the end of data*/
nico@207: 
nico@207:         d->dcf_cursor += target_Size;
nico@207:         d->dcf_count_targets++;
nico@207: 
nico@207:         return ;
nico@207:       }
nico@207:     nodeId++;
nico@207:     d->dcf_cursor = NULL;
nico@207:   }
nico@215:   /*  Switch Master to preOperational state */
nico@207:   (*d->preOperational)();
nico@207: 
greg@178: }