src/states.c
author frdupin
Tue, 19 Dec 2006 16:45:39 +0100
changeset 61 813ffdfbffb2
parent 53 73bc47a0db55
child 71 95cd3376cc9f
permissions -rw-r--r--
some improvements
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
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    22
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
#include "states.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
#include "def.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
#include "nmtSlave.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
#ifdef LED_ENABLE
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
#include "led.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
#else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
#define led_set_state(a,b)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
#endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
53
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
    34
// Prototypes for internals functions
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
    35
void switchCommunicationState(CO_Data* d, 
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
    36
	s_state_communication *newCommunicationState);
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
    37
	
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
    38
/*****************************************************************************/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
e_nodeState getState(CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
  return d->nodeState;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
53
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
    44
/*****************************************************************************/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
void canDispatch(CO_Data* d, Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
	 switch(m->cob_id.w >> 7)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
		case SYNC:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
			if(d->CurrentCommunicationState.csSYNC)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
				proceedSYNC(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
		//case TIME_STAMP:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
		case PDO1tx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
		case PDO1rx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
		case PDO2tx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
		case PDO2rx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
		case PDO3tx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
		case PDO3rx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
		case PDO4tx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
		case PDO4rx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
			if (d->CurrentCommunicationState.csPDO)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
				proceedPDO(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
		case SDOtx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
		case SDOrx:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
			if (d->CurrentCommunicationState.csSDO)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
				proceedSDO(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
		case NODE_GUARD:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
			if (d->CurrentCommunicationState.csHeartbeat)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
				proceedNODE_GUARD(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
		case NMT:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
			if (d->iam_a_slave)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
			{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
				proceedNMTstateChange(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
			}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
#ifdef CANOPEN_LSS_ENABLE
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
		default:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
			if (m->cob_id.w == 0x7E4 || m->cob_id.w == 0x705)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
			{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
				proceedLSS(d,m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
			}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
#endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
#define StartOrStop(CommType, FuncStart, FuncStop) \
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
	if(newCommunicationState->CommType && !d->CurrentCommunicationState.CommType){\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
		MSG_ERR(0x9999,#FuncStart, 9999);\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
		d->CurrentCommunicationState.CommType = 1;\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
		FuncStart;\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
	}else if(!newCommunicationState->CommType && d->CurrentCommunicationState.CommType){\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
		MSG_ERR(0x9999,#FuncStop, 9999);\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
		d->CurrentCommunicationState.CommType = 0;\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
		FuncStop;\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
#define None
53
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
   100
	
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
   101
/*****************************************************************************/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
void switchCommunicationState(CO_Data* d, s_state_communication *newCommunicationState)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
	StartOrStop(csSDO,	None,		resetSDO(d))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
	StartOrStop(csSYNC,	startSYNC(d),		stopSYNC(d))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
	StartOrStop(csHeartbeat,	heartbeatInit(d),	heartbeatStop(d))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
//	StartOrStop(Emergency,,)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
	StartOrStop(csPDO,	None,	None)
14
1fbdf88163b3 d?placement de l'envoi du bootup
dejoigny
parents: 0
diff changeset
   109
	StartOrStop(csBoot_Up,	None,	slaveSendBootUp(d))
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
53
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
   112
/*****************************************************************************/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
UNS8 setState(CO_Data* d, e_nodeState newState)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
	while(newState != d->nodeState){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
		switch( newState ){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
			case Initialisation:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
			{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
				s_state_communication newCommunicationState = {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
					csBoot_Up: 1,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
					csSDO: 0,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
					csEmergency: 0,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
					csSYNC: 0,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
					csHeartbeat: 0,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
					csPDO: 0};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
				// This will force a second loop for the state switch
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
				d->nodeState = Initialisation;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
				newState = Pre_operational;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
				switchCommunicationState(d, &newCommunicationState);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   130
				// call user app related state func.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   131
				(*d->initialisation)();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   132
			}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
								
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
			case Pre_operational:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
			{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   137
				s_state_communication newCommunicationState = {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
					csBoot_Up: 0,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
					csSDO: 1,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
					csEmergency: 1,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
					csSYNC: 1,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
					csHeartbeat: 1,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
					csPDO: 0};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
				d->nodeState = Pre_operational;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
				newState = Pre_operational;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
				switchCommunicationState(d, &newCommunicationState);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
				(*d->preOperational)();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
			}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
								
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
			case Operational:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
			if(d->nodeState == Initialisation) return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
			{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
				s_state_communication newCommunicationState = {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
					csBoot_Up: 0,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
					csSDO: 1,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
					csEmergency: 1,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
					csSYNC: 1,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
					csHeartbeat: 1,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
					csPDO: 1};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
				d->nodeState = Operational;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
				newState = Operational;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
				switchCommunicationState(d, &newCommunicationState);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
				(*d->operational)();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
			}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
						
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
			case Stopped:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
			if(d->nodeState == Initialisation) return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
			{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
				s_state_communication newCommunicationState = {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
					csBoot_Up: 0,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
					csSDO: 0,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
					csEmergency: 0,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
					csSYNC: 0,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
					csHeartbeat: 1,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
					csPDO: 0};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
				d->nodeState = Stopped;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
				newState = Stopped;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   180
				switchCommunicationState(d, &newCommunicationState);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
				(*d->stopped)();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
			}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
			break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
			
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
			default:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
				return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
		}//end switch case
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
		led_set_state(d, newState);		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
	return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
53
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
   194
/*****************************************************************************/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
UNS8 getNodeId(CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
  return *d->bDeviceNodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
53
73bc47a0db55 Add prototypes
frdupin
parents: 14
diff changeset
   200
/*****************************************************************************/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
void setNodeId(CO_Data* d, UNS8 nodeId)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
  UNS16 offset = d->firstIndex->SDO_SVR;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
  if(offset){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
      //cob_id_client = 0x600 + nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
      *(UNS32*)d->objdict[offset].pSubindex[1].pObject = 0x600 + nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
      //cob_id_server = 0x580 + nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
      *(UNS32*)d->objdict[offset].pSubindex[2].pObject = 0x580 + nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
      // node Id client. As we do not know the value, we put the node Id Server
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
      //*(UNS8*)d->objdict[offset].pSubindex[3].pObject = nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
  // ** Initialize the server(s) SDO parameters
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
  // Remember that only one SDO server is allowed, defined at index 0x1200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
  // ** Initialize the client(s) SDO parameters  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
  // Nothing to initialize (no default values required by the DS 401)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
  // ** Initialize the receive PDO communication parameters. Only for 0x1400 to 0x1403
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
    UNS8 i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
    UNS16 offset = d->firstIndex->PDO_RCV;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
    UNS16 lastIndex = d->lastIndex->PDO_RCV;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
    UNS32 cobID[] = {0x200, 0x300, 0x400, 0x500};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
    if( offset ) while( (offset <= lastIndex) && (i < 4)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
      if(*(UNS32*)d->objdict[offset].pSubindex[1].pObject == cobID[i] + *d->bDeviceNodeId)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
	      *(UNS32*)d->objdict[offset].pSubindex[1].pObject = cobID[i] + nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
      i ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
      offset ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
  // ** Initialize the transmit PDO communication parameters. Only for 0x1800 to 0x1803
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
    UNS8 i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   234
    UNS16 offset = d->firstIndex->PDO_TRS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
    UNS16 lastIndex = d->lastIndex->PDO_TRS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
    UNS32 cobID[] = {0x180, 0x280, 0x380, 0x480};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
    i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
    if( offset ) while ((offset <= lastIndex) && (i < 4)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
      if(*(UNS32*)d->objdict[offset].pSubindex[1].pObject == cobID[i] + *d->bDeviceNodeId)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
	      *(UNS32*)d->objdict[offset].pSubindex[1].pObject = cobID[i] + nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
      i ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
      offset ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
  // bDeviceNodeId is defined in the object dictionary.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
  *d->bDeviceNodeId = nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
}