src/dcf.c
changeset 207 b6572d0336c3
parent 204 44ce74232ccb
child 208 05d95c45b388
equal deleted inserted replaced
206:6787754b251b 207:b6572d0336c3
     1 /*
     1 /*
     2 This file is part of CanFestival, a library implementing CanOpen Stack. 
     2   This file is part of CanFestival, a library implementing CanOpen
       
     3   Stack.
     3 
     4 
     4 Copyright (C): Edouard TISSERANT and Francis DUPIN
     5   Copyright (C): Edouard TISSERANT and Francis DUPIN
     5 
     6 
     6 See COPYING file for copyrights details.
     7   See COPYING file for copyrights details.
     7 
     8 
     8 This library is free software; you can redistribute it and/or
     9   This library is free software; you can redistribute it and/or
     9 modify it under the terms of the GNU Lesser General Public
    10   modify it under the terms of the GNU Lesser General Public
    10 License as published by the Free Software Foundation; either
    11   License as published by the Free Software Foundation; either
    11 version 2.1 of the License, or (at your option) any later version.
    12   version 2.1 of the License, or (at your option) any later version.
    12 
    13 
    13 This library is distributed in the hope that it will be useful,
    14   This library is distributed in the hope that it will be useful,
    14 but WITHOUT ANY WARRANTY; without even the implied warranty of
    15   but WITHOUT ANY WARRANTY; without even the implied warranty of
    15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    16 Lesser General Public License for more details.
    17   Lesser General Public License for more details.
    17 
    18 
    18 You should have received a copy of the GNU Lesser General Public
    19   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   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   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
       
    22   USA
    21 */
    23 */
    22 
    24 
       
    25 /*!
       
    26 ** @file   dcf.c
       
    27 ** @author Edouard TISSERANT and Francis DUPIN
       
    28 ** @date   Mon Jun  4 17:06:12 2007
       
    29 **
       
    30 ** @brief
       
    31 **
       
    32 **
       
    33 */
    23 #include "objacces.h"
    34 #include "objacces.h"
    24 #include "sdo.h"
    35 #include "sdo.h"
    25 #include "dcf.h"
    36 #include "dcf.h"
    26 #include "sysdep.h"
    37 #include "sysdep.h"
    27 
    38 
    28 
    39 
    29 extern UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, 
    40 
    30 		       UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize);
    41 extern UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
       
    42                                UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize);
    31 
    43 
    32 const indextable *ptrTable;
    44 const indextable *ptrTable;
    33 
    45 
       
    46 /*!
       
    47 **
       
    48 **
       
    49 ** @param d
       
    50 ** @param nodeId
       
    51 **/
    34 static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId)
    52 static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId)
    35 {
    53 {
    36 	UNS32 abortCode;
    54   UNS32 abortCode;
    37 	
       
    38 	if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
       
    39 	{
       
    40 		MSG_ERR(0x1A01, "SDO error in consise DCF", abortCode);
       
    41 		MSG_WAR(0x2A02, "server node : ", nodeId);
       
    42 	}
       
    43 
    55 
    44 	closeSDOtransfer(d, nodeId, SDO_CLIENT);
    56   if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
    45 	decompo_dcf(d,nodeId);
    57     {
       
    58       MSG_ERR(0x1A01, "SDO error in consise DCF", abortCode);
       
    59       MSG_WAR(0x2A02, "server node : ", nodeId);
       
    60     }
       
    61 
       
    62   closeSDOtransfer(d, nodeId, SDO_CLIENT);
       
    63   decompo_dcf(d,nodeId);
    46 }
    64 }
    47 
    65 
       
    66 /*!
       
    67 **
       
    68 **
       
    69 ** @param d
       
    70 ** @param nodeId
       
    71 **
       
    72 ** @return
       
    73 **/
    48 UNS32 decompo_dcf(CO_Data* d,UNS8 nodeId)
    74 UNS32 decompo_dcf(CO_Data* d,UNS8 nodeId)
    49 {
    75 {
    50 		UNS32 errorCode;
    76   UNS32 errorCode;
    51 		UNS16 target_Index;
    77   UNS16 target_Index;
    52 		UNS8 target_Subindex;
    78   UNS8 target_Subindex;
    53 		UNS32 target_Size;
    79   UNS32 target_Size;
    54 		UNS32 res;
    80   UNS32 res;
    55   		ODCallback_t *Callback;
    81   ODCallback_t *Callback;
    56 
    82 
    57 		ptrTable = (*d->scanIndexOD)(0x1F22, &errorCode, &Callback);
    83   ptrTable = (*d->scanIndexOD)(0x1F22, &errorCode, &Callback);
    58 		if (errorCode != OD_SUCCESSFUL)
    84   if (errorCode != OD_SUCCESSFUL)
    59 		{
    85     {
    60     		return errorCode;
    86       return errorCode;
    61 		}
    87     }
    62 
    88 
    63 		/*Loop on all Nodes supported in DCF subindexes*/
    89   /*Loop on all Nodes supported in DCF subindexes*/
    64 		while (nodeId < ptrTable->bSubCount){
    90   while (nodeId < ptrTable->bSubCount){
    65 			UNS32 nb_targets;
    91     UNS32 nb_targets;
    66 	  		
    92 
    67 	  		UNS8 szData = ptrTable->pSubindex[nodeId].size;
    93     UNS8 szData = ptrTable->pSubindex[nodeId].size;
    68 	  		UNS8* dcfend;
    94     UNS8* dcfend;
    69 	  		
    95 
    70 		  	{
    96     {
    71 			  	UNS8* dcf = *((UNS8**)ptrTable->pSubindex[nodeId].pObject);
    97       UNS8* dcf = *((UNS8**)ptrTable->pSubindex[nodeId].pObject);
    72 		  		dcfend = dcf + szData;
    98       dcfend = dcf + szData;
    73 				if (!d->dcf_cursor)	{
    99       if (!d->dcf_cursor){
    74 					d->dcf_cursor = (UNS8*)dcf + 4;
   100         d->dcf_cursor = (UNS8*)dcf + 4;
    75 					d->dcf_count_targets = 0;
   101         d->dcf_count_targets = 0;
    76 				}
   102       }
    77 				nb_targets = UNS32_LE(*((UNS32*)dcf));
   103       nb_targets = UNS32_LE(*((UNS32*)dcf));
    78 		  	}
   104     }
    79 			
   105 
    80 			// condition on consise DCF string for NodeID, if big enough
   106     // condition on consise DCF string for NodeID, if big enough
    81 			if((UNS8*)d->dcf_cursor + 7 < (UNS8*)dcfend && d->dcf_count_targets < nb_targets)
   107     if((UNS8*)d->dcf_cursor + 7 < (UNS8*)dcfend && d->dcf_count_targets < nb_targets)
    82 			{
   108       {
    83 				// pointer to the DCF string for NodeID
   109         // pointer to the DCF string for NodeID
    84 				target_Index = UNS16_LE(*((UNS16*)(d->dcf_cursor))); d->dcf_cursor += 2;
   110         target_Index = UNS16_LE(*((UNS16*)(d->dcf_cursor))); d->dcf_cursor += 2;
    85 				target_Subindex = *((UNS8*)(((UNS8*)d->dcf_cursor)++));
   111         target_Subindex = *((UNS8*)(((UNS8*)d->dcf_cursor)++));
    86 				target_Size = UNS32_LE(*((UNS32*)(d->dcf_cursor))); d->dcf_cursor += 4;
   112         target_Size = UNS32_LE(*((UNS32*)(d->dcf_cursor))); d->dcf_cursor += 4;
    87 					
   113 
    88 					/*printf("Master : ConfigureSlaveNode %2.2x (Concise DCF)\n",nodeId);*/
   114         /*printf("Master : ConfigureSlaveNode %2.2x (Concise
    89 					res = _writeNetworkDict(d, /*CO_Data* d*/
   115           DCF)\n",nodeId);*/
    90 							nodeId, /*UNS8 nodeId*/
   116         res = _writeNetworkDict(d, /*CO_Data* d*/
    91 							target_Index, /*UNS16 index*/
   117                                 nodeId, /*UNS8 nodeId*/
    92 							target_Subindex, /*UNS8 subindex*/
   118                                 target_Index, /*UNS16 index*/
    93 							target_Size, /*UNS8 count*/
   119                                 target_Subindex, /*UNS8 subindex*/
    94 							0, /*UNS8 dataType*/
   120                                 target_Size, /*UNS8 count*/
    95 							d->dcf_cursor,/*void *data*/
   121                                 0, /*UNS8 dataType*/
    96 							CheckSDOAndContinue,/*SDOCallback_t Callback*/	
   122                                 d->dcf_cursor,/*void *data*/
    97 							0); /* no endianize		*/
   123                                 CheckSDOAndContinue,/*SDOCallback_t
    98 					/*Push d->dcf_cursor to the end of data*/
   124                                                       Callback*/
    99 					
   125                                 0); /* no endianize*/
   100 					d->dcf_cursor += target_Size;
   126         /*Push d->dcf_cursor to the end of data*/
   101 					d->dcf_count_targets++;
   127 
   102 					
   128         d->dcf_cursor += target_Size;
   103 					return ;
   129         d->dcf_count_targets++;
   104 			}			
   130 
   105 				nodeId++;
   131         return ;
   106 				d->dcf_cursor = NULL;
   132       }
   107 		}
   133     nodeId++;
   108 		/* Switch Master to preOperational state */
   134     d->dcf_cursor = NULL;
   109 		(*d->preOperational)();
   135   }
   110 		
   136   /* Switch Master to preOperational state */
       
   137   (*d->preOperational)();
       
   138 
   111 }
   139 }