📄 blocks.c
字号:
return retval; } /* export pins for select input */ rtapi_snprintf(buf, HAL_NAME_LEN, "mux4.%d.sel0", num); retval = hal_pin_bit_new(buf, HAL_RD, &(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_RD, &(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_RD, &(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_RD, &(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_WR, &(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_WR, &(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_WR, &(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_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_RD, &(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_WR, &(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_RD, &(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_WR, &(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 */ msg = rtapi_get_msg_level(); rtapi_set_msg_level(RTAPI_MSG_WARN); /* allocate shared memory for first order limiter */ limit1 = hal_malloc(sizeof(limit1_t)); if (limit1 == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: hal_malloc() failed\n"); return -1; } /* export pin for input */ rtapi_snprintf(buf, HAL_NAME_LEN, "limit1.%d.in", num); retval = hal_pin_float_new(buf, HAL_RD, &(limit1->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, "limit1.%d.out", num); retval = hal_pin_float_new(buf, HAL_WR, &(limit1->out), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export params */ rtapi_snprintf(buf, HAL_NAME_LEN, "limit1.%d.min", num); retval = hal_param_float_new(buf, HAL_WR, &(limit1->min), 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, "limit1.%d.max", num); retval = hal_param_float_new(buf, HAL_WR, &(limit1->max), 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, "limit1.%d", num); retval = hal_export_funct(buf, limit1_funct, limit1, 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 */ limit1->min = -1e20; limit1->max = 1e20; /* restore saved message level */ rtapi_set_msg_level(msg); return 0;}static int export_limit2(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; limit2_t *limit2; /* 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 second order limiter */ limit2 = hal_malloc(sizeof(limit2_t)); if (limit2 == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: hal_malloc() failed\n"); return -1; } /* export pin for input */ rtapi_snprintf(buf, HAL_NAME_LEN, "limit2.%d.in", num); retval = hal_pin_float_new(buf, HAL_RD, &(limit2->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, "limit2.%d.out", num); retval = hal_pin_float_new(buf, HAL_WR, &(limit2->out), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export params */ rtapi_snprintf(buf, HAL_NAME_LEN, "limit2.%d.min", num); retval = hal_param_float_new(buf, HAL_WR, &(limit2->min), 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, "limit2.%d.max", num); retval = hal_param_float_new(buf, HAL_WR, &(limit2->max), 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, "limit2.%d.maxv", num); retval = hal_param_float_new(buf, HAL_WR, &(limit2->maxv), 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, "limit2.%d", num); retval = hal_export_funct(buf, limit2_funct, limit2, 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 */ limit2->min = -1e20; limit2->max = 1e20; limit2->maxv = 1e20; /* restore saved message level */ rtapi_set_msg_level(msg); return 0;}static int export_limit3(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; limit3_t *limit3; /* 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 third order limiter */ limit3 = hal_malloc(sizeof(limit3_t)); if (limit3 == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: hal_malloc() failed\n"); return -1; } /* export pin for input */ rtapi_snprintf(buf, HAL_NAME_LEN, "limit3.%d.in", num); retval = hal_pin_float_new(buf, HAL_RD, &(limit3->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, "limit3.%d.out", num); retval = hal_pin_float_new(buf, HAL_WR, &(limit3->out), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export params */ rtapi_snprintf(buf, HAL_NAME_LEN, "limit3.%d.min", num); retval = hal_param_float_new(buf, HAL_WR, &(limit3->min), 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, "limit3.%d.max", num); retval = hal_param_float_new(buf, HAL_WR, &(limit3->max), 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, "limit3.%d.maxv", num); retval = hal_param_float_new(buf, HAL_WR, &(limit3->maxv), 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, "limit3.%d.maxa", num); retval = hal_param_float_new(buf, HAL_WR, &(limit3->maxa), 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, "limit3.%d", num); retval = hal_export_funct(buf, limit3_funct, limit3, 1, 0, comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' funct export failed\n", buf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -