src/dcf.c
author lbessard
Fri, 11 May 2007 15:24:43 +0200
changeset 188 00245bc2e6fe
parent 178 01d81faa3350
child 191 1e6e3d261b8f
permissions -rw-r--r--
Bugs on C File generating corrected
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
     1
/*
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack. 
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
     3
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
     5
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
     6
See COPYING file for copyrights details.
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
     7
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    12
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    16
Lesser General Public License for more details.
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    17
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    21
*/
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    22
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    23
#include "objacces.h"
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    24
#include "sdo.h"
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    25
#include "dcf.h"
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    26
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    27
const indextable *ptrTable;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    28
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    29
static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId)
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    30
{
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    31
	UNS32 res;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    32
	UNS8 line;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    33
	UNS8 err;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    34
	UNS16 Index;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    35
	UNS8 SubIndex;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    36
	UNS32 abortCode;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    37
	
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    38
	if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    39
		printf("Master : Failed in initializing slave %2.2x, AbortCode :%4.4x \n", nodeId, abortCode);
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    40
	
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    41
	closeSDOtransfer(d, nodeId, SDO_CLIENT);
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    42
	res = decompo_dcf(d,nodeId);
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    43
}
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    44
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    45
UNS32 decompo_dcf(CO_Data* d,UNS8 nodeId)
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    46
{
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    47
		UNS32 errorCode;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    48
		UNS16 target_Index;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    49
		UNS8 target_Subindex;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    50
		UNS32 target_Size;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    51
		void* target_data = NULL;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    52
		UNS32 res;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    53
  		ODCallback_t *Callback;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    54
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    55
		ptrTable = (*d->scanIndexOD)(0x1F22, &errorCode, &Callback);
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    56
		if (errorCode != OD_SUCCESSFUL)
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    57
		{
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    58
    		return errorCode;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    59
		}
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    60
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    61
		/*Loop on all Nodes supported in DCF subindexes*/
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    62
		while (nodeId < ptrTable->bSubCount){
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    63
			UNS32 nb_targets;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    64
	  		
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    65
	  		UNS8 szData = ptrTable->pSubindex[nodeId].size;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    66
	  		void* dcfend;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    67
	  		
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    68
		  	{
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    69
			  	void* dcf = *((void**)ptrTable->pSubindex[nodeId].pObject);
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    70
		  		dcfend = dcf + szData;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    71
				if (!d->dcf_cursor)	{
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    72
					d->dcf_cursor = dcf + 4;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    73
					d->dcf_count_targets = 0;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    74
				}
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    75
	#ifdef CANOPEN_BIG_ENDIAN
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    76
				nb_targets = ((UNS8*)d->dcf++) | ((UNS8*)d->dcf++) << 8 | ((UNS8*)d->dcf++) << 16 | ((UNS8*)d->dcf++) << 24;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    77
	#else
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    78
				nb_targets = *((UNS32*)dcf);
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    79
	#endif
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    80
		  	}
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    81
			
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    82
			// condition on consise DCF string for NodeID, if big enough
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    83
			if(d->dcf_cursor + 7 < dcfend && d->dcf_count_targets < nb_targets)
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    84
			{
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    85
				// pointer to the DCF string for NodeID
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    86
	#ifdef CANOPEN_BIG_ENDIAN
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    87
				target_Index = ((UNS8*)d->dcf_cursor++) | ((UNS8*)d->dcf_cursor++) << 8;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    88
				target_Subindex = ((UNS8*)d->dcf_cursor++);
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    89
				target_Size = ((UNS8*)d->dcf_cursor++) | ((UNS8*)d->dcf_cursor++) << 8 | ((UNS8*)d->dcf_cursor++) << 16 | ((UNS8*)d->dcf_cursor++) << 24;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    90
	#else
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    91
				target_Index = *((UNS16*)(d->dcf_cursor)); d->dcf_cursor += 2;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    92
				target_Subindex = *((UNS8*)(d->dcf_cursor++));
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    93
				target_Size = *((UNS32*)(d->dcf_cursor)); d->dcf_cursor += 4;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    94
	#endif
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    95
				
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    96
					printf("Master : ConfigureSlaveNode %2.2x (Concise DCF)\n",nodeId);
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    97
					res = writeNetworkDictCallBack(d, /*CO_Data* d*/
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    98
							nodeId, /*UNS8 nodeId*/
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    99
							target_Index, /*UNS16 index*/
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   100
							target_Subindex, /*UNS8 subindex*/
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   101
							target_Size, /*UNS8 count*/
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   102
							0, /*UNS8 dataType*/
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   103
							d->dcf_cursor,/*void *data*/
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   104
							CheckSDOAndContinue); /*SDOCallback_t Callback*/					
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   105
					/*Push d->dcf_cursor to the end of data*/
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   106
					
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   107
					d->dcf_cursor += target_Size;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   108
					d->dcf_count_targets++;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   109
					
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   110
					return ;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   111
			}			
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   112
				nodeId++;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   113
				d->dcf_cursor = NULL;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   114
		}
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   115
		/* Switch Master to preOperational state */
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   116
		(*d->preOperational)();
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   117
		
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   118
}