00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 extern "C" {
00013 #ifndef UNDER_CE
00014 #include <stdio.h>              
00015 #endif
00016 #include <stdlib.h>             
00017 }
00018 
00019 #include "emc.hh"
00020 #include "inifile.h"
00021 #include "inicool.hh"           
00022 #include "emcglb.h"             
00023 
00024 
00025 static INIFILE *coolantInifile = 0;
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
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           
00059           if (0 != emcCoolantSetMistIndex(i))
00060             {
00061               printf("bad return value from emcCoolantSetMistIndex\n");
00062               retval = -1;
00063             }
00064         }
00065       else
00066         {
00067           
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   
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           
00089           if (0 != emcCoolantSetFloodIndex(i))
00090             {
00091               printf("bad return value from emcCoolantSetFloodIndex\n");
00092               retval = -1;
00093             }
00094         }
00095       else
00096         {
00097           
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   
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           
00118           if (0 != emcCoolantSetMistPolarity(i))
00119             {
00120               printf("bad return value from emcCoolantSetMistPolarity\n");
00121               retval = -1;
00122             }
00123         }
00124       else
00125         {
00126           
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   
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           
00147           if (0 != emcCoolantSetFloodPolarity(i))
00148             {
00149               printf("bad return value from emcCoolantSetFloodPolarity\n");
00150               retval = -1;
00151             }
00152         }
00153       else
00154         {
00155           
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   
00169 
00170   return retval;
00171 }
00172 
00173 
00174 
00175 
00176 
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   
00190   if (0 != loadCoolant())
00191     {
00192       retval = -1;
00193     }
00194 
00195   
00196   coolantInifile->close();
00197   delete coolantInifile;
00198 
00199   return retval;
00200 }
00201 
00202 
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 }