📄 keystick.cc
字号:
} // close program file if (programFp) { fclose(programFp); programFp = 0; } // close error log file if (errorFp) { fclose(errorFp); errorFp = NULL; } // reset signal handlers to default signal(SIGALRM, SIG_DFL); signal(SIGINT, SIG_DFL); exit(0);}static int emcTaskNmlGet(){ int retval = 0; // try to connect to EMC cmd if (emcCommandBuffer == 0) { emcCommandBuffer = new RCS_CMD_CHANNEL(emcFormat, "emcCommand", "keystick", EMC_NMLFILE); if (! emcCommandBuffer->valid()) { rcs_print_error("emcCommand buffer not available\n"); delete emcCommandBuffer; emcCommandBuffer = 0; retval = -1; } } // try to connect to EMC status if (emcStatusBuffer == 0) { emcStatusBuffer = new RCS_STAT_CHANNEL(emcFormat, "emcStatus", "keystick", EMC_NMLFILE); if (! emcStatusBuffer->valid() || EMC_STAT_TYPE != emcStatusBuffer->peek()) { rcs_print_error("emcStatus buffer not available\n"); delete emcStatusBuffer; emcStatusBuffer = 0; emcStatus = 0; retval = -1; } else { emcStatus = (EMC_STAT *) emcStatusBuffer->get_address(); } } return retval;}static int emcErrorNmlGet(){ int retval = 0; if (emcErrorBuffer == 0) { emcErrorBuffer = new NML(nmlErrorFormat, "emcError", "keystick", EMC_NMLFILE); if (! emcErrorBuffer->valid()) { rcs_print_error("emcError buffer not available\n"); delete emcErrorBuffer; emcErrorBuffer = 0; retval = -1; } } return retval;}// string for ini file version numstatic char version_string[LINELEN] = "";// destructively converts string to its uppercase counterpartstatic char *upcase(char *string){ char *ptr = string; while (*ptr) { *ptr = toupper(*ptr); ptr++; } return string;}static int iniLoad(const char *filename){ IniFile inifile; const char *inistring; char machine[LINELEN] = ""; char version[LINELEN] = ""; char displayString[LINELEN] = ""; int jogPol; // open it if (-1 == inifile.Open(filename)) { return -1; } if ((inistring = inifile.Find("MACHINE", "EMC"))) { strcpy(machine, inistring); if ((inistring = inifile.Find("VERSION", "EMC"))) { sscanf(inistring, "$Revision: %s", version); sprintf(version_string, "%s EMC Version %s", machine, version); } } if ((inistring = inifile.Find("MAX_VELOCITY", "TRAJ"))) { if (1 != sscanf(inistring, "%lf", &TRAJ_MAX_VELOCITY)) { TRAJ_MAX_VELOCITY = DEFAULT_TRAJ_MAX_VELOCITY; } } else { TRAJ_MAX_VELOCITY = DEFAULT_TRAJ_MAX_VELOCITY; } if ((inistring = inifile.Find("PROGRAM_PREFIX", "DISPLAY"))) { if (1 != sscanf(inistring, "%s", programPrefix)) { programPrefix[0] = 0; } } else { programPrefix[0] = 0; } if ((inistring = inifile.Find("POSITION_OFFSET", "DISPLAY"))) { if (1 == sscanf(inistring, "%s", displayString)) { upcase(displayString); if (! strcmp(displayString, "ABSOLUTE")) { coords = COORD_ABSOLUTE; } else if (! strcmp(displayString, "RELATIVE")) { coords = COORD_RELATIVE; } else { // error-- invalid value // ignore } } else { // error-- no value provided // ignore } } else { // no line at all // ignore } if ((inistring = inifile.Find("POSITION_FEEDBACK", "DISPLAY"))) { if (1 == sscanf(inistring, "%s", displayString)) { upcase(displayString); if (! strcmp(displayString, "ACTUAL")) { posDisplay = POS_DISPLAY_ACT; } else if (! strcmp(displayString, "COMMANDED")) { posDisplay = POS_DISPLAY_CMD; } else { // error-- invalid value // ignore } } else { // error-- no value provided // ignore } } else { // no line at all // ignore } xJogPol = 1; // set to default if ((inistring = inifile.Find("JOGGING_POLARITY", "AXIS_0")) && 1 == sscanf(inistring, "%d", &jogPol) && jogPol == 0) { // it read as 0, so override default xJogPol = 0; } yJogPol = 1; // set to default if ((inistring = inifile.Find("JOGGING_POLARITY", "AXIS_1")) && 1 == sscanf(inistring, "%d", &jogPol) && jogPol == 0) { // it read as 0, so override default yJogPol = 0; } zJogPol = 1; // set to default if ((inistring = inifile.Find("JOGGING_POLARITY", "AXIS_2")) && 1 == sscanf(inistring, "%d", &jogPol) && jogPol == 0) { // it read as 0, so override default zJogPol = 0; } // close it inifile.Close(); return 0;;}int main(int argc, char *argv[]){ int dump = 0; struct winsize size; int curx, cury; int t; int typing = 0;#define TYPEBUFFERSIZE ASCLINELEN char typebuffer[TYPEBUFFERSIZE]; char lastmdi[TYPEBUFFERSIZE] = ""; int typeindex = 0; enum {IACT_NONE = 1, IACT_OPEN, IACT_MDI, IACT_LOAD_TOOL, IACT_OPEN_LOG, IACT_END} interactive = IACT_NONE; //char keystick[] = "keystick"; int charHandled; // process command line args, indexing argv[] from [1] for (t = 1; t < argc; t++) { // try -dump if (!strcmp(argv[t], "-dump")) { dump = 1; t++; // step over nmlfile continue; } // try -nml if (!strcmp(argv[t], "-nml")) { if (t == argc - 1) // if last, can't read past it { printf("syntax: -nml <nmlfile>\n"); exit(1); } else { strcpy(EMC_NMLFILE, argv[t+1]); t++; // step over nmlfile continue; } } // try -ini if (!strcmp(argv[t], "-ini")) { if (t == argc - 1) { printf("syntax: -ini <inifile\n"); exit(1); } else { strcpy(EMC_INIFILE, argv[t+1]); t++; // step over inifile continue; } } // try -noerror if (!strcmp(argv[t], "-noerror")) { catchErrors = 0; continue; } // try -usecs for cycle time in microseconds if (!strcmp(argv[t], "-usecs")) { if (t == argc - 1 || 1 != sscanf(argv[t + 1], "%d", &usecs) || usecs <= 0 || usecs >= 1000000) { printf("syntax: -usecs <1..999999 microsecond polling period>\n"); exit(1); } else { t++; continue; } } // try -dur for delay until repeat if (!strcmp(argv[t], "-dur")) { if (t == argc - 1 || 1 != sscanf(argv[t + 1], "%d", &FIRST_KEYUP_DELAY) || FIRST_KEYUP_DELAY < 0) { printf("syntax: -dur <usecs delay until first repeat>\n"); exit(1); } else { t++; continue; } } // try -dbr for delay between repeats if (!strcmp(argv[t], "-dbr")) { if (t == argc - 1 || 1 != sscanf(argv[t + 1], "%d", &NEXT_KEYUP_DELAY) || NEXT_KEYUP_DELAY < 0) { printf("syntax: -dbr <usecs delay between repeats>\n"); exit(1); } else { t++; continue; } } } // read INI file iniLoad(EMC_INIFILE); // trap SIGINT signal(SIGINT, quit); // set up handler for SIGALRM to handle periodic timer events signal(SIGALRM, alarmHandler);#ifdef LOG errorFp = fopen(ERROR_FILE, "w"); // failure here just disables logging#endif // init NML if (! dump) { if (emcTaskNmlGet()) { exit(1); } if (emcErrorNmlGet()) { exit(1); } } // set up curses initscr(); cbreak(); noecho(); nonl(); intrflush(stdscr, FALSE); keypad(stdscr, TRUE); helpwin = newwin(0, 0, 0, 0); diagwin = newwin(0, 0, 0, 0); toolwin = newwin(0, 0, 0, 0); logwin = newwin(0, 0, 0, 0); progwin = newwin(0, 0, 0, 0); window = stdscr; // fill in strings for (t = 0; t < ASCLINELEN; t++) { line_blank[t] = ' '; } line_blank[ASCLINELEN] = 0; for (t = 0; t < ASCLINELEN; t++) { bottom_string[t] = '-'; } bottom_string[ASCLINELEN] = 0; t = (ASCLINELEN - strlen(version_string)) / 2; if (t >= 0) { memcpy(&bottom_string[t], version_string, strlen(version_string)); } // get screen width and height wbegy = 0; wbegx = 0; if (ioctl(STDIN_FILENO, TIOCGWINSZ, &size) < 0) { // use 80x24 as default wmaxy = 23; wmaxx = 79; } else { wmaxy = size.ws_row - 1; wmaxx = size.ws_col - 1; } // and set them here cury = wmaxy; curx = wbegx; wmove(window, cury, curx); wrefresh(window); // set up interval timer if (!dump) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -