📄 halcmd_commands.c
字号:
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 12 character wide 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_s32_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;}int do_save_cmd(char *type, char *filename){ FILE *dst; if (rtapi_get_msg_level() == RTAPI_MSG_NONE) { /* must be -Q, don't print anything */ return 0; } if (filename == NULL || *filename == '\0' ) { dst = stdout; } else { dst = fopen(filename, "w" ); if ( dst == NULL ) { halcmd_error("Can't open 'save' destination '%s'\n", filename); return -1; } } if (type == 0 || *type == '\0') { type = "all"; } if (strcmp(type, "all" ) == 0) { /* save everything */ save_comps(dst); save_signals(dst, 1); save_nets(dst, 3); save_params(dst); save_threads(dst); } else if (strcmp(type, "comp") == 0) { save_comps(dst); } else if (strcmp(type, "sig") == 0) { save_signals(dst, 0); } else if (strcmp(type, "sigu") == 0) { save_signals(dst, 1); } 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, "netl") == 0) { save_nets(dst, 2); } else if (strcmp(type, "netla") == 0 || strcmp(type, "netal") == 0) { save_nets(dst, 3); } else if (strcmp(type, "param") == 0) { save_params(dst); } else if (strcmp(type, "thread") == 0) { save_threads(dst); } else { halcmd_error("Unknown 'save' type '%s'\n", type); return -1; } if (dst != stdout) { 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; } next = hal_data->comp_list_ptr;#if 0 /* newinst deferred to version 2.2 */ while (next != 0) { comp = SHMPTR(next); if ( comp->type == 2 ) { hal_comp_t *comp1 = halpr_find_comp_by_id(comp->comp_id & 0xffff); fprintf(dst, "newinst %s %s\n", comp1->name, comp->name); } next = comp->next_ptr; }#endif rtapi_mutex_give(&(hal_data->mutex));}static void save_signals(FILE *dst, int only_unlinked){ int next; hal_sig_t *sig; fprintf(dst, "# signals\n"); rtapi_mutex_get(&(hal_data->mutex)); for( next = hal_data->sig_list_ptr; next; next = sig->next_ptr) { sig = SHMPTR(next); if(only_unlinked && (sig->readers || sig->writers)) continue; fprintf(dst, "newsig %s %s\n", sig->name, data_type((int) sig->type)); } 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)); for (next = hal_data->sig_list_ptr; next != 0; next = sig->next_ptr) { sig = SHMPTR(next); if(arrow == 3) { int state = 0, first = 1; /* If there are no pins connected to this signal, do nothing */ pin = halpr_find_pin_by_sig(sig, 0); if(!pin) continue; fprintf(dst, "net %s", sig->name); /* Step 1: Output pin, if any */ for(pin = halpr_find_pin_by_sig(sig, 0); pin; pin = halpr_find_pin_by_sig(sig, pin)) { if(pin->dir != HAL_OUT) continue; fprintf(dst, " %s", pin->name); state = 1; } /* Step 2: I/O pins, if any */ for(pin = halpr_find_pin_by_sig(sig, 0); pin; pin = halpr_find_pin_by_sig(sig, pin)) { if(pin->dir != HAL_IO) continue; fprintf(dst, " "); if(state) { fprintf(dst, "=> "); state = 0; } else if(!first) { fprintf(dst, "<=> "); } fprintf(dst, "%s", pin->name); first = 0; } if(!first) state = 1; /* Step 3: Input pins, if any */ for(pin = halpr_find_pin_by_sig(sig, 0); pin; pin = halpr_find_pin_by_sig(sig, pin)) { if(pin->dir != HAL_IN) continue; fprintf(dst, " "); if(state) { fprintf(dst, "=> "); state = 0; } fprintf(dst, "%s", pin->name); } fprintf(dst, "\n"); } else if(arrow == 2) { /* If there are no pins connected to this signal, do nothing */ pin = halpr_find_pin_by_sig(sig, 0); if(!pin) continue; fprintf(dst, "net %s", sig->name); pin = halpr_find_pin_by_sig(sig, 0); while (pin != 0) { fprintf(dst, " %s", pin->name); pin = halpr_find_pin_by_sig(sig, pin); } fprintf(dst, "\n"); } else { 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); } } } 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));}int do_setexact_cmd() { int retval = HAL_SUCCESS; rtapi_mutex_get(&(hal_data->mutex)); if(hal_data->base_period) { halcmd_error( "HAL_LIB: Cannot run 'setexact'" " after a thread has been created\n"); retval = HAL_FAIL; } else { halcmd_warning( "HAL_LIB: HAL will pretend that the exact" " base period requested is possible.\n" "This mode is not suitable for running real hardware."); hal_data->exact_base_period = 1; } rtapi_mutex_give(&(hal_data->mutex)); return retval;}int do_help_cmd(char *command){ if (!command) { print_help_commands(); } else 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");#if 0 /* newinst deferred to version 2.2 */ } else if (strcmp(command, "newinst") == 0) { printf("newinst modname instname\n"); printf(" Creates another instance of previously loaded module\n" ); printf(" 'modname', nameing it 'instname'.\n");#endif } else if (strcmp(command, "unload")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -