src/nmtMaster.c
author etisserant
Fri, 25 May 2007 23:57:17 +0200
changeset 204 44ce74232ccb
parent 149 fe50ada8020b
child 208 05d95c45b388
permissions -rw-r--r--
Some fixes for visual studio C compiler compatiblity.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack. 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
See COPYING file for copyrights details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     7
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
Lesser General Public License for more details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    21
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    22
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
#include "nmtMaster.h"
149
fe50ada8020b Changes in the API:
etisserant
parents: 71
diff changeset
    24
#include "canfestival.h"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
UNS8 masterSendNMTstateChange(CO_Data* d, UNS8 Node_ID, UNS8 cs)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
  Message m;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
  MSG_WAR(0x3501, "Send_NMT cs : ", cs);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
  MSG_WAR(0x3502, "    to node : ", Node_ID);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
  /* message configuration */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
  m.cob_id.w = 0x0000; /*(NMT) << 7*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
  m.rtr = NOT_A_REQUEST;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
  m.len = 2;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
  m.data[0] = cs;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
  m.data[1] = Node_ID;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
  
149
fe50ada8020b Changes in the API:
etisserant
parents: 71
diff changeset
    40
  return canSend(d->canHandle,&m);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
/****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
UNS8 masterSendNMTnodeguard(CO_Data* d, UNS8 nodeId)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
  Message m;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
  MSG_WAR(0x3503, "Send_NODE_GUARD to node : ", nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
  /* message configuration */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
  m.cob_id.w = nodeId | (NODE_GUARD << 7);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
  m.rtr = REQUEST;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
  m.len = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
  
149
fe50ada8020b Changes in the API:
etisserant
parents: 71
diff changeset
    56
  return canSend(d->canHandle,&m);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
/******************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
void masterRequestNodeState(CO_Data* d, UNS8 nodeId)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
{
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    62
  /* FIXME: should warn for bad toggle bit. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
  /* NMTable configuration to indicate that the master is waiting
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
   * for a Node_Guard frame from the slave whose node_id is ID */
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    66
  d->NMTable[nodeId] = Unknown_state; /* A state that does not exist */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    68
  if (nodeId == 0) { /* NMT broadcast */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
    UNS8 i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
    for (i = 0 ; i < NMT_MAX_NODE_ID ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
      d->NMTable[i] = Unknown_state;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
  masterSendNMTnodeguard(d,nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84