src/nmtSlave.c
author etisserant
Mon, 19 Jun 2006 16:35:12 +0200
changeset 34 3e24a4d68325
parent 0 4472ee7c6c3e
child 71 95cd3376cc9f
permissions -rw-r--r--
Fixed Xeno crash when no more alarm are set...
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"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
/*******************************************************************)*********/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
/* put the slave in the state wanted by the master */	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
void proceedNMTstateChange(CO_Data* d, Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
  if( d->nodeState == Pre_operational ||
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
      d->nodeState == Operational ||
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
      d->nodeState == Stopped ) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
    MSG_WAR(0x3400, "NMT received. for node :  ", (*m).data[1]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
    // Check if this NMT-message is for this node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
    // byte 1 = 0 : all the nodes are concerned (broadcast)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
    	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
    if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == *d->bDeviceNodeId ) ){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
      switch( (*m).data[0]){ // command specifier (cs)			
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
      case NMT_Start_Node:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
        if ( (d->nodeState == Pre_operational) || (d->nodeState == Stopped) )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
          setState(d,Operational);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
        break; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
      case NMT_Stop_Node:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
        if ( d->nodeState == Pre_operational ||
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
	     d->nodeState == Operational )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
          setState(d,Stopped);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
        break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
      case NMT_Enter_PreOperational:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
        if ( d->nodeState == Operational || 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
	     d->nodeState == Stopped )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
	  setState(d,Pre_operational);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
        break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
      case NMT_Reset_Node:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
          setState(d,Initialisation);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
        break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
      case NMT_Reset_Comunication:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
          setState(d,Initialisation);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
        break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
      }// end switch
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
    }// end if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == bDeviceNodeId ) )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
  }
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
UNS8 slaveSendBootUp(CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
  Message m;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
  MSG_WAR(0x3407, "Send a Boot-Up msg ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
  /* message configuration */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
  m.cob_id.w = NODE_GUARD << 7 | *d->bDeviceNodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
  m.rtr = NOT_A_REQUEST;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
  m.len = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
  m.data[0] = 0x00;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
  return (*d->canSend)(&m);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89