examples/SillySlave/main.c
author Edouard Tisserant
Sat, 21 Jan 2012 19:32:58 +0100
changeset 690 1c2cb6088050
parent 642 f77ad188c2b1
permissions -rw-r--r--
Merge further Ica changes
400
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     1
/*
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     2
Copyright (C): Giuseppe Massimo BERTANI
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     3
gmbertani@users.sourceforge.net
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     4
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     5
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     6
See COPYING file for copyrights details.
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     7
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    12
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    16
Lesser General Public License for more details.
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    17
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    21
*/
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    22
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    23
/**
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    24
 * @file main.c
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    25
 * @author GMB
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    26
 * @date 17/1/08
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    27
 *
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    28
 * This file is part of SillySlave demo for CANfestival
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    29
 * open source CANopen stack.
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    30
 */ 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    31
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    32
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    33
#include "main.h"                   
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    34
#include "slave.h"
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    35
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    36
#if !defined(WIN32) || defined(__CYGWIN__)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    37
void catch_signal(int sig)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    38
{
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    39
  signal(SIGTERM, catch_signal);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    40
  signal(SIGINT, catch_signal);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    41
  
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    42
  printf("Got Signal %d\n",sig);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    43
}
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    44
#endif
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    45
642
f77ad188c2b1 ADDED: - pause() for win32
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents: 400
diff changeset
    46
#if defined(WIN32) && !defined(__CYGWIN__)
f77ad188c2b1 ADDED: - pause() for win32
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents: 400
diff changeset
    47
void pause(void)
f77ad188c2b1 ADDED: - pause() for win32
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents: 400
diff changeset
    48
{
f77ad188c2b1 ADDED: - pause() for win32
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents: 400
diff changeset
    49
	system("PAUSE");
f77ad188c2b1 ADDED: - pause() for win32
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents: 400
diff changeset
    50
}
f77ad188c2b1 ADDED: - pause() for win32
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents: 400
diff changeset
    51
#endif
f77ad188c2b1 ADDED: - pause() for win32
Christian Taedcke <Christian.Taedcke@ica-traffic.de>
parents: 400
diff changeset
    52
400
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    53
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    54
/**
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    55
 * Please edit main.h defines before compiling
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    56
 */ 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    57
int main(int argc,char **argv)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    58
{
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    59
    char* LibraryPath= DRIVER_LIBRARY; 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    60
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    61
#if !defined(WIN32) || defined(__CYGWIN__)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    62
    /* install signal handler for manual break */
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    63
	signal(SIGTERM, catch_signal);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    64
	signal(SIGINT, catch_signal);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    65
#endif
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    66
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    67
#ifndef NOT_USE_DYNAMIC_LOADING
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    68
	LoadCanDriver(LibraryPath);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    69
#endif		
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    70
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    71
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    72
    if(InitCANdevice( BUS, BAUDRATE,  NODE_SLAVE ) < 0)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    73
    {
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    74
        printf("\nInitCANdevice() failed, exiting.\n");
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    75
        return -1;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    76
    }
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    77
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    78
    return 0;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    79
}
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    80
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    81