]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - examples/DS401_Slave_Gui/TestSlaveGui.cpp
Minor changes, mostly PCAN/windows related.
[CanFestival-3.git] / examples / DS401_Slave_Gui / TestSlaveGui.cpp
1 /*
2 This file is part of CanFestival, a library implementing CanOpen Stack. 
3
4 Copyright (C): Edouard TISSERANT and Francis DUPIN
5
6 See COPYING file for copyrights details.
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 */
22
23
24 #include <wx/wxprec.h>
25 #include <wx/wx.h>
26 #include <wx/textctrl.h>
27 #include <iostream>
28
29 #if defined(WIN32) && !defined(__CYGWIN__)
30         #include <windows.h>
31 #else
32         #include <stdio.h>
33         #include <string.h>
34         #include <unistd.h>
35         #include <stdlib.h>
36         #include <signal.h>
37 #endif
38
39 //#include <can_driver.h>
40 //#include <timers_driver.h>
41 extern "C" 
42   {
43         #include "canfestival.h"
44   }
45 #include "CallBack.h"
46 #include "TestSlaveGui.h"
47 #include "main.h"
48
49 extern wxTextCtrl       *textLog;
50 extern int                      node_id_ext;
51
52 //***************************  INIT  *****************************************
53 void InitNodes(CO_Data* d, UNS32 id)
54 {
55         //****************************** INITIALISATION SLAVE *******************************
56                 /* Defining the node Id */
57                 setNodeId(&ObjDict_Data, node_id_ext);
58                 /* init */
59                 setState(&ObjDict_Data, Initialisation);
60 }
61
62 //****************************************************************************
63 //***************************  MAIN  *****************************************
64 //****************************************************************************
65 int main_can(s_BOARD SlaveBoard, char* LibraryPath)
66 {
67   printf("Bus name: %s        Freq: %s       Driver: %s\n", SlaveBoard.busname, SlaveBoard.baudrate, LibraryPath);
68
69   #ifndef NOT_USE_DYNAMIC_LOADING
70         if (LoadCanDriver(LibraryPath) == NULL)
71                 *textLog << wxT("Unable to load library\n");
72   #endif                
73         // Open CAN devices
74
75         ObjDict_Data.heartbeatError = Call_heartbeatError;
76         ObjDict_Data.initialisation = Call_initialisation;
77         ObjDict_Data.preOperational = Call_preOperational;
78         ObjDict_Data.operational = Call_operational;
79         ObjDict_Data.stopped = Call_stopped;
80         ObjDict_Data.post_sync = Call_post_sync;
81         ObjDict_Data.post_TPDO = Call_post_TPDO;
82         ObjDict_Data.storeODSubIndex = Call_storeODSubIndex;            
83
84         if(!canOpen(&SlaveBoard,&ObjDict_Data))
85           {
86                 printf("Cannot open Slave Board (%s,%s)\n",SlaveBoard.busname, SlaveBoard.baudrate);
87                 return (1);
88           }
89
90         StartTimerLoop(&InitNodes);
91
92         return 0;
93 }
94
95 void stop_slave()
96 {       
97     EnterMutex();
98         setState(&ObjDict_Data, Stopped);
99     LeaveMutex();
100
101     StopTimerLoop();
102     canClose(&ObjDict_Data);
103
104         return;
105 }