src/states.c
author etisserant
Thu, 30 Aug 2007 17:01:45 +0200
changeset 261 dbcd80bcab82
parent 236 905677ed00f3
child 263 d221d387ad2f
permissions -rw-r--r--
Prevent potential problem with missing 0x1005 OD entry
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack. 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
See COPYING file for copyrights details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     7
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
Lesser General Public License for more details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    21
*/
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    22
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    23
** @file   states.c
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    24
** @author Edouard TISSERANT and Francis DUPIN
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    25
** @date   Tue Jun  5 09:32:32 2007
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    26
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    27
** @brief
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    28
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    29
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    30
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
#include "states.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
#include "def.h"
204
44ce74232ccb Some fixes for visual studio C compiler compatiblity.
etisserant
parents: 195
diff changeset
    34
#include "dcf.h"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
#include "nmtSlave.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    37
/** Prototypes for internals functions */
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    38
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    39
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    40
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    41
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    42
** @param newCommunicationState                                                                    
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    43
**/     
53
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
    44
void switchCommunicationState(CO_Data* d, 
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
    45
	s_state_communication *newCommunicationState);
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
    46
	
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    47
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    48
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    49
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    50
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    51
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    52
** @return                                                                                         
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    53
**/    
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
e_nodeState getState(CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
  return d->nodeState;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    59
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    60
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    61
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    62
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    63
** @param m                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
    64
**/  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
void canDispatch(CO_Data* d, Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
	 switch(m->cob_id.w >> 7)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
		case SYNC:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
			if(d->CurrentCommunicationState.csSYNC)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
				proceedSYNC(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
			break;
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    73
		/* case TIME_STAMP: */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
		case PDO1tx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
		case PDO1rx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
		case PDO2tx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
		case PDO2rx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
		case PDO3tx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
		case PDO3rx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
		case PDO4tx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
		case PDO4rx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
			if (d->CurrentCommunicationState.csPDO)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
				proceedPDO(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
		case SDOtx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
		case SDOrx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
			if (d->CurrentCommunicationState.csSDO)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
				proceedSDO(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
		case NODE_GUARD:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
			if (d->CurrentCommunicationState.csHeartbeat)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
				proceedNODE_GUARD(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
		case NMT:
88
b6e0b91d073a pointer bogue for *(d->iam_a_slave)
frdupin
parents: 71
diff changeset
    95
			if (*(d->iam_a_slave))
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
			{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
				proceedNMTstateChange(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
			}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
#define StartOrStop(CommType, FuncStart, FuncStop) \
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
	if(newCommunicationState->CommType && !d->CurrentCommunicationState.CommType){\
195
1510dd61ead0 Added debug level opt in configure and re-enabled debug macros.
etisserant
parents: 183
diff changeset
   104
		MSG_WAR(0x9999,#FuncStart, 9999);\
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
		d->CurrentCommunicationState.CommType = 1;\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
		FuncStart;\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
	}else if(!newCommunicationState->CommType && d->CurrentCommunicationState.CommType){\
195
1510dd61ead0 Added debug level opt in configure and re-enabled debug macros.
etisserant
parents: 183
diff changeset
   108
		MSG_WAR(0x9999,#FuncStop, 9999);\
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
		d->CurrentCommunicationState.CommType = 0;\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
		FuncStop;\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
#define None
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   113
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   114
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   115
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   116
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   117
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   118
** @param newCommunicationState                                                                    
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   119
**/  	
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
void switchCommunicationState(CO_Data* d, s_state_communication *newCommunicationState)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
	StartOrStop(csSDO,	None,		resetSDO(d))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
	StartOrStop(csSYNC,	startSYNC(d),		stopSYNC(d))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
	StartOrStop(csHeartbeat,	heartbeatInit(d),	heartbeatStop(d))
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   125
/*	StartOrStop(Emergency,,) */
235
f812bf6b7237 Preliminary implementation of Event Timer and Inhibit Timer driven TPDO
etisserant
parents: 215
diff changeset
   126
	StartOrStop(csPDO,	PDOInit(d),	PDOStop(d))
14
1fbdf88163b3 d?placement de l'envoi du bootup
dejoigny
parents: 0
diff changeset
   127
	StartOrStop(csBoot_Up,	None,	slaveSendBootUp(d))
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   130
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   131
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   132
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   133
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   134
** @param newState                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   135
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   136
** @return                                                                                         
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   137
**/  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
UNS8 setState(CO_Data* d, e_nodeState newState)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
{
183
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   140
	UNS16 wIndex = 0x1F22;
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   141
	const indextable *ptrTable;
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   142
  	ODCallback_t *Callback;
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   143
	UNS32 errorCode;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
	while(newState != d->nodeState){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
		switch( newState ){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
			case Initialisation:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
			{
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   148
				s_state_communication newCommunicationState = {1, 0, 0, 0, 0, 0};
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   149
				/* This will force a second loop for the state switch */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
				d->nodeState = Initialisation;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
				newState = Pre_operational;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
				switchCommunicationState(d, &newCommunicationState);
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   153
				/* call user app related state func. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
				(*d->initialisation)();
178
01d81faa3350 Add concise DCF support
greg
parents: 152
diff changeset
   155
				
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
			}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
								
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
			case Pre_operational:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
			{
178
01d81faa3350 Add concise DCF support
greg
parents: 152
diff changeset
   161
				
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   162
				s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 0};
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
				d->nodeState = Pre_operational;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
				newState = Pre_operational;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
				switchCommunicationState(d, &newCommunicationState);
178
01d81faa3350 Add concise DCF support
greg
parents: 152
diff changeset
   166
				if (!(*(d->iam_a_slave)))
01d81faa3350 Add concise DCF support
greg
parents: 152
diff changeset
   167
				{
183
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   168
					ptrTable =(*d->scanIndexOD)(wIndex, &errorCode, &Callback);
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   169
  					
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   170
  					if (errorCode != OD_SUCCESSFUL)
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   171
  						{
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   172
  							(*d->preOperational)();
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   173
  						}
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   174
					else
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   175
						{
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   176
							UNS32 res;
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   177
							res = decompo_dcf(d,0x01);
4cddad17c81f Test if index 1F22 exists for Master OD (Concise DCF)
greg
parents: 178
diff changeset
   178
						}				
178
01d81faa3350 Add concise DCF support
greg
parents: 152
diff changeset
   179
				}
01d81faa3350 Add concise DCF support
greg
parents: 152
diff changeset
   180
				else 
01d81faa3350 Add concise DCF support
greg
parents: 152
diff changeset
   181
				{
01d81faa3350 Add concise DCF support
greg
parents: 152
diff changeset
   182
					(*d->preOperational)();
01d81faa3350 Add concise DCF support
greg
parents: 152
diff changeset
   183
				}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
			}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
								
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
			case Operational:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
			if(d->nodeState == Initialisation) return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
			{
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   190
				s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 1};
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
				d->nodeState = Operational;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
				newState = Operational;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
				switchCommunicationState(d, &newCommunicationState);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
				(*d->operational)();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
			}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
						
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
			case Stopped:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
			if(d->nodeState == Initialisation) return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
			{
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   201
				s_state_communication newCommunicationState = {0, 0, 0, 0, 1, 0};
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
				d->nodeState = Stopped;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
				newState = Stopped;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
				switchCommunicationState(d, &newCommunicationState);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
				(*d->stopped)();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
			}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
			
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
			default:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
				return 0xFF;
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   211
		}/* end switch case */
94
bdf4c86be6b2 Removed all non-supported and uncontrolled source code. Please refer to CVS version "Before_..." to see old code.
etisserant
parents: 88
diff changeset
   212
	
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
	return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   217
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   218
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   219
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   220
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   221
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   222
** @return                                                                                         
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   223
**/ 
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
UNS8 getNodeId(CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
  return *d->bDeviceNodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   229
/*!                                                                                                
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   230
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   231
**                                                                                                 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   232
** @param d                                                                                        
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   233
** @param nodeId                                                                                   
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   234
**/   
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
void setNodeId(CO_Data* d, UNS8 nodeId)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
  UNS16 offset = d->firstIndex->SDO_SVR;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
  if(offset){
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   239
      /* cob_id_client = 0x600 + nodeId; */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
      *(UNS32*)d->objdict[offset].pSubindex[1].pObject = 0x600 + nodeId;
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   241
      /* cob_id_server = 0x580 + nodeId; */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
      *(UNS32*)d->objdict[offset].pSubindex[2].pObject = 0x580 + nodeId;
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   243
      /* node Id client. As we do not know the value, we put the node Id Server */
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   244
      /* *(UNS8*)d->objdict[offset].pSubindex[3].pObject = nodeId; */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   247
  /* 
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   248
   	Initialize the server(s) SDO parameters
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   249
  	Remember that only one SDO server is allowed, defined at index 0x1200	
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   250
 		
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   251
  	Initialize the client(s) SDO parameters 	
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   252
  	Nothing to initialize (no default values required by the DS 401)	
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   253
  	Initialize the receive PDO communication parameters. Only for 0x1400 to 0x1403 
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 204
diff changeset
   254
  */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
    UNS8 i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
    UNS16 offset = d->firstIndex->PDO_RCV;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
    UNS16 lastIndex = d->lastIndex->PDO_RCV;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
    UNS32 cobID[] = {0x200, 0x300, 0x400, 0x500};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
    if( offset ) while( (offset <= lastIndex) && (i < 4)) {
236
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   261
      if(*(UNS32*)d->objdict[offset].pSubindex[1].pObject == cobID[i] + *d->bDeviceNodeId)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
	      *(UNS32*)d->objdict[offset].pSubindex[1].pObject = cobID[i] + nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
      i ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
      offset ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
  }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   267
  /* ** Initialize the transmit PDO communication parameters. Only for 0x1800 to 0x1803 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
    UNS8 i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
    UNS16 offset = d->firstIndex->PDO_TRS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
    UNS16 lastIndex = d->lastIndex->PDO_TRS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
    UNS32 cobID[] = {0x180, 0x280, 0x380, 0x480};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
    i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
    if( offset ) while ((offset <= lastIndex) && (i < 4)) {
236
905677ed00f3 Full preliminary implementation of TPDO transmit type:
etisserant
parents: 235
diff changeset
   275
      if(*(UNS32*)d->objdict[offset].pSubindex[1].pObject == cobID[i] + *d->bDeviceNodeId)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
	      *(UNS32*)d->objdict[offset].pSubindex[1].pObject = cobID[i] + nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
      i ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
      offset ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
  }
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   281
  /* bDeviceNodeId is defined in the object dictionary. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
  *d->bDeviceNodeId = nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
}
149
fe50ada8020b Changes in the API:
etisserant
parents: 94
diff changeset
   284
fe50ada8020b Changes in the API:
etisserant
parents: 94
diff changeset
   285
void _initialisation(){}
fe50ada8020b Changes in the API:
etisserant
parents: 94
diff changeset
   286
void _preOperational(){}
fe50ada8020b Changes in the API:
etisserant
parents: 94
diff changeset
   287
void _operational(){}
fe50ada8020b Changes in the API:
etisserant
parents: 94
diff changeset
   288
void _stopped(){}