examples/TestMasterSlave/TestMasterSlave.c
author etisserant
Tue, 15 Jan 2008 09:30:26 +0100
changeset 356 171830d836ce
parent 343 118c1cabd0b0
child 381 854c43cdc24a
permissions -rw-r--r--
.cvsignore updated for windows targets.
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
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    23
#if defined(WIN32) && !defined(__CYGWIN__)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    24
#include <windows.h>
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    25
#include "getopt.h"
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    26
void pause(void)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    27
{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    28
	system("PAUSE");
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    29
}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    30
#else
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
#include <stdio.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
#include <string.h>
169
90c0a676e631 Removed compilation warnings with some GCC. + Fixed test for baudrate = none
etisserant
parents: 161
diff changeset
    33
#include <unistd.h>
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
#include <stdlib.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
#include <signal.h>
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    36
#endif
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
156
515d11cb496e Removed dead code.
etisserant
parents: 149
diff changeset
    38
#include "canfestival.h"
515d11cb496e Removed dead code.
etisserant
parents: 149
diff changeset
    39
//#include <can_driver.h>
515d11cb496e Removed dead code.
etisserant
parents: 149
diff changeset
    40
//#include <timers_driver.h>
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
#include "Master.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
#include "Slave.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
#include "TestMasterSlave.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
UNS32 OnMasterMap1Update(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
	eprintf("OnSlaveMap1Update:%d\n", SlaveMap1);
31
a82b70738e5c Code clean-up and fixed xenomai compile problem
lbessard
parents: 0
diff changeset
    49
	return 0;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
    52
s_BOARD SlaveBoard = {"0", "125K"};
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
    53
s_BOARD MasterBoard = {"1", "125K"};
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    54
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    55
#if !defined(WIN32) || defined(__CYGWIN__)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
void catch_signal(int sig)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
  signal(SIGTERM, catch_signal);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
  signal(SIGINT, catch_signal);
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
    60
  eprintf("Got Signal %d\n",sig);
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
    61
}
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    62
#endif
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
void help()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
  printf("**************************************************************\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
  printf("*  TestMasterSlave                                           *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
  printf("*                                                            *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
  printf("*  A simple example for PC. It does implement 2 CanOpen      *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
  printf("*  nodes in the same process. A master and a slave. Both     *\n");
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    71
  printf("*  communicate together, exchanging periodically NMT, SYNC,  *\n");
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
    72
  printf("*  SDO and PDO. Master configure heartbeat producer time     *\n");
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
    73
  printf("*  at 1000 ms for slave node-id 0x02 by concise DCF.         *\n");                                  
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    74
  printf("*                                                            *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    75
  printf("*   Usage:                                                   *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    76
  printf("*   ./TestMasterSlave  [OPTIONS]                             *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    77
  printf("*                                                            *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    78
  printf("*   OPTIONS:                                                 *\n");
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    79
  printf("*     -l : Can library [\"libcanfestival_can_virtual.so\"]     *\n");
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    80
  printf("*                                                            *\n");
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    81
  printf("*    Slave:                                                  *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    82
  printf("*     -s : bus name [\"0\"]                                    *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    83
  printf("*     -S : 1M,500K,250K,125K,100K,50K,20K,10K,none(disable)  *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    84
  printf("*                                                            *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    85
  printf("*    Master:                                                 *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    86
  printf("*     -m : bus name [\"1\"]                                    *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    87
  printf("*     -M : 1M,500K,250K,125K,100K,50K,20K,10K,none(disable)  *\n");
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
  printf("*                                                            *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
  printf("**************************************************************\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    92
/***************************  INIT  *****************************************/
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    93
void InitNodes(CO_Data* d, UNS32 id)
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    94
{
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    95
	/****************************** INITIALISATION SLAVE *******************************/
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
    96
	if(strcmp(SlaveBoard.baudrate, "none")) {
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 331
diff changeset
    97
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 331
diff changeset
    98
#ifdef CO_ENABLE_LSS
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 331
diff changeset
    99
		/* Set an invalid nodeID */
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 331
diff changeset
   100
		setNodeId(&TestSlave_Data, 0xFF);
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 331
diff changeset
   101
#else
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   102
		setNodeId(&TestSlave_Data, 0x02);
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 331
diff changeset
   103
#endif
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 331
diff changeset
   104
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   105
		/* init */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   106
		setState(&TestSlave_Data, Initialisation);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   107
	}
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   108
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   109
	/****************************** INITIALISATION MASTER *******************************/
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   110
	if(strcmp(MasterBoard.baudrate, "none")){
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   111
 		RegisterSetODentryCallBack(&TestMaster_Data, 0x2000, 0, &OnMasterMap1Update);
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   112
		
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   113
		/* Defining the node Id */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   114
		setNodeId(&TestMaster_Data, 0x01);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   115
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   116
		/* init */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   117
		setState(&TestMaster_Data, Initialisation);
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   118
			
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   119
	}
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   120
}
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   121
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
/****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
/***************************  MAIN  *****************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
/****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
int main(int argc,char **argv)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
191
1e6e3d261b8f CleanUp and minor fixes
etisserant
parents: 179
diff changeset
   128
  int c;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
  extern char *optarg;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 331
diff changeset
   130
  char* LibraryPath="../../drivers/can_virtual/libcanfestival_can_virtual.so";
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   131
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   132
  while ((c = getopt(argc, argv, "-m:s:M:S:l:")) != EOF)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
    switch(c)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
      case 's' :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   137
        if (optarg[0] == 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
        {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
          help();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
          exit(1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
        }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
        SlaveBoard.busname = optarg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
        break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
      case 'm' :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
        if (optarg[0] == 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
        {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
          help();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
          exit(1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
        }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
        MasterBoard.busname = optarg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
        break;
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   152
      case 'S' :
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   153
        if (optarg[0] == 0)
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   154
        {
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   155
          help();
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   156
          exit(1);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   157
        }
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   158
        SlaveBoard.baudrate = optarg;
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   159
        break;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   160
      case 'M' :
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   161
        if (optarg[0] == 0)
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   162
        {
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   163
          help();
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   164
          exit(1);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   165
        }
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   166
        MasterBoard.baudrate = optarg;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   167
        break;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   168
      case 'l' :
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   169
        if (optarg[0] == 0)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   170
        {
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   171
          help();
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   172
          exit(1);
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   173
        }
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   174
        LibraryPath = optarg;
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   175
        break;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
      default:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
        help();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
        exit(1);
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
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   182
#if !defined(WIN32) || defined(__CYGWIN__)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   183
  /* install signal handler for manual break */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
	signal(SIGTERM, catch_signal);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
	signal(SIGINT, catch_signal);
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   186
#endif
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   187
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   188
#ifndef NOT_USE_DYNAMIC_LOADING
331
da55aa2f9e64 Minor changes, mostly PCAN/windows related.
etisserant
parents: 284
diff changeset
   189
	if (LoadCanDriver(LibraryPath) == NULL)
da55aa2f9e64 Minor changes, mostly PCAN/windows related.
etisserant
parents: 284
diff changeset
   190
	    printf("Unable to load library: %s\n",LibraryPath);
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   191
#endif		
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
	// Open CAN devices
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   193
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   194
	if(strcmp(SlaveBoard.baudrate, "none")){
149
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   195
		
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   196
		TestSlave_Data.heartbeatError = TestSlave_heartbeatError;
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   197
		TestSlave_Data.initialisation = TestSlave_initialisation;
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   198
		TestSlave_Data.preOperational = TestSlave_preOperational;
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   199
		TestSlave_Data.operational = TestSlave_operational;
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   200
		TestSlave_Data.stopped = TestSlave_stopped;
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   201
		TestSlave_Data.post_sync = TestSlave_post_sync;
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   202
		TestSlave_Data.post_TPDO = TestSlave_post_TPDO;
284
24bf3d692993 Implemented EMCY objects.
luis
parents: 262
diff changeset
   203
		TestSlave_Data.storeODSubIndex = TestSlave_storeODSubIndex;
24bf3d692993 Implemented EMCY objects.
luis
parents: 262
diff changeset
   204
		TestSlave_Data.post_emcy = TestSlave_post_emcy;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 331
diff changeset
   205
#ifdef CO_ENABLE_LSS
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 331
diff changeset
   206
		/* in this example the slave doesn't support Store configuration*/
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 331
diff changeset
   207
		//TestSlave_Data.lss_StoreConfiguration = TestSlave_StoreConfiguration;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 331
diff changeset
   208
		TestSlave_Data.lss_ChangeBaudRate=TestSlave_ChangeBaudRate;
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 331
diff changeset
   209
#endif
149
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   210
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   211
		if(!canOpen(&SlaveBoard,&TestSlave_Data)){
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   212
			eprintf("Cannot open Slave Board (%s,%s)\n",SlaveBoard.busname, SlaveBoard.baudrate);
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   213
			goto fail_slave;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   214
		}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   215
	}
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   216
	if(strcmp(MasterBoard.baudrate, "none")){
149
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   217
		
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   218
		TestMaster_Data.heartbeatError = TestMaster_heartbeatError;
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   219
		TestMaster_Data.initialisation = TestMaster_initialisation;
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   220
		TestMaster_Data.preOperational = TestMaster_preOperational;
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   221
		TestMaster_Data.operational = TestMaster_operational;
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   222
		TestMaster_Data.stopped = TestMaster_stopped;
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   223
		TestMaster_Data.post_sync = TestMaster_post_sync;
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   224
		TestMaster_Data.post_TPDO = TestMaster_post_TPDO;
284
24bf3d692993 Implemented EMCY objects.
luis
parents: 262
diff changeset
   225
		TestMaster_Data.post_emcy = TestMaster_post_emcy;
343
118c1cabd0b0 Primary LSS support, thanks to Jorge Berzosa.
etisserant
parents: 331
diff changeset
   226
		TestMaster_Data.post_SlaveBootup=TestMaster_post_SlaveBootup;
149
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   227
		
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   228
		if(!canOpen(&MasterBoard,&TestMaster_Data)){
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   229
			eprintf("Cannot open Master Board (%s,%s)\n",MasterBoard.busname, MasterBoard.baudrate);
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   230
			goto fail_master;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   231
		}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   232
	}
194
90d740ff7c21 Removed dummy sleep.
etisserant
parents: 191
diff changeset
   233
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   234
	// Start timer thread
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   235
	StartTimerLoop(&InitNodes);
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   236
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   237
	// wait Ctrl-C
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   238
	
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   239
	pause();
262
f1c892f3f93c Added exclusion mechanism to TestMasterSlave finish code
etisserant
parents: 194
diff changeset
   240
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   241
	eprintf("Finishing.\n");
262
f1c892f3f93c Added exclusion mechanism to TestMasterSlave finish code
etisserant
parents: 194
diff changeset
   242
    EnterMutex();
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   243
	masterSendNMTstateChange (&TestMaster_Data, 0x02, NMT_Reset_Node);
262
f1c892f3f93c Added exclusion mechanism to TestMasterSlave finish code
etisserant
parents: 194
diff changeset
   244
    LeaveMutex();
f1c892f3f93c Added exclusion mechanism to TestMasterSlave finish code
etisserant
parents: 194
diff changeset
   245
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   246
	eprintf("reset\n");
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   247
	// Stop master
262
f1c892f3f93c Added exclusion mechanism to TestMasterSlave finish code
etisserant
parents: 194
diff changeset
   248
    EnterMutex();
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   249
	setState(&TestMaster_Data, Stopped);
262
f1c892f3f93c Added exclusion mechanism to TestMasterSlave finish code
etisserant
parents: 194
diff changeset
   250
    LeaveMutex();
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   251
	
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   252
	// Stop timer thread
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   253
	StopTimerLoop();
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   254
	
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   255
	// Close CAN devices (and can threads)
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   256
	if(strcmp(SlaveBoard.baudrate, "none")) canClose(&TestSlave_Data);
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   257
fail_master:
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   258
	if(strcmp(MasterBoard.baudrate, "none")) canClose(&TestMaster_Data);	
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   259
fail_slave:
179
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   260
	return 0;
763b6d32c1a6 Master configure slave's heartbeat producer time by concise DCF.
greg
parents: 172
diff changeset
   261
}