examples/AppliMaster_Linux/appli.c
author etisserant
Tue, 20 Jun 2006 17:41:13 +0200
changeset 36 ff3ba4a90548
parent 0 4472ee7c6c3e
permissions -rwxr-xr-x
Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
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 <stdio.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
#include <string.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
#include <sys/time.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
#include <pthread.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
#include <unistd.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
#include <stdlib.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
#include <applicfg.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
#include <timerhw.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
#include <linuxCan.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
#include "def.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
#include "can.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
#include "objdictdef.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
#include "objacces.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
#include "canOpenDriver.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
#include "sdo.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
#include "pdo.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
#include "init.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
#include "timer.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
#include "lifegrd.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
#include "sync.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
#include "nmtMaster.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
// For prototype of exit();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
#define exit _exit
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
// Adlink 7841 or Peak PCI/CAN board
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
// ---------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
// Baudrate values for Peak board :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
// CAN_BAUD_1M CAN_BAUD_500K CAN_BAUD_250K CAN_BAUD_125K CAN_BAUD_100K CAN_BAUD_50K
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
// CAN_BAUD_20K CAN_BAUD_10K CAN_BAUD_5K
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
#ifdef CAN_BAUD_250K
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
# define BAUDRATE CAN_BAUD_250K
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
#else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
// Appli have been compiled for Adlink-arbraca. Baudrate not used
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
# define BAUDRATE 0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
#endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
s_BOARD board = {"0", BAUDRATE};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
// Required definition variables
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
// -----------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
// The variables that you should define for debugging.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
// They are used by the macro MSG_ERR and MSG_WAR in applicfg.h
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
// if the node is a slave, they can be mapped in the object dictionnary.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
UNS8 printMsgErrToConsole = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
UNS8 printMsgWarToConsole = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
// The variables mapped in the object dictionnary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
// ----------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
extern UNS32 canopenErrNB_node5;   // Mapped at index 0x6000, subindex 0x0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
extern UNS32 canopenErrVAL_node5;  // Mapped at index 0x6001, subindex 0x0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
extern UNS8 second;		   // Mapped at index 0x6002, subindex 0x1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
extern UNS8 minutes;		   // Mapped at index 0x6002, subindex 0x2
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
extern UNS8 hour;		   // Mapped at index 0x6002, subindex 0x3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
extern UNS8 day;		   // Mapped at index 0x6002, subindex 0x4
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
extern UNS32 canopenErrNB;	   // Mapped at index 0x6003, subindex 0x1
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
extern UNS32 canopenErrVAL;	   // Mapped at index 0x6003, subindex 0x2
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
/*************************User's variables declaration**************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
pthread_t threadM;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
pthread_t threadH;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
pthread_t threadS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
UNS8 connectedNode[128];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
/* The variable to map in a PDO is defined at index and subIndex. Its length is size bytes */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
typedef struct mappedVar 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
  UNS32 index;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
  UNS8  subIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
  UNS8  size; // in byte
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
} s_mappedVar;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
typedef struct heartbeatConsumer
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
  UNS8 nodeProducer;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
  UNS16 time_ms;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
} s_heartbeatConsumer;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
/**************************prototypes*****************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
/* You *must* have these 2 functions in your code*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
void heartbeatError (UNS8 heartbeatID );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
void SD0timeoutError(UNS8 bus_id, UNS8 line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
void waitMessage (void );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
void heartBeat (void );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
void transmitSync (void);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
e_nodeState stateNode (UNS8 node);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
void configure_master_SDO (UNS32 index, UNS8 serverNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
UNS8 waitingWriteToSlaveDict (UNS8 slaveNode, UNS8 error);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
UNS8 waitingReadToSlaveDict (UNS8 slaveNode, void * data, UNS8 * size, UNS8 error);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
UNS8 configure_client_SDO (UNS8 slaveNode, UNS8 clientNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
void masterMappingPDO (UNS32 indexPDO, UNS32 cobId, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
		      s_mappedVar *tabMappedVar, UNS8 nbVar);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
void slaveMappingPDO (UNS8 slaveNode, UNS32 indexPDO, UNS32 cobId, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
		     s_mappedVar *tabMappedVar, UNS8 nbVar);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   130
void masterHeartbeatConsumer (s_heartbeatConsumer 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   131
			     *tabHeartbeatConsumer, UNS8 nbHeartbeats);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   132
void masterHeartbeatProducer (UNS16 time);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
void slaveHeartbeatConsumer (UNS8 slaveNode, s_heartbeatConsumer 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
			    *tabHeartbeatConsumer, UNS8 nbHeartbeats);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
void slaveHeartbeatProducer (UNS8 slaveNode, UNS16 time);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
void masterPDOTransmissionMode (UNS32 indexPDO,  UNS8 transType);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   137
void slavePDOTransmissionMode (UNS8 slaveNode, UNS32 indexPDO,  UNS8 transType);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
void masterSYNCPeriod (UNS32 SYNCPeriod);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
int main (int argc,char **argv);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
/*****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
void heartbeatError(UNS8 heartbeatID)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
  // MSG_ERR should send the values canopenErrNB and canopenErrVAL on event in a PDO,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
  // But we do not have mapped the variables in a PDO, so it sends nothing.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
  // See the note at the end of END CONFIGURING THE NETWORK.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
  MSG_WAR(0x2F00, "HeartBeat, no response from node : ", heartbeatID);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
/*****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
void SD0timeoutError (UNS8 bus_id, UNS8 line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
  // Informations on what occurs are in transfers[bus_id][line]....
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
  // See scanSDOtimeout() in sdo.c
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
/*********************************** THREADS **********************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
// Wait for a received message
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
void waitMessage(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
{       
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
  while (1) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
    receiveMsgHandler(0); // blocked until new message
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
/* Sending SYNC */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
void transmitSync(void)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
  while (1) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
  computeSYNC(); // Use the value in the dictionnary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
  usleep(1000); // Sleep 1 ms
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
/************************** FUNCTIONS TO CONFIGURE THE NETWORK******************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   180
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
/* Node mode result after NodeGuard query */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
e_nodeState stateNode(UNS8 node) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
  e_nodeState state = getNodeState(0, node);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
  switch (state) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
  case Unknown_state: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
    MSG_WAR(0x3F05, "Not connected (Does not have sent its status) node :", node);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
  case Operational: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
    MSG_WAR(0x3F06, "Ok, in operational mode, node : ", node);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
  case Pre_operational: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
    MSG_WAR(0x3F07, "OK in pre-operational mode, node : ", node);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
  default:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
    MSG_WAR(0x3F08, "OK connected but in curious mode, node : ", node);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
  return state;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
/* The master is writing in its dictionnary to configure the SDO parameters 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
to communicate with server_node
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
void configure_master_SDO(UNS32 index, UNS8 serverNode)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
  UNS32 data32;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
  UNS8  data8;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
  UNS8 sizeData = 4 ; // in bytes
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
  /* At subindex 1, the cobId of the Can message from the client.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
  It is always defined inside the server dictionnary as 0x600 + server_node.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
  So, we have no choice here ! */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
  data32 = 0x600 + serverNode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
  setODentry(index, 1, &data32, sizeData, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
    // Test
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
    UNS32  *pbData;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
    UNS8 length;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
    UNS32 returnValue;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
    UNS8 dataType;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
    // Relecture
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
    MSG_WAR(0x1000, "Reading index : ", index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
    MSG_WAR(0x1000, "     subindex : ", 1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
    returnValue = getODentry(index, 1, (void * *)&pbData, (UNS8 *)&length, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
    MSG_WAR(0x1000, "          val : ", *pbData);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
  /* At subindex 2, the cobId of the Can message from the server to the client.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   234
  It is always defined inside the server dictionnary as 0x580 + client_node.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
  So, we have no choice here ! */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
  data32 = 0x580 + serverNode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
  setODentry(index, 2, &data32, sizeData, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
  /* At subindex 3, the node of the server */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
  data8 = serverNode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
  sizeData = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
  setODentry(index, 3, &data8, sizeData, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
    UNS8  *pbData;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
    UNS8 length;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
    UNS32 returnValue;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
    UNS8 dataType;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
    // Relecture
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
    MSG_WAR(0x1000, "Reading  index : ", index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
    MSG_WAR(0x1000, "      subindex : ", 3);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
    returnValue = getODentry(index, 1, (void * *)&pbData, (UNS8 *)&length, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
    MSG_WAR(0x1000, "           val : ", *pbData);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
UNS8 waitingWriteToSlaveDict(UNS8 slaveNode, UNS8 error)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
  UNS32 abortCode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
  MSG_WAR(0x3F21, "Sending SDO to write in dictionnary of node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
  if (error) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
    MSG_ERR(0x1F22, "Unable to send the SDO to node ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
    return -1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
  /* Waiting until the slave has responded */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
  while (getWriteResultNetworkDict (0, slaveNode, &abortCode) == SDO_DOWNLOAD_IN_PROGRESS) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
    // Check if some SDO response are missing
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
    scanSDOtimeout();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
  err = getWriteResultNetworkDict (0, slaveNode, &abortCode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
  if (err == SDO_FINISHED) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
    MSG_WAR(0x3F22, "SDO download finished to Node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
    // Release the line. Don't forget !!!
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
    closeSDOtransfer(0, slaveNode, SDO_CLIENT);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
    return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
  if (err == SDO_ABORTED_RCV) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
    MSG_WAR(0x2F20, "Received SDO abort from node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
  if (err == SDO_ABORTED_INTERNAL) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   288
    MSG_WAR(0x2F20, "Internal SDO abort for node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   289
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
  // Looking for the line transfert number to read the index, subindex and releasing the line.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   292
    UNS8 line;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   293
    err = getSDOlineOnUse(0, slaveNode, SDO_CLIENT, &line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   294
    if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   295
      MSG_WAR(0x2F21, "No line found for node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   296
      exit(-1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
    MSG_WAR (0x2F22, "while writing at his index : ", transfers[0][line].index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
    MSG_WAR (0x2F23, "                  subIndex : ", transfers[0][line].subIndex);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
    //Releasing the line.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
    closeSDOtransfer(0, slaveNode, SDO_CLIENT);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   302
    exit(-1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
 return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   306
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   307
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   310
UNS8 waitingReadToSlaveDict(UNS8 slaveNode, void * data, UNS8 * size, UNS8 error)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   311
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   312
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   313
  UNS32 abortCode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   314
  MSG_WAR(0x3F2A, "Sending SDO to read in dictionnary of node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   315
  if (error) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   316
    MSG_ERR(0x1F2B, "Unable to send the SDO to node ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
    return -1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   318
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   319
  /* Waiting until the slave has responded */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   320
  while (getReadResultNetworkDict (0, slaveNode, data, size, &abortCode) == SDO_UPLOAD_IN_PROGRESS) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   321
    // Check if some SDO response are missing
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   322
    scanSDOtimeout();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   323
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   324
  err = getReadResultNetworkDict (0, slaveNode, data, size, &abortCode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   325
  if (err == SDO_FINISHED) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   326
    MSG_WAR(0x3F2C, "SDO upload finished to Node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   327
    // Release the line. Don't forget !!!
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   328
    closeSDOtransfer(0, slaveNode, SDO_CLIENT);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   329
    return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   330
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   331
  if (err == SDO_ABORTED_RCV) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   332
    MSG_WAR(0x2F2D, "Received SDO abort from node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   333
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   334
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   335
  if (err == SDO_ABORTED_INTERNAL) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   336
    MSG_WAR(0x2F2E, "Internal SDO abort for node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   337
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   338
  // Looking for the line transfert number to read the index, subindex and releasing the line.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   339
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   340
    UNS8 line;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   341
    err = getSDOlineOnUse(0, slaveNode, SDO_CLIENT, &line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   342
    if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   343
      MSG_WAR(0x2F2F, "No line found for node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   344
      exit(-1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   345
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   346
    MSG_WAR (0x2F30, "while writing at his index : ", transfers[0][line].index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   347
    MSG_WAR (0x2F31, "                  subIndex : ", transfers[0][line].subIndex);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   348
    //Releasing the line.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   349
    closeSDOtransfer(0, slaveNode, SDO_CLIENT);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   350
    exit(-1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   351
  }    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   352
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   353
 return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   354
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   355
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   356
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   357
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   358
/* The master is writing in the slave dictionnary to configure the SDO parameters
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   359
Remember that the slave is the server, and the master is the client.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   360
 */ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   361
UNS8 configure_client_SDO(UNS8 slaveNode, UNS8 clientNode)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   362
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   363
  UNS8 data;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   364
  UNS8 NbDataToWrite = 1 ; // in bytes
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   365
  UNS8 err = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   366
  MSG_WAR(0x3F20, "Configuring SDO by writing in dictionnary Node", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   367
  /* It is only to put at subindex 3 the serverNode. It is optionnal.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   368
     In the slave dictionary, only one SDO server is defined, at index 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   369
     0x1200 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   370
  data = clientNode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   371
  err = writeNetworkDict(0, slaveNode, 0x1200, 3, NbDataToWrite, 0, &data); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   372
  waitingWriteToSlaveDict(slaveNode, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   373
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   374
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   375
}		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   376
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   377
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   378
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   379
void masterMappingPDO(UNS32 indexPDO, UNS32 cobId, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   380
		      s_mappedVar *tabMappedVar, UNS8 nbVar)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   381
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   382
  UNS32 *pbData;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   383
  UNS32 data32; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   384
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   385
  UNS8 size = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   386
  UNS8 dataType;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   387
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   388
  if ((indexPDO >= 0x1400) && (indexPDO <= 0x15FF))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   389
    MSG_WAR(0x3F30, "Configuring MASTER for PDO receive, COBID : ", cobId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   390
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   391
  if ((indexPDO >= 0x1800) && (indexPDO <= 0x19FF))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   392
    MSG_WAR(0x3F31, "Configuring MASTER for PDO transmit, COBID : ", cobId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   393
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   394
  /* At indexPDO, subindex 1, defining the cobId of the PDO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   395
  setODentry(indexPDO, 1, &cobId, 4, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   396
  /* The mapping ... */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   397
  /* ----------------*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   398
  /* At subindex 0, the number of variables in the PDO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   399
  setODentry(indexPDO + 0x200, 0, &nbVar, 1, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   400
  getODentry(indexPDO + 0x200, 0, (void * *)&pbData, &size, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   401
  /* At each subindex 1 .. nbVar, The index,subindex and size of the variable to map in 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   402
     the PDO. The first variable after the COBID is defined at subindex 1, ... 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   403
     The data to write is the concatenation on 32 bits of (msb ... lsb) : 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   404
     index(16b),subIndex(8b),sizeVariable(8b)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   405
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   406
  for (i = 0 ; i < nbVar ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   407
    data32 = ((tabMappedVar + i)->index << 16) |
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   408
      (((tabMappedVar + i)->subIndex & 0xFF) << 8) |
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   409
      ((tabMappedVar + i)->size & 0xFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   410
    // Write dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   411
    setODentry(indexPDO + 0x200, i + 1, &data32, 4, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   412
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   413
#   ifdef MORE_COMMENTS
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   414
    printf("Mapped variable defined  at index 0x%X, subIndex 0x%X, %d bits\n", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   415
	   (tabMappedVar + i)->index, (tabMappedVar + i)->subIndex, 8 * (tabMappedVar + i)->size);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   416
    // Only to verify.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   417
    // Read dictionnary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   418
    getODentry(indexPDO + 0x200, i + 1, (void * *)&pbData, &size, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   419
    printf("Writen à  index 0x%X, subIndex 0x%X, %d bits : 0x%08X\n", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   420
	   indexPDO + 0x200, i + 1, 8 * size, *pbData);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   421
#   endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   422
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   423
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   424
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   425
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   426
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   427
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   428
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   429
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   430
void slaveMappingPDO(UNS8 slaveNode, UNS32 indexPDO, UNS32 cobId, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   431
		     s_mappedVar *tabMappedVar, UNS8 nbVar)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   432
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   433
  UNS32 data32; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   434
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   435
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   436
  UNS8 nbBytes = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   437
  if ((indexPDO >= 0x1400) && (indexPDO <= 0x15FF))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   438
    MSG_WAR(0x3F32, "Configuring slave for PDO receive, COBID : ", cobId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   439
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   440
  if ((indexPDO >= 0x1800) && (indexPDO <= 0x19FF))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   441
    MSG_WAR(0x3F33, "Configuring slave for PDO transmit, COBID : ", cobId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   442
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   443
  /* At indexPDO, subindex 1, defining the cobId of the PDO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   444
  err = writeNetworkDict(0, slaveNode, indexPDO, 1, 4, 0, &cobId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   445
  waitingWriteToSlaveDict(slaveNode, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   446
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   447
  /* The mapping ... */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   448
  /* ----------------*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   449
  /* At subindex 0, the number of variables in the PDO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   450
  err = writeNetworkDict(0, slaveNode, indexPDO + 0x200, 0, nbBytes, 0, &nbVar); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   451
  waitingWriteToSlaveDict(slaveNode, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   452
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   453
  /* At each subindex 1 .. nbVar, The index,subindex and size of the variable to map in 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   454
     the PDO. The first variable after the COBID is defined at subindex 1, ... 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   455
     The data to write is the concatenation on 32 bits of (msb ... lsb) : 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   456
     index(16b),subIndex(8b),sizeVariable(8b)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   457
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   458
  for (i = 0 ; i < nbVar ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   459
    data32 = ((tabMappedVar + i)->index << 16) |
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   460
      (((tabMappedVar + i)->subIndex & 0xFF) << 8) |
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   461
      ((tabMappedVar + i)->size & 0xFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   462
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   463
    // Write dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   464
    err = writeNetworkDict(0, slaveNode, indexPDO + 0x200, i + 1, 4, 0, &data32); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   465
    waitingWriteToSlaveDict(slaveNode, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   466
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   467
#   ifdef MORE_COMMENTS
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   468
    printf("Mapped variable defined  at index 0x%X, subIndex 0x%X, %d bits\n", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   469
	   (tabMappedVar + i)->index, (tabMappedVar + i)->subIndex, 8 * (tabMappedVar + i)->size);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   470
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   471
    printf("At node 0x%X Writen at  index 0x%X, subIndex 0x%X, %d bits : 0x%08X\n", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   472
	   slaveNode, indexPDO + 0x200, i + 1, 32, data32);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   473
#   endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   474
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   475
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   476
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   477
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   478
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   479
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   480
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   481
void masterHeartbeatConsumer(s_heartbeatConsumer 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   482
			     *tabHeartbeatConsumer, UNS8 nbHeartbeats)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   483
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   484
  UNS32 data;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   485
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   486
  UNS8 nbHB = nbHeartbeats;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   487
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   488
  MSG_WAR(0x3F40, "Configuring heartbeats consumers for master", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   489
  /* At index 1016, subindex 0 : the nb of consumers (ie nb of nodes of which are expecting heartbeats) */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   490
  setODentry(0x1016, 0, & nbHB, 1, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   491
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   492
  /* At Index 1016, subindex 1, ... : 32 bit values : msb ... lsb :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   493
     00 - node_consumer (8b) - time_ms (16b)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   494
     Put 0 to ignore the entry.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   495
  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   496
  for (i = 0 ; i < nbHeartbeats ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   497
    data = (((tabHeartbeatConsumer + i)->nodeProducer & 0xFF)<< 16) | ((tabHeartbeatConsumer + i)->time_ms & 0xFFFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   498
    setODentry(0x1016, i + 1, & data, 4, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   499
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   500
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   501
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   502
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   503
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   504
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   505
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   506
void masterHeartbeatProducer(UNS16 time)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   507
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   508
  UNS16 hbTime = time;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   509
  MSG_WAR(0x3F45, "Configuring heartbeat producer for master", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   510
  /* At index 1017, subindex 0, defining the time to send the heartbeat. Put 0 to never send heartbeat */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   511
  setODentry(0x1017, 0, &hbTime, 2, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   512
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   513
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   514
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   515
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   516
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   517
void slaveHeartbeatConsumer(UNS8 slaveNode, s_heartbeatConsumer 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   518
			    *tabHeartbeatConsumer, UNS8 nbHeartbeats)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   519
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   520
  UNS32 data;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   521
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   522
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   523
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   524
  MSG_WAR(0x3F46, "Configuring heartbeats consumers for node  : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   525
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   526
  /* At Index 1016, subindex 1, ... : 32 bit values : msb ... lsb :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   527
     00 - node_consumer (8b) - time_ms (16b)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   528
     Put 0 to ignore the entry.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   529
  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   530
  for (i = 0 ; i < nbHeartbeats ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   531
    data = (((tabHeartbeatConsumer + i)->nodeProducer & 0xFF)<< 16) | 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   532
      ((tabHeartbeatConsumer + i)->time_ms & 0xFFFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   533
    err = writeNetworkDict(0, slaveNode, 0x1016, i + 1, 4, 0, &data); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   534
    waitingWriteToSlaveDict(slaveNode, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   535
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   536
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   537
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   538
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   539
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   540
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   541
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   542
void slaveHeartbeatProducer(UNS8 slaveNode, UNS16 time)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   543
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   544
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   545
  MSG_WAR(0x3F47, "Configuring heartbeat producer for node  : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   546
  /* At index 1017, subindex 0, defining the time to send the heartbeat. Put 0 to never send heartbeat */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   547
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   548
  err = writeNetworkDict(0, slaveNode, 0x1017, 0, 2, 0, &time); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   549
  waitingWriteToSlaveDict(slaveNode, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   550
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   551
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   552
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   553
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   554
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   555
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   556
void masterPDOTransmissionMode(UNS32 indexPDO,  UNS8 transType)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   557
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   558
  MSG_WAR(0x3F48, "Configuring transmission from master, indexPDO : ", indexPDO);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   559
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   560
  /* At subindex 2, the transmission type */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   561
  setODentry(indexPDO, 2, &transType, 1, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   562
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   563
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   564
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   565
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   566
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   567
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   568
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   569
void slavePDOTransmissionMode(UNS8 slaveNode, UNS32 indexPDO,  UNS8 transType)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   570
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   571
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   572
  MSG_WAR(0x3F41, "Configuring transmission mode for node : ", slaveNode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   573
  MSG_WAR(0x3F42, "                              indexPDO : ", indexPDO);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   574
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   575
  err = writeNetworkDict(0, slaveNode, indexPDO, 2, 1, 0, &transType); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   576
  waitingWriteToSlaveDict(slaveNode, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   577
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   578
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   579
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   580
//------------------------------------------------------------------------------
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   581
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   582
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   583
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   584
void masterSYNCPeriod(UNS32 SYNCPeriod)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   585
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   586
  UNS32 cobId = 0x40000080;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   587
  MSG_WAR(0x3F49, "Configuring master to send SYNC every ... micro-seconds :", SYNCPeriod);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   588
  /* At index 0x1006, subindex 0 : the period in ms */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   589
  setODentry(0x1006, 0, &SYNCPeriod , 4, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   590
  /* At index 0x1005, subindex 0 : Device generate SYNC signal with CobId 0x80 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   591
  setODentry(0x1005, 0, &cobId, 4, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   592
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   593
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   594
void help()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   595
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   596
  printf("**************************************************************\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   597
  printf("*  AppliMaster                                               *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   598
  printf("*                [-b b]                                      *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   599
  printf("*                                                            *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   600
  printf("*     b : bus [default 0]                                    *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   601
  printf("*                                                            *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   602
  printf("*  This exemple run AppliMaster on bus 0                     *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   603
  printf("*   AppliMaster -b 0                                         *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   604
  printf("*                                                            *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   605
  printf("**************************************************************\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   606
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   607
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   608
/****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   609
/***************************  MAIN  *****************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   610
/****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   611
int main(int argc,char **argv)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   612
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   613
  UNS8 second_last;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   614
  UNS8 minutes_last;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   615
  UNS8 sendingResetError = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   616
  int i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   617
  HANDLE ok;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   618
  char c;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   619
  extern char *optarg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   620
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   621
  while ((c = getopt(argc, argv, "-b:")) != EOF)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   622
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   623
    switch(c)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   624
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   625
      case 'b' :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   626
        if (optarg[0] == 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   627
        {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   628
          help();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   629
          exit(1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   630
        }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   631
        board.busname = optarg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   632
        break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   633
      default:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   634
        help();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   635
        exit(1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   636
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   637
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   638
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   639
  /****************************** INITIALISATION *******************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   640
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   641
  /* Launch the timer*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   642
    initTimer( );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   643
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   644
  /* arrays initialisation, etc */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   645
  initCANopenMain();     
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   646
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   647
  /* arrays initialisation, etc */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   648
  initCANopenMaster();  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   649
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   650
  /* Defining the node Id */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   651
  setNodeId(0x01);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   652
  MSG_WAR(0x3F50, "My node ID is : ", getNodeId()); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   653
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   654
  /* Put the master in operational mode */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   655
  setState(Operational);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   656
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   657
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   658
  /* Init the table of connected nodes */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   659
  for (i = 0 ; i < 128 ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   660
    connectedNode[i] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   661
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   662
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   663
  ok = f_can_open(& board);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   664
  if (ok == NULL) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   665
    MSG_ERR(0x1F02,"Unable to open the board", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   666
    MSG_ERR(0x1F03,"Edit includeMakefileLinux to verify that the application is configured for the good board", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   667
    exit (-1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   668
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   669
  else {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   670
    MSG_WAR(0x3F03, "Board 0 opened ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   671
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   672
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   673
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   674
  /* Launch the thread to receive the messages */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   675
  pthread_create( &threadM, NULL, (void *)&waitMessage, NULL);	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   676
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   677
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   678
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   679
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   680
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   681
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   682
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   683
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   684
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   685
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   686
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   687
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   688
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   689
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   690
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   691
  /******************** CONFIGURING THE NETWORK **************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   692
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   693
  /* Which nodes are connected ? */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   694
  /* Sending a request Node guard to node 5 and 6 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   695
  MSG_WAR(0x3F04, "Sending a node guard to node : ", 5);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   696
  masterReadNodeState(0, 0x05);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   697
  /* Sending a message to the node 6, only as example */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   698
  MSG_WAR(0x3F04, "Sending a node guard to node : ", 6);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   699
  masterReadNodeState(0, 0x06);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   700
  /* Waiting for a second the response */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   701
  sleep(1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   702
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   703
  /* Whose node have answered ? */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   704
  connectedNode[5] = stateNode(5);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   705
  connectedNode[6] = stateNode(6);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   706
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   707
  /* Configure the SDO master to communicate with node 5 and node 6 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   708
  configure_master_SDO(0x1280, 0x05);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   709
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   710
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   711
  /* Configure the SDO of node 5 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   712
  /* getNodeId() returns my node Id */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   713
  configure_client_SDO(0x05, getNodeId());
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   714
  /* Mapping of the PDO 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   715
     Chose some COBID in (hexa) 181-1FF, 201-27F, 281-2FF, 301-37F, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   716
     381-3FF, 401-47F, 481-4FF, 501-57F,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   717
     without other restriction.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   718
     (Of course, you must not define 2 PDO transmit with the same cobId !!)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   719
  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   720
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   721
  /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   722
     *** PDO node 1 <-- node 5 ***
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   723
     *** cobId 0x181 *************
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   724
     MASTER (node 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   725
     Mapped to variables (node1) [index-subindex-size_bits]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   726
       day    [0x6002 - 0x04 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   727
       hour   [0x6002 - 0x03 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   728
       second [0x6002 - 0x01 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   729
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   730
     SLAVE (node 5)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   731
     Mapped to variables (node5) [index-subindex-size_bits]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   732
       day    [0x2000 - 0x04 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   733
       hour   [0x2000 - 0x03 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   734
       second [0x2000 - 0x01 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   735
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   736
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   737
  /* Configuring the first PDO receive, defined at index 0x1400 and 0x1600 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   738
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   739
    s_mappedVar tabMappedVar[8] = { {0x6002,4,8}, {0x6002,3,8}, {0x6002,1,8}, };
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   740
    masterMappingPDO(0x1400, 0x181, tabMappedVar, 3);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   741
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   742
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   743
  /* Configuring the first PDO transmit, defined at index 0x1800 and 0x1A00 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   744
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   745
    s_mappedVar tabMappedVar[8] = { {0x2000,4,8}, {0x2000,3,8}, {0x2000,1,8}, };
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   746
    slaveMappingPDO(0x05, 0x1800, 0x181, tabMappedVar, 3);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   747
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   748
   /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   749
     *** PDO node 1 <-- node 5 ***
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   750
     *** cobId 0x182 *************
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   751
     MASTER (node 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   752
     Mapped to variables (node1) [index-subindex-size_bits]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   753
       minute    [0x6002 - 0x02 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   754
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   755
     SLAVE (node 5)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   756
     Mapped to variables (node5) [index-subindex-size_bits]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   757
       minute    [0x2000 - 0x02 - 8]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   758
   */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   759
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   760
  /* Configuring PDO receive, defined at index 0x1400 and 0x1600 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   761
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   762
    s_mappedVar tabMappedVar[8] = { {0x6002,2,8} };
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   763
    masterMappingPDO(0x1401, 0x182, tabMappedVar, 1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   764
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   765
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   766
  /* Configuring PDO transmit, defined at index 0x1800 and 0x1A00 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   767
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   768
    s_mappedVar tabMappedVar[8] = { {0x2000,2,8} };
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   769
    slaveMappingPDO(0x05, 0x1801, 0x182, tabMappedVar, 1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   770
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   771
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   772
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   773
  /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   774
     *** PDO node 1 <-- node 5 ***
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   775
     *** cobId 0x183 *************
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   776
     Error management :  By this way, The node can send by PDO an error
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   777
     MASTER (node 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   778
     Mapped to variables (node1) [index-subindex-size_bits]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   779
       canopenErrNb_node5   [0x6000 - 0x00 - 32]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   780
       canopenErrVal_node5  [0x6001 - 0x00 - 32] 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   781
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   782
     SLAVE (node 5)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   783
     Mapped to variables (node5) [index-subindex-size_bytes]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   784
       canopenErrNb     [0x6000 - 0x00 - 32]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   785
       canopenErrVal    [0x6001 - 0x00 - 32]  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   786
  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   787
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   788
  /* Configuring  PDO receive, defined at index 0x1402 and 0x1602 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   789
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   790
    s_mappedVar tabMappedVar[8] = { {0x6000,0,32}, {0x6001, 0, 32}};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   791
    masterMappingPDO(0x1402, 0x183, tabMappedVar, 2);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   792
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   793
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   794
  /* Configuring PDO transmit, defined at index 0x1802 and 0x1A02 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   795
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   796
    s_mappedVar tabMappedVar[8] = { {0x6000,0,32}, {0x6001, 0, 32}};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   797
    slaveMappingPDO(0x05, 0x1802, 0x183, tabMappedVar, 2);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   798
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   799
 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   800
  /*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   801
     *** PDO node 1 --> node 5 ***
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   802
     *** cobId 0x184 *************
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   803
     Error management :  To reset the error
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   804
     MASTER (node 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   805
     Mapped to variables (node1) [index-subindex-size_bits]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   806
       canopenErrNb_node5     [0x6000 - 0x00 - 32]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   807
       canopenErrVal_node5    [0x6001 - 0x00 - 32] 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   808
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   809
     SLAVE (node 5)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   810
     Mapped to variables (node5) [index-subindex-size_bytes]: 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   811
       canopenErrNb     [0x6000 - 0x00 - 32]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   812
       canopenErrVal    [0x6001 - 0x00 - 32]  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   813
  */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   814
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   815
  /* Configuring  PDO transmit, defined at index 0x1803 and 0x1103 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   816
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   817
    s_mappedVar tabMappedVar[8] = { {0x6000,0,32}, {0x6001, 0, 32}};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   818
    masterMappingPDO(0x1801, 0x184, tabMappedVar, 2);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   819
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   820
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   821
  /* Configuring PDO transmit, defined at index 0x1403 and 0x1603 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   822
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   823
    s_mappedVar tabMappedVar[8] = { {0x6000,0,32}, {0x6001, 0, 32}};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   824
    slaveMappingPDO(0x05, 0x1400, 0x184, tabMappedVar, 2);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   825
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   826
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   827
  /* Configuring the node 5 heartbeat */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   828
  /* Check every 3000 ms if it have received a heartbeat from node 1 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   829
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   830
    UNS8 nbHeartbeatsToReceive = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   831
    s_heartbeatConsumer tabHeartbeatConsumer[10] = {{1, 0xBB8}};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   832
    slaveHeartbeatConsumer(0x05, tabHeartbeatConsumer, nbHeartbeatsToReceive);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   833
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   834
  /* Sending every 1000 ms an heartbeat */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   835
  slaveHeartbeatProducer(0x05, 0x3E8);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   836
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   837
  /* Configuring the master heartbeat */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   838
  /* Check every 3000 ms if it have received a heartbeat from node 5 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   839
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   840
    UNS8 nbHeartbeatsToReceive = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   841
    s_heartbeatConsumer tabHeartbeatConsumer[10] = {{5, 0xBB8}};
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   842
    masterHeartbeatConsumer(tabHeartbeatConsumer, nbHeartbeatsToReceive);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   843
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   844
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   845
    /* Sending every 1000 ms an heartbeat */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   846
    masterHeartbeatProducer(0x3E8);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   847
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   848
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   849
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   850
    /* Configuring the transmission mode of the PDO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   851
    slavePDOTransmissionMode(0x05, 0x1800,  TRANS_EVERY_N_SYNC (1));
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   852
    slavePDOTransmissionMode(0x05, 0x1801,  TRANS_EVENT);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   853
    slavePDOTransmissionMode(0x05, 0x1802,  TRANS_EVENT);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   854
    masterPDOTransmissionMode(0x1801,  TRANS_EVENT);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   855
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   856
    /* Configuring the master to send a SYNC message every 1 s */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   857
    /* Note than any other node can send the SYNC instead of the master */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   858
    masterSYNCPeriod(1000000); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   859
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   860
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   861
      // Reading the period of heartbeat which has been written in node 5 dictionary
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   862
      UNS8 node = 5;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   863
      UNS16 index = 0x1017;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   864
      UNS8 subindex = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   865
      //UNS8 notused = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   866
      UNS16 hb = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   867
      UNS8  size_data = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   868
      UNS8 error;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   869
      MSG_WAR(0x3F50, "Reading dictionary noeud 5, 1017/0", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   870
      error = readNetworkDict(0, node, index, subindex, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   871
      //error = readNetworkDict(0, node, index, subindex, &notused);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   872
      if (error) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   873
	MSG_ERR(0x1F50, "!!! ERROR reading dictionary noeud 5, 1017/0", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   874
	exit (-1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   875
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   876
      /* Waiting until the server has responded */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   877
      error = waitingReadToSlaveDict(node,  (UNS16 *)&hb,  &size_data, error);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   878
      MSG_WAR(0x1F51, "Read dictionary of node 5, index/subindex 1017/0 value = ", hb);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   879
      MSG_WAR(0x1F51, "         size of data (bytes) = ", size_data);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   880
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   881
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   882
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   883
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   884
    /* Put the node 5 in operational mode 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   885
       The mode is changed according to the slave state machine mode :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   886
         initialisation  ---> pre-operational (Automatic transition)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   887
         pre-operational <--> operational
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   888
         pre-operational <--> stopped
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   889
         pre-operational, operational, stopped -> initialisation
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   890
       NMT_Start_Node           // Put the node in operational mode       
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   891
       NMT_Stop_Node		// Put the node in stopped mode    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   892
       NMT_Enter_PreOperational // Put the node in pre_operational mode
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   893
       NMT_Reset_Node		// Put the node in initialization mode 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   894
       NMT_Reset_Comunication	// Put the node in initialization mode 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   895
    */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   896
    masterSendNMTstateChange(0, 0x05, NMT_Start_Node);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   897
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   898
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   899
    // Note
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   900
    //-----
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   901
    // We do not have mapped the variable canopenErrNB and canopenErrVAL.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   902
    // We should have done that !
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   903
    // the macro MSG_ERR try to send the PDO(s) which contains these two variables.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   904
    // While the PDO will not be found, if you are printing the warnings in file pdo.c,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   905
    // it will print "0X393B Unable to send variable on event :  not mapped in a PDO to send on event" for  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   906
    // example when you enter the function heartbeatError. 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   907
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   908
   /******************** END CONFIGURING THE NETWORK **********************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   909
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   910
    /* Launch the thread to send the SYNC message    */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   911
    pthread_create( &threadS, NULL, (void *)&transmitSync , NULL);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   912
    /* Init the errors values that may send the node 5 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   913
    canopenErrNB_node5 = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   914
    canopenErrVAL_node5 = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   915
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   916
    /****************************** RUNNING *******************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   917
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   918
  /* SDO test with node 5 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   919
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   920
    // Reading string
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   921
    UNS8 dataW[20];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   922
    UNS8 dataR[20];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   923
    UNS8 size;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   924
    UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   925
    MSG_WAR(0x3F05, "Test SDO", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   926
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   927
    MSG_WAR(0x3F10, "Writing string to node 5 index 0x6002, subindex 0 ...", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   928
    strcpy(dataW, "Au Revoir");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   929
    MSG_WAR(0x3F10, dataW, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   930
    size = 20;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   931
    err = writeNetworkDict(0, 5, 0x6002, 0, 10, visible_string, dataW);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   932
    err = waitingWriteToSlaveDict(5, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   933
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   934
    err = readNetworkDict(0, 5, 0x6002, 0, visible_string);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   935
    err = waitingReadToSlaveDict(5, dataR, &size, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   936
    MSG_WAR(0x3F08, "Data read from node 5 index 0x6002, subindex 0 ..." , 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   937
    MSG_WAR(0x3F08, dataR, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   938
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   939
    MSG_WAR(0x3F08, "node 5. Hardware version. (default = compil. date) ...", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   940
    err = readNetworkDict(0, 5, 0x1009, 0, visible_string);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   941
    err = waitingReadToSlaveDict(5, dataR, &size, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   942
    MSG_WAR(0x3F08, dataR, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   943
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   944
    MSG_WAR(0x3F08, "node 5. Software version. (default = compil. time) ...", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   945
    err = readNetworkDict(0, 5, 0x100A, 0, visible_string);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   946
    err = waitingReadToSlaveDict(5, dataR, &size, err);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   947
    MSG_WAR(0x3F08, dataR, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   948
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   949
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   950
  // Node identity ?
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   951
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   952
      UNS8 *data;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   953
      UNS8 size;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   954
      UNS8 dataType;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   955
      // Manufacturer Device name (default = empty string)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   956
      getODentry(0x1008, 0x0, (void **)&data, &size, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   957
      MSG_WAR(0x3F09, data, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   958
      // Manufacturer Hardware version. (default = compilation. date)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   959
      getODentry(0x1009, 0x0, (void **)&data, &size, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   960
      MSG_WAR(0x3F09, data, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   961
      // Manufacturer Software version. (default = compilation. time)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   962
      getODentry(0x100A, 0x0, (void **)&data, &size, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   963
      MSG_WAR(0x3F09, data, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   964
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   965
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   966
    while (1) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   967
      if (minutes != minutes_last) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   968
	printf("Minutes changed\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   969
	minutes_last = minutes;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   970
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   971
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   972
      if (second != second_last) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   973
	printf("Date : %d, %02dH%02d-%02d\n", day, hour, minutes, second);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   974
	second_last = second;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   975
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   976
	if (canopenErrNB_node5) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   977
	  printf("Received an error from node 5, NB : 0x%X, value : 0x%X\n", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   978
		canopenErrNB_node5 , canopenErrVAL_node5);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   979
	  // Resetting the error
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   980
	  canopenErrNB_node5 = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   981
	  canopenErrVAL_node5 = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   982
	  sendingResetError = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   983
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   984
       
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   985
	if ((second < 5) && sendingResetError) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   986
	  printf("Sending to node 5 a PDO event to reset the error NB: 0x%X and VAL: 0x%X\n",
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   987
		 canopenErrNB_node5, canopenErrVAL_node5);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   988
	    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   989
	  sendPDOevent(0, &canopenErrNB_node5);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   990
	  sendingResetError = 0; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   991
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   992
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   993
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   994
      }	// end if (second != second_last)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   995
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   996
      // Testing if heartsbeat have been received, and send a heartbeat if it is time.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   997
      // I have put that in a thread, but I don't know why, on HB not received,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   998
      // it doesn't returns from heartbeatError() to the thread.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   999
      heartbeatMGR();  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1000
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1001
      usleep(10000);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1002
      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1003
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1004
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1005
}