00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 extern "C" {
00014 #ifndef UNDER_CE
00015 #include <stdio.h>
00016 #endif
00017 #include <stdlib.h>
00018 }
00019
00020 #include "emc.hh"
00021 #include "inifile.h"
00022 #include "inilube.hh"
00023 #include "emcglb.h"
00024
00025
00026 static INIFILE *lubeInifile = 0;
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
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
00058 if (0 != emcLubeSetSenseIndex(i))
00059 {
00060 printf("bad return value from emcLubeSetSenseIndex\n");
00061 retval = -1;
00062 }
00063 }
00064 else
00065 {
00066
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
00086 if (0 != emcLubeSetSensePolarity(i))
00087 {
00088 printf("bad return value from emcLubeSetSensePolarity\n");
00089 retval = -1;
00090 }
00091 }
00092 else
00093 {
00094
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
00114 if (0 != emcLubeSetWriteIndex(i))
00115 {
00116 printf("bad return value from emcLubeSetWriteIndex\n");
00117 retval = -1;
00118 }
00119 }
00120 else
00121 {
00122
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
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
00143 if (0 != emcLubeSetWritePolarity(i))
00144 {
00145 printf("bad return value from emcLubeSetWritePolarity\n");
00146 retval = -1;
00147 }
00148 }
00149 else
00150 {
00151
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
00166
00167 return retval;
00168 }
00169
00170
00171
00172
00173
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
00187 if (0 != loadLube())
00188 {
00189 retval = -1;
00190 }
00191
00192
00193 lubeInifile->close();
00194 delete lubeInifile;
00195
00196 return retval;
00197 }
00198
00199
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 }