Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

minimilliomain.cc

Go to the documentation of this file.
00001 /*
00002   minimilliomain.cc
00003 
00004   Main controller for minimill I/O: tool, estop auxiliary
00005 
00006   Modification history:
00007 
00008   8-Nov-1999 WPS If'd out RCS_TIMER::wait() calls.
00009   1-Oct-1999  FMP took out lookup of PARPORT_IO_ADDRESS since no one uses it
00010   3-Sep-1999  FMP looked for PARPORT_IO_ADDRESS in EMCIO section first;
00011   used EMC_DEBUG to inhibit version printing
00012   31-Aug-1999  FMP changed to minimilliomain.cc; took out -nml option
00013   15-Jun-1999  FMP set EMC_DEBUG in iniLoad()
00014   7-Aug-1998  FMP changed extInit/Quit() to extDioInit/Quit()
00015   6-Jul-1998  FMP added Argc,Argv copies; call to emcGetArgs()
00016   2-Apr-1998  FMP created from emciomain, with no spindle
00017   */
00018 
00019 #include <string.h>             // strcpy()
00020 #include <stdlib.h>             // exit()
00021 #include <signal.h>             // SIGINT, signal()
00022 #include "rcs.hh"               // RCS_TIMER
00023 #include "emcglb.h"             // EMC_IO_CYCLE_TIME, EMC_NMLFILE
00024 #include "emcio.hh"             // EMC_IO_INIFILE, EMC_TOOL_MODULE
00025 #include "extintf.h"            // extInit(), extQuit()
00026 
00027 // ident tag
00028 /* ident tag */
00029 #ifndef __GNUC__
00030 #ifndef __attribute__
00031 #define __attribute__(x)
00032 #endif
00033 #endif
00034 
00035 static char __attribute__((unused)) ident[] = "$Id: minimilliomain.cc,v 1.5 2001/06/29 20:27:29 wshackle Exp $";
00036 
00037 // command line args-- global so that other modules can access
00038 int Argc;
00039 char **Argv;
00040 
00041 // flag signifying main loop is to terminate
00042 static int done;
00043 
00044 // signal handler for ^C
00045 static void quit(int sig)
00046 {
00047   done = 1;
00048 }
00049 
00050 static int iniLoad(const char *filename)
00051 {
00052   INIFILE inifile;
00053   const char *inistring;
00054   char version[INIFILE_MAX_LINELEN];
00055   double saveDouble;
00056 
00057   // open it
00058   if (-1 == inifile.open(filename)) {
00059     return -1;
00060   }
00061 
00062   if (NULL != (inistring = inifile.find("DEBUG", "EMC"))) {
00063     // copy to global
00064     if (1 != sscanf(inistring, "%i", &EMC_DEBUG)) {
00065       EMC_DEBUG = 0;
00066     }
00067   }
00068   else {
00069     // not found, use default
00070     EMC_DEBUG = 0;
00071   }
00072 
00073   if (EMC_DEBUG & EMC_DEBUG_VERSIONS) {
00074     if (NULL != (inistring = inifile.find("VERSION", "EMC"))) {
00075       // print version
00076       sscanf(inistring, "$Revision: %s", version);
00077       rcs_print("Version:  %s\n", version);
00078     }
00079     else {
00080       // not found, not fatal
00081       rcs_print("Version:  (not found)\n");
00082     }
00083 
00084     if (NULL != (inistring = inifile.find("MACHINE", "EMC"))) {
00085       // print machine
00086       rcs_print("Machine:  %s\n", inistring);
00087     }
00088     else {
00089       // not found, not fatal
00090       rcs_print("Machine:  (not found)\n");
00091     }
00092   }
00093 
00094   if (NULL != (inistring = inifile.find("NML_FILE", "EMC"))) {
00095     // copy to global
00096     strcpy(EMC_NMLFILE, inistring);
00097   }
00098   else {
00099     // not found, use default
00100   }
00101 
00102   saveDouble = EMC_IO_CYCLE_TIME;
00103   if (NULL != (inistring = inifile.find("CYCLE_TIME", "EMCIO"))) {
00104     if (1 == sscanf(inistring, "%lf", &EMC_IO_CYCLE_TIME)) {
00105       // found it
00106     }
00107     else {
00108       // found, but invalid
00109       EMC_IO_CYCLE_TIME = saveDouble;
00110       rcs_print("invalid [EMCIO] CYCLE_TIME in %s (%s); using default %f\n",
00111                 filename, inistring, EMC_IO_CYCLE_TIME);
00112     }
00113   }
00114   else {
00115     // not found, using default
00116     rcs_print("[EMCIO] CYCLE_TIME not found in %s; using default %f\n",
00117               filename, EMC_IO_CYCLE_TIME);
00118   }
00119 
00120   // close it
00121   inifile.close();
00122 
00123   return 0;
00124 }
00125 
00126 /*
00127   syntax: a.out {<inifile>} {<nmlfile>}
00128   */
00129 int main(int argc, char *argv[])
00130 {
00131   EMC_TOOL_MODULE *tool;
00132   EMC_AUX_MODULE *aux;
00133   RCS_TIMER *timer;
00134 
00135   // copy command line args
00136   Argc = argc;
00137   Argv = argv;
00138 
00139   // set print destination to stdout, for console apps
00140   set_rcs_print_destination(RCS_PRINT_TO_STDOUT);
00141 
00142   // process command line args, indexing argv[] from [1]
00143   if (0 != emcGetArgs(argc, argv)) {
00144     rcs_print_error("error in argument list\n");
00145     exit(1);
00146   }
00147 
00148   // get configuration information
00149   iniLoad(EMC_INIFILE);
00150 
00151   // init external IO here, since everyone uses it
00152   if (0 != extDioInit(EMC_INIFILE)) {
00153     rcs_print_error("can't initialize IO-- privilege problems?\n");
00154     exit(1);
00155   }
00156 
00157   // get controllers to run
00158   tool = new EMC_TOOL_MODULE();
00159   aux = new EMC_AUX_MODULE();
00160 
00161   // get timer
00162   timer = new RCS_TIMER(EMC_IO_CYCLE_TIME);
00163 
00164   // set the SIGINT handler
00165   signal(SIGINT, quit);
00166 
00167   // enter main loop
00168   while (!done) {
00169     // run controller logic
00170     tool->controller();
00171     aux->controller();
00172 
00173     // wait on timer
00174     if (EMC_IO_CYCLE_TIME > 0.0) {
00175 #if defined(LINUX_KERNEL_2_2)
00176       // work around bug in gettimeofday() by running off nominal time
00177       esleep(EMC_IO_CYCLE_TIME);
00178 #else
00179       timer->wait();
00180 #endif
00181     }
00182   }
00183 
00184   // clean up timer
00185   delete timer;
00186 
00187   // clean up controller
00188   delete aux;
00189   delete tool;
00190 
00191   // quit external IO here, since everyone uses it
00192   extDioQuit();
00193 
00194   exit(0);
00195 }

Generated on Sun Dec 2 15:27:41 2001 for EMC by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001