00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "rcs.hh"
00010 #include "demon.h"
00011 #include "ch1.h"
00012 #include "ch2.h"
00013
00014 #include <signal.h>
00015 #include <stdlib.h>
00016 #include <string.h>
00017 #if defined(MSDOS) && !defined(_Windows)
00018 #include <conio.h>
00019 #endif
00020
00021
00022
00023
00024
00025 #ifndef NO_TIMER
00026 static RCS_TIMER *timer = 0;
00027 #endif
00028
00029 int want_to_quit = 0;
00030
00031 void
00032 quit (int sig)
00033 {
00034 want_to_quit = 1;
00035 }
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 void
00049 main (int argc, char **argv)
00050 {
00051 set_rcs_print_destination (RCS_PRINT_TO_STDOUT);
00052
00053
00054
00055 CH1_MODULE *ch1 = new CH1_MODULE ();
00056 CH2_MODULE *ch2 = new CH2_MODULE ();
00057
00058
00059
00060 #ifndef NO_TIMER
00061 timer = new RCS_TIMER (1.0);
00062 if (NULL == timer)
00063 {
00064 rcs_print_error ("Can't create timer.\n");
00065 exit (-1);
00066 }
00067 #endif
00068
00069
00070 rcs_print ("Set up SIGINT handler.\n");
00071 signal (SIGINT, quit);
00072
00073 rcs_print ("Running Modules.\n");
00074 double start_time = etime ();
00075 int cycles = 0;
00076
00077
00078 while (!want_to_quit)
00079 {
00080 ch1->controller ();
00081 ch2->controller ();
00082 #ifndef NO_TIMER
00083
00084 timer->wait ();
00085 #endif
00086 cycles++;
00087 #if defined(MSDOS) && !defined(_Windows)
00088 if (_kbhit ())
00089 {
00090 want_to_quit = 1;
00091 break;
00092 }
00093 #endif
00094
00095
00096 }
00097 double finish_time = etime ();
00098 rcs_print ("Exiting Loop.\n");
00099
00100 if (NULL != ch1)
00101 {
00102 rcs_print ("Deleting ch1.\n");
00103 delete ch1;
00104 ch1 = NULL;
00105 }
00106
00107 if (NULL != ch2)
00108 {
00109 rcs_print ("Deleting ch2.\n");
00110 delete ch2;
00111 ch2 = NULL;
00112 }
00113
00114 rcs_print ("Totals: cycles = %d, time = %f\n", cycles,
00115 finish_time - start_time);
00116 rcs_print ("Average Cycle Time = %f\n",
00117 (finish_time - start_time) / cycles);
00118
00119
00120 #ifndef NO_TIMER
00121 rcs_print ("Deleting Timer.\n");
00122 delete timer;
00123 #endif
00124 }