src/nmtSlave.c
author etisserant
Fri, 25 May 2007 23:57:17 +0200
changeset 204 44ce74232ccb
parent 150 d2fc5d5f8a36
child 208 05d95c45b388
permissions -rw-r--r--
Some fixes for visual studio C compiler compatiblity.
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 "nmtSlave.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
#include "states.h"
150
d2fc5d5f8a36 Some win32 fixes following yesterday's API changes.
etisserant
parents: 149
diff changeset
    25
#include "canfestival.h"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
/*******************************************************************)*********/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
/* put the slave in the state wanted by the master */	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
void proceedNMTstateChange(CO_Data* d, Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
  if( d->nodeState == Pre_operational ||
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
      d->nodeState == Operational ||
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
      d->nodeState == Stopped ) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
    MSG_WAR(0x3400, "NMT received. for node :  ", (*m).data[1]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
    
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    37
    /* Check if this NMT-message is for this node */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    38
    /* byte 1 = 0 : all the nodes are concerned (broadcast) */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
    	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
    if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == *d->bDeviceNodeId ) ){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
      
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    42
      switch( (*m).data[0]){ /* command specifier (cs) */			
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
      case NMT_Start_Node:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
        if ( (d->nodeState == Pre_operational) || (d->nodeState == Stopped) )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
          setState(d,Operational);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
        break; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
      case NMT_Stop_Node:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
        if ( d->nodeState == Pre_operational ||
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
	     d->nodeState == Operational )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
          setState(d,Stopped);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
        break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
      case NMT_Enter_PreOperational:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
        if ( d->nodeState == Operational || 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
	     d->nodeState == Stopped )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
	  setState(d,Pre_operational);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
        break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
      case NMT_Reset_Node:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
          setState(d,Initialisation);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
        break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
      case NMT_Reset_Comunication:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
          setState(d,Initialisation);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
        break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
        
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    68
      }/* end switch */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
      
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    70
    }/* end if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == bDeviceNodeId ) ) */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
/*****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
UNS8 slaveSendBootUp(CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
  Message m;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
  MSG_WAR(0x3407, "Send a Boot-Up msg ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
  /* message configuration */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
  m.cob_id.w = NODE_GUARD << 7 | *d->bDeviceNodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
  m.rtr = NOT_A_REQUEST;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
  m.len = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
  m.data[0] = 0x00;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
    
149
fe50ada8020b Changes in the API:
etisserant
parents: 71
diff changeset
    88
  return canSend(d->canHandle,&m);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90