examples/TestMasterSlaveLSS/TestMasterSlaveLSS.c
author greg
Tue, 19 Feb 2008 14:53:59 +0100
changeset 403 57d5da3b6228
parent 387 6efc85c5493e
child 454 bc000083297a
permissions -rw-r--r--
add changes in configure to force xeno --library-dir
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
     1
/*
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack. 
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
     3
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
     5
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
     6
See COPYING file for copyrights details.
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
     7
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    12
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    16
Lesser General Public License for more details.
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    17
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    21
*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    22
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    23
#if defined(WIN32) && !defined(__CYGWIN__)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    24
#include <windows.h>
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    25
#include "getopt.h"
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    26
void pause(void)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    27
{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    28
	system("PAUSE");
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    29
}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    30
#else
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    31
#include <stdio.h>
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    32
#include <string.h>
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    33
#include <unistd.h>
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    34
#include <stdlib.h>
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    35
#include <signal.h>
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    36
#endif
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    37
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    38
#include "canfestival.h"
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    39
//#include <can_driver.h>
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    40
//#include <timers_driver.h>
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    41
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    42
#include "Master.h"
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    43
#include "SlaveA.h"
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    44
#include "SlaveB.h"
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    45
#include "TestMasterSlaveLSS.h"
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    46
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    47
s_BOARD SlaveBoardA = {"0", "125K"};
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    48
s_BOARD SlaveBoardB = {"1", "125K"};
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    49
s_BOARD MasterBoard = {"2", "125K"};
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    50
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    51
#if !defined(WIN32) || defined(__CYGWIN__)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    52
void catch_signal(int sig)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    53
{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    54
  signal(SIGTERM, catch_signal);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    55
  signal(SIGINT, catch_signal);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    56
  eprintf("Got Signal %d\n",sig);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    57
}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    58
#endif
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    59
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    60
void help()
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    61
{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    62
  printf("**************************************************************\n");
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    63
  printf("*  TestMasterSlaveLSS                                        *\n");
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    64
  printf("*                                                            *\n");
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    65
  printf("*  A LSS example for PC. It does implement 3 CanOpen         *\n");
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    66
  printf("*  nodes in the same process. A master and 2 slaves. All     *\n");
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    67
  printf("*  communicate together, exchanging periodically NMT, SYNC,  *\n");
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    68
  printf("*  SDO and PDO. Master configure heartbeat producer time     *\n");
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    69
  printf("*  at 0 ms for slave node-id 0x02 and 0x03 by concise DCF.   *\n");                                  
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    70
  printf("*                                                            *\n");
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    71
  printf("*   Usage:                                                   *\n");
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    72
  printf("*   ./TestMasterSlaveLSS  [OPTIONS]                          *\n");
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    73
  printf("*                                                            *\n");
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    74
  printf("*   OPTIONS:                                                 *\n");
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    75
  printf("*     -l : Can library [\"libcanfestival_can_virtual.so\"]   *\n");
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    76
  printf("*                                                            *\n");
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    77
  printf("*    SlaveA:                                                 *\n");
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    78
  printf("*     -a : bus name [\"0\"]                                  *\n");
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    79
  printf("*     -A : 1M,500K,250K,125K,100K,50K,20K,10K,none(disable)  *\n");
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    80
  printf("*                                                            *\n");
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    81
   printf("*    SlaveB:                                                *\n");
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    82
  printf("*     -b : bus name [\"1\"]                                  *\n");
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    83
  printf("*     -B : 1M,500K,250K,125K,100K,50K,20K,10K,none(disable)  *\n");
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    84
  printf("*                                                            *\n");
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    85
  printf("*    Master:                                                 *\n");
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
    86
  printf("*     -m : bus name [\"2\"]                                  *\n");
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    87
  printf("*     -M : 1M,500K,250K,125K,100K,50K,20K,10K,none(disable)  *\n");
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    88
  printf("*                                                            *\n");
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    89
  printf("**************************************************************\n");
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    90
}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    91
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    92
/***************************  INIT  *****************************************/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    93
void InitNodes(CO_Data* d, UNS32 id)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    94
{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    95
	/****************************** INITIALISATION SLAVE_A *******************************/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    96
	if(strcmp(SlaveBoardA.baudrate, "none")) {
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    97
		/* Set an invalid nodeID */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    98
		setNodeId(&TestSlaveA_Data, 0xFF);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
    99
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   100
		/* init */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   101
		setState(&TestSlaveA_Data, Initialisation);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   102
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   103
	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   104
	/****************************** INITIALISATION SLAVE_B *******************************/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   105
	if(strcmp(SlaveBoardB.baudrate, "none")) {
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   106
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   107
		/* Set an invalid nodeID */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   108
		setNodeId(&TestSlaveB_Data, 0xFF);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   109
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   110
		/* init */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   111
		setState(&TestSlaveB_Data, Initialisation);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   112
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   113
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   114
	/****************************** INITIALISATION MASTER *******************************/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   115
	if(strcmp(MasterBoard.baudrate, "none")){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   116
		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   117
		/* Defining the node Id */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   118
		setNodeId(&TestMaster_Data, 0x01);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   119
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   120
		/* init */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   121
		setState(&TestMaster_Data, Initialisation);		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   122
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   123
}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   124
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   125
/****************************************************************************/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   126
/***************************  MAIN  *****************************************/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   127
/****************************************************************************/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   128
int main(int argc,char **argv)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   129
{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   130
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   131
  int c;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   132
  extern char *optarg;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   133
  char* LibraryPath="../../drivers/can_virtual/libcanfestival_can_virtual.so";
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   134
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   135
  while ((c = getopt(argc, argv, "-m:a:b:M:A:B:l:")) != EOF)
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   136
  {
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   137
    switch(c)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   138
    {
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   139
      case 'a' :
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   140
        if (optarg[0] == 0)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   141
        {
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   142
          help();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   143
          exit(1);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   144
        }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   145
        SlaveBoardA.busname = optarg;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   146
        break;
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   147
      case 'b' :
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   148
        if (optarg[0] == 0)
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   149
        {
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   150
          help();
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   151
          exit(1);
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   152
        }
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   153
        SlaveBoardB.busname = optarg;
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   154
        break;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   155
      case 'm' :
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   156
        if (optarg[0] == 0)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   157
        {
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   158
          help();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   159
          exit(1);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   160
        }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   161
        MasterBoard.busname = optarg;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   162
        break;
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   163
      case 'A' :
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   164
        if (optarg[0] == 0)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   165
        {
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   166
          help();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   167
          exit(1);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   168
        }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   169
        SlaveBoardA.baudrate = optarg;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   170
        break;
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   171
      case 'B' :
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   172
        if (optarg[0] == 0)
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   173
        {
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   174
          help();
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   175
          exit(1);
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   176
        }
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   177
        SlaveBoardB.baudrate = optarg;
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   178
        break;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   179
      case 'M' :
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   180
        if (optarg[0] == 0)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   181
        {
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   182
          help();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   183
          exit(1);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   184
        }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   185
        MasterBoard.baudrate = optarg;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   186
        break;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   187
      case 'l' :
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   188
        if (optarg[0] == 0)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   189
        {
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   190
          help();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   191
          exit(1);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   192
        }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   193
        LibraryPath = optarg;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   194
        break;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   195
      default:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   196
        help();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   197
        exit(1);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   198
    }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   199
  }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   200
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   201
#if !defined(WIN32) || defined(__CYGWIN__)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   202
  /* install signal handler for manual break */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   203
	signal(SIGTERM, catch_signal);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   204
	signal(SIGINT, catch_signal);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   205
#endif
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   206
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   207
#ifndef NOT_USE_DYNAMIC_LOADING
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   208
	if (LoadCanDriver(LibraryPath) == NULL)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   209
	    printf("Unable to load library: %s\n",LibraryPath);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   210
#endif		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   211
	// Open CAN devices
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   212
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   213
	if(strcmp(SlaveBoardA.baudrate, "none")){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   214
		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   215
		TestSlaveA_Data.heartbeatError = TestSlaveA_heartbeatError;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   216
		TestSlaveA_Data.initialisation = TestSlaveA_initialisation;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   217
		TestSlaveA_Data.preOperational = TestSlaveA_preOperational;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   218
		TestSlaveA_Data.operational = TestSlaveA_operational;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   219
		TestSlaveA_Data.stopped = TestSlaveA_stopped;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   220
		TestSlaveA_Data.post_sync = TestSlaveA_post_sync;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   221
		TestSlaveA_Data.post_TPDO = TestSlaveA_post_TPDO;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   222
		TestSlaveA_Data.storeODSubIndex = TestSlaveA_storeODSubIndex;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   223
		TestSlaveA_Data.post_emcy = TestSlaveA_post_emcy;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   224
		/* in this example the slave doesn't support Store configuration*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   225
		TestSlaveA_Data.lss_StoreConfiguration = TestSlaveA_StoreConfiguration;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   226
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   227
		if(!canOpen(&SlaveBoardA,&TestSlaveA_Data)){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   228
			eprintf("Cannot open SlaveA Board (%s,%s)\n",SlaveBoardA.busname, SlaveBoardA.baudrate);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   229
			goto fail_slaveA;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   230
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   231
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   232
	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   233
	if(strcmp(SlaveBoardB.baudrate, "none")){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   234
		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   235
		TestSlaveB_Data.heartbeatError = TestSlaveB_heartbeatError;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   236
		TestSlaveB_Data.initialisation = TestSlaveB_initialisation;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   237
		TestSlaveB_Data.preOperational = TestSlaveB_preOperational;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   238
		TestSlaveB_Data.operational = TestSlaveB_operational;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   239
		TestSlaveB_Data.stopped = TestSlaveB_stopped;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   240
		TestSlaveB_Data.post_sync = TestSlaveB_post_sync;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   241
		TestSlaveB_Data.post_TPDO = TestSlaveB_post_TPDO;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   242
		TestSlaveB_Data.storeODSubIndex = TestSlaveB_storeODSubIndex;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   243
		TestSlaveB_Data.post_emcy = TestSlaveB_post_emcy;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   244
		TestSlaveB_Data.lss_StoreConfiguration = TestSlaveB_StoreConfiguration;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   245
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   246
		if(!canOpen(&SlaveBoardB,&TestSlaveB_Data)){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   247
			eprintf("Cannot open SlaveB Board (%s,%s)\n",SlaveBoardB.busname, SlaveBoardB.baudrate);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   248
			goto fail_slaveB;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   249
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   250
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   251
	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   252
	if(strcmp(MasterBoard.baudrate, "none")){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   253
		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   254
		TestMaster_Data.heartbeatError = TestMaster_heartbeatError;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   255
		TestMaster_Data.initialisation = TestMaster_initialisation;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   256
		TestMaster_Data.preOperational = TestMaster_preOperational;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   257
		TestMaster_Data.operational = TestMaster_operational;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   258
		TestMaster_Data.stopped = TestMaster_stopped;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   259
		TestMaster_Data.post_sync = TestMaster_post_sync;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   260
		TestMaster_Data.post_TPDO = TestMaster_post_TPDO;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   261
		TestMaster_Data.post_emcy = TestMaster_post_emcy;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   262
		TestMaster_Data.post_SlaveBootup=TestMaster_post_SlaveBootup;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   263
		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   264
		if(!canOpen(&MasterBoard,&TestMaster_Data)){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   265
			eprintf("Cannot open Master Board (%s,%s)\n",MasterBoard.busname, MasterBoard.baudrate);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   266
			goto fail_master;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   267
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   268
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   269
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   270
	// Start timer thread
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   271
	StartTimerLoop(&InitNodes);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   272
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   273
	// wait Ctrl-C
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   274
	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   275
	pause();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   276
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   277
	eprintf("Finishing.\n");
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   278
    EnterMutex();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   279
	masterSendNMTstateChange (&TestMaster_Data, 0x00, NMT_Stop_Node);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   280
    LeaveMutex();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   281
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   282
	eprintf("reset\n");
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   283
	// Stop master
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   284
    EnterMutex();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   285
	setState(&TestMaster_Data, Stopped);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   286
    LeaveMutex();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   287
	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   288
	// Stop timer thread
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   289
	StopTimerLoop();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   290
	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   291
	// Close CAN devices (and can threads)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   292
	if(strcmp(MasterBoard.baudrate, "none")) canClose(&TestMaster_Data);	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   293
fail_master:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   294
	if(strcmp(SlaveBoardB.baudrate, "none")) canClose(&TestSlaveB_Data);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   295
fail_slaveB:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   296
	if(strcmp(SlaveBoardA.baudrate, "none")) canClose(&TestSlaveA_Data);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   297
fail_slaveA:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   298
	return 0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   299
}