examples/TestMasterSlave/TestMasterSlave.c
author etisserant
Wed, 04 Apr 2007 13:04:31 +0200
changeset 145 e747d2e26af0
parent 40 ddeeb217ed71
child 149 fe50ada8020b
permissions -rw-r--r--
Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack. 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
See COPYING file for copyrights details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     7
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
Lesser General Public License for more details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    21
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    22
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    23
#if defined(WIN32) && !defined(__CYGWIN__)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    24
#include <windows.h>
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    25
#include "getopt.h"
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    26
void pause(void)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    27
{
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    28
	system("PAUSE");
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    29
}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    30
#else
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
#include <stdio.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
#include <string.h>
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    33
//#include <sys/time.h>
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    34
//#include <unistd.h>
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
#include <stdlib.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
#include <signal.h>
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    37
#endif
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
#include <applicfg.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
#include <can_driver.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
#include <timers_driver.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
#include "Master.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
#include "Slave.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
#include "TestMasterSlave.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
#define MyCase(fc) case fc: eprintf(#fc);break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
void print_message(Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
	int i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
	switch(m->cob_id.w >> 7)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
		MyCase(SYNC)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
		MyCase(TIME_STAMP)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
		MyCase(PDO1tx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
		MyCase(PDO1rx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
		MyCase(PDO2tx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
		MyCase(PDO2rx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
		MyCase(PDO3tx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
		MyCase(PDO3rx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
		MyCase(PDO4tx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
		MyCase(PDO4rx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
		MyCase(SDOtx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
		MyCase(SDOrx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
		MyCase(NODE_GUARD)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
		MyCase(NMT)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
	eprintf(" rtr:%d", m->rtr);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
	eprintf(" len:%d", m->len);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
	for (i = 0 ; i < m->len ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
		eprintf(" %02x", m->data[i]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
	eprintf("\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
UNS32 OnMasterMap1Update(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
	eprintf("OnSlaveMap1Update:%d\n", SlaveMap1);
31
a82b70738e5c Code clean-up and fixed xenomai compile problem
lbessard
parents: 0
diff changeset
    78
	return 0;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    81
CAN_PORT SlaveCanHandle;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    82
CAN_PORT MasterCanHandle;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    83
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    84
s_BOARD SlaveBoard = {"0", "500K"};
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    85
s_BOARD MasterBoard = {"1", "500K"};
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    86
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    87
#if !defined(WIN32) || defined(__CYGWIN__)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
void catch_signal(int sig)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
  signal(SIGTERM, catch_signal);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
  signal(SIGINT, catch_signal);
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
    92
  eprintf("Got Signal %d\n",sig);
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
    93
}
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
    94
#endif
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
void help()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
  printf("**************************************************************\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
  printf("*  TestMasterSlave                                           *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
  printf("*                                                            *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
  printf("*  A simple example for PC. It does implement 2 CanOpen      *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
  printf("*  nodes in the same process. A master and a slave. Both     *\n");
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   103
  printf("*  communicate together, exchanging periodically NMT, SYNC,  *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   104
  printf("*  SDO and PDO.                                              *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   105
  printf("*                                                            *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   106
  printf("*   Usage:                                                   *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   107
  printf("*   ./TestMasterSlave  [OPTIONS]                             *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   108
  printf("*                                                            *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   109
  printf("*   OPTIONS:                                                 *\n");
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   110
  printf("*     -l : Can library [\"libcanfestival_can_virtual.so\"]     *\n");
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   111
  printf("*                                                            *\n");
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   112
  printf("*    Slave:                                                  *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   113
  printf("*     -s : bus name [\"0\"]                                    *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   114
  printf("*     -S : 1M,500K,250K,125K,100K,50K,20K,10K,none(disable)  *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   115
  printf("*                                                            *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   116
  printf("*    Master:                                                 *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   117
  printf("*     -m : bus name [\"1\"]                                    *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   118
  printf("*     -M : 1M,500K,250K,125K,100K,50K,20K,10K,none(disable)  *\n");
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
  printf("*                                                            *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
  printf("**************************************************************\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   123
/***************************  INIT  *****************************************/
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   124
void InitNodes(CO_Data* d, UNS32 id)
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   125
{
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   126
	/****************************** INITIALISATION SLAVE *******************************/
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   127
	if(SlaveBoard.baudrate) {
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   128
		/* Defining the node Id */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   129
		setNodeId(&TestSlave_Data, 0x02);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   130
		/* init */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   131
		setState(&TestSlave_Data, Initialisation);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   132
	}
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   133
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   134
	/****************************** INITIALISATION MASTER *******************************/
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   135
	if(MasterBoard.baudrate){
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   136
 		RegisterSetODentryCallBack(&TestMaster_Data, 0x2000, 0, &OnMasterMap1Update);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   137
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   138
		/* Defining the node Id */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   139
		setNodeId(&TestMaster_Data, 0x01);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   140
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   141
		/* init */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   142
		setState(&TestMaster_Data, Initialisation);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   143
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   144
		/****************************** START *******************************/
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   145
		/* Put the master in operational mode */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   146
		setState(&TestMaster_Data, Operational);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   147
  
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   148
		/* Ask slave node to go in operational mode */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   149
		masterSendNMTstateChange (&TestMaster_Data, 0x02, NMT_Start_Node);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   150
	}
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   151
}
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   152
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
/****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
/***************************  MAIN  *****************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
/****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
int main(int argc,char **argv)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   158
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
  char c;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
  extern char *optarg;
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   161
  char* LibraryPath="libcanfestival_can_virtual.so";
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   162
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   163
  while ((c = getopt(argc, argv, "-m:s:M:S:l:")) != EOF)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
    switch(c)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
      case 's' :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
        if (optarg[0] == 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
        {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
          help();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
          exit(1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
        }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
        SlaveBoard.busname = optarg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
        break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
      case 'm' :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
        if (optarg[0] == 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
        {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
          help();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
          exit(1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   180
        }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
        MasterBoard.busname = optarg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
        break;
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   183
      case 'S' :
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   184
        if (optarg[0] == 0)
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   185
        {
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   186
          help();
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   187
          exit(1);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   188
        }
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   189
        SlaveBoard.baudrate = optarg;
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   190
        break;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   191
      case 'M' :
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   192
        if (optarg[0] == 0)
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   193
        {
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   194
          help();
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   195
          exit(1);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   196
        }
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   197
        MasterBoard.baudrate = optarg;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   198
        break;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   199
      case 'l' :
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   200
        if (optarg[0] == 0)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   201
        {
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   202
          help();
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   203
          exit(1);
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   204
        }
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   205
        LibraryPath = optarg;
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   206
        break;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
      default:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
        help();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
        exit(1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   213
#if !defined(WIN32) || defined(__CYGWIN__)
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   214
  /* install signal handler for manual break */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
	signal(SIGTERM, catch_signal);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
	signal(SIGINT, catch_signal);
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   217
#endif
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   218
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   219
#ifndef NOT_USE_DYNAMIC_LOADING
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   220
	LoadCanDriver(LibraryPath);
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   221
#endif		
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
	// Open CAN devices
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   223
	if(SlaveBoard.baudrate){
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   224
		SlaveCanHandle = canOpen(&SlaveBoard,&TestSlave_Data);
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   225
		if(SlaveCanHandle == NULL){
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   226
			eprintf("Cannot open Slave Board (%s,%s)\n",SlaveBoard.busname, SlaveBoard.baudrate);
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   227
			goto fail_slave;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   228
		}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   229
	}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   230
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   231
	if(MasterBoard.baudrate){
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   232
		MasterCanHandle = canOpen(&MasterBoard,&TestMaster_Data);
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   233
		if(MasterCanHandle == NULL){
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   234
			eprintf("Cannot open Master Board (%s,%s)\n",SlaveBoard.busname, SlaveBoard.baudrate);
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   235
			goto fail_master;
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   236
		}
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 40
diff changeset
   237
	}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
	
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   239
	// Start timer thread
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   240
	StartTimerLoop(&InitNodes);
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   241
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   242
	// wait Ctrl-C
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   243
	pause();
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   244
	eprintf("Finishing.\n");
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   245
	
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   246
	// Stop timer thread
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   247
	StopTimerLoop();
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   248
	
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   249
	// Close CAN devices (and can threads)
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   250
	if(SlaveBoard.baudrate) canClose(SlaveCanHandle);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   251
fail_master:
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   252
	if(MasterBoard.baudrate) canClose(MasterCanHandle);	
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   253
fail_slave:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
}