📄 blocks.c
字号:
"BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "hypot.%d.in2", num); retval = hal_pin_float_new(buf, HAL_IN, &(h->in2), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export pin for output */ rtapi_snprintf(buf, HAL_NAME_LEN, "hypot.%d.out", num); retval = hal_pin_float_new(buf, HAL_OUT, &(h->out), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export function */ rtapi_snprintf(buf, HAL_NAME_LEN, "hypot.%d", num); retval = hal_export_funct(buf, hypot_funct, h, 1, 0, comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' funct export failed\n", buf); return -1; } /* restore saved message level */ rtapi_set_msg_level(msg); return 0;}static int export_mux2(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; mux2_t *mux2; /* This function exports a lot of stuff, which results in a lot of logging if msg_level is at INFO or ALL. So we save the current value of msg_level and restore it later. If you actually need to log this function's actions, change the second line below */ msg = rtapi_get_msg_level(); rtapi_set_msg_level(RTAPI_MSG_WARN); /* allocate shared memory for 2 input multiplexor */ mux2 = hal_malloc(sizeof(mux2_t)); if (mux2 == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: hal_malloc() failed\n"); return -1; } /* export pins for inputs */ rtapi_snprintf(buf, HAL_NAME_LEN, "mux2.%d.in0", num); retval = hal_pin_float_new(buf, HAL_IN, &(mux2->in0), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "mux2.%d.in1", num); retval = hal_pin_float_new(buf, HAL_IN, &(mux2->in1), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export pin for output */ rtapi_snprintf(buf, HAL_NAME_LEN, "mux2.%d.out", num); retval = hal_pin_float_new(buf, HAL_OUT, &(mux2->out), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export pin for select input */ rtapi_snprintf(buf, HAL_NAME_LEN, "mux2.%d.sel", num); retval = hal_pin_bit_new(buf, HAL_IN, &(mux2->sel), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export function */ rtapi_snprintf(buf, HAL_NAME_LEN, "mux2.%d", num); retval = hal_export_funct(buf, mux2_funct, mux2, 1, 0, comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' funct export failed\n", buf); return -1; } /* restore saved message level */ rtapi_set_msg_level(msg); return 0;}static int export_mux4(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; mux4_t *mux4; /* This function exports a lot of stuff, which results in a lot of logging if msg_level is at INFO or ALL. So we save the current value of msg_level and restore it later. If you actually need to log this function's actions, change the second line below */ msg = rtapi_get_msg_level(); rtapi_set_msg_level(RTAPI_MSG_WARN); /* allocate shared memory for 4 input multiplexor */ mux4 = hal_malloc(sizeof(mux4_t)); if (mux4 == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: hal_malloc() failed\n"); return -1; } /* export pins for inputs */ rtapi_snprintf(buf, HAL_NAME_LEN, "mux4.%d.in0", num); retval = hal_pin_float_new(buf, HAL_IN, &(mux4->in0), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "mux4.%d.in1", num); retval = hal_pin_float_new(buf, HAL_IN, &(mux4->in1), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "mux4.%d.in2", num); retval = hal_pin_float_new(buf, HAL_IN, &(mux4->in2), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "mux4.%d.in3", num); retval = hal_pin_float_new(buf, HAL_IN, &(mux4->in3), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export pin for output */ rtapi_snprintf(buf, HAL_NAME_LEN, "mux4.%d.out", num); retval = hal_pin_float_new(buf, HAL_OUT, &(mux4->out), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export pins for select input */ rtapi_snprintf(buf, HAL_NAME_LEN, "mux4.%d.sel0", num); retval = hal_pin_bit_new(buf, HAL_IN, &(mux4->sel0), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "mux4.%d.sel1", num); retval = hal_pin_bit_new(buf, HAL_IN, &(mux4->sel1), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export function */ rtapi_snprintf(buf, HAL_NAME_LEN, "mux4.%d", num); retval = hal_export_funct(buf, mux4_funct, mux4, 1, 0, comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' funct export failed\n", buf); return -1; } /* restore saved message level */ rtapi_set_msg_level(msg); return 0;}static int export_sum2(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; sum2_t *sum2; /* This function exports a lot of stuff, which results in a lot of logging if msg_level is at INFO or ALL. So we save the current value of msg_level and restore it later. If you actually need to log this function's actions, change the second line below */ msg = rtapi_get_msg_level(); rtapi_set_msg_level(RTAPI_MSG_WARN); /* allocate shared memory for 2-input summer */ sum2 = hal_malloc(sizeof(sum2_t)); if (sum2 == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: hal_malloc() failed\n"); return -1; } /* export pins for inputs */ rtapi_snprintf(buf, HAL_NAME_LEN, "sum2.%d.in0", num); retval = hal_pin_float_new(buf, HAL_IN, &(sum2->in0), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "sum2.%d.in1", num); retval = hal_pin_float_new(buf, HAL_IN, &(sum2->in1), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export pin for output */ rtapi_snprintf(buf, HAL_NAME_LEN, "sum2.%d.out", num); retval = hal_pin_float_new(buf, HAL_OUT, &(sum2->out), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export params for gains */ rtapi_snprintf(buf, HAL_NAME_LEN, "sum2.%d.gain0", num); retval = hal_param_float_new(buf, HAL_RW, &(sum2->gain0), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' param export failed\n", buf); return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "sum2.%d.gain1", num); retval = hal_param_float_new(buf, HAL_RW, &(sum2->gain1), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' param export failed\n", buf); return retval; } /* export function */ rtapi_snprintf(buf, HAL_NAME_LEN, "sum2.%d", num); retval = hal_export_funct(buf, sum2_funct, sum2, 1, 0, comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' funct export failed\n", buf); return -1; } /* set default parameter values */ sum2->gain0 = 1.0; sum2->gain1 = 1.0; /* restore saved message level */ rtapi_set_msg_level(msg); return 0;}static int export_mult2(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; mult2_t *mult2; /* This function exports a lot of stuff, which results in a lot of logging if msg_level is at INFO or ALL. So we save the current value of msg_level and restore it later. If you actually need to log this function's actions, change the second line below */ msg = rtapi_get_msg_level(); rtapi_set_msg_level(RTAPI_MSG_WARN); /* allocate shared memory for 2-input multiplier */ mult2 = hal_malloc(sizeof(mult2_t)); if (mult2 == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: hal_malloc() failed\n"); return -1; } /* export pins for inputs */ rtapi_snprintf(buf, HAL_NAME_LEN, "mult2.%d.in0", num); retval = hal_pin_float_new(buf, HAL_IN, &(mult2->in0), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } rtapi_snprintf(buf, HAL_NAME_LEN, "mult2.%d.in1", num); retval = hal_pin_float_new(buf, HAL_IN, &(mult2->in1), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export pin for output */ rtapi_snprintf(buf, HAL_NAME_LEN, "mult2.%d.out", num); retval = hal_pin_float_new(buf, HAL_OUT, &(mult2->out), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export function */ rtapi_snprintf(buf, HAL_NAME_LEN, "mult2.%d", num); retval = hal_export_funct(buf, mult2_funct, mult2, 1, 0, comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' funct export failed\n", buf); return -1; } /* restore saved message level */ rtapi_set_msg_level(msg); return 0;}static int export_integ(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; integ_t *integ; /* This function exports a lot of stuff, which results in a lot of logging if msg_level is at INFO or ALL. So we save the current value of msg_level and restore it later. If you actually need to log this function's actions, change the second line below */ msg = rtapi_get_msg_level(); rtapi_set_msg_level(RTAPI_MSG_WARN); /* allocate shared memory for integrator */ integ = hal_malloc(sizeof(integ_t)); if (integ == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: hal_malloc() failed\n"); return -1; } /* export pins for input */ rtapi_snprintf(buf, HAL_NAME_LEN, "integ.%d.in", num); retval = hal_pin_float_new(buf, HAL_IN, &(integ->in), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export pin for output */ rtapi_snprintf(buf, HAL_NAME_LEN, "integ.%d.out", num); retval = hal_pin_float_new(buf, HAL_OUT, &(integ->out), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export function */ rtapi_snprintf(buf, HAL_NAME_LEN, "integ.%d", num); retval = hal_export_funct(buf, integ_funct, integ, 1, 0, comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' funct export failed\n", buf); return -1; } /* restore saved message level */ rtapi_set_msg_level(msg); return 0;}static int export_ddt(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; ddt_t *ddt; /* This function exports a lot of stuff, which results in a lot of logging if msg_level is at INFO or ALL. So we save the current value of msg_level and restore it later. If you actually need to log this function's actions, change the second line below */ msg = rtapi_get_msg_level(); rtapi_set_msg_level(RTAPI_MSG_WARN); /* allocate shared memory for differentiator */ ddt = hal_malloc(sizeof(ddt_t)); if (ddt == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: hal_malloc() failed\n"); return -1; } /* export pins for input */ rtapi_snprintf(buf, HAL_NAME_LEN, "ddt.%d.in", num); retval = hal_pin_float_new(buf, HAL_IN, &(ddt->in), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export pin for output */ rtapi_snprintf(buf, HAL_NAME_LEN, "ddt.%d.out", num); retval = hal_pin_float_new(buf, HAL_OUT, &(ddt->out), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export function */ rtapi_snprintf(buf, HAL_NAME_LEN, "ddt.%d", num); retval = hal_export_funct(buf, ddt_funct, ddt, 1, 0, comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' funct export failed\n", buf); return -1; } /* restore saved message level */ rtapi_set_msg_level(msg); return 0;}static int export_limit1(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; limit1_t *limit1; /* This function exports a lot of stuff, which results in a lot of logging if msg_level is at INFO or ALL. So we save the current value of msg_level and restore it later. If you actually need to log this function's actions, change the second line below */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -