#include "emc.hh"
Include dependency graph for iniaxis.hh:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Functions | |
int | iniAxis (int axis, const char *filename) |
int | dumpAxis (int axis, const char *filename, EMC_AXIS_STAT *stat) |
End of UNDER_CE ifdefing out. More... |
|
End of UNDER_CE ifdefing out.
Definition at line 1417 of file iniaxis.cc. Referenced by emcAxisHalt().
01418 { 01419 #ifdef UNDER_CE 01420 return -1; 01421 #else 01422 char ourAxisSection[256]; 01423 int ourAxis = 0; 01424 FILE *infp = NULL; 01425 FILE *outfp = NULL; 01426 char line[256]; 01427 char section[256]; 01428 char var[256], val[256]; 01429 char fmt[256]; 01430 01431 // rename with backup suffix 01432 strcpy(line, filename); 01433 strcat(line, INIFILE_BACKUP_SUFFIX); 01434 if (0 != rename(filename, line)) { 01435 fprintf(stderr, "can't make backup copy of INI file %s\n", filename); 01436 return -1; 01437 } 01438 01439 // open backup for reading 01440 if (NULL == (infp = fopen(line, "r"))) { 01441 fprintf(stderr, "can't open backup copy of INI file %s\n", line); 01442 return -1; 01443 } 01444 01445 // open original for writing 01446 if (NULL == (outfp = fopen(filename, "w"))) { 01447 fprintf(stderr, "can't open original copy of INI file %s\n", line); 01448 return -1; 01449 } 01450 01451 // set our axis string and flag that we're in that section 01452 sprintf(ourAxisSection, "AXIS_%d", axis); 01453 ourAxis = 0; 01454 01455 while (!feof(infp)) { 01456 if (NULL == fgets(line, 256, infp)) { 01457 break; 01458 } 01459 01460 if (iniIsSection(line, section)) { 01461 // if this is "AXIS_0,1,...", it's what we want 01462 if (!strcmp(section, ourAxisSection)) { 01463 ourAxis = 1; 01464 } 01465 else { 01466 ourAxis = 0; 01467 } 01468 } 01469 01470 if (ourAxis) { 01471 if (iniIsEntry(line, var, val)) { 01472 if (!strcmp(var, "P")) { 01473 iniFormatFloat(fmt, var, val); 01474 fprintf(outfp, fmt, stat->p); 01475 continue; // avoid fputs() below, since we wrote it 01476 } 01477 else if (!strcmp(var, "I")) { 01478 iniFormatFloat(fmt, var, val); 01479 fprintf(outfp, fmt, stat->i); 01480 continue; 01481 } 01482 else if (!strcmp(var, "D")) { 01483 iniFormatFloat(fmt, var, val); 01484 fprintf(outfp, fmt, stat->d); 01485 continue; 01486 } 01487 else if (!strcmp(var, "FF0")) { 01488 iniFormatFloat(fmt, var, val); 01489 fprintf(outfp, fmt, stat->ff0); 01490 continue; 01491 } 01492 else if (!strcmp(var, "FF1")) { 01493 iniFormatFloat(fmt, var, val); 01494 fprintf(outfp, fmt, stat->ff1); 01495 continue; 01496 } 01497 else if (!strcmp(var, "FF2")) { 01498 iniFormatFloat(fmt, var, val); 01499 fprintf(outfp, fmt, stat->ff2); 01500 continue; 01501 } 01502 else if (!strcmp(var, "BACKLASH")) { 01503 iniFormatFloat(fmt, var, val); 01504 fprintf(outfp, fmt, stat->backlash); 01505 continue; 01506 } 01507 else if (!strcmp(var, "BIAS")) { 01508 iniFormatFloat(fmt, var, val); 01509 fprintf(outfp, fmt, stat->bias); 01510 continue; 01511 } 01512 else if (!strcmp(var, "MAX_ERROR")) { 01513 iniFormatFloat(fmt, var, val); 01514 fprintf(outfp, fmt, stat->maxError); 01515 continue; 01516 } 01517 else if (!strcmp(var, "DEADBAND")) { 01518 iniFormatFloat(fmt, var, val); 01519 fprintf(outfp, fmt, stat->deadband); 01520 continue; 01521 } 01522 else if (!strcmp(var, "OUTPUT_SCALE")) { 01523 // val will be a string with two floats, e.g., "1.0 0.0", 01524 // and iniFormatFloat2() will set fmt to convert 2 floats 01525 // at the precision of the first in the string 01526 iniFormatFloat2(fmt, var, val); 01527 fprintf(outfp, fmt, stat->outputScale, stat->outputOffset); 01528 continue; 01529 } 01530 else if (!strcmp(var, "FERROR")) { 01531 iniFormatFloat(fmt, var, val); 01532 fprintf(outfp, fmt, stat->maxFerror); 01533 continue; 01534 } 01535 else if (!strcmp(var, "MIN_FERROR")) { 01536 iniFormatFloat(fmt, var, val); 01537 fprintf(outfp, fmt, stat->minFerror); 01538 continue; 01539 } 01540 } 01541 } 01542 01543 // write it out 01544 fputs(line, outfp); 01545 } 01546 01547 fclose(infp); 01548 fclose(outfp); 01549 01550 return 0; 01551 #endif 01552 } |
|
Definition at line 1095 of file iniaxis.cc. Referenced by emcAxisInit(), and main().
01096 { 01097 int retval = 0; 01098 const char *inistring; 01099 int axes; 01100 01101 axisInifile = new INIFILE; 01102 if (-1 == axisInifile->open(filename)) { 01103 return -1; 01104 } 01105 01106 if (NULL != (inistring = axisInifile->find("AXES", "TRAJ"))) { 01107 #ifndef UNDER_CE 01108 if (1 == sscanf(inistring, "%d", &axes)) { 01109 // found, and valid 01110 } 01111 else { 01112 // found, but invalid 01113 if (EMC_DEBUG & EMC_DEBUG_INVALID) { 01114 rcs_print_error("invalid inifile value for [TRAJ] AXES: %s\n", inistring); 01115 } 01116 axes = 0; 01117 } 01118 #else 01119 axes = atol(inistring); 01120 #endif 01121 } 01122 else { 01123 // not found at all 01124 axes = 1; 01125 if (EMC_DEBUG & EMC_DEBUG_DEFAULTS) { 01126 rcs_print_error("can't find [TRAJ] AXES, using default %d\n", axes); 01127 } 01128 } 01129 01130 if (axis < 0 || 01131 axis >= axes) { 01132 // requested axis exceeds machine axes 01133 axisInifile->close(); 01134 delete axisInifile; 01135 return -1; 01136 } 01137 01138 // load its values 01139 if (0 != loadAxis(axis)) { 01140 retval = -1; 01141 } 01142 01143 // close the inifile 01144 axisInifile->close(); 01145 delete axisInifile; 01146 01147 return retval; 01148 } |