📄 halrmt.c
字号:
} next = sig->next_ptr; } rtapi_mutex_give(&(hal_data->mutex));}static void getParamInfo(char *pattern, int valuesOnly, connectionRecType *context){ int next, len; hal_param_t *param; hal_comp_t *comp; rtapi_mutex_get(&(hal_data->mutex)); len = strlen(pattern); next = hal_data->param_list_ptr; while (next != 0) { param = SHMPTR(next); if ( strncmp(pattern, param->name, len) == 0 ) { comp = SHMPTR(param->owner_ptr); if (valuesOnly == 0) sprintf(context->outBuf, "PARAM %s %s %02d %s %s", param->name, data_value((int) param->type, SHMPTR(param->data_ptr)), comp->comp_id, data_type((int) param->type), param_data_dir((int) param->dir)); else sprintf(context->outBuf, "PARAMVAL %s %s", param->name, data_value((int) param->type, SHMPTR(param->data_ptr))); sockWrite(context); } next = param->next_ptr; } rtapi_mutex_give(&(hal_data->mutex));}static void getFunctInfo(char *pattern, connectionRecType *context){ int next, len; hal_funct_t *fptr; hal_comp_t *comp; rtapi_mutex_get(&(hal_data->mutex)); len = strlen(pattern); next = hal_data->funct_list_ptr; while (next != 0) { fptr = SHMPTR(next); if (strncmp(pattern, fptr->name, len) == 0) { comp = SHMPTR(fptr->owner_ptr); sprintf(context->outBuf, "FUNCT %s %02d %08lX %08lX %s %3d", fptr->name, comp->comp_id, (unsigned long)fptr->funct, (unsigned long)fptr->arg, (fptr->uses_fp ? "YES" : "NO"), fptr->users); sockWrite(context); } next = fptr->next_ptr; } rtapi_mutex_give(&(hal_data->mutex));}static void getThreadInfo(char *pattern, connectionRecType *context){ int next_thread, len, n; hal_thread_t *tptr; hal_list_t *list_root, *list_entry; hal_funct_entry_t *fentry; hal_funct_t *funct; rtapi_mutex_get(&(hal_data->mutex)); len = strlen(pattern); next_thread = hal_data->thread_list_ptr; while (next_thread != 0) { tptr = SHMPTR(next_thread); if (strncmp(pattern, tptr->name, len) == 0) { sprintf(context->outBuf, "THREAD %s %11d %s %d %d", tptr->name, (unsigned int)tptr->period, (tptr->uses_fp ? "YES" : "NO "), (unsigned int)tptr->runtime, (unsigned int)tptr->maxtime); sockWrite(context); list_root = &(tptr->funct_list); list_entry = list_next(list_root); n = 1; while (list_entry != list_root) { /* print the function info */ fentry = (hal_funct_entry_t *) list_entry; funct = SHMPTR(fentry->funct_ptr); /* scriptmode only uses one line per thread, which contains: thread period, FP flag, name, then all functs separated by spaces */ sprintf(context->outBuf, "SUBTHREAD %s %2d", funct->name, n); sockWrite(context); n++; list_entry = list_next(list_entry); } } next_thread = tptr->next_ptr; } rtapi_mutex_give(&(hal_data->mutex));}/* Switch function for pin/sig/param type for the print_*_list functions */static char *data_type(int type){ char *type_str; switch (type) { case HAL_BIT: type_str = "bit "; break; case HAL_FLOAT: type_str = "float"; break; case HAL_S32: type_str = "s32 "; break; case HAL_U32: type_str = "u32 "; break; default: /* Shouldn't get here, but just in case... */ type_str = "undef"; } return type_str;}/* Switch function for pin direction for the print_*_list functions */static char *pin_data_dir(int dir){ char *pin_dir; switch (dir) { case HAL_IN: pin_dir = "IN "; break; case HAL_OUT: pin_dir = "OUT"; break; case HAL_IO: pin_dir = "I/O"; break; default: /* Shouldn't get here, but just in case... */ pin_dir = "???"; } return pin_dir;}/* Switch function for param direction for the print_*_list functions */static char *param_data_dir(int dir){ char *param_dir; switch (dir) { case HAL_RO: param_dir = "RO"; break; case HAL_RW: param_dir = "RW"; break; default: /* Shouldn't get here, but just in case... */ param_dir = "??"; } return param_dir;}/* Switch function for arrow direction for the print_*_list functions */static char *data_arrow1(int dir){ char *arrow; switch (dir) { case HAL_IN: arrow = "<=="; break; case HAL_OUT: arrow = "==>"; break; case HAL_IO: arrow = "<=>"; break; default: /* Shouldn't get here, but just in case... */ arrow = "???"; } return arrow;}/* Switch function for arrow direction for the print_*_list functions */static char *data_arrow2(int dir){ char *arrow; switch (dir) { case HAL_IN: arrow = "==>"; break; case HAL_OUT: arrow = "<=="; break; case HAL_IO: arrow = "<=>"; break; default: /* Shouldn't get here, but just in case... */ arrow = "???"; } return arrow;}/* Switch function to return var value for the print_*_list functions *//* the value is printed in a fixed width field */static char *data_value(int type, void *valptr){ char *value_str; static char buf[15]; switch (type) { case HAL_BIT: if (*((char *) valptr) == 0) value_str = " FALSE"; else value_str = " TRUE"; break; case HAL_FLOAT: snprintf(buf, 14, "%12.7g", (double)*((hal_float_t *) valptr)); value_str = buf; break; case HAL_S32: snprintf(buf, 14, " %10ld", (long)*((hal_u32_t *) valptr)); value_str = buf; break; case HAL_U32: snprintf(buf, 14, " %08lX", (unsigned long)*((hal_u32_t *) valptr)); value_str = buf; break; default: /* Shouldn't get here, but just in case... */ value_str = " undef "; } return value_str;}/* Switch function to return var value in string form *//* the value is printed as a packed string (no whitespace */static char *data_value2(int type, void *valptr){ char *value_str; static char buf[15]; switch (type) { case HAL_BIT: if (*((char *) valptr) == 0) value_str = "FALSE"; else value_str = "TRUE"; break; case HAL_FLOAT: snprintf(buf, 14, "%.7g", (double)*((hal_float_t *) valptr)); value_str = buf; break; case HAL_S32: snprintf(buf, 14, "%ld", (long)*((hal_s32_t *) valptr)); value_str = buf; break; case HAL_U32: snprintf(buf, 14, "%ld", (unsigned long)*((hal_u32_t *) valptr)); value_str = buf; break; default: /* Shouldn't get here, but just in case... */ value_str = "unknown_type"; } return value_str;}static int doSave(char *type, char *filename, connectionRecType *context){ FILE *dst; char *nakStr = "SET SAVE NAK"; if (rtapi_get_msg_level() == RTAPI_MSG_NONE) { /* must be -Q, don't print anything */ return 0; } if (*filename == '\0' ) dst = stdout; else { dst = fopen(filename, "w" ); if (dst == NULL) { sprintf(errorStr, "HAL:%d: Can't open 'save' destination '%s'", linenumber, filename); sockWriteError(nakStr, context); return -1; } } if (*type == '\0') type = "all"; if (strcmp(type, "all" ) == 0) { /* save everything */ save_comps(dst); save_signals(dst); save_links(dst, 0); save_params(dst); save_threads(dst); } else if (strcmp(type, "comp") == 0) save_comps(dst); else if (strcmp(type, "sig") == 0) save_signals(dst); else if (strcmp(type, "link") == 0) save_links(dst, 0); else if (strcmp(type, "linka") == 0) save_links(dst, 1); else if (strcmp(type, "net") == 0) save_nets(dst, 0); else if (strcmp(type, "neta") == 0) save_nets(dst, 1); else if (strcmp(type, "param") == 0) save_params(dst); else if (strcmp(type, "thread") == 0) save_threads(dst); else { sprintf(errorStr, "HAL:%d: Unknown 'save' type '%s'", linenumber, type); sockWriteError(nakStr, context); return -1; } if (*filename != '\0' ) fclose(dst); return 0;}static void save_comps(FILE *dst){ int next; hal_comp_t *comp; fprintf(dst, "# components\n"); rtapi_mutex_get(&(hal_data->mutex)); next = hal_data->comp_list_ptr; while (next != 0) { comp = SHMPTR(next); if ( comp->type == 1 ) { /* only print realtime components */ if ( comp->insmod_args == 0 ) { fprintf(dst, "#loadrt %s (not loaded by loadrt, no args saved)\n", comp->name); } else { fprintf(dst, "loadrt %s %s\n", comp->name, (char *)SHMPTR(comp->insmod_args)); } } next = comp->next_ptr; } rtapi_mutex_give(&(hal_data->mutex));}static void save_signals(FILE *dst){ int next; hal_sig_t *sig; fprintf(dst, "# signals\n"); rtapi_mutex_get(&(hal_data->mutex)); next = hal_data->sig_list_ptr; while (next != 0) { sig = SHMPTR(next); fprintf(dst, "newsig %s %s\n", sig->name, data_type((int) sig->type)); next = sig->next_ptr; } rtapi_mutex_give(&(hal_data->mutex));}static void save_links(FILE *dst, int arrow){ int next; hal_pin_t *pin; hal_sig_t *sig; char *arrow_str; fprintf(dst, "# links\n"); rtapi_mutex_get(&(hal_data->mutex)); next = hal_data->pin_list_ptr; while (next != 0) { pin = SHMPTR(next); if (pin->signal != 0) { sig = SHMPTR(pin->signal); if (arrow != 0) { arrow_str = data_arrow1((int) pin->dir); } else { arrow_str = "\0"; } fprintf(dst, "linkps %s %s %s\n", pin->name, arrow_str, sig->name); } next = pin->next_ptr; } rtapi_mutex_give(&(hal_data->mutex));}static void save_nets(FILE *dst, int arrow){ int next; hal_pin_t *pin; hal_sig_t *sig; char *arrow_str; fprintf(dst, "# nets\n"); rtapi_mutex_get(&(hal_data->mutex)); next = hal_data->sig_list_ptr; while (next != 0) { sig = SHMPTR(next); fprintf(dst, "newsig %s %s\n", sig->name, data_type((int) sig->type)); pin = halpr_find_pin_by_sig(sig, 0); while (pin != 0) { if (arrow != 0) { arrow_str = data_arrow2((int) pin->dir); } else { arrow_str = "\0"; } fprintf(dst, "linksp %s %s %s\n", sig->name, arrow_str, pin->name); pin = halpr_find_pin_by_sig(sig, pin); } next = sig->next_ptr; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -