00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "rcs.hh"
00022 #include "emc.hh"
00023 #include "inifile.h"
00024 #include "emcio.hh"
00025 #include "emcglb.h"
00026 #include "extintf.h"
00027 #include "iniaux.hh"
00028
00029
00030 #ifndef __GNUC__
00031 #ifndef __attribute__
00032 #define __attribute__(x)
00033 #endif
00034 #endif
00035
00036 static char __attribute__((unused)) ident[] = "$Id: bridgeportaux.cc,v 1.4 2001/06/29 20:27:29 wshackle Exp $";
00037
00038
00039
00040 static int estopOut = 1;
00041 static int checkEstopWorks = 1;
00042
00043 static void estopOn()
00044 {
00045 estopOut = 1;
00046 extDioWrite(ESTOP_WRITE_INDEX, ESTOP_WRITE_POLARITY);
00047 }
00048
00049 static void estopOff()
00050 {
00051 estopOut = 0;
00052 extDioWrite(ESTOP_WRITE_INDEX, ! ESTOP_WRITE_POLARITY);
00053 }
00054
00055
00056 static int isEstop()
00057 {
00058 int eIn;
00059
00060 extDioRead(ESTOP_SENSE_INDEX, &eIn);
00061
00062 return eIn == ESTOP_SENSE_POLARITY;
00063 }
00064
00065
00066 static int checkEstop()
00067 {
00068 int eOut;
00069
00070 extDioCheck(ESTOP_WRITE_INDEX, &eOut);
00071
00072 return eOut == ESTOP_WRITE_POLARITY;
00073 }
00074
00075
00076
00077 EMC_AUX_MODULE::EMC_AUX_MODULE()
00078 {
00079 setErrorLogChannel(new NML(nmlErrorFormat, "emcError", "aux", EMC_NMLFILE));
00080
00081 setCmdChannel(new RCS_CMD_CHANNEL(emcFormat, "auxCmd", "aux", EMC_NMLFILE));
00082
00083 setStatChannel(new RCS_STAT_CHANNEL(emcFormat, "auxSts", "aux", EMC_NMLFILE), &auxStatus);
00084 }
00085
00086
00087
00088 EMC_AUX_MODULE::~EMC_AUX_MODULE(void)
00089 {
00090 }
00091
00092 void EMC_AUX_MODULE::DECISION_PROCESS(void)
00093 {
00094 switch (commandInData->type)
00095 {
00096 case EMC_AUX_INIT_TYPE:
00097 INIT((EMC_AUX_INIT *) commandInData);
00098 break;
00099
00100 case EMC_AUX_HALT_TYPE:
00101 HALT((EMC_AUX_HALT *) commandInData);
00102 break;
00103
00104 case EMC_AUX_ABORT_TYPE:
00105 ABORT((EMC_AUX_ABORT *) commandInData);
00106 break;
00107
00108 case EMC_AUX_DIO_WRITE_TYPE:
00109 DIO_WRITE((EMC_AUX_DIO_WRITE *) commandInData);
00110 break;
00111
00112 case EMC_AUX_AIO_WRITE_TYPE:
00113 AIO_WRITE((EMC_AUX_AIO_WRITE *) commandInData);
00114 break;
00115
00116 case EMC_AUX_ESTOP_ON_TYPE:
00117 ESTOP_ON((EMC_AUX_ESTOP_ON *) commandInData);
00118 break;
00119
00120 case EMC_AUX_ESTOP_OFF_TYPE:
00121 ESTOP_OFF((EMC_AUX_ESTOP_OFF *) commandInData);
00122 break;
00123
00124 default:
00125 REPORT_ERROR(commandInData);
00126 break;
00127 }
00128 }
00129
00130 void EMC_AUX_MODULE::PRE_PROCESS(void)
00131 {
00132 }
00133
00134 void EMC_AUX_MODULE::POST_PROCESS(void)
00135 {
00136 int eIn, eOut;
00137 int t;
00138 unsigned char in;
00139
00140 eIn = isEstop();
00141 if(checkEstopWorks)
00142 {
00143 eOut = checkEstop();
00144 }
00145 else
00146 {
00147 eOut = estopOut;
00148 }
00149
00150
00151 auxStatus.estopIn = eIn;
00152
00153
00154
00155 if (eIn &&
00156 ! eOut)
00157 {
00158 estopOn();
00159 eOut = 1;
00160 }
00161
00162
00163
00164 auxStatus.estop = eIn || eOut;
00165
00166
00167 for (t = 0; t < EMC_AUX_MAX_DIN; t++)
00168 {
00169 extDioByteRead(t, &in);
00170 auxStatus.din[t] = in;
00171 }
00172 for (t = 0; t < EMC_AUX_MAX_DOUT; t++)
00173 {
00174 extDioByteCheck(t, &in);
00175 auxStatus.dout[t] = in;
00176 }
00177
00178
00179 for (t = 0; t < EMC_AUX_MAX_AIN; t++)
00180 {
00181 extAioRead(t, &auxStatus.ain[t]);
00182 }
00183 for (t = 0; t < EMC_AUX_MAX_AOUT; t++)
00184 {
00185 extAioCheck(t, &auxStatus.aout[t]);
00186 }
00187 }
00188
00189 void EMC_AUX_MODULE::INIT(EMC_AUX_INIT *cmdIn)
00190 {
00191 if (STATE_MATCH(NEW_COMMAND))
00192 {
00193
00194 iniAux(EMC_INIFILE);
00195
00196
00197 estopOn();
00198
00199 status = RCS_DONE;
00200 stateNext(S0);
00201 }
00202 else if (STATE_MATCH(S0))
00203 {
00204
00205 }
00206 }
00207
00208 void EMC_AUX_MODULE::HALT(EMC_AUX_HALT *cmdIn)
00209 {
00210 if (STATE_MATCH(NEW_COMMAND))
00211 {
00212
00213 estopOn();
00214
00215 status = RCS_DONE;
00216 stateNext(S0);
00217 }
00218 else if (STATE_MATCH(S0))
00219 {
00220
00221 }
00222 }
00223
00224 void EMC_AUX_MODULE::ABORT(EMC_AUX_ABORT *cmdIn)
00225 {
00226 if (STATE_MATCH(NEW_COMMAND))
00227 {
00228
00229 status = RCS_DONE;
00230 stateNext(S0);
00231 }
00232 else if (STATE_MATCH(S0))
00233 {
00234
00235 }
00236 }
00237
00238 void EMC_AUX_MODULE::REPORT_ERROR(RCS_CMD_MSG *cmdIn)
00239 {
00240 if (STATE_MATCH(NEW_COMMAND))
00241 {
00242 rcs_print_error("EMC_AUX_MODULE: unknown command %d\n",
00243 cmdIn->type);
00244 status = RCS_ERROR;
00245 stateNext(S0);
00246 }
00247 else if (STATE_MATCH(S0))
00248 {
00249
00250 }
00251 }
00252
00253 void EMC_AUX_MODULE::ESTOP_ON(EMC_AUX_ESTOP_ON *cmdIn)
00254 {
00255 if (STATE_MATCH(NEW_COMMAND))
00256 {
00257
00258 estopOn();
00259
00260 status = RCS_DONE;
00261 stateNext(S0);
00262 }
00263 else if (STATE_MATCH(S0))
00264 {
00265 if (! auxStatus.estop)
00266 {
00267 logError("The estop output bit was read back in and indicates the bit
00268 is still in the off state after an estopOn should have set it to the on state. (Check connectors, IO address settings etc.)\n");
00269 checkEstopWorks=0;
00270 }
00271 else
00272 {
00273 checkEstopWorks=1;
00274 }
00275 stateNext(S1);
00276
00277 }
00278 }
00279
00280 void EMC_AUX_MODULE::DIO_WRITE(EMC_AUX_DIO_WRITE *cmdIn)
00281 {
00282 if (STATE_MATCH(NEW_COMMAND))
00283 {
00284
00285 extDioWrite(cmdIn->index, cmdIn->value);
00286
00287 status = RCS_DONE;
00288 stateNext(S0);
00289 }
00290 else if (STATE_MATCH(S0))
00291 {
00292
00293 }
00294 }
00295
00296 void EMC_AUX_MODULE::AIO_WRITE(EMC_AUX_AIO_WRITE *cmdIn)
00297 {
00298 if (STATE_MATCH(NEW_COMMAND))
00299 {
00300
00301 extAioWrite(cmdIn->index, cmdIn->value);
00302
00303 status = RCS_DONE;
00304 stateNext(S0);
00305 }
00306 else if (STATE_MATCH(S0))
00307 {
00308
00309 }
00310 }
00311
00312 void EMC_AUX_MODULE::ESTOP_OFF(EMC_AUX_ESTOP_OFF *cmdIn)
00313 {
00314 if (STATE_MATCH(NEW_COMMAND))
00315 {
00316
00317 estopOff();
00318
00319 status = RCS_DONE;
00320 stateNext(S0);
00321 }
00322 else if (STATE_MATCH(S0))
00323 {
00324 if(auxStatus.estopIn)
00325 {
00326 logError("Can't come out of estop while the button is in.\n");
00327 }
00328 else if (auxStatus.estop)
00329 {
00330 logError("The estop output bit was read back in and indicates the bit
00331 is still in the on state after an estopOff should have set it to the off state. (Check connectors, IO address settings etc.)\n");
00332 checkEstopWorks=0;
00333 }
00334 else
00335 {
00336 checkEstopWorks = 1;
00337 }
00338 stateNext(S1);
00339
00340 }
00341 }
00342
00343
00344
00345
00346
00347
00348
00349