]> rtime.felk.cvut.cz Git - CanFestival-3.git/blobdiff - examples/DS401_Slave_Gui/TestSlaveGui.cpp
- add RTAI support
[CanFestival-3.git] / examples / DS401_Slave_Gui / TestSlaveGui.cpp
index 9f04cfda80b3ac1561ae1ecb97827c8cb9834b1f..182d18d4244f9e468b1fc5f3b9383b1b2cf90fbd 100644 (file)
@@ -27,88 +27,86 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #include <iostream>
 
 #if defined(WIN32) && !defined(__CYGWIN__)
-       #include <windows.h>
-
-       extern "C" {
-               #include "getopt.h"
-       }
-
-       void pause(void)
-       {
-               system("PAUSE");
-       }
+#include <windows.h>
 #else
-       #include <stdio.h>
-       #include <string.h>
-       #include <unistd.h>
-       #include <stdlib.h>
-       #include <signal.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
 #endif
 
 //#include <can_driver.h>
 //#include <timers_driver.h>
-extern "C" 
-  {
-       #include "canfestival.h"
-  }
+extern "C"
+{
+#include "canfestival.h"
+}
 #include "CallBack.h"
 #include "TestSlaveGui.h"
 #include "main.h"
 
-extern wxTextCtrl      *textLog;
-extern int                     node_id_ext;
+extern wxTextCtrl *textLog;
+extern int node_id_ext;
 
 //***************************  INIT  *****************************************
-void InitNodes(CO_Data* d, UNS32 id)
+void
+InitNodes (CO_Data * d, UNS32 id)
 {
-       //****************************** INITIALISATION SLAVE *******************************
-               /* Defining the node Id */
-               setNodeId(&ObjDict_Data, node_id_ext);
-               /* init */
-               setState(&ObjDict_Data, Initialisation);
+  //****************************** INITIALISATION SLAVE *******************************
+  /* Defining the node Id */
+  setNodeId (&ObjDict_Data, node_id_ext);
+  /* init */
+  setState (&ObjDict_Data, Initialisation);
 }
 
+/***************************  EXIT  *****************************************/
+void Exit(CO_Data* d, UNS32 id)
+{
+       setState (&ObjDict_Data, Stopped);
+       canClose (&ObjDict_Data);
+}
 //****************************************************************************
 //***************************  MAIN  *****************************************
 //****************************************************************************
-int main_can(s_BOARD SlaveBoard, char* LibraryPath)
+int
+main_can (s_BOARD SlaveBoard, char *LibraryPath)
 {
-  printf("Bus name: %s        Freq: %s       Driver: %s\n", SlaveBoard.busname, SlaveBoard.baudrate, LibraryPath);
-
-  #ifndef NOT_USE_DYNAMIC_LOADING
-       LoadCanDriver(LibraryPath);
-  #endif               
-       // Open CAN devices
-
-       ObjDict_Data.heartbeatError = Call_heartbeatError;
-       ObjDict_Data.initialisation = Call_initialisation;
-       ObjDict_Data.preOperational = Call_preOperational;
-       ObjDict_Data.operational = Call_operational;
-       ObjDict_Data.stopped = Call_stopped;
-       ObjDict_Data.post_sync = Call_post_sync;
-       ObjDict_Data.post_TPDO = Call_post_TPDO;
-       ObjDict_Data.storeODSubIndex = Call_storeODSubIndex;            
-
-       if(!canOpen(&SlaveBoard,&ObjDict_Data))
-         {
-               printf("Cannot open Slave Board (%s,%s)\n",SlaveBoard.busname, SlaveBoard.baudrate);
-               return (1);
-         }
-
-       StartTimerLoop(&InitNodes);
-
-       return 0;
-}
-
-void stop_slave()
-{      
-    EnterMutex();
-
-       setState(&ObjDict_Data, Stopped);
-    StopTimerLoop();
-    canClose(&ObjDict_Data);
+  printf ("Bus name: %s        Freq: %s       Driver: %s\n",
+         SlaveBoard.busname, SlaveBoard.baudrate, LibraryPath);
 
-    LeaveMutex();
+  TimerInit();
+#ifndef NOT_USE_DYNAMIC_LOADING
+  if (LoadCanDriver (LibraryPath) == NULL)
+    *textLog << wxT ("Unable to load library\n");
+#endif
+  // Open CAN devices
+
+  ObjDict_Data.heartbeatError = Call_heartbeatError;
+  ObjDict_Data.initialisation = Call_initialisation;
+  ObjDict_Data.preOperational = Call_preOperational;
+  ObjDict_Data.operational = Call_operational;
+  ObjDict_Data.stopped = Call_stopped;
+  ObjDict_Data.post_sync = Call_post_sync;
+  ObjDict_Data.post_TPDO = Call_post_TPDO;
+  ObjDict_Data.storeODSubIndex = Call_storeODSubIndex;
+
+  if (!canOpen (&SlaveBoard, &ObjDict_Data))
+    {
+      printf ("Cannot open Slave Board (%s,%s)\n", SlaveBoard.busname,
+             SlaveBoard.baudrate);
+      return (1);
+    }
+
+  StartTimerLoop (&InitNodes);
+
+  return 0;
+}
 
-       return;
+void
+stop_slave ()
+{
+  StopTimerLoop (&Exit);
+  TimerCleanup();
+  return;
 }