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

bridgeportiomain.cc

Go to the documentation of this file.
00001 /*
00002   bridgeportiomain.cc
00003 
00004   Main controller for Bridgeport I/O: spindle, coolant,
00005   lube, estop auxiliary
00006 
00007   Modification history:
00008 
00009   10-Nov-1999 FMP If'd out RCS_TIMER::wait() calls.
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 bridgeportiomain.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.cc
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 #include "parport.h"            // PARPORT_IO_ADDRESS
00027 
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: bridgeportiomain.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   int saveInt;
00056   double saveDouble;
00057 
00058   // open it
00059   if (-1 == inifile.open(filename)) {
00060     return -1;
00061   }
00062 
00063   if (NULL != (inistring = inifile.find("DEBUG", "EMC"))) {
00064     // copy to global
00065     if (1 != sscanf(inistring, "%i", &EMC_DEBUG)) {
00066       EMC_DEBUG = 0;
00067     }
00068   }
00069   else {
00070     // not found, use default
00071     EMC_DEBUG = 0;
00072   }
00073 
00074   if (EMC_DEBUG & EMC_DEBUG_VERSIONS) {
00075     if (NULL != (inistring = inifile.find("VERSION", "EMC"))){
00076       // print version
00077       sscanf(inistring, "$Revision: %s", version);
00078       rcs_print("Version:  %s\n", version);
00079     }
00080     else {
00081       // not found, not fatal
00082       rcs_print("Version:  (not found)\n");
00083     }
00084 
00085     if (NULL != (inistring = inifile.find("MACHINE", "EMC"))) {
00086       // print machine
00087       rcs_print("Machine:  %s\n", inistring);
00088     }
00089     else {
00090       // not found, not fatal
00091       rcs_print("Machine:  (not found)\n");
00092     }
00093   }
00094 
00095   if (NULL != (inistring = inifile.find("NML_FILE", "EMC"))) {
00096     // copy to global
00097     strcpy(EMC_NMLFILE, inistring);
00098   }
00099   else {
00100     // not found, use default
00101   }
00102 
00103   saveDouble = EMC_IO_CYCLE_TIME;
00104   if (NULL != (inistring = inifile.find("CYCLE_TIME", "EMCIO"))) {
00105     if (1 == sscanf(inistring, "%lf", &EMC_IO_CYCLE_TIME)) {
00106       // found it
00107     }
00108     else {
00109       // found, but invalid
00110       EMC_IO_CYCLE_TIME = saveDouble;
00111       rcs_print("invalid [EMCIO] CYCLE_TIME in %s (%s); using default %f\n",
00112                 filename, inistring, EMC_IO_CYCLE_TIME);
00113     }
00114   }
00115   else {
00116     // not found, using default
00117     rcs_print("[EMCIO] CYCLE_TIME not found in %s; using default %f\n",
00118               filename, EMC_IO_CYCLE_TIME);
00119   }
00120 
00121   // do miscellaneous ones
00122 
00123   saveInt = PARPORT_IO_ADDRESS;
00124   // look for it as [EMCIO] section first
00125   if (NULL != (inistring = inifile.find("PARPORT_IO_ADDRESS", "EMCIO"))) {
00126     if (1 == sscanf(inistring, "%li", &PARPORT_IO_ADDRESS)) {
00127       // found it
00128     }
00129     else {
00130       // found, but invalid
00131       PARPORT_IO_ADDRESS = saveInt;
00132       rcs_print("invalid [EMCIO] PARPORT_IO_ADDRESS in %s (%s); using default %X\n",
00133                 filename, inistring, PARPORT_IO_ADDRESS);
00134     }
00135   }
00136   else if (NULL != (inistring = inifile.find("PARPORT_IO_ADDRESS", "EMC"))) {
00137     if (1 == sscanf(inistring, "%li", &PARPORT_IO_ADDRESS)) {
00138       // found it
00139     }
00140     else {
00141       // found, but invalid
00142       PARPORT_IO_ADDRESS = saveInt;
00143       rcs_print("invalid [EMC] PARPORT_IO_ADDRESS in %s (%s); using default %X\n",
00144                 filename, inistring, PARPORT_IO_ADDRESS);
00145     }
00146   }
00147   else {
00148     // not found, using default
00149     rcs_print("[EMC] PARPORT_IO_ADDRESS not found in %s; using default %X\n",
00150               filename, PARPORT_IO_ADDRESS);
00151   }
00152 
00153   // close it
00154   inifile.close();
00155 
00156   return 0;
00157 }
00158 
00159 /*
00160   syntax: a.out {-ini <inifile>}
00161   */
00162 int main(int argc, char *argv[])
00163 {
00164   EMC_TOOL_MODULE *tool;
00165   EMC_SPINDLE_MODULE *spindle;
00166   EMC_COOLANT_MODULE *coolant;
00167   EMC_AUX_MODULE *aux;
00168   EMC_LUBE_MODULE *lube;
00169   RCS_TIMER *timer;
00170 
00171   // copy command line args
00172   Argc = argc;
00173   Argv = argv;
00174 
00175   // set print destination to stdout, for console apps
00176   set_rcs_print_destination(RCS_PRINT_TO_STDOUT);
00177 
00178   // process command line args, indexing argv[] from [1]
00179   if (0 != emcGetArgs(argc, argv)) {
00180     rcs_print_error("error in argument list\n");
00181     exit(1);
00182   }
00183 
00184   // get configuration information
00185   iniLoad(EMC_INIFILE);
00186 
00187   // init external IO here, since everyone uses it
00188   if (0 != extDioInit(EMC_INIFILE)) {
00189     rcs_print_error("can't initialize IO-- privilege problems?\n");
00190     exit(1);
00191   }
00192 
00193   // get controllers to run
00194   tool = new EMC_TOOL_MODULE();
00195   spindle = new EMC_SPINDLE_MODULE();
00196   coolant = new EMC_COOLANT_MODULE();
00197   aux = new EMC_AUX_MODULE();
00198   lube = new EMC_LUBE_MODULE();
00199 
00200   // get timer
00201   timer = new RCS_TIMER(EMC_IO_CYCLE_TIME);
00202 
00203   // set the SIGINT handler
00204   signal(SIGINT, quit);
00205 
00206   // enter main loop
00207   while (!done) {
00208     // run controller logic
00209     tool->controller();
00210     spindle->controller();
00211     coolant->controller();
00212     aux->controller();
00213     lube->controller();
00214 
00215     // wait on timer
00216     if (EMC_IO_CYCLE_TIME > 0.0) {
00217 #if defined(LINUX_KERNEL_2_2)
00218       // work around bug in gettimeofday() by running off nominal time
00219       esleep(EMC_IO_CYCLE_TIME);
00220 #else
00221       timer->wait();
00222 #endif
00223     }
00224   }
00225 
00226   // clean up timer
00227   delete timer;
00228 
00229   // clean up controller
00230   delete lube;
00231   delete aux;
00232   delete coolant;
00233   delete spindle;
00234   delete tool;
00235 
00236   // quit external IO here, since everyone uses it
00237   extDioQuit();
00238 
00239   exit(0);
00240 }
00241 

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