examples/TestMasterSlaveLSS/TestMasterSlaveLSS.c
author greg
Tue, 06 May 2008 09:11:41 +0200
changeset 457 ee7f0092bcb1
parent 454 bc000083297a
child 465 2ef560acfa86
permissions -rw-r--r--
fix typo line 135
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
454
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
    60
void help(void)
381
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
454
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   125
/***************************  EXIT  *****************************************/
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   126
void Exit(CO_Data* d, UNS32 id)
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   127
{
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   128
	eprintf("Finishing.\n");
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   129
	masterSendNMTstateChange (&TestMaster_Data, 0x00, NMT_Stop_Node);
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   130
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   131
	eprintf("reset\n");
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   132
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   133
	// Stop master
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   134
	setState(&TestMaster_Data, Stopped);
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   135
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   136
}
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   137
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   138
/****************************************************************************/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   139
/***************************  MAIN  *****************************************/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   140
/****************************************************************************/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   141
int main(int argc,char **argv)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   142
{
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   143
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   144
  int c;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   145
  extern char *optarg;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   146
  char* LibraryPath="../../drivers/can_virtual/libcanfestival_can_virtual.so";
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   147
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   148
  while ((c = getopt(argc, argv, "-m:a:b:M:A:B:l:")) != EOF)
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   149
  {
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   150
    switch(c)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   151
    {
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   152
      case 'a' :
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   153
        if (optarg[0] == 0)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   154
        {
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   155
          help();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   156
          exit(1);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   157
        }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   158
        SlaveBoardA.busname = optarg;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   159
        break;
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   160
      case 'b' :
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   161
        if (optarg[0] == 0)
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   162
        {
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   163
          help();
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   164
          exit(1);
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   165
        }
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   166
        SlaveBoardB.busname = optarg;
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   167
        break;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   168
      case 'm' :
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   169
        if (optarg[0] == 0)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   170
        {
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   171
          help();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   172
          exit(1);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   173
        }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   174
        MasterBoard.busname = optarg;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   175
        break;
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   176
      case 'A' :
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   177
        if (optarg[0] == 0)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   178
        {
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   179
          help();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   180
          exit(1);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   181
        }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   182
        SlaveBoardA.baudrate = optarg;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   183
        break;
387
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   184
      case 'B' :
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   185
        if (optarg[0] == 0)
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   186
        {
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   187
          help();
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   188
          exit(1);
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   189
        }
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   190
        SlaveBoardB.baudrate = optarg;
6efc85c5493e fixed TextMasterSlaveLSS
groke6
parents: 384
diff changeset
   191
        break;
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   192
      case 'M' :
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   193
        if (optarg[0] == 0)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   194
        {
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   195
          help();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   196
          exit(1);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   197
        }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   198
        MasterBoard.baudrate = optarg;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   199
        break;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   200
      case 'l' :
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   201
        if (optarg[0] == 0)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   202
        {
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   203
          help();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   204
          exit(1);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   205
        }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   206
        LibraryPath = optarg;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   207
        break;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   208
      default:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   209
        help();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   210
        exit(1);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   211
    }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   212
  }
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   213
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   214
#if !defined(WIN32) || defined(__CYGWIN__)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   215
  /* install signal handler for manual break */
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   216
	signal(SIGTERM, catch_signal);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   217
	signal(SIGINT, catch_signal);
454
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   218
	TimerInit();
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   219
#endif
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   220
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   221
#ifndef NOT_USE_DYNAMIC_LOADING
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   222
	if (LoadCanDriver(LibraryPath) == NULL)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   223
	    printf("Unable to load library: %s\n",LibraryPath);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   224
#endif		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   225
	// Open CAN devices
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   226
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   227
	if(strcmp(SlaveBoardA.baudrate, "none")){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   228
		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   229
		TestSlaveA_Data.heartbeatError = TestSlaveA_heartbeatError;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   230
		TestSlaveA_Data.initialisation = TestSlaveA_initialisation;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   231
		TestSlaveA_Data.preOperational = TestSlaveA_preOperational;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   232
		TestSlaveA_Data.operational = TestSlaveA_operational;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   233
		TestSlaveA_Data.stopped = TestSlaveA_stopped;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   234
		TestSlaveA_Data.post_sync = TestSlaveA_post_sync;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   235
		TestSlaveA_Data.post_TPDO = TestSlaveA_post_TPDO;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   236
		TestSlaveA_Data.storeODSubIndex = TestSlaveA_storeODSubIndex;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   237
		TestSlaveA_Data.post_emcy = TestSlaveA_post_emcy;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   238
		/* in this example the slave doesn't support Store configuration*/
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   239
		TestSlaveA_Data.lss_StoreConfiguration = TestSlaveA_StoreConfiguration;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   240
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   241
		if(!canOpen(&SlaveBoardA,&TestSlaveA_Data)){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   242
			eprintf("Cannot open SlaveA Board (%s,%s)\n",SlaveBoardA.busname, SlaveBoardA.baudrate);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   243
			goto fail_slaveA;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   244
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   245
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   246
	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   247
	if(strcmp(SlaveBoardB.baudrate, "none")){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   248
		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   249
		TestSlaveB_Data.heartbeatError = TestSlaveB_heartbeatError;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   250
		TestSlaveB_Data.initialisation = TestSlaveB_initialisation;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   251
		TestSlaveB_Data.preOperational = TestSlaveB_preOperational;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   252
		TestSlaveB_Data.operational = TestSlaveB_operational;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   253
		TestSlaveB_Data.stopped = TestSlaveB_stopped;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   254
		TestSlaveB_Data.post_sync = TestSlaveB_post_sync;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   255
		TestSlaveB_Data.post_TPDO = TestSlaveB_post_TPDO;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   256
		TestSlaveB_Data.storeODSubIndex = TestSlaveB_storeODSubIndex;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   257
		TestSlaveB_Data.post_emcy = TestSlaveB_post_emcy;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   258
		TestSlaveB_Data.lss_StoreConfiguration = TestSlaveB_StoreConfiguration;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   259
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   260
		if(!canOpen(&SlaveBoardB,&TestSlaveB_Data)){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   261
			eprintf("Cannot open SlaveB Board (%s,%s)\n",SlaveBoardB.busname, SlaveBoardB.baudrate);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   262
			goto fail_slaveB;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   263
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   264
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   265
	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   266
	if(strcmp(MasterBoard.baudrate, "none")){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   267
		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   268
		TestMaster_Data.heartbeatError = TestMaster_heartbeatError;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   269
		TestMaster_Data.initialisation = TestMaster_initialisation;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   270
		TestMaster_Data.preOperational = TestMaster_preOperational;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   271
		TestMaster_Data.operational = TestMaster_operational;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   272
		TestMaster_Data.stopped = TestMaster_stopped;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   273
		TestMaster_Data.post_sync = TestMaster_post_sync;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   274
		TestMaster_Data.post_TPDO = TestMaster_post_TPDO;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   275
		TestMaster_Data.post_emcy = TestMaster_post_emcy;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   276
		TestMaster_Data.post_SlaveBootup=TestMaster_post_SlaveBootup;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   277
		
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   278
		if(!canOpen(&MasterBoard,&TestMaster_Data)){
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   279
			eprintf("Cannot open Master Board (%s,%s)\n",MasterBoard.busname, MasterBoard.baudrate);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   280
			goto fail_master;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   281
		}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   282
	}
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   283
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   284
	// Start timer thread
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   285
	StartTimerLoop(&InitNodes);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   286
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   287
	// wait Ctrl-C
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   288
	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   289
	pause();
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   290
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   291
	// Stop timer thread
454
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   292
	StopTimerLoop(&Exit);
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   293
	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   294
	// Close CAN devices (and can threads)
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   295
	if(strcmp(MasterBoard.baudrate, "none")) canClose(&TestMaster_Data);	
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   296
fail_master:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   297
	if(strcmp(SlaveBoardB.baudrate, "none")) canClose(&TestSlaveB_Data);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   298
fail_slaveB:
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   299
	if(strcmp(SlaveBoardA.baudrate, "none")) canClose(&TestSlaveA_Data);
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   300
fail_slaveA:
454
bc000083297a - add RTAI support
greg
parents: 387
diff changeset
   301
	TimerCleanup();
381
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   302
	return 0;
854c43cdc24a added TestMasterSlaveLSS. LSS protocol revised.
groke6
parents:
diff changeset
   303
}