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

iniaux.cc

Go to the documentation of this file.
00001 /*
00002   iniaux.cc
00003 
00004   INI file initialization for aux controller
00005 
00006   Modification history:
00007 
00008   21-Sep-1999  WPS eliminate sscanf and printf calls not supported under CE.
00009   23-Apr-1998  FMP created from inispin.cc
00010   */
00011 
00012 
00013 extern "C" {
00014 #ifndef UNDER_CE
00015 #include <stdio.h>              // NULL, sscanf
00016 #else
00017 #include <stdlib.h>             // atol()
00018 #endif
00019 
00020 }
00021 
00022 #include "emc.hh"
00023 #include "inifile.h"
00024 #include "iniaux.hh"            // these decls
00025 #include "emcglb.h"             // ESTOP_SENSE_INDEX, etc
00026 
00027 // inifile ref'ed by iniAux(), loadAux()
00028 static INIFILE *auxInifile = 0;
00029 
00030 /*
00031   loadAux()
00032 
00033   Loads ini file params for aux from [EMCIO] section
00034 
00035   ESTOP_SENSE_INDEX <int>      dio point for mist aux on/off
00036   ESTOP_WRITE_INDEX <int>     dio point for flood aux on/off
00037 
00038   ESTOP_SENSE_POLARITY <0,1>   polarity for mist on
00039   ESTOP_WRITE_POLARITY <0,1>  polarity for flood on
00040 
00041   calls:
00042 
00043   emcAuxEstopSetSenseIndex(int index);
00044   emcAuxEstopSetWriteIndex(int index);
00045 
00046   emcAuxEstopSetSensePolarity(int polarity);
00047   emcAuxEstopSetWritePolarity(int polarity);
00048   */
00049 
00050 static int loadAux()
00051 {
00052   int retval = 0;
00053   const char *inistring;
00054   int i;
00055 
00056   if (NULL != (inistring = auxInifile->find("ESTOP_SENSE_INDEX", "EMCIO")))
00057     {
00058 #ifndef UNDER_CE
00059       if (1 == sscanf(inistring, "%d", &i))
00060         {
00061           // found, and valid
00062           if (0 != emcAuxEstopSetSenseIndex(i))
00063             {
00064               printf("bad return value from emcAuxEstopSetSenseIndex\n");
00065               retval = -1;
00066             }
00067         }
00068       else
00069         {
00070           // found, but invalid, so warn
00071           printf("invalid inifile value for ESTOP_SENSE_INDEX: %s\n",
00072                           inistring);
00073         }
00074 #else
00075       i = atol(inistring);
00076       if (0 != emcAuxEstopSetSenseIndex(i))
00077         {
00078           rcs_print_error("bad return value from emcAuxEstopSetSenseIndex\n");
00079           retval = -1;
00080         }
00081 #endif
00082     }
00083   // else ignore omission
00084 
00085   if (NULL != (inistring = auxInifile->find("ESTOP_WRITE_INDEX", "EMCIO")))
00086     {
00087 #ifndef UNDER_CE
00088       if (1 == sscanf(inistring, "%d", &i))
00089         {
00090           // found, and valid
00091           if (0 != emcAuxEstopSetWriteIndex(i))
00092             {
00093               printf("bad return value from emcAuxEstopSetWriteIndex\n");
00094               retval = -1;
00095             }
00096         }
00097       else
00098         {
00099           // found, but invalid, so warn
00100           printf("invalid inifile value for ESTOP_WRITE_INDEX: %s\n",
00101                           inistring);
00102         }
00103 #else
00104       i = atol(inistring);
00105       if (0 != emcAuxEstopSetWriteIndex(i))
00106         {
00107           rcs_print_error("bad return value from emcAuxEstopSetWriteIndex\n");
00108           retval = -1;
00109         }
00110 #endif
00111     }
00112   // else ignore omission
00113 
00114   if (NULL != (inistring = auxInifile->find("ESTOP_SENSE_POLARITY", "EMCIO")))
00115     {
00116 #ifndef UNDER_CE
00117       if (1 == sscanf(inistring, "%d", &i))
00118         {
00119           // found, and valid
00120           if (0 != emcAuxEstopSetSensePolarity(i))
00121             {
00122               printf("bad return value from emcAuxEstopSetSensePolarity\n");
00123               retval = -1;
00124             }
00125         }
00126       else
00127         {
00128           // found, but invalid, so warn
00129           printf("invalid inifile value for ESTOP_SENSE_POLARITY: %s\n",
00130                           inistring);
00131         }
00132 #else
00133       i = atol(inistring);
00134       if (0 != emcAuxEstopSetSensePolarity(i))
00135         {
00136           rcs_print_error("bad return value from emcAuxEstopSetSensePolarity\n");
00137           retval = -1;
00138         }
00139 #endif
00140     }
00141   // else ignore omission
00142 
00143   if (NULL != (inistring = auxInifile->find("ESTOP_WRITE_POLARITY", "EMCIO")))
00144     {
00145 #ifndef UNDER_CE
00146       if (1 == sscanf(inistring, "%d", &i))
00147         {
00148           // found, and valid
00149           if (0 != emcAuxEstopSetWritePolarity(i))
00150             {
00151               printf("bad return value from emcAuxEstopSetWritePolarity\n");
00152               retval = -1;
00153             }
00154         }
00155       else
00156         {
00157           // found, but invalid, so warn
00158           printf("invalid inifile value for ESTOP_WRITE_POLARITY: %s\n",
00159                           inistring);
00160         }
00161 #else
00162       i = atol(inistring);
00163        if (0 != emcAuxEstopSetWritePolarity(i))
00164          {
00165            rcs_print_error("bad return value from emcAuxEstopSetWritePolarity\n");
00166            retval = -1;
00167          }
00168 #endif
00169     }
00170   // else ignore omission
00171 
00172   return retval;
00173 }
00174 
00175 /*
00176   iniAux(const char *filename)
00177 
00178   Loads ini file parameters for aux controller, from [EMCIO] section
00179  */
00180 int iniAux(const char *filename)
00181 {
00182   int retval = 0;
00183 
00184   auxInifile = new INIFILE;
00185 
00186   if (-1 == auxInifile->open(filename))
00187     {
00188       return -1;
00189     }
00190 
00191   // load aux values
00192   if (0 != loadAux())
00193     {
00194       retval = -1;
00195     }
00196 
00197   // close the inifile
00198   auxInifile->close();
00199   delete auxInifile;
00200 
00201   return retval;
00202 }
00203 
00204 // implementations of functions to set ini file global variables
00205 
00206 int emcAuxEstopSetSenseIndex(int index)
00207 {
00208   ESTOP_SENSE_INDEX = index;
00209 
00210   return 0;
00211 }
00212 
00213 int emcAuxEstopSetWriteIndex(int index)
00214 {
00215   ESTOP_WRITE_INDEX = index;
00216 
00217   return 0;
00218 }
00219 
00220 int emcAuxEstopSetSensePolarity(int polarity)
00221 {
00222   ESTOP_SENSE_POLARITY = polarity;
00223 
00224   return 0;
00225 }
00226 
00227 int emcAuxEstopSetWritePolarity(int polarity)
00228 {
00229   ESTOP_WRITE_POLARITY = polarity;
00230 
00231   return 0;
00232 }

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