25 #include <wx/wx.h> |
25 #include <wx/wx.h> |
26 #include <wx/textctrl.h> |
26 #include <wx/textctrl.h> |
27 #include <iostream> |
27 #include <iostream> |
28 |
28 |
29 #if defined(WIN32) && !defined(__CYGWIN__) |
29 #if defined(WIN32) && !defined(__CYGWIN__) |
30 #include <windows.h> |
30 #include <windows.h> |
31 #else |
31 #else |
32 #include <stdio.h> |
32 #include <stdio.h> |
33 #include <string.h> |
33 #include <string.h> |
34 #include <unistd.h> |
34 #include <unistd.h> |
35 #include <stdlib.h> |
35 #include <stdlib.h> |
36 #include <signal.h> |
36 #include <signal.h> |
37 #endif |
37 #endif |
38 |
38 |
39 //#include <can_driver.h> |
39 //#include <can_driver.h> |
40 //#include <timers_driver.h> |
40 //#include <timers_driver.h> |
41 extern "C" |
41 extern "C" |
42 { |
42 { |
43 #include "canfestival.h" |
43 #include "canfestival.h" |
44 } |
44 } |
45 #include "CallBack.h" |
45 #include "CallBack.h" |
46 #include "TestSlaveGui.h" |
46 #include "TestSlaveGui.h" |
47 #include "main.h" |
47 #include "main.h" |
48 |
48 |
49 extern wxTextCtrl *textLog; |
49 extern wxTextCtrl *textLog; |
50 extern int node_id_ext; |
50 extern int node_id_ext; |
51 |
51 |
52 //*************************** INIT ***************************************** |
52 //*************************** INIT ***************************************** |
53 void InitNodes(CO_Data* d, UNS32 id) |
53 void |
|
54 InitNodes (CO_Data * d, UNS32 id) |
54 { |
55 { |
55 //****************************** INITIALISATION SLAVE ******************************* |
56 //****************************** INITIALISATION SLAVE ******************************* |
56 /* Defining the node Id */ |
57 /* Defining the node Id */ |
57 setNodeId(&ObjDict_Data, node_id_ext); |
58 setNodeId (&ObjDict_Data, node_id_ext); |
58 /* init */ |
59 /* init */ |
59 setState(&ObjDict_Data, Initialisation); |
60 setState (&ObjDict_Data, Initialisation); |
60 } |
61 } |
61 |
62 |
62 //**************************************************************************** |
63 //**************************************************************************** |
63 //*************************** MAIN ***************************************** |
64 //*************************** MAIN ***************************************** |
64 //**************************************************************************** |
65 //**************************************************************************** |
65 int main_can(s_BOARD SlaveBoard, char* LibraryPath) |
66 int |
|
67 main_can (s_BOARD SlaveBoard, char *LibraryPath) |
66 { |
68 { |
67 printf("Bus name: %s Freq: %s Driver: %s\n", SlaveBoard.busname, SlaveBoard.baudrate, LibraryPath); |
69 printf ("Bus name: %s Freq: %s Driver: %s\n", |
|
70 SlaveBoard.busname, SlaveBoard.baudrate, LibraryPath); |
68 |
71 |
69 #ifndef NOT_USE_DYNAMIC_LOADING |
72 #ifndef NOT_USE_DYNAMIC_LOADING |
70 if (LoadCanDriver(LibraryPath) == NULL) |
73 if (LoadCanDriver (LibraryPath) == NULL) |
71 *textLog << wxT("Unable to load library\n"); |
74 *textLog << wxT ("Unable to load library\n"); |
72 #endif |
75 #endif |
73 // Open CAN devices |
76 // Open CAN devices |
74 |
77 |
75 ObjDict_Data.heartbeatError = Call_heartbeatError; |
78 ObjDict_Data.heartbeatError = Call_heartbeatError; |
76 ObjDict_Data.initialisation = Call_initialisation; |
79 ObjDict_Data.initialisation = Call_initialisation; |
77 ObjDict_Data.preOperational = Call_preOperational; |
80 ObjDict_Data.preOperational = Call_preOperational; |
78 ObjDict_Data.operational = Call_operational; |
81 ObjDict_Data.operational = Call_operational; |
79 ObjDict_Data.stopped = Call_stopped; |
82 ObjDict_Data.stopped = Call_stopped; |
80 ObjDict_Data.post_sync = Call_post_sync; |
83 ObjDict_Data.post_sync = Call_post_sync; |
81 ObjDict_Data.post_TPDO = Call_post_TPDO; |
84 ObjDict_Data.post_TPDO = Call_post_TPDO; |
82 ObjDict_Data.storeODSubIndex = Call_storeODSubIndex; |
85 ObjDict_Data.storeODSubIndex = Call_storeODSubIndex; |
83 |
86 |
84 if(!canOpen(&SlaveBoard,&ObjDict_Data)) |
87 if (!canOpen (&SlaveBoard, &ObjDict_Data)) |
85 { |
88 { |
86 printf("Cannot open Slave Board (%s,%s)\n",SlaveBoard.busname, SlaveBoard.baudrate); |
89 printf ("Cannot open Slave Board (%s,%s)\n", SlaveBoard.busname, |
87 return (1); |
90 SlaveBoard.baudrate); |
88 } |
91 return (1); |
|
92 } |
89 |
93 |
90 StartTimerLoop(&InitNodes); |
94 StartTimerLoop (&InitNodes); |
91 |
95 |
92 return 0; |
96 return 0; |
93 } |
97 } |
94 |
98 |
95 void stop_slave() |
99 void |
96 { |
100 stop_slave () |
97 EnterMutex(); |
101 { |
98 setState(&ObjDict_Data, Stopped); |
102 EnterMutex (); |
99 LeaveMutex(); |
103 setState (&ObjDict_Data, Stopped); |
|
104 LeaveMutex (); |
100 |
105 |
101 StopTimerLoop(); |
106 StopTimerLoop (); |
102 canClose(&ObjDict_Data); |
107 canClose (&ObjDict_Data); |
103 |
108 |
104 return; |
109 return; |
105 } |
110 } |