author | Laurent Bessard |
Mon, 23 Sep 2013 00:27:39 +0200 | |
changeset 786 | 8dbe0aec4f36 |
parent 517 | 003679edc437 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
208 | 2 |
This file is part of CanFestival, a library implementing CanOpen |
3 |
Stack. |
|
0 | 4 |
|
208 | 5 |
Copyright (C): Edouard TISSERANT and Francis DUPIN |
0 | 6 |
|
208 | 7 |
See COPYING file for copyrights details. |
0 | 8 |
|
208 | 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. |
|
0 | 13 |
|
208 | 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. |
|
0 | 18 |
|
208 | 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 |
|
0 | 23 |
*/ |
208 | 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 |
*/ |
|
0 | 33 |
#include "nmtSlave.h" |
34 |
#include "states.h" |
|
150
d2fc5d5f8a36
Some win32 fixes following yesterday's API changes.
etisserant
parents:
149
diff
changeset
|
35 |
#include "canfestival.h" |
370
6fecf36df407
Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents:
365
diff
changeset
|
36 |
#include "sysdep.h" |
0 | 37 |
|
208 | 38 |
/*! |
39 |
** put the slave in the state wanted by the master |
|
40 |
** |
|
41 |
** @param d |
|
42 |
** @param m |
|
43 |
**/ |
|
0 | 44 |
void proceedNMTstateChange(CO_Data* d, Message *m) |
45 |
{ |
|
46 |
if( d->nodeState == Pre_operational || |
|
47 |
d->nodeState == Operational || |
|
48 |
d->nodeState == Stopped ) { |
|
208 | 49 |
|
0 | 50 |
MSG_WAR(0x3400, "NMT received. for node : ", (*m).data[1]); |
208 | 51 |
|
215 | 52 |
/* Check if this NMT-message is for this node */ |
53 |
/* byte 1 = 0 : all the nodes are concerned (broadcast) */ |
|
208 | 54 |
|
0 | 55 |
if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == *d->bDeviceNodeId ) ){ |
208 | 56 |
|
215 | 57 |
switch( (*m).data[0]){ /* command specifier (cs) */ |
0 | 58 |
case NMT_Start_Node: |
59 |
if ( (d->nodeState == Pre_operational) || (d->nodeState == Stopped) ) |
|
60 |
setState(d,Operational); |
|
208 | 61 |
break; |
62 |
||
0 | 63 |
case NMT_Stop_Node: |
64 |
if ( d->nodeState == Pre_operational || |
|
208 | 65 |
d->nodeState == Operational ) |
0 | 66 |
setState(d,Stopped); |
67 |
break; |
|
208 | 68 |
|
0 | 69 |
case NMT_Enter_PreOperational: |
208 | 70 |
if ( d->nodeState == Operational || |
71 |
d->nodeState == Stopped ) |
|
72 |
setState(d,Pre_operational); |
|
0 | 73 |
break; |
208 | 74 |
|
0 | 75 |
case NMT_Reset_Node: |
475 | 76 |
if(d->NMT_Slave_Node_Reset_Callback != NULL) |
77 |
d->NMT_Slave_Node_Reset_Callback(d); |
|
208 | 78 |
setState(d,Initialisation); |
0 | 79 |
break; |
208 | 80 |
|
0 | 81 |
case NMT_Reset_Comunication: |
498
aae8531341df
Edward's patch fixing nmtSlave compilation with LSS enabled.
etisserant
parents:
483
diff
changeset
|
82 |
{ |
517 | 83 |
UNS8 currentNodeId = getNodeId(d); |
498
aae8531341df
Edward's patch fixing nmtSlave compilation with LSS enabled.
etisserant
parents:
483
diff
changeset
|
84 |
|
aae8531341df
Edward's patch fixing nmtSlave compilation with LSS enabled.
etisserant
parents:
483
diff
changeset
|
85 |
if(d->NMT_Slave_Communications_Reset_Callback != NULL) |
aae8531341df
Edward's patch fixing nmtSlave compilation with LSS enabled.
etisserant
parents:
483
diff
changeset
|
86 |
d->NMT_Slave_Communications_Reset_Callback(d); |
381 | 87 |
#ifdef CO_ENABLE_LSS |
498
aae8531341df
Edward's patch fixing nmtSlave compilation with LSS enabled.
etisserant
parents:
483
diff
changeset
|
88 |
// LSS changes NodeId here in case lss_transfer.nodeID doesn't |
aae8531341df
Edward's patch fixing nmtSlave compilation with LSS enabled.
etisserant
parents:
483
diff
changeset
|
89 |
// match current getNodeId() |
517 | 90 |
if(currentNodeId!=d->lss_transfer.nodeID) |
91 |
currentNodeId = d->lss_transfer.nodeID; |
|
381 | 92 |
#endif |
498
aae8531341df
Edward's patch fixing nmtSlave compilation with LSS enabled.
etisserant
parents:
483
diff
changeset
|
93 |
|
aae8531341df
Edward's patch fixing nmtSlave compilation with LSS enabled.
etisserant
parents:
483
diff
changeset
|
94 |
// clear old NodeId to make SetNodeId reinitializing |
aae8531341df
Edward's patch fixing nmtSlave compilation with LSS enabled.
etisserant
parents:
483
diff
changeset
|
95 |
// SDO, EMCY and other COB Ids |
aae8531341df
Edward's patch fixing nmtSlave compilation with LSS enabled.
etisserant
parents:
483
diff
changeset
|
96 |
*d->bDeviceNodeId = 0xFF; |
aae8531341df
Edward's patch fixing nmtSlave compilation with LSS enabled.
etisserant
parents:
483
diff
changeset
|
97 |
|
517 | 98 |
setNodeId(d, currentNodeId); |
498
aae8531341df
Edward's patch fixing nmtSlave compilation with LSS enabled.
etisserant
parents:
483
diff
changeset
|
99 |
} |
aae8531341df
Edward's patch fixing nmtSlave compilation with LSS enabled.
etisserant
parents:
483
diff
changeset
|
100 |
setState(d,Initialisation); |
aae8531341df
Edward's patch fixing nmtSlave compilation with LSS enabled.
etisserant
parents:
483
diff
changeset
|
101 |
break; |
208 | 102 |
|
215 | 103 |
}/* end switch */ |
208 | 104 |
|
215 | 105 |
}/* end if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == |
208 | 106 |
bDeviceNodeId ) ) */ |
0 | 107 |
} |
108 |
} |
|
109 |
||
110 |
||
208 | 111 |
/*! |
112 |
** |
|
113 |
** |
|
114 |
** @param d |
|
115 |
** |
|
116 |
** @return |
|
117 |
**/ |
|
0 | 118 |
UNS8 slaveSendBootUp(CO_Data* d) |
119 |
{ |
|
120 |
Message m; |
|
208 | 121 |
|
343 | 122 |
#ifdef CO_ENABLE_LSS |
123 |
if(*d->bDeviceNodeId==0xFF)return 0; |
|
124 |
#endif |
|
125 |
||
0 | 126 |
MSG_WAR(0x3407, "Send a Boot-Up msg ", 0); |
208 | 127 |
|
215 | 128 |
/* message configuration */ |
370
6fecf36df407
Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents:
365
diff
changeset
|
129 |
{ |
6fecf36df407
Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents:
365
diff
changeset
|
130 |
UNS16 tmp = NODE_GUARD << 7 | *d->bDeviceNodeId; |
6fecf36df407
Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents:
365
diff
changeset
|
131 |
m.cob_id = UNS16_LE(tmp); |
6fecf36df407
Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents:
365
diff
changeset
|
132 |
} |
0 | 133 |
m.rtr = NOT_A_REQUEST; |
134 |
m.len = 1; |
|
135 |
m.data[0] = 0x00; |
|
208 | 136 |
|
149 | 137 |
return canSend(d->canHandle,&m); |
0 | 138 |
} |
139 |