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

inicool.cc

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

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