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

inilube.cc

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

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