00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <string.h>
00020 #include <stdlib.h>
00021 #include <signal.h>
00022 #include "rcs.hh"
00023 #include "emcglb.h"
00024 #include "emcio.hh"
00025 #include "extintf.h"
00026 #include "parport.h"
00027
00028
00029 #ifndef __GNUC__
00030 #ifndef __attribute__
00031 #define __attribute__(x)
00032 #endif
00033 #endif
00034
00035 static char __attribute__((unused)) ident[] = "$Id: bridgeportiomain.cc,v 1.5 2001/06/29 20:27:29 wshackle Exp $";
00036
00037
00038 int Argc;
00039 char **Argv;
00040
00041
00042 static int done;
00043
00044
00045 static void quit(int sig)
00046 {
00047 done = 1;
00048 }
00049
00050 static int iniLoad(const char *filename)
00051 {
00052 INIFILE inifile;
00053 const char *inistring;
00054 char version[INIFILE_MAX_LINELEN];
00055 int saveInt;
00056 double saveDouble;
00057
00058
00059 if (-1 == inifile.open(filename)) {
00060 return -1;
00061 }
00062
00063 if (NULL != (inistring = inifile.find("DEBUG", "EMC"))) {
00064
00065 if (1 != sscanf(inistring, "%i", &EMC_DEBUG)) {
00066 EMC_DEBUG = 0;
00067 }
00068 }
00069 else {
00070
00071 EMC_DEBUG = 0;
00072 }
00073
00074 if (EMC_DEBUG & EMC_DEBUG_VERSIONS) {
00075 if (NULL != (inistring = inifile.find("VERSION", "EMC"))){
00076
00077 sscanf(inistring, "$Revision: %s", version);
00078 rcs_print("Version: %s\n", version);
00079 }
00080 else {
00081
00082 rcs_print("Version: (not found)\n");
00083 }
00084
00085 if (NULL != (inistring = inifile.find("MACHINE", "EMC"))) {
00086
00087 rcs_print("Machine: %s\n", inistring);
00088 }
00089 else {
00090
00091 rcs_print("Machine: (not found)\n");
00092 }
00093 }
00094
00095 if (NULL != (inistring = inifile.find("NML_FILE", "EMC"))) {
00096
00097 strcpy(EMC_NMLFILE, inistring);
00098 }
00099 else {
00100
00101 }
00102
00103 saveDouble = EMC_IO_CYCLE_TIME;
00104 if (NULL != (inistring = inifile.find("CYCLE_TIME", "EMCIO"))) {
00105 if (1 == sscanf(inistring, "%lf", &EMC_IO_CYCLE_TIME)) {
00106
00107 }
00108 else {
00109
00110 EMC_IO_CYCLE_TIME = saveDouble;
00111 rcs_print("invalid [EMCIO] CYCLE_TIME in %s (%s); using default %f\n",
00112 filename, inistring, EMC_IO_CYCLE_TIME);
00113 }
00114 }
00115 else {
00116
00117 rcs_print("[EMCIO] CYCLE_TIME not found in %s; using default %f\n",
00118 filename, EMC_IO_CYCLE_TIME);
00119 }
00120
00121
00122
00123 saveInt = PARPORT_IO_ADDRESS;
00124
00125 if (NULL != (inistring = inifile.find("PARPORT_IO_ADDRESS", "EMCIO"))) {
00126 if (1 == sscanf(inistring, "%li", &PARPORT_IO_ADDRESS)) {
00127
00128 }
00129 else {
00130
00131 PARPORT_IO_ADDRESS = saveInt;
00132 rcs_print("invalid [EMCIO] PARPORT_IO_ADDRESS in %s (%s); using default %X\n",
00133 filename, inistring, PARPORT_IO_ADDRESS);
00134 }
00135 }
00136 else if (NULL != (inistring = inifile.find("PARPORT_IO_ADDRESS", "EMC"))) {
00137 if (1 == sscanf(inistring, "%li", &PARPORT_IO_ADDRESS)) {
00138
00139 }
00140 else {
00141
00142 PARPORT_IO_ADDRESS = saveInt;
00143 rcs_print("invalid [EMC] PARPORT_IO_ADDRESS in %s (%s); using default %X\n",
00144 filename, inistring, PARPORT_IO_ADDRESS);
00145 }
00146 }
00147 else {
00148
00149 rcs_print("[EMC] PARPORT_IO_ADDRESS not found in %s; using default %X\n",
00150 filename, PARPORT_IO_ADDRESS);
00151 }
00152
00153
00154 inifile.close();
00155
00156 return 0;
00157 }
00158
00159
00160
00161
00162 int main(int argc, char *argv[])
00163 {
00164 EMC_TOOL_MODULE *tool;
00165 EMC_SPINDLE_MODULE *spindle;
00166 EMC_COOLANT_MODULE *coolant;
00167 EMC_AUX_MODULE *aux;
00168 EMC_LUBE_MODULE *lube;
00169 RCS_TIMER *timer;
00170
00171
00172 Argc = argc;
00173 Argv = argv;
00174
00175
00176 set_rcs_print_destination(RCS_PRINT_TO_STDOUT);
00177
00178
00179 if (0 != emcGetArgs(argc, argv)) {
00180 rcs_print_error("error in argument list\n");
00181 exit(1);
00182 }
00183
00184
00185 iniLoad(EMC_INIFILE);
00186
00187
00188 if (0 != extDioInit(EMC_INIFILE)) {
00189 rcs_print_error("can't initialize IO-- privilege problems?\n");
00190 exit(1);
00191 }
00192
00193
00194 tool = new EMC_TOOL_MODULE();
00195 spindle = new EMC_SPINDLE_MODULE();
00196 coolant = new EMC_COOLANT_MODULE();
00197 aux = new EMC_AUX_MODULE();
00198 lube = new EMC_LUBE_MODULE();
00199
00200
00201 timer = new RCS_TIMER(EMC_IO_CYCLE_TIME);
00202
00203
00204 signal(SIGINT, quit);
00205
00206
00207 while (!done) {
00208
00209 tool->controller();
00210 spindle->controller();
00211 coolant->controller();
00212 aux->controller();
00213 lube->controller();
00214
00215
00216 if (EMC_IO_CYCLE_TIME > 0.0) {
00217 #if defined(LINUX_KERNEL_2_2)
00218
00219 esleep(EMC_IO_CYCLE_TIME);
00220 #else
00221 timer->wait();
00222 #endif
00223 }
00224 }
00225
00226
00227 delete timer;
00228
00229
00230 delete lube;
00231 delete aux;
00232 delete coolant;
00233 delete spindle;
00234 delete tool;
00235
00236
00237 extDioQuit();
00238
00239 exit(0);
00240 }
00241