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 "inispin.hh"
00023 #include "emcglb.h"
00024
00025 #ifdef UNDER_CE
00026 #include "rcs_ce.h"
00027 #endif
00028
00029
00030 static INIFILE *spindleInifile = 0;
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 static int loadSpindle()
00078 {
00079 int retval = 0;
00080 const char *inistring;
00081 int i;
00082 double d;
00083
00084 if (NULL != (inistring = spindleInifile->find("SPINDLE_OFF_WAIT", "EMCIO")))
00085 {
00086 #ifndef UNDER_CE
00087 if (1 == sscanf(inistring, "%lf", &d))
00088 {
00089
00090 if (0 != emcSpindleSetOffWait(d))
00091 {
00092 printf("bad return value from emcSpindleSetOffWait\n");
00093 retval = -1;
00094 }
00095 }
00096 else
00097 {
00098
00099 printf("invalid inifile value for SPINDLE_OFF_WAIT: %s\n",
00100 inistring);
00101 }
00102 #else
00103 d = RCS_CE_ATOF(inistring);
00104 if (0 != emcSpindleSetOffWait(d))
00105 {
00106 rcs_print("bad return value from emcSpindleSetOffWait\n");
00107 retval = -1;
00108 }
00109 #endif
00110
00111 }
00112
00113
00114 if (NULL != (inistring = spindleInifile->find("SPINDLE_ON_WAIT", "EMCIO")))
00115 {
00116 #ifndef UNDER_CE
00117 if (1 == sscanf(inistring, "%lf", &d))
00118 {
00119
00120 if (0 != emcSpindleSetOnWait(d))
00121 {
00122 printf("bad return value from emcSpindleSetOnWait\n");
00123 retval = -1;
00124 }
00125 }
00126 else
00127 {
00128
00129 printf("invalid inifile value for SPINDLE_ON_WAIT: %s\n",
00130 inistring);
00131 }
00132 #else
00133 d = RCS_CE_ATOF(inistring);
00134 if (0 != emcSpindleSetOnWait(d))
00135 {
00136 rcs_print("bad return value from emcSpindleSetOnWait\n");
00137 retval = -1;
00138 }
00139 #endif
00140 }
00141
00142
00143 if (NULL != (inistring = spindleInifile->find("SPINDLE_FORWARD_INDEX", "EMCIO")))
00144 {
00145 #ifndef UNDER_CE
00146 if (1 == sscanf(inistring, "%d", &i))
00147 {
00148
00149 if (0 != emcSpindleSetForwardIndex(i))
00150 {
00151 printf("bad return value from emcSpindleSetForwardIndex\n");
00152 retval = -1;
00153 }
00154 }
00155 else
00156 {
00157
00158 printf("invalid inifile value for SPINDLE_FORWARD_INDEX: %s\n",
00159 inistring);
00160 }
00161 #else
00162 i = atol(inistring);
00163 if (0 != emcSpindleSetForwardIndex(i))
00164 {
00165 rcs_print("bad return value from emcSpindleSetForwardIndex\n");
00166 retval = -1;
00167 }
00168 #endif
00169 }
00170
00171
00172 if (NULL != (inistring = spindleInifile->find("SPINDLE_REVERSE_INDEX", "EMCIO")))
00173 {
00174 #ifndef UNDER_CE
00175 if (1 == sscanf(inistring, "%d", &i))
00176 {
00177
00178 if (0 != emcSpindleSetReverseIndex(i))
00179 {
00180 printf("bad return value from emcSpindleSetReverseIndex\n");
00181 retval = -1;
00182 }
00183 }
00184 else
00185 {
00186
00187 printf("invalid inifile value for SPINDLE_REVERSE_INDEX: %s\n",
00188 inistring);
00189 }
00190 #else
00191 i = atol(inistring);
00192 if (0 != emcSpindleSetReverseIndex(i))
00193 {
00194 rcs_print("bad return value from emcSpindleSetReverseIndex\n");
00195 retval = -1;
00196 }
00197 #endif
00198 }
00199
00200
00201 if (NULL != (inistring = spindleInifile->find("SPINDLE_DECREASE_INDEX", "EMCIO")))
00202 {
00203 #ifndef UNDER_CE
00204 if (1 == sscanf(inistring, "%d", &i))
00205 {
00206
00207 if (0 != emcSpindleSetDecreaseIndex(i))
00208 {
00209 printf("bad return value from emcSpindleSetDecreaseIndex\n");
00210 retval = -1;
00211 }
00212 }
00213 else
00214 {
00215
00216 printf("invalid inifile value for SPINDLE_DECREASE_INDEX: %s\n",
00217 inistring);
00218 }
00219 #else
00220 i = atol(inistring);
00221 if (0 != emcSpindleSetDecreaseIndex(i))
00222 {
00223 rcs_print("bad return value from emcSpindleSetDecreaseIndex\n");
00224 retval = -1;
00225 }
00226 #endif
00227 }
00228
00229
00230 if (NULL != (inistring = spindleInifile->find("SPINDLE_INCREASE_INDEX", "EMCIO")))
00231 {
00232 #ifndef UNDER_CE
00233 if (1 == sscanf(inistring, "%d", &i))
00234 {
00235
00236 if (0 != emcSpindleSetIncreaseIndex(i))
00237 {
00238 printf("bad return value from emcSpindleSetIncreaseIndex\n");
00239 retval = -1;
00240 }
00241 }
00242 else
00243 {
00244
00245 printf("invalid inifile value for SPINDLE_INCREASE_INDEX: %s\n",
00246 inistring);
00247 }
00248 #else
00249 i = atol(inistring);
00250 if (0 != emcSpindleSetIncreaseIndex(i))
00251 {
00252 rcs_print("bad return value from emcSpindleSetIncreaseIndex\n");
00253 retval = -1;
00254 }
00255 #endif
00256 }
00257
00258
00259 if (NULL != (inistring = spindleInifile->find("SPINDLE_BRAKE_INDEX", "EMCIO")))
00260 {
00261 #ifndef UNDER_CE
00262 if (1 == sscanf(inistring, "%d", &i))
00263 {
00264
00265 if (0 != emcSpindleSetBrakeIndex(i))
00266 {
00267 printf("bad return value from emcSpindleSetBrakeIndex\n");
00268 retval = -1;
00269 }
00270 }
00271 else
00272 {
00273
00274 printf("invalid inifile value for SPINDLE_BRAKE_INDEX: %s\n",
00275 inistring);
00276 }
00277 #else
00278 i = atol(inistring);
00279 if (0 != emcSpindleSetBrakeIndex(i))
00280 {
00281 rcs_print("bad return value from emcSpindleSetBrakeIndex\n");
00282 retval = -1;
00283 }
00284 #endif
00285 }
00286
00287
00288 if (NULL != (inistring = spindleInifile->find("SPINDLE_ENABLE_INDEX", "EMCIO")))
00289 {
00290 #ifndef UNDER_CE
00291 if (1 == sscanf(inistring, "%d", &i))
00292 {
00293
00294 if (0 != emcSpindleSetEnableIndex(i))
00295 {
00296 printf("bad return value from emcSpindleSetEnableIndex\n");
00297 retval = -1;
00298 }
00299 }
00300 else
00301 {
00302
00303 printf("invalid inifile value for SPINDLE_ENABLE_INDEX: %s\n",
00304 inistring);
00305 }
00306 #else
00307 i = atol(inistring);
00308 if (0 != emcSpindleSetEnableIndex(i))
00309 {
00310 rcs_print("bad return value from emcSpindleSetEnableIndex\n");
00311 retval = -1;
00312 }
00313 #endif
00314 }
00315
00316
00317 if (NULL != (inistring = spindleInifile->find("SPINDLE_ON_INDEX", "EMCIO")))
00318 {
00319 #ifndef UNDER_CE
00320 if (1 == sscanf(inistring, "%d", &i))
00321 {
00322
00323 if (0 != emcSpindleSetOnIndex(i))
00324 {
00325 printf("bad return value from emcSpindleSetOnIndex\n");
00326 retval = -1;
00327 }
00328 }
00329 else
00330 {
00331
00332 printf("invalid inifile value for SPINDLE_ON_INDEX: %s\n",
00333 inistring);
00334 }
00335 #else
00336 i = atol(inistring);
00337 if (0 != emcSpindleSetOnIndex(i))
00338 {
00339 rcs_print("bad return value from emcSpindleSetOnIndex\n");
00340 retval = -1;
00341 }
00342 #endif
00343 }
00344
00345
00346 if (NULL != (inistring = spindleInifile->find("SPINDLE_FORWARD_POLARITY", "EMCIO")))
00347 {
00348 #ifndef UNDER_CE
00349 if (1 == sscanf(inistring, "%d", &i))
00350 {
00351
00352 if (0 != emcSpindleSetForwardPolarity(i))
00353 {
00354 printf("bad return value from emcSpindleSetSpindleForwardPolarity\n");
00355 retval = -1;
00356 }
00357 }
00358 else
00359 {
00360
00361 printf("invalid inifile value for SPINDLE_FORWARD_POLARITY: %s\n",
00362 inistring);
00363 }
00364 #else
00365 i = atol(inistring);
00366 if (0 != emcSpindleSetForwardPolarity(i))
00367 {
00368 rcs_print("bad return value from emcSpindleSetForwardPolarity\n");
00369 retval = -1;
00370 }
00371 #endif
00372 }
00373
00374
00375 if (NULL != (inistring = spindleInifile->find("SPINDLE_REVERSE_POLARITY", "EMCIO")))
00376 {
00377 #ifndef UNDER_CE
00378 if (1 == sscanf(inistring, "%d", &i))
00379 {
00380
00381 if (0 != emcSpindleSetReversePolarity(i))
00382 {
00383 printf("bad return value from emcSpindleSetReversePolarity\n");
00384 retval = -1;
00385 }
00386 }
00387 else
00388 {
00389
00390 printf("invalid inifile value for SPINDLE_REVERSE_POLARITY: %s\n",
00391 inistring);
00392 }
00393 #else
00394 i = atol(inistring);
00395 if (0 != emcSpindleSetReversePolarity(i))
00396 {
00397 rcs_print("bad return value from emcSpindleSetReversePolarity\n");
00398 retval = -1;
00399 }
00400 #endif
00401 }
00402
00403
00404 if (NULL != (inistring = spindleInifile->find("SPINDLE_DECREASE_POLARITY", "EMCIO")))
00405 {
00406 #ifndef UNDER_CE
00407 if (1 == sscanf(inistring, "%d", &i))
00408 {
00409
00410 if (0 != emcSpindleSetDecreasePolarity(i))
00411 {
00412 printf("bad return value from emcSpindleSetDecreasePolarity\n");
00413 retval = -1;
00414 }
00415 }
00416 else
00417 {
00418
00419 printf("invalid inifile value for SPINDLE_DECREASE_POLARITY: %s\n",
00420 inistring);
00421 }
00422 #else
00423 i = atol(inistring);
00424 if (0 != emcSpindleSetDecreasePolarity(i))
00425 {
00426 rcs_print("bad return value from emcSpindleSetDecreasePolarity\n");
00427 retval = -1;
00428 }
00429 #endif
00430 }
00431
00432
00433 if (NULL != (inistring = spindleInifile->find("SPINDLE_INCREASE_POLARITY", "EMCIO")))
00434 {
00435 #ifndef UNDER_CE
00436 if (1 == sscanf(inistring, "%d", &i))
00437 {
00438
00439 if (0 != emcSpindleSetIncreasePolarity(i))
00440 {
00441 printf("bad return value from emcSpindleSetIncreasePolarity\n");
00442 retval = -1;
00443 }
00444 }
00445 else
00446 {
00447
00448 printf("invalid inifile value for SPINDLE_INCREASE_POLARITY: %s\n",
00449 inistring);
00450 }
00451 #else
00452 i = atol(inistring);
00453 if (0 != emcSpindleSetForwardPolarity(i))
00454 {
00455 rcs_print("bad return value from emcSpindleSetForwardPolarity\n");
00456 retval = -1;
00457 }
00458 #endif
00459 }
00460
00461
00462 if (NULL != (inistring = spindleInifile->find("SPINDLE_BRAKE_POLARITY", "EMCIO")))
00463 {
00464 #ifndef UNDER_CE
00465 if (1 == sscanf(inistring, "%d", &i))
00466 {
00467
00468 if (0 != emcSpindleSetBrakePolarity(i))
00469 {
00470 printf("bad return value from emcSpindleSetBrakePolarity\n");
00471 retval = -1;
00472 }
00473 }
00474 else
00475 {
00476
00477 printf("invalid inifile value for SPINDLE_BRAKE_POLARITY: %s\n",
00478 inistring);
00479 }
00480 #else
00481 i = atol(inistring);
00482 if (0 != emcSpindleSetBrakePolarity(i))
00483 {
00484 rcs_print("bad return value from emcSpindleSetBrakePolarity\n");
00485 retval = -1;
00486 }
00487 #endif
00488 }
00489
00490
00491 if (NULL != (inistring = spindleInifile->find("SPINDLE_ENABLE_POLARITY", "EMCIO")))
00492 {
00493 #ifndef UNDER_CE
00494 if (1 == sscanf(inistring, "%d", &i))
00495 {
00496
00497 if (0 != emcSpindleSetEnablePolarity(i))
00498 {
00499 printf("bad return value from emcSpindleSetEnablePolarity\n");
00500 retval = -1;
00501 }
00502 }
00503 else
00504 {
00505
00506 printf("invalid inifile value for SPINDLE_ENABLE_POLARITY: %s\n",
00507 inistring);
00508 }
00509 #else
00510 i = atol(inistring);
00511 if (0 != emcSpindleSetEnablePolarity(i))
00512 {
00513 rcs_print("bad return value from emcSpindleSetEnablePolarity\n");
00514 retval = -1;
00515 }
00516 #endif
00517 }
00518
00519
00520 return retval;
00521 }
00522
00523
00524
00525
00526
00527
00528 int iniSpindle(const char *filename)
00529 {
00530 int retval = 0;
00531
00532 spindleInifile = new INIFILE;
00533
00534 if (-1 == spindleInifile->open(filename))
00535 {
00536 return -1;
00537 }
00538
00539
00540 if (0 != loadSpindle())
00541 {
00542 retval = -1;
00543 }
00544
00545
00546 spindleInifile->close();
00547 delete spindleInifile;
00548
00549 return retval;
00550 }
00551
00552
00553
00554 int emcSpindleSetForwardIndex(int index)
00555 {
00556 SPINDLE_FORWARD_INDEX = index;
00557
00558 return 0;
00559 }
00560
00561 int emcSpindleSetReverseIndex(int index)
00562 {
00563 SPINDLE_REVERSE_INDEX = index;
00564
00565 return 0;
00566 }
00567
00568 int emcSpindleSetDecreaseIndex(int index)
00569 {
00570 SPINDLE_DECREASE_INDEX = index;
00571
00572 return 0;
00573 }
00574
00575 int emcSpindleSetIncreaseIndex(int index)
00576 {
00577 SPINDLE_INCREASE_INDEX = index;
00578
00579 return 0;
00580 }
00581
00582 int emcSpindleSetBrakeIndex(int index)
00583 {
00584 SPINDLE_BRAKE_INDEX = index;
00585
00586 return 0;
00587 }
00588
00589 int emcSpindleSetEnableIndex(int index)
00590 {
00591 SPINDLE_ENABLE_INDEX = index;
00592
00593 return 0;
00594 }
00595
00596 int emcSpindleSetOnIndex(int index)
00597 {
00598 SPINDLE_ON_INDEX = index;
00599
00600 return 0;
00601 }
00602
00603 int emcSpindleSetForwardPolarity(int polarity)
00604 {
00605 SPINDLE_FORWARD_POLARITY = polarity;
00606
00607 return 0;
00608 }
00609
00610 int emcSpindleSetReversePolarity(int polarity)
00611 {
00612 SPINDLE_REVERSE_POLARITY = polarity;
00613
00614 return 0;
00615 }
00616
00617 int emcSpindleSetDecreasePolarity(int polarity)
00618 {
00619 SPINDLE_DECREASE_POLARITY = polarity;
00620
00621 return 0;
00622 }
00623
00624 int emcSpindleSetIncreasePolarity(int polarity)
00625 {
00626 SPINDLE_INCREASE_POLARITY = polarity;
00627
00628 return 0;
00629 }
00630
00631 int emcSpindleSetBrakePolarity(int polarity)
00632 {
00633 SPINDLE_BRAKE_POLARITY = polarity;
00634
00635 return 0;
00636 }
00637
00638 int emcSpindleSetEnablePolarity(int polarity)
00639 {
00640 SPINDLE_ENABLE_POLARITY = polarity;
00641
00642 return 0;
00643 }
00644
00645 int emcSpindleSetOffWait(double wait)
00646 {
00647 SPINDLE_OFF_WAIT = wait;
00648
00649 return 0;
00650 }
00651
00652 int emcSpindleSetOnWait(double wait)
00653 {
00654 SPINDLE_ON_WAIT = wait;
00655
00656 return 0;
00657 }