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