examples/TestMasterSlave/TestMasterSlave.c
author frdupin
Tue, 30 Jan 2007 10:25:19 +0100
changeset 83 3a7d54b0a299
parent 40 ddeeb217ed71
child 145 e747d2e26af0
permissions -rw-r--r--
BIG endian def is moved to config.h
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
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
#include <stdio.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
#include <string.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
#include <sys/time.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
#include <unistd.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
#include <stdlib.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
#include <signal.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
#include <applicfg.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
#include <can_driver.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
#include <timers_driver.h>
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
#include "Master.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
#include "Slave.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
#include "TestMasterSlave.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
#define MyCase(fc) case fc: eprintf(#fc);break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
void print_message(Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
	int i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
	switch(m->cob_id.w >> 7)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
	{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
		MyCase(SYNC)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
		MyCase(TIME_STAMP)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
		MyCase(PDO1tx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
		MyCase(PDO1rx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
		MyCase(PDO2tx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
		MyCase(PDO2rx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
		MyCase(PDO3tx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
		MyCase(PDO3rx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
		MyCase(PDO4tx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
		MyCase(PDO4rx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
		MyCase(SDOtx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
		MyCase(SDOrx)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
		MyCase(NODE_GUARD)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
		MyCase(NMT)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
	eprintf(" rtr:%d", m->rtr);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
	eprintf(" len:%d", m->len);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
	for (i = 0 ; i < m->len ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
		eprintf(" %02x", m->data[i]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
	eprintf("\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
UNS32 OnMasterMap1Update(CO_Data* d, const indextable * unsused_indextable, UNS8 unsused_bSubindex)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
	eprintf("OnSlaveMap1Update:%d\n", SlaveMap1);
31
a82b70738e5c Code clean-up and fixed xenomai compile problem
lbessard
parents: 0
diff changeset
    69
	return 0;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
CAN_HANDLE SlaveCanHandle;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
CAN_HANDLE MasterCanHandle;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
// Baudrate values for Peak board :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
// CAN_BAUD_1M CAN_BAUD_500K CAN_BAUD_250K CAN_BAUD_125K CAN_BAUD_100K CAN_BAUD_50K
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
// CAN_BAUD_20K CAN_BAUD_10K CAN_BAUD_5K
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
#ifdef CAN_BAUD_500K
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    80
int TranslateBaudeRate(char* optarg){
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    81
	if(!strcmp( optarg, "1M")) return CAN_BAUD_1M;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    82
	if(!strcmp( optarg, "500K")) return CAN_BAUD_500K;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    83
	if(!strcmp( optarg, "250K")) return CAN_BAUD_250K;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    84
	if(!strcmp( optarg, "125K")) return CAN_BAUD_125K;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    85
	if(!strcmp( optarg, "100K")) return CAN_BAUD_100K;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    86
	if(!strcmp( optarg, "50K")) return CAN_BAUD_50K;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    87
	if(!strcmp( optarg, "20K")) return CAN_BAUD_20K;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    88
	if(!strcmp( optarg, "10K")) return CAN_BAUD_10K;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    89
	if(!strcmp( optarg, "5K")) return CAN_BAUD_5K;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    90
	if(!strcmp( optarg, "none")) return 0;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    91
	return 0x0000;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    92
}
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    93
s_BOARD SlaveBoard = {"0", CAN_BAUD_500K, &TestSlave_Data};
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    94
s_BOARD MasterBoard = {"1", CAN_BAUD_500K, &TestMaster_Data};
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
#else
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    96
int TranslateBaudeRate(char* optarg){
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    97
	if(!strcmp( optarg, "1M")) return 1000;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    98
	if(!strcmp( optarg, "500K")) return 500;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
    99
	if(!strcmp( optarg, "250K")) return 250;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   100
	if(!strcmp( optarg, "125K")) return 125;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   101
	if(!strcmp( optarg, "100K")) return 100;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   102
	if(!strcmp( optarg, "50K")) return 50;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   103
	if(!strcmp( optarg, "20K")) return 20;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   104
	if(!strcmp( optarg, "10K")) return 10;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   105
	if(!strcmp( optarg, "5K")) return 5;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   106
	if(!strcmp( optarg, "none")) return 0;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   107
	return 0;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   108
}
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   109
s_BOARD SlaveBoard = {"0", 500, &TestSlave_Data};
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   110
s_BOARD MasterBoard = {"1", 500, &TestMaster_Data};
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
#endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   113
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
void catch_signal(int sig)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
  signal(SIGTERM, catch_signal);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
  signal(SIGINT, catch_signal);
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   118
  eprintf("Got Signal %d\n",sig);
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   119
}
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
void help()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
  printf("**************************************************************\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
  printf("*  TestMasterSlave                                           *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
  printf("*                                                            *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
  printf("*  A simple example for PC. It does implement 2 CanOpen      *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
  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
   128
  printf("*  communicate together, exchanging periodically NMT, SYNC,  *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   129
  printf("*  SDO and PDO.                                              *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   130
  printf("*                                                            *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   131
  printf("*   Usage:                                                   *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   132
  printf("*   ./TestMasterSlave  [OPTIONS]                             *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   133
  printf("*                                                            *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   134
  printf("*   OPTIONS:                                                 *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   135
  printf("*    Slave:                                                  *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   136
  printf("*     -s : bus name [\"0\"]                                    *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   137
  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
   138
  printf("*                                                            *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   139
  printf("*    Master:                                                 *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   140
  printf("*     -m : bus name [\"1\"]                                    *\n");
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   141
  printf("*     -M : 1M,500K,250K,125K,100K,50K,20K,10K,none(disable)  *\n");
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
  printf("*                                                            *\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
  printf("**************************************************************\n");
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   146
/***************************  INIT  *****************************************/
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   147
void InitNodes(CO_Data* d, UNS32 id)
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   148
{
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   149
	/****************************** INITIALISATION SLAVE *******************************/
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   150
	if(SlaveBoard.baudrate) {
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   151
		/* Defining the node Id */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   152
		setNodeId(&TestSlave_Data, 0x02);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   153
		/* init */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   154
		setState(&TestSlave_Data, Initialisation);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   155
	}
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   156
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   157
	/****************************** INITIALISATION MASTER *******************************/
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   158
	if(MasterBoard.baudrate){
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   159
 		RegisterSetODentryCallBack(&TestMaster_Data, 0x2000, 0, &OnMasterMap1Update);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   160
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   161
		/* Defining the node Id */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   162
		setNodeId(&TestMaster_Data, 0x01);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   163
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   164
		/* init */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   165
		setState(&TestMaster_Data, Initialisation);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   166
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   167
		/****************************** START *******************************/
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   168
		/* Put the master in operational mode */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   169
		setState(&TestMaster_Data, Operational);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   170
  
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   171
		/* Ask slave node to go in operational mode */
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   172
		masterSendNMTstateChange (&TestMaster_Data, 0x02, NMT_Start_Node);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   173
	}
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   174
}
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   175
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
/****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
/***************************  MAIN  *****************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
/****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
int main(int argc,char **argv)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   180
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
  char c;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
  extern char *optarg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   185
  while ((c = getopt(argc, argv, "-m:s:M:S:")) != EOF)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
    switch(c)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
    {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
      case 's' :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
        if (optarg[0] == 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
        {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
          help();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
          exit(1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
        }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
        SlaveBoard.busname = optarg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
        break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
      case 'm' :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
        if (optarg[0] == 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
        {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
          help();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
          exit(1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
        }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
        MasterBoard.busname = optarg;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
        break;
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   205
      case 'S' :
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   206
        if (optarg[0] == 0)
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   207
        {
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   208
          help();
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   209
          exit(1);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   210
        }
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   211
        SlaveBoard.baudrate = TranslateBaudeRate(optarg);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   212
        break;
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   213
      case 'M' :
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   214
        if (optarg[0] == 0)
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   215
        {
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   216
          help();
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   217
          exit(1);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   218
        }
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   219
        MasterBoard.baudrate = TranslateBaudeRate(optarg);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   220
        break;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
      default:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
        help();
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
        exit(1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
	/* install signal handler for manual break */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
	signal(SIGTERM, catch_signal);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
	signal(SIGINT, catch_signal);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
	// Open CAN devices
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   232
	if(SlaveBoard.baudrate)
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   233
		if((SlaveCanHandle = canOpen(&SlaveBoard))==NULL) goto fail_slave;
40
ddeeb217ed71 Updated configure and fixes in Makefiles.in for cygwin compiling.
etisserant
parents: 36
diff changeset
   234
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   235
	if(MasterBoard.baudrate)
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   236
		if((MasterCanHandle = canOpen(&MasterBoard))==NULL) goto fail_master;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
	
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   238
	// Start timer thread
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   239
	StartTimerLoop(&InitNodes);
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   240
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   241
	// wait Ctrl-C
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   242
	pause();
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   243
	eprintf("Finishing.\n");
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   244
	
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   245
	// Stop timer thread
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   246
	StopTimerLoop();
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   247
	
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   248
	// Close CAN devices (and can threads)
36
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   249
	if(SlaveBoard.baudrate) canClose(SlaveCanHandle);
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   250
fail_master:
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   251
	if(MasterBoard.baudrate) canClose(MasterCanHandle);	
ff3ba4a90548 Added bauderate/disable option to TestMasterSlave Master and Slave nodes.
etisserant
parents: 32
diff changeset
   252
fail_slave:
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
}