📄 blocks.c
字号:
return -1; } /* set default parameter values */ limit3->min = -1e20; limit3->max = 1e20; limit3->maxv = 1e20; limit3->maxa = 1e20; /* restore saved message level */ rtapi_set_msg_level(msg); return 0;}static int export_estop(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; estop_t *estop; /* 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 an estop latch */ estop = hal_malloc(sizeof(estop_t)); if (estop == 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, "estop.%d.ok-in", num); retval = hal_pin_bit_new(buf, HAL_RD, &(estop->ok_in), 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, "estop.%d.fault-in", num); retval = hal_pin_bit_new(buf, HAL_RD, &(estop->fault_in), 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, "estop.%d.reset", num); retval = hal_pin_bit_new(buf, HAL_RD, &(estop->reset), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export pins for outputs */ rtapi_snprintf(buf, HAL_NAME_LEN, "estop.%d.ok-out", num); retval = hal_pin_bit_new(buf, HAL_WR, &(estop->ok_out), 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, "estop.%d.fault-out", num); retval = hal_pin_bit_new(buf, HAL_WR, &(estop->fault_out), 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, "estop.%d.watchdog", num); retval = hal_pin_bit_new(buf, HAL_WR, &(estop->wd), 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, "estop.%d", num); retval = hal_export_funct(buf, estop_funct, estop, 0, 0, comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' funct export failed\n", buf); return -1; } /* initialize internal vars */ estop->old_reset = 1; /* restore saved message level */ rtapi_set_msg_level(msg); return 0;}static int export_not(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; not_t *not; /* 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 1-input logical not */ not = hal_malloc(sizeof(not_t)); if (not == 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, "not.%d.in", num); retval = hal_pin_bit_new(buf, HAL_RD, &(not->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, "not.%d.out", num); retval = hal_pin_bit_new(buf, HAL_WR, &(not->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, "not.%d", num); retval = hal_export_funct(buf, not_funct, not, 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_and2(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; and2_t *and2; /* 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 logical and */ and2 = hal_malloc(sizeof(and2_t)); if (and2 == 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, "and2.%d.in0", num); retval = hal_pin_bit_new(buf, HAL_RD, &(and2->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, "and2.%d.in1", num); retval = hal_pin_bit_new(buf, HAL_RD, &(and2->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, "and2.%d.out", num); retval = hal_pin_bit_new(buf, HAL_WR, &(and2->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, "and2.%d", num); retval = hal_export_funct(buf, and2_funct, and2, 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_or2(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; or2_t *or2; /* 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 logical or */ or2 = hal_malloc(sizeof(or2_t)); if (or2 == 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, "or2.%d.in0", num); retval = hal_pin_bit_new(buf, HAL_RD, &(or2->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, "or2.%d.in1", num); retval = hal_pin_bit_new(buf, HAL_RD, &(or2->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, "or2.%d.out", num); retval = hal_pin_bit_new(buf, HAL_WR, &(or2->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, "or2.%d", num); retval = hal_export_funct(buf, or2_funct, or2, 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_scale(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; scale_t *scale; /* 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 scaler */ scale = hal_malloc(sizeof(scale_t)); if (scale == 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, "scale.%d.in", num); retval = hal_pin_float_new(buf, HAL_RD, &(scale->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, "scale.%d.out", num); retval = hal_pin_float_new(buf, HAL_WR, &(scale->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, "scale.%d.gain", num); retval = hal_param_float_new(buf, HAL_WR, &(scale->gain), 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, "scale.%d.offset", num); retval = hal_param_float_new(buf, HAL_WR, &(scale->offset), 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, "scale.%d", num); retval = hal_export_funct(buf, scale_funct, scale, 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 */ scale->gain = 1.0; scale->offset = 0.0; /* restore saved message level */ rtapi_set_msg_level(msg); return 0;}static int export_lowpass(int num){ int retval, msg; char buf[HAL_NAME_LEN + 2]; lowpass_t *lowpass; /* 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 lowpass filter */ lowpass = hal_malloc(sizeof(lowpass_t)); if (lowpass == 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, "lowpass.%d.in", num); retval = hal_pin_float_new(buf, HAL_RD, &(lowpass->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, "lowpass.%d.out", num); retval = hal_pin_float_new(buf, HAL_WR, &(lowpass->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, "lowpass.%d.gain", num); retval = hal_param_float_new(buf, HAL_WR, &(lowpass->gain), 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, "lowpass.%d", num); retval = hal_export_funct(buf, lowpass_funct, lowpass, 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 */ lowpass->gain = 1.0; /* restore saved message level */ rtapi_set_msg_level(msg); return 0;}static int export_match8(int num){ int retval, msg, n; char buf[HAL_NAME_LEN + 2]; match8_t *match8; /* 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 match detector filter */ match8 = hal_malloc(sizeof(match8_t)); if (match8 == 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: hal_malloc() failed\n"); return -1; } /* export pin for cascade/enable input */ rtapi_snprintf(buf, HAL_NAME_LEN, "match8.%d.in", num); retval = hal_pin_bit_new(buf, HAL_RD, &(match8->in), comp_id); if (retval != 0) { rtapi_print_msg(RTAPI_MSG_ERR, "BLOCKS: ERROR: '%s' pin export failed\n", buf); return retval; } /* export pins for A and B inputs */ for ( n = 0 ; n < 8 ; n++ ) { rtapi_snprintf(buf, HAL_NAME_LEN, "match8.%d.a%1d", num, n); retval
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -