etisserant@0: /* nico@208: This file is part of CanFestival, a library implementing CanOpen nico@208: Stack. etisserant@0: nico@208: Copyright (C): Edouard TISSERANT and Francis DUPIN etisserant@0: nico@208: See COPYING file for copyrights details. etisserant@0: nico@208: This library is free software; you can redistribute it and/or nico@208: modify it under the terms of the GNU Lesser General Public nico@208: License as published by the Free Software Foundation; either nico@208: version 2.1 of the License, or (at your option) any later version. etisserant@0: nico@208: This library is distributed in the hope that it will be useful, nico@208: but WITHOUT ANY WARRANTY; without even the implied warranty of nico@208: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU nico@208: Lesser General Public License for more details. etisserant@0: nico@208: You should have received a copy of the GNU Lesser General Public nico@208: License along with this library; if not, write to the Free Software nico@208: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 nico@208: USA etisserant@0: */ nico@208: /*! nico@208: ** @file nmtSlave.c nico@208: ** @author Edouard TISSERANT and Francis DUPIN nico@208: ** @date Tue Jun 5 08:50:53 2007 nico@208: ** nico@208: ** @brief nico@208: ** nico@208: ** nico@208: */ etisserant@0: #include "nmtSlave.h" etisserant@0: #include "states.h" etisserant@150: #include "canfestival.h" etisserant@370: #include "sysdep.h" etisserant@0: nico@208: /*! nico@208: ** put the slave in the state wanted by the master nico@208: ** nico@208: ** @param d nico@208: ** @param m nico@208: **/ etisserant@0: void proceedNMTstateChange(CO_Data* d, Message *m) etisserant@0: { etisserant@0: if( d->nodeState == Pre_operational || etisserant@0: d->nodeState == Operational || etisserant@0: d->nodeState == Stopped ) { nico@208: etisserant@0: MSG_WAR(0x3400, "NMT received. for node : ", (*m).data[1]); nico@208: nico@215: /* Check if this NMT-message is for this node */ nico@215: /* byte 1 = 0 : all the nodes are concerned (broadcast) */ nico@208: etisserant@0: if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == *d->bDeviceNodeId ) ){ nico@208: nico@215: switch( (*m).data[0]){ /* command specifier (cs) */ etisserant@0: case NMT_Start_Node: etisserant@0: if ( (d->nodeState == Pre_operational) || (d->nodeState == Stopped) ) etisserant@0: setState(d,Operational); nico@208: break; nico@208: etisserant@0: case NMT_Stop_Node: etisserant@0: if ( d->nodeState == Pre_operational || nico@208: d->nodeState == Operational ) etisserant@0: setState(d,Stopped); etisserant@0: break; nico@208: etisserant@0: case NMT_Enter_PreOperational: nico@208: if ( d->nodeState == Operational || nico@208: d->nodeState == Stopped ) nico@208: setState(d,Pre_operational); etisserant@0: break; nico@208: etisserant@0: case NMT_Reset_Node: etisserant@475: if(d->NMT_Slave_Node_Reset_Callback != NULL) etisserant@475: d->NMT_Slave_Node_Reset_Callback(d); nico@208: setState(d,Initialisation); etisserant@0: break; nico@208: etisserant@0: case NMT_Reset_Comunication: etisserant@498: { etisserant@498: UNS8 newNodeId = getNodeId(d); etisserant@498: etisserant@498: if(d->NMT_Slave_Communications_Reset_Callback != NULL) etisserant@498: d->NMT_Slave_Communications_Reset_Callback(d); groke6@381: #ifdef CO_ENABLE_LSS etisserant@498: // LSS changes NodeId here in case lss_transfer.nodeID doesn't etisserant@498: // match current getNodeId() etisserant@498: if(newNodeId!=d->lss_transfer.nodeID && newNodeId>0 && newNodeId<=127 ) etisserant@498: newNodeId = d->lss_transfer.nodeID; groke6@381: #endif etisserant@498: etisserant@498: // clear old NodeId to make SetNodeId reinitializing etisserant@498: // SDO, EMCY and other COB Ids etisserant@498: *d->bDeviceNodeId = 0xFF; etisserant@498: etisserant@498: setNodeId(d, newNodeId); etisserant@498: } etisserant@498: setState(d,Initialisation); etisserant@498: break; nico@208: nico@215: }/* end switch */ nico@208: nico@215: }/* end if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == nico@208: bDeviceNodeId ) ) */ etisserant@0: } etisserant@0: } etisserant@0: etisserant@0: nico@208: /*! nico@208: ** nico@208: ** nico@208: ** @param d nico@208: ** nico@208: ** @return nico@208: **/ etisserant@0: UNS8 slaveSendBootUp(CO_Data* d) etisserant@0: { etisserant@0: Message m; nico@208: etisserant@343: #ifdef CO_ENABLE_LSS etisserant@343: if(*d->bDeviceNodeId==0xFF)return 0; etisserant@343: #endif etisserant@343: etisserant@0: MSG_WAR(0x3407, "Send a Boot-Up msg ", 0); nico@208: nico@215: /* message configuration */ etisserant@370: { etisserant@370: UNS16 tmp = NODE_GUARD << 7 | *d->bDeviceNodeId; etisserant@370: m.cob_id = UNS16_LE(tmp); etisserant@370: } etisserant@0: m.rtr = NOT_A_REQUEST; etisserant@0: m.len = 1; etisserant@0: m.data[0] = 0x00; nico@208: etisserant@149: return canSend(d->canHandle,&m); etisserant@0: } etisserant@0: