src/nmtSlave.c
author etisserant
Fri, 08 Feb 2008 14:52:48 +0100
changeset 385 fff25f16c923
parent 381 854c43cdc24a
child 475 4b63ea646964
permissions -rw-r--r--
Cleaned DS-401GUI (definitively removed graph) added options to open directly on the right Input or Output page. Little fixes.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
     2
  This file is part of CanFestival, a library implementing CanOpen
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
     3
  Stack.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
     5
  Copyright (C): Edouard TISSERANT and Francis DUPIN
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
     7
  See COPYING file for copyrights details.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
     9
  This library is free software; you can redistribute it and/or
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    10
  modify it under the terms of the GNU Lesser General Public
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    11
  License as published by the Free Software Foundation; either
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    12
  version 2.1 of the License, or (at your option) any later version.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    14
  This library is distributed in the hope that it will be useful,
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    17
  Lesser General Public License for more details.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    19
  You should have received a copy of the GNU Lesser General Public
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    20
  License along with this library; if not, write to the Free Software
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    21
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    22
  USA
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
*/
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    24
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    25
** @file   nmtSlave.c
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    26
** @author Edouard TISSERANT and Francis DUPIN
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    27
** @date   Tue Jun  5 08:50:53 2007
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    28
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    29
** @brief
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    30
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    31
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    32
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
#include "nmtSlave.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    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
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    38
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    39
** put the slave in the state wanted by the master
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    40
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    41
** @param d
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    42
** @param m
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    43
**/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
void proceedNMTstateChange(CO_Data* d, Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
  if( d->nodeState == Pre_operational ||
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
      d->nodeState == Operational ||
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
      d->nodeState == Stopped ) {
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    49
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
    MSG_WAR(0x3400, "NMT received. for node :  ", (*m).data[1]);
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    51
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    52
    /* Check if this NMT-message is for this node */
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    53
    /* byte 1 = 0 : all the nodes are concerned (broadcast) */
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    54
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
    if( ( (*m).data[1] == 0 ) || ( (*m).data[1] == *d->bDeviceNodeId ) ){
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    56
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    57
      switch( (*m).data[0]){ /* command specifier (cs) */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
      case NMT_Start_Node:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
        if ( (d->nodeState == Pre_operational) || (d->nodeState == Stopped) )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
          setState(d,Operational);
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    61
        break;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    62
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
      case NMT_Stop_Node:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
        if ( d->nodeState == Pre_operational ||
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    65
             d->nodeState == Operational )
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
          setState(d,Stopped);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
        break;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    68
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
      case NMT_Enter_PreOperational:
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    70
        if ( d->nodeState == Operational ||
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    71
             d->nodeState == Stopped )
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    72
          setState(d,Pre_operational);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
        break;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    74
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
      case NMT_Reset_Node:
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    76
#ifdef CO_ENABLE_LSS
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    77
  		if(getNodeId(d)!=d->lss_transfer.nodeID)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    78
  			setNodeId(d, d->lss_transfer.nodeID);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    79
#endif
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    80
        setState(d,Initialisation);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
        break;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    82
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
      case NMT_Reset_Comunication:
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    84
#ifdef CO_ENABLE_LSS
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    85
  		if(getNodeId(d)!=d->lss_transfer.nodeID && getNodeId(d)>0 && getNodeId(d)<=127)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    86
  			setNodeId(d, d->lss_transfer.nodeID);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents: 370
diff changeset
    87
#endif
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    88
        setState(d,Initialisation);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
        break;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    90
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    91
      }/* end switch */
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    92
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    93
    }/* end if( ( (*m).data[1] == 0 ) || ( (*m).data[1] ==
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    94
        bDeviceNodeId ) ) */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
    99
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
   100
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
   101
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
   102
** @param d
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
   103
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
   104
** @return
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
   105
**/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
UNS8 slaveSendBootUp(CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
  Message m;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
   109
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 215
diff changeset
   110
#ifdef CO_ENABLE_LSS
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 215
diff changeset
   111
  if(*d->bDeviceNodeId==0xFF)return 0;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 215
diff changeset
   112
#endif
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 215
diff changeset
   113
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
  MSG_WAR(0x3407, "Send a Boot-Up msg ", 0);
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
   115
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   116
  /* 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
   117
  {
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
   118
	  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
   119
	  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
   120
  }
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
  m.rtr = NOT_A_REQUEST;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
  m.len = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
  m.data[0] = 0x00;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 150
diff changeset
   124
149
fe50ada8020b Changes in the API:
etisserant
parents: 71
diff changeset
   125
  return canSend(d->canHandle,&m);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127