]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - src/nmtSlave.c
*** empty log message ***
[CanFestival-3.git] / src / nmtSlave.c
1 /*
2   This file is part of CanFestival, a library implementing CanOpen
3   Stack.
4
5   Copyright (C): Edouard TISSERANT and Francis DUPIN
6
7   See COPYING file for copyrights details.
8
9   This library is free software; you can redistribute it and/or
10   modify it under the terms of the GNU Lesser General Public
11   License as published by the Free Software Foundation; either
12   version 2.1 of the License, or (at your option) any later version.
13
14   This library is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17   Lesser General Public License for more details.
18
19   You should have received a copy of the GNU Lesser General Public
20   License along with this library; if not, write to the Free Software
21   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
22   USA
23 */
24 /*!
25 ** @file   nmtSlave.c
26 ** @author Edouard TISSERANT and Francis DUPIN
27 ** @date   Tue Jun  5 08:50:53 2007
28 **
29 ** @brief
30 **
31 **
32 */
33 #include "nmtSlave.h"
34 #include "states.h"
35 #include "canfestival.h"
36 #include "sysdep.h"
37
38 /*!
39 ** put the slave in the state wanted by the master
40 **
41 ** @param d
42 ** @param m
43 **/
44 void proceedNMTstateChange(CO_Data* d, Message *m)
45 {
46   if( d->nodeState == Pre_operational ||
47       d->nodeState == Operational ||
48       d->nodeState == Stopped ) {
49
50     MSG_WAR(0x3400, "NMT received. for node :  ", (*m).data[1]);
51
52     /* Check if this NMT-message is for this node */
53     /* byte 1 = 0 : all the nodes are concerned (broadcast) */
54
55     if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == *d->bDeviceNodeId ) ){
56
57       switch( (*m).data[0]){ /* command specifier (cs) */
58       case NMT_Start_Node:
59         if ( (d->nodeState == Pre_operational) || (d->nodeState == Stopped) )
60           setState(d,Operational);
61         break;
62
63       case NMT_Stop_Node:
64         if ( d->nodeState == Pre_operational ||
65              d->nodeState == Operational )
66           setState(d,Stopped);
67         break;
68
69       case NMT_Enter_PreOperational:
70         if ( d->nodeState == Operational ||
71              d->nodeState == Stopped )
72           setState(d,Pre_operational);
73         break;
74
75       case NMT_Reset_Node:
76          if(d->NMT_Slave_Node_Reset_Callback != NULL)
77             d->NMT_Slave_Node_Reset_Callback(d);
78         setState(d,Initialisation);
79         break;
80
81       case NMT_Reset_Comunication:
82          if(d->NMT_Slave_Communications_Reset_Callback != NULL)
83             d->NMT_Slave_Communications_Reset_Callback(d);
84 #ifdef CO_ENABLE_LSS
85          // LSS changes NodeId here in case lss_transfer.nodeID
86          // doesn't match current getNodeId()
87          if(newNodeId!=d->lss_transfer.nodeID && newNodeId>0 && newNodeId<=127 )
88             newNodeId = d->lss_transfer.nodeID;
89 #endif
90         setState(d,Initialisation);
91         break;
92
93       }/* end switch */
94
95     }/* end if( ( (*m).data[1] == 0 ) || ( (*m).data[1] ==
96         bDeviceNodeId ) ) */
97   }
98 }
99
100
101 /*!
102 **
103 **
104 ** @param d
105 **
106 ** @return
107 **/
108 UNS8 slaveSendBootUp(CO_Data* d)
109 {
110   Message m;
111
112 #ifdef CO_ENABLE_LSS
113   if(*d->bDeviceNodeId==0xFF)return 0;
114 #endif
115
116   MSG_WAR(0x3407, "Send a Boot-Up msg ", 0);
117
118   /* message configuration */
119   {
120           UNS16 tmp = NODE_GUARD << 7 | *d->bDeviceNodeId; 
121           m.cob_id = UNS16_LE(tmp);
122   }
123   m.rtr = NOT_A_REQUEST;
124   m.len = 1;
125   m.data[0] = 0x00;
126
127   return canSend(d->canHandle,&m);
128 }
129