]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - examples/DS401_Slave_Gui/TestSlaveGui.cpp
DS401 Slave GUI : Added command line interface, cleaned up parts of code, added EDS.
[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
32         extern "C" {
33                 #include "getopt.h"
34         }
35
36         void pause(void)
37         {
38                 system("PAUSE");
39         }
40 #else
41         #include <stdio.h>
42         #include <string.h>
43         #include <unistd.h>
44         #include <stdlib.h>
45         #include <signal.h>
46 #endif
47
48 //#include <can_driver.h>
49 //#include <timers_driver.h>
50 extern "C" 
51   {
52         #include "canfestival.h"
53   }
54 #include "CallBack.h"
55 #include "TestSlaveGui.h"
56 #include "main.h"
57
58 extern wxTextCtrl       *textLog;
59 extern int                      node_id_ext;
60
61 //***************************  INIT  *****************************************
62 void InitNodes(CO_Data* d, UNS32 id)
63 {
64         //****************************** INITIALISATION SLAVE *******************************
65                 /* Defining the node Id */
66                 setNodeId(&ObjDict_Data, node_id_ext);
67                 /* init */
68                 setState(&ObjDict_Data, Initialisation);
69 }
70
71 //****************************************************************************
72 //***************************  MAIN  *****************************************
73 //****************************************************************************
74 int main_can(s_BOARD SlaveBoard, char* LibraryPath)
75 {
76   printf("Bus name: %s        Freq: %s       Driver: %s\n", SlaveBoard.busname, SlaveBoard.baudrate, LibraryPath);
77
78   #ifndef NOT_USE_DYNAMIC_LOADING
79         LoadCanDriver(LibraryPath);
80   #endif                
81         // Open CAN devices
82
83         ObjDict_Data.heartbeatError = Call_heartbeatError;
84         ObjDict_Data.initialisation = Call_initialisation;
85         ObjDict_Data.preOperational = Call_preOperational;
86         ObjDict_Data.operational = Call_operational;
87         ObjDict_Data.stopped = Call_stopped;
88         ObjDict_Data.post_sync = Call_post_sync;
89         ObjDict_Data.post_TPDO = Call_post_TPDO;
90         ObjDict_Data.storeODSubIndex = Call_storeODSubIndex;            
91
92         if(!canOpen(&SlaveBoard,&ObjDict_Data))
93           {
94                 printf("Cannot open Slave Board (%s,%s)\n",SlaveBoard.busname, SlaveBoard.baudrate);
95                 return (1);
96           }
97
98         StartTimerLoop(&InitNodes);
99
100         return 0;
101 }
102
103 void stop_slave()
104 {       
105     EnterMutex();
106
107         setState(&ObjDict_Data, Stopped);
108     StopTimerLoop();
109     canClose(&ObjDict_Data);
110
111     LeaveMutex();
112
113         return;
114 }