0
|
1 |
/*
|
|
2 |
This file is part of CanFestival, a library implementing CanOpen Stack.
|
|
3 |
|
|
4 |
Copyright (C): Edouard TISSERANT and Francis DUPIN
|
|
5 |
|
|
6 |
See COPYING file for copyrights details.
|
|
7 |
|
|
8 |
This library is free software; you can redistribute it and/or
|
|
9 |
modify it under the terms of the GNU Lesser General Public
|
|
10 |
License as published by the Free Software Foundation; either
|
|
11 |
version 2.1 of the License, or (at your option) any later version.
|
|
12 |
|
|
13 |
This library is distributed in the hope that it will be useful,
|
|
14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
16 |
Lesser General Public License for more details.
|
|
17 |
|
|
18 |
You should have received a copy of the GNU Lesser General Public
|
|
19 |
License along with this library; if not, write to the Free Software
|
|
20 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 |
*/
|
|
22 |
|
|
23 |
#include "nmtSlave.h"
|
|
24 |
#include "states.h"
|
|
25 |
|
|
26 |
/*******************************************************************)*********/
|
|
27 |
/* put the slave in the state wanted by the master */
|
|
28 |
void proceedNMTstateChange(CO_Data* d, Message *m)
|
|
29 |
{
|
|
30 |
if( d->nodeState == Pre_operational ||
|
|
31 |
d->nodeState == Operational ||
|
|
32 |
d->nodeState == Stopped ) {
|
|
33 |
|
|
34 |
MSG_WAR(0x3400, "NMT received. for node : ", (*m).data[1]);
|
|
35 |
|
71
|
36 |
/* Check if this NMT-message is for this node */
|
|
37 |
/* byte 1 = 0 : all the nodes are concerned (broadcast) */
|
0
|
38 |
|
|
39 |
if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == *d->bDeviceNodeId ) ){
|
|
40 |
|
71
|
41 |
switch( (*m).data[0]){ /* command specifier (cs) */
|
0
|
42 |
case NMT_Start_Node:
|
|
43 |
if ( (d->nodeState == Pre_operational) || (d->nodeState == Stopped) )
|
|
44 |
setState(d,Operational);
|
|
45 |
break;
|
|
46 |
|
|
47 |
case NMT_Stop_Node:
|
|
48 |
if ( d->nodeState == Pre_operational ||
|
|
49 |
d->nodeState == Operational )
|
|
50 |
setState(d,Stopped);
|
|
51 |
break;
|
|
52 |
|
|
53 |
case NMT_Enter_PreOperational:
|
|
54 |
if ( d->nodeState == Operational ||
|
|
55 |
d->nodeState == Stopped )
|
|
56 |
setState(d,Pre_operational);
|
|
57 |
break;
|
|
58 |
|
|
59 |
case NMT_Reset_Node:
|
|
60 |
setState(d,Initialisation);
|
|
61 |
break;
|
|
62 |
|
|
63 |
case NMT_Reset_Comunication:
|
|
64 |
setState(d,Initialisation);
|
|
65 |
break;
|
|
66 |
|
71
|
67 |
}/* end switch */
|
0
|
68 |
|
71
|
69 |
}/* end if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == bDeviceNodeId ) ) */
|
0
|
70 |
}
|
|
71 |
}
|
|
72 |
|
|
73 |
|
|
74 |
/*****************************************************************************/
|
|
75 |
UNS8 slaveSendBootUp(CO_Data* d)
|
|
76 |
{
|
|
77 |
Message m;
|
|
78 |
|
|
79 |
MSG_WAR(0x3407, "Send a Boot-Up msg ", 0);
|
|
80 |
|
|
81 |
/* message configuration */
|
|
82 |
m.cob_id.w = NODE_GUARD << 7 | *d->bDeviceNodeId;
|
|
83 |
m.rtr = NOT_A_REQUEST;
|
|
84 |
m.len = 1;
|
|
85 |
m.data[0] = 0x00;
|
|
86 |
|
|
87 |
return (*d->canSend)(&m);
|
|
88 |
}
|
|
89 |
|