examples/SillySlave/main.c
author etisserant
Tue, 17 Mar 2009 00:03:18 +0100
changeset 539 187058b4a4b8
parent 400 7d845f5d730c
child 642 f77ad188c2b1
permissions -rw-r--r--
Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
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
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    46
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    47
/**
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    48
 * Please edit main.h defines before compiling
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    49
 */ 
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    50
int main(int argc,char **argv)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    51
{
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    52
    char* LibraryPath= DRIVER_LIBRARY; 
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
#if !defined(WIN32) || defined(__CYGWIN__)
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    55
    /* install signal handler for manual break */
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    56
	signal(SIGTERM, catch_signal);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    57
	signal(SIGINT, catch_signal);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    58
#endif
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    59
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    60
#ifndef NOT_USE_DYNAMIC_LOADING
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    61
	LoadCanDriver(LibraryPath);
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    62
#endif		
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    63
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    64
    
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    65
    if(InitCANdevice( BUS, BAUDRATE,  NODE_SLAVE ) < 0)
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
        printf("\nInitCANdevice() failed, exiting.\n");
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    68
        return -1;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    69
    }
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
    return 0;
7d845f5d730c Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff changeset
    72
}
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