📄 halrmt.c
字号:
rtapi_mutex_give(&(hal_data->mutex));}static void save_params(FILE *dst){ int next; hal_param_t *param; fprintf(dst, "# parameter values\n"); rtapi_mutex_get(&(hal_data->mutex)); next = hal_data->param_list_ptr; while (next != 0) { param = SHMPTR(next); if (param->dir != HAL_RO) { /* param is writable, save it's value */ fprintf(dst, "setp %s %s\n", param->name, data_value((int) param->type, SHMPTR(param->data_ptr))); } next = param->next_ptr; } rtapi_mutex_give(&(hal_data->mutex));}static void save_threads(FILE *dst){ int next_thread; hal_thread_t *tptr; hal_list_t *list_root, *list_entry; hal_funct_entry_t *fentry; hal_funct_t *funct; fprintf(dst, "# realtime thread/function links\n"); rtapi_mutex_get(&(hal_data->mutex)); next_thread = hal_data->thread_list_ptr; while (next_thread != 0) { tptr = SHMPTR(next_thread); list_root = &(tptr->funct_list); list_entry = list_next(list_root); while (list_entry != list_root) { /* print the function info */ fentry = (hal_funct_entry_t *) list_entry; funct = SHMPTR(fentry->funct_ptr); fprintf(dst, "addf %s %s\n", funct->name, tptr->name); list_entry = list_next(list_entry); } next_thread = tptr->next_ptr; } rtapi_mutex_give(&(hal_data->mutex));}static int do_help_cmd(char *command){ if (strcmp(command, "help") == 0) { printf("If you need help to use 'help', then I can't help you.\n"); } else if (strcmp(command, "loadrt") == 0) { printf("loadrt modname [modarg(s)]\n"); printf(" Loads realtime HAL module 'modname', passing 'modargs'\n"); printf(" to the module.\n"); } else if (strcmp(command, "unloadrt") == 0) { printf("unloadrt modname\n"); printf(" Unloads realtime HAL module 'modname'. If 'modname'\n"); printf(" is 'all', unloads all realtime modules.\n"); } else if (strcmp(command, "loadusr") == 0) { printf("loadusr [options] progname [progarg(s)]\n"); printf(" Starts user space program 'progname', passing\n"); printf(" 'progargs' to it. Options are:\n"); printf(" -w wait for program to finish\n"); printf(" -i ignore program return value (use with -w)\n"); } else if ((strcmp(command, "linksp") == 0) || (strcmp(command,"linkps") == 0)) { printf("linkps pinname [arrow] signame\n"); printf("linksp signame [arrow] pinname\n"); printf(" Links pin 'pinname' to signal 'signame'. Both forms do\n"); printf(" the same thing. Use whichever makes sense. The optional\n"); printf(" 'arrow' can be '==>', '<==', or '<=>' and is ignored. It\n"); printf(" can be used in files to show the direction of data flow,\n"); printf(" but don't use arrows on the command line.\n"); } else if (strcmp(command, "linkpp") == 0) { printf("linkpp firstpin secondpin\n"); printf(" Creates a signal with the name of the first pin,\n"); printf(" then links both pins to the signal. \n"); }else if (strcmp(command, "unlinkp") == 0) { printf("unlinkp pinname\n"); printf(" Unlinks pin 'pinname' if it is linked to any signal.\n"); } else if (strcmp(command, "lock") == 0) { printf("lock [all|tune|none]\n"); printf(" Locks HAL to some degree.\n"); printf(" none - no locking done.\n"); printf(" tune - some tuning is possible (setp & such).\n"); printf(" all - HAL completely locked.\n"); } else if (strcmp(command, "unlock") == 0) { printf("unlock [all|tune]\n"); printf(" Unlocks HAL to some degree.\n"); printf(" tune - some tuning is possible (setp & such).\n"); printf(" all - HAL completely unlocked.\n"); } else if (strcmp(command, "newsig") == 0) { printf("newsig signame type\n"); printf(" Creates a new signal called 'signame'. Type is 'bit',\n"); printf(" 'float', 'u8', 's8', 'u16', 's16', 'u32', or 's32'.\n"); } else if (strcmp(command, "delsig") == 0) { printf("delsig signame\n"); printf(" Deletes signal 'signame'. If 'signame is 'all',\n"); printf(" deletes all signals\n"); } else if (strcmp(command, "setp") == 0) { printf("setp paramname value\n"); printf("paramname = value\n"); printf(" Sets parameter 'paramname' to 'value' (if writable).\n"); printf(" 'setp' and '=' work the same, don't use '=' on the\n"); printf(" command line. 'value' may be a constant such as 1.234\n"); printf(" or TRUE, or a reference to an environment variable,\n");#ifdef NO_INI printf(" using the syntax '$name'./n");#else printf(" using the syntax '$name'. If option -i was given,\n"); printf(" 'value' may also be a reference to an ini file entry\n"); printf(" using the syntax '[section]name'.\n");#endif } else if (strcmp(command, "sets") == 0) { printf("sets signame value\n"); printf(" Sets signal 'signame' to 'value' (if sig has no writers).\n"); } else if (strcmp(command, "getp") == 0) { printf("getp paramname\n"); printf(" Gets the value of parameter 'paramname'.\n"); } else if (strcmp(command, "gets") == 0) { printf("gets signame\n"); printf(" Gets the value of signal 'signame'.\n"); } else if (strcmp(command, "addf") == 0) { printf("addf functname threadname [position]\n"); printf(" Adds function 'functname' to thread 'threadname'. If\n"); printf(" 'position' is specified, adds the function to that spot\n"); printf(" in the thread, otherwise adds it to the end. Negative\n"); printf(" 'position' means position with respect to the end of the\n"); printf(" thread. For example '1' is start of thread, '-1' is the\n"); printf(" end of the thread, '-3' is third from the end.\n"); } else if (strcmp(command, "delf") == 0) { printf("delf functname threadname\n"); printf(" Removes function 'functname' from thread 'threadname'.\n"); } else if (strcmp(command, "show") == 0) { printf("show [type] [pattern]\n"); printf(" Prints info about HAL items of the specified type.\n"); printf(" 'type' is 'comp', 'pin', 'sig', 'param', 'funct',\n"); printf(" 'thread', or 'all'. If 'type' is omitted, it assumes\n"); printf(" 'all' with no pattern. If 'pattern' is specified\n"); printf(" it prints only those items whose names match the\n"); printf(" pattern (no fancy regular expressions, just a simple\n"); printf(" match: 'foo' matches 'foo', 'foobar' and 'foot' but\n"); printf(" not 'fo' or 'frobz' or 'ffoo').\n"); } else if (strcmp(command, "list") == 0) { printf("list type [pattern]\n"); printf(" Prints the names of HAL items of the specified type.\n"); printf(" 'type' is 'comp', 'pin', 'sig', 'param', 'funct', or\n"); printf(" 'thread'. If 'pattern' is specified it prints only\n"); printf(" those names that match the pattern (no fancy regular\n"); printf(" expressions, just a simple match: 'foo' matches 'foo',\n"); printf(" 'foobar' and 'foot' but not 'fo' or 'frobz' or 'ffoo').\n"); printf(" Names are printed on a single line, space separated.\n"); } else if (strcmp(command, "status") == 0) { printf("status [type]\n"); printf(" Prints status info about HAL.\n"); printf(" 'type' is 'lock', 'mem', or 'all'. \n"); printf(" If 'type' is omitted, it assumes\n"); printf(" 'all'.\n"); } else if (strcmp(command, "save") == 0) { printf("save [type] [filename]\n"); printf(" Prints HAL state to 'filename' (or stdout), as a series\n"); printf(" of HAL commands. State can later be restored by using\n"); printf(" \"halrmt -f filename\".\n"); printf(" Type can be 'comp', 'sig', 'link[a]', 'net[a]', 'param',\n"); printf(" or 'thread'. ('linka' and 'neta' show arrows for pin\n"); printf(" direction.) If 'type' is omitted or 'all', does the\n"); printf(" equivalent of 'comp', 'sig', 'link', 'param', and 'thread'.\n"); } else if (strcmp(command, "start") == 0) { printf("start\n"); printf(" Starts all realtime threads.\n"); } else if (strcmp(command, "stop") == 0) { printf("stop\n"); printf(" Stops all realtime threads.\n"); } else if (strcmp(command, "quit") == 0) { printf("quit\n"); printf(" Stop processing input and terminate halrmt (when\n"); printf(" reading from a file or stdin).\n"); } else if (strcmp(command, "exit") == 0) { printf("exit\n"); printf(" Stop processing input and terminate halrmt (when\n"); printf(" reading from a file or stdin).\n"); } else { printf("No help for unknown command '%s'\n", command); } return 0;}static void print_help_general(int showR){ printf("\nUsage: halrmt [options] [cmd [args]]\n\n"); printf("options:\n\n"); printf(" -f [filename] Read commands from 'filename', not command\n"); printf(" line. If no filename, read from stdin.\n");#ifndef NO_INI printf(" -i filename Open .ini file 'filename', allow commands\n"); printf(" to get their values from ini file.\n");#endif printf(" -k Keep going after failed command. Default\n"); printf(" is to exit if any command fails. (Useful with -f)\n"); printf(" -q Quiet - print errors only (default).\n"); printf(" -Q Very quiet - print nothing.\n"); if (showR != 0) { printf(" -R Release mutex (for crash recovery only).\n"); } printf(" -s Script friendly - don't print headers on output.\n"); printf(" -v Verbose - print result of every command.\n"); printf(" -V Very verbose - print lots of junk.\n"); printf(" -h Help - print this help screen and exit.\n\n"); printf("commands:\n\n"); printf(" loadrt, unloadrt, loadusr, lock, unlock, linkps, linksp, linkpp,\n"); printf(" unlinkp, newsig, delsig, setp, getp, sets, gets, addf, delf, show,\n"); printf(" list, save, status, start, stop, quit, exit\n"); printf(" help Lists all commands with short descriptions\n"); printf(" help command Prints detailed help for 'command'\n\n");}static halCommandType lookupHalCommand(char *s){ halCommandType i = hcEcho; int temp; while (i < hcUnknown) { if (strcmp(halCommands[i], s) == 0) return i;// (int)i += 1; temp = i; temp++; i = (halCommandType) temp; } return i;} static int commandHello(connectionRecType *context){ char *pch; char *password = "EMC"; pch = strtok(NULL, delims); if (pch == NULL) return -1; if (strcmp(pch, password) != 0) return -1; pch = strtok(NULL, delims); if (pch == NULL) return -1; strcpy(context->hostName, pch); pch = strtok(NULL, delims); if (pch == NULL) return -1; context->linked = 1; strcpy(context->version, pch); printf("Connected to %s\n\r", context->hostName); return 0;}static cmdResponseType getEcho(char *s, connectionRecType *context){ char *pEchoStr = "ECHO %s"; if (context->echo == 1) sprintf(context->outBuf, pEchoStr, "ON"); else sprintf(context->outBuf, pEchoStr, "OFF"); return rtNoError;}static cmdResponseType getVerbose(char *s, connectionRecType *context){ char *pVerboseStr = "VERBOSE %s"; if (context->verbose == 1) sprintf(context->outBuf, pVerboseStr, "ON"); else sprintf(context->outBuf, pVerboseStr, "OFF"); return rtNoError;}static cmdResponseType getEnable(char *s, connectionRecType *context){ char *pEnableStr = "ENABLE %s"; if (context->cliSock == enabledConn) sprintf(context->outBuf, pEnableStr, "ON"); else sprintf(context->outBuf, pEnableStr, "OFF"); return rtNoError;}static cmdResponseType getConfig(char *s, connectionRecType *context){ char *pConfigStr = "CONFIG"; strcpy(context->outBuf, pConfigStr); return rtNoError;}static cmdResponseType getCommMode(char *s, connectionRecType *context){ char *pCommModeStr = "COMM_MODE %s"; switch (context->commMode) { case 0: sprintf(context->outBuf, pCommModeStr, "ASCII"); break; case 1: sprintf(context->outBuf, pCommModeStr, "BINARY"); break; } return rtNoError;}static cmdResponseType getCommProt(char *s, connectionRecType *context){ char *pCommProtStr = "COMM_PROT %s"; sprintf(context->outBuf, pCommProtStr, context->version); return rtNoError;}static cmdResponseType getComps(char *s, connectionRecType *context){ getCompInfo("", context); return rtHandledNoError;}static cmdResponseType getPins(char *s, connectionRecType *context){ getPinInfo("", 0, context); return rtHandledNoError;}static cmdResponseType getPinVals(char *s, connectionRecType *context){ getPinInfo("", 1, context); return rtHandledNoError;}static cmdResponseType getSignals(char *s, connectionRecType *context){ getSigInfo("", 0, context); return rtHandledNoError;}static cmdResponseType getSignalVals(char *s, connectionRecType *context){ getSigInfo("", 1, context); return rtHandledNoError;}static cmdResponseType getParams(char *s, connectionRecType *context){ getParamInfo("", 0, context); return rtHandledNoError;}static cmdResponseType getParamVals(char *s, connectionRecType *context){ getParamInfo("", 1, context); return rtHandledNoError;}static cmdResponseType getFuncts(char *s, connectionRecType *context){ getFunctInfo("", context); return rtHandledNoError;}static cmdResponseType getThreads(char *s, connectionRecType *context){ getThreadInfo("", context); return rtHandledNoError;}static cmdResponseType getComp(char *s, connectionRecType *context){ if (s == NULL) return rtStandardError; getCompInfo(s, context); return rtHandledNoError;}static cmdResponseType getPin(char *s, connectionRecType *context){ if (s == NULL) return rtStandardError; getPinInfo(s, 0, context); return rtHandledNoError;}static cmdResponseType getPinVal(char *s, connectionRecType *context){ if (s == NULL) return rtStandardError; getPinInfo(s, 1, context); return rtHandledNoError;}static cmdResponseType getSignal(char *s, connectionRecType *context){ if (s == NULL) return rtStandardError; getSigInfo(s, 0, context); return rtHandledNoError;}static cmdResponseType getSignalVal(char *s, connectionRecType *context){ if (s == NULL) return rtStandardError; getSigInfo(s, 1, context); return rtHandledNoError;}static cmdResponseType getParam(char *s, connectionRecType *context){ if (s == NULL) return rtStandardError; getParamInfo(s, 0, context); return rtHandledNoError;}static cmdResponseType getParamVal(char *s, connectionRecType *context){ if (s == NULL) return rtStandardError; getParamInfo(s, 1, context); return rtHandledNoError;}static cmdResponseType getFunct(char *s, connectionRecType *context){ if (s == NULL) return rtStandardError; getFunctInfo(s, context); return rtHandledNoError;}static cmdResponseType getThread(char *s, connectionRecType *context){ if (s == NULL) return rtStandardError; getThreadInfo(s, context); return rtHandledNoError;}int commandGet(connectionRecType *context){ static char *setNakStr = "GET NAK\r\n"; static char *setCmdNakStr = "GET %s NAK\r\n"; halCommandType cmd; char *pch; cmdResponseType ret = rtNoError; pch = strtok(NULL, delims); if (pch == NULL) { write(context->cliSock, setNakStr,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -