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

emcsvr.cc

Go to the documentation of this file.
00001 /*
00002   emcsvr.cc
00003 
00004   Network server for EMC NML
00005 
00006   Modification history:
00007 
00008   25-Jan-2001 WPS added string.h and stdlib.h
00009   21-Jul-2000  FMP added #include <math.h> for fabs()
00010   8-Jun-2000 WPS added code so that it would try the connections for
00011   10 seconds before printing any errors.
00012   1-Oct-1999  FMP added emcGetArgs, DEBUG to suppress version printing
00013   12-Apr-1999 WPS changed emcError to use emcFormat instead of nmlErrorFormat
00014   and to be a RCS_CMD_CHANNEL
00015   18-Mar-1998  FMP added tool command, status channels since emcpanel
00016   uses them directly
00017   4-Mar-1998  FMP added -nml command line arg
00018   15-Jan-1998  FMP added version printing niceties
00019   15-Jan-1998  WPS updated with new emc-style buffer names, and forgot
00020   to edit the modification history
00021   17-Oct-1997  FMP added ident tag
00022   */
00023 
00024 #include <stdio.h>              // sscanf()
00025 #include <math.h>               // fabs()
00026 #include <stdlib.h>             // exit()
00027 #include <string.h>             // strncpy()
00028 
00029 
00030 #include "rcs.hh"               // RCS_CMD_CHANNEL, RCS_STAT_CHANNEL, etc.
00031 #include "emc.hh"               // EMC NML
00032 #include "emcglb.h"             // emcGetArgs(), EMC_NMLFILE
00033 
00034 /* ident tag */
00035 #ifndef __GNUC__
00036 #ifndef __attribute__
00037 #define __attribute__(x)
00038 #endif
00039 #endif
00040 
00041 static char __attribute__((unused)) ident[] = "$Id: emcsvr.cc,v 1.7 2001/07/09 15:56:17 wshackle Exp $";
00042 
00043 static int iniLoad(const char *filename)
00044 {
00045   INIFILE inifile;
00046   const char *inistring;
00047 
00048   // open it
00049   if (-1 == inifile.open(filename)) {
00050     return -1;
00051   }
00052 
00053   if (NULL != (inistring = inifile.find("DEBUG", "EMC"))) {
00054     // copy to global
00055     if (1 != sscanf(inistring, "%i", &EMC_DEBUG)) {
00056       EMC_DEBUG = 0;
00057     }
00058   }
00059   else {
00060     // not found, use default
00061     EMC_DEBUG = 0;
00062   }
00063   if(EMC_DEBUG & EMC_DEBUG_RCS)
00064     {
00065       //set_rcs_print_flag(PRINT_EVERYTHING);
00066       max_rcs_errors_to_print=-1;
00067     }
00068 
00069 
00070   if (NULL != (inistring = inifile.find("NML_FILE", "EMC"))) {
00071     // copy to global
00072     strcpy(EMC_NMLFILE, inistring);
00073   }
00074   else {
00075     // not found, use default
00076   }
00077 
00078   // close it
00079   inifile.close();
00080 
00081   return 0;
00082 }
00083 
00084 static RCS_CMD_CHANNEL *emcCommandChannel=NULL;
00085 static RCS_STAT_CHANNEL *emcStatusChannel=NULL;
00086 static NML *emcErrorChannel=NULL;
00087 static RCS_CMD_CHANNEL *toolCommandChannel=NULL;
00088 static RCS_STAT_CHANNEL *toolStatusChannel=NULL;
00089 static RCS_CMD_CHANNEL *auxCommandChannel=NULL;
00090 static RCS_STAT_CHANNEL *auxStatusChannel=NULL;
00091 static RCS_CMD_CHANNEL *lubeCommandChannel=NULL;
00092 static RCS_STAT_CHANNEL *lubeStatusChannel=NULL;
00093 static RCS_CMD_CHANNEL *spindleCommandChannel=NULL;
00094 static RCS_STAT_CHANNEL *spindleStatusChannel=NULL;
00095 static RCS_CMD_CHANNEL *coolantCommandChannel=NULL;
00096 static RCS_STAT_CHANNEL *coolantStatusChannel=NULL;
00097 
00098 int main(int argc, char *argv[])
00099 {
00100   double start_time;
00101 
00102   // don't print the RCS library version
00103   rcs_version_printed = 1;
00104 
00105   // process command line args
00106   if (0 != emcGetArgs(argc, argv)) {
00107     rcs_print_error("Error in argument list\n");
00108     exit(1);
00109   }
00110 
00111   // get configuration information
00112   iniLoad(EMC_INIFILE);
00113 
00114   set_rcs_print_destination(RCS_PRINT_TO_NULL);
00115 
00116   start_time = etime();
00117 
00118   while(fabs(etime() - start_time) < 10.0 &&
00119         ( emcCommandChannel == NULL || emcStatusChannel == NULL || toolCommandChannel == NULL ||
00120           toolStatusChannel == NULL || emcErrorChannel == NULL)
00121         )
00122     {
00123       if(NULL == emcCommandChannel)
00124         {
00125           emcCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "emcsvr", EMC_NMLFILE);
00126         }
00127       if(NULL == emcStatusChannel)
00128         {
00129           emcStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "emcsvr", EMC_NMLFILE);
00130         }
00131       if(NULL == emcErrorChannel)
00132         {
00133           emcErrorChannel = new NML(nmlErrorFormat, "emcError", "emcsvr", EMC_NMLFILE);
00134         }
00135       if(NULL == toolCommandChannel)
00136         {
00137           toolCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "toolCmd", "emcsvr", EMC_NMLFILE);
00138         }
00139       if(NULL == toolStatusChannel)
00140         {
00141           toolStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "toolSts", "emcsvr", EMC_NMLFILE);
00142         }
00143       if(NULL == spindleCommandChannel)
00144         {
00145           spindleCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "spindleCmd", "emcsvr", EMC_NMLFILE);
00146         }
00147       if(NULL == spindleStatusChannel)
00148         {
00149           spindleStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "spindleSts", "emcsvr", EMC_NMLFILE);
00150         }
00151       if(NULL == auxCommandChannel)
00152         {
00153           auxCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "auxCmd", "emcsvr", EMC_NMLFILE);
00154         }
00155       if(NULL == auxStatusChannel)
00156         {
00157           auxStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "auxSts", "emcsvr", EMC_NMLFILE);
00158         }
00159       if(NULL == coolantCommandChannel)
00160         {
00161           coolantCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "coolantCmd", "emcsvr", EMC_NMLFILE);
00162         }
00163       if(NULL == coolantStatusChannel)
00164         {
00165           coolantStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "coolantSts", "emcsvr", EMC_NMLFILE);
00166         }
00167       if(NULL == lubeCommandChannel)
00168         {
00169           lubeCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "lubeCmd", "emcsvr", EMC_NMLFILE);
00170         }
00171       if(NULL == lubeStatusChannel)
00172         {
00173           lubeStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "lubeSts", "emcsvr", EMC_NMLFILE);
00174         }
00175 
00176       if(!emcCommandChannel->valid())
00177         {
00178           delete emcCommandChannel;
00179           emcCommandChannel = NULL;
00180         }
00181       if(!emcStatusChannel->valid())
00182         {
00183           delete emcStatusChannel;
00184           emcStatusChannel = NULL;
00185         }
00186       if(!emcErrorChannel->valid())
00187         {
00188           delete emcErrorChannel;
00189           emcErrorChannel = NULL;
00190         }
00191       if(!toolCommandChannel->valid())
00192         {
00193           delete toolCommandChannel;
00194           toolCommandChannel = NULL;
00195         }
00196       if(!toolStatusChannel->valid())
00197         {
00198           delete toolStatusChannel;
00199           toolStatusChannel = NULL;
00200         }
00201       if(!auxCommandChannel->valid())
00202         {
00203           delete auxCommandChannel;
00204           auxCommandChannel = NULL;
00205         }
00206       if(!auxStatusChannel->valid())
00207         {
00208           delete auxStatusChannel;
00209           auxStatusChannel = NULL;
00210         }
00211       if(!coolantCommandChannel->valid())
00212         {
00213           delete coolantCommandChannel;
00214           coolantCommandChannel = NULL;
00215         }
00216       if(!coolantStatusChannel->valid())
00217         {
00218           delete coolantStatusChannel;
00219           coolantStatusChannel = NULL;
00220         }
00221       if(!lubeCommandChannel->valid())
00222         {
00223           delete lubeCommandChannel;
00224           lubeCommandChannel = NULL;
00225         }
00226       if(!lubeStatusChannel->valid())
00227         {
00228           delete lubeStatusChannel;
00229           lubeStatusChannel = NULL;
00230         }
00231       if(!spindleCommandChannel->valid())
00232         {
00233           delete spindleCommandChannel;
00234           spindleCommandChannel = NULL;
00235         }
00236       if(!spindleStatusChannel->valid())
00237         {
00238           delete spindleStatusChannel;
00239           spindleStatusChannel = NULL;
00240         }
00241       esleep(0.200);
00242     }
00243 
00244   set_rcs_print_destination(RCS_PRINT_TO_STDERR);
00245 
00246   if(NULL == emcCommandChannel)
00247     {
00248       emcCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "emcsvr", EMC_NMLFILE);
00249     }
00250   if(NULL == emcStatusChannel)
00251     {
00252       emcStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "emcsvr", EMC_NMLFILE);
00253     }
00254   if(NULL == emcErrorChannel)
00255     {
00256       emcErrorChannel = new NML(nmlErrorFormat, "emcError", "emcsvr", EMC_NMLFILE);
00257     }
00258   if(NULL == toolCommandChannel)
00259     {
00260       toolCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "toolCmd", "emcsvr", EMC_NMLFILE);
00261     }
00262   if(NULL == toolStatusChannel)
00263     {
00264       toolStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "toolSts", "emcsvr", EMC_NMLFILE);
00265     }
00266 
00267   if(NULL == spindleCommandChannel)
00268     {
00269       spindleCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "spindleCmd", "emcsvr", EMC_NMLFILE);
00270     }
00271   if(NULL == spindleStatusChannel)
00272     {
00273       spindleStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "spindleSts", "emcsvr", EMC_NMLFILE);
00274     }
00275   if(NULL == auxCommandChannel)
00276     {
00277       auxCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "auxCmd", "emcsvr", EMC_NMLFILE);
00278     }
00279   if(NULL == auxStatusChannel)
00280     {
00281       auxStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "auxSts", "emcsvr", EMC_NMLFILE);
00282     }
00283   if(NULL == coolantCommandChannel)
00284     {
00285       coolantCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "coolantCmd", "emcsvr", EMC_NMLFILE);
00286     }
00287   if(NULL == coolantStatusChannel)
00288     {
00289       coolantStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "coolantSts", "emcsvr", EMC_NMLFILE);
00290     }
00291   if(NULL == lubeCommandChannel)
00292     {
00293       lubeCommandChannel = new RCS_CMD_CHANNEL(emcFormat, "lubeCmd", "emcsvr", EMC_NMLFILE);
00294     }
00295   if(NULL == lubeStatusChannel)
00296     {
00297       lubeStatusChannel = new RCS_STAT_CHANNEL(emcFormat, "lubeSts", "emcsvr", EMC_NMLFILE);
00298     }
00299 
00300 
00301   run_nml_servers();
00302 
00303   return 0;
00304 }
00305 
00306 

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