Skip to content

Commit 4cd038d

Browse files
author
daniel
committed
eliminate unneeded rtapi_snprintf(); use new hal_export_functf()
1 parent a0b0bba commit 4cd038d

22 files changed

+66
-148
lines changed

src/hal/components/debounce.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ static void debounce(void *arg, long period)
229229
static int export_group(int num, debounce_group_t * addr, int group_size)
230230
{
231231
int n, retval, msg;
232-
char buf[HAL_NAME_LEN + 1];
233232

234233
/* This function exports a lot of stuff, which results in a lot of
235234
logging if msg_level is at INFO or ALL. So we save the current value
@@ -246,19 +245,17 @@ static int export_group(int num, debounce_group_t * addr, int group_size)
246245
return -1;
247246
}
248247
/* export param variable for delay */
249-
rtapi_snprintf(buf, sizeof(buf), "debounce.%d.delay", num);
250-
retval = hal_param_s32_new(buf, HAL_RW, &(addr->delay), comp_id);
248+
retval = hal_param_s32_newf(HAL_RW, &(addr->delay), comp_id, "debounce.%d.delay", num);
251249
if (retval != 0) {
252250
rtapi_print_msg(RTAPI_MSG_ERR,
253-
"DEBOUNCE: ERROR: '%s' param export failed\n", buf);
251+
"DEBOUNCE: ERROR: 'debounce.%d.delay' param export failed\n", num);
254252
return retval;
255253
}
256254
/* export function */
257-
rtapi_snprintf(buf, sizeof(buf), "debounce.%d", num);
258-
retval = hal_export_funct(buf, debounce, addr, 0, 0, comp_id);
255+
retval = hal_export_functf(debounce, addr, 0, 0, comp_id, "debounce.%d", num);
259256
if (retval != 0) {
260257
rtapi_print_msg(RTAPI_MSG_ERR,
261-
"DEBOUNCE: ERROR: '%s' funct export failed\n", buf);
258+
"DEBOUNCE: ERROR: 'debounce.%d' funct export failed\n", num);
262259
return -1;
263260
}
264261
/* set default parameter values */

src/hal/components/mux_generic.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,8 @@ int rtapi_app_main(void){
168168
inst->out_type = inst->in_type;
169169
}
170170

171-
retval = rtapi_snprintf(hal_name, HAL_NAME_LEN, "mux-gen.%02i", i);
172-
if (retval >= HAL_NAME_LEN) {
173-
goto fail0;
174-
}
175171
if (inst->in_type == HAL_FLOAT || inst->out_type == HAL_FLOAT) {
176-
retval = hal_export_funct(hal_name, write_fp, inst, 1, 0, comp_id);
172+
retval = hal_export_functf(write_fp, inst, 1, 0, comp_id, "mux-gen.%02i", i);
177173
if (retval < 0) {
178174
rtapi_print_msg(RTAPI_MSG_ERR, "mux_generic: ERROR: function export"
179175
" failed\n");
@@ -182,7 +178,7 @@ int rtapi_app_main(void){
182178
}
183179
else
184180
{
185-
retval = hal_export_funct(hal_name, write_nofp, inst, 0, 0, comp_id);
181+
retval = hal_export_functf(write_nofp, inst, 0, 0, comp_id, "mux-gen.%02i", i);
186182
if (retval < 0) {
187183
rtapi_print_msg(RTAPI_MSG_ERR, "mux_generic: ERROR: function export"
188184
" failed\n");

src/hal/components/pid.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,6 @@ static void calc_pid(void *arg, long period)
689689
static int export_pid(hal_pid_t * addr, char * prefix)
690690
{
691691
int retval, msg;
692-
char buf[HAL_NAME_LEN + 1];
693692

694693
/* This function exports a lot of stuff, which results in a lot of
695694
logging if msg_level is at INFO or ALL. So we save the current value
@@ -963,9 +962,8 @@ static int export_pid(hal_pid_t * addr, char * prefix)
963962
*(addr->pTuneStart) = 0;
964963
#endif /* AUTO_TUNER */
965964
/* export function for this loop */
966-
rtapi_snprintf(buf, sizeof(buf), "%s.do-pid-calcs", prefix);
967965
retval =
968-
hal_export_funct(buf, calc_pid, addr, 1, 0, comp_id);
966+
hal_export_functf(calc_pid, addr, 1, 0, comp_id, "%s.do-pid-calcs", prefix);
969967
if (retval != 0) {
970968
rtapi_print_msg(RTAPI_MSG_ERR,
971969
NAME ": ERROR: do_pid_calcs funct export failed\n");

src/hal/components/sampler.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ static int init_sampler(int num, sampler_t *str)
289289
pptr++;
290290
}
291291
/* export update function */
292-
rtapi_snprintf(buf, sizeof(buf), "sampler.%d", num);
293-
retval = hal_export_funct(buf, sample, str, usefp, 0, comp_id);
292+
retval = hal_export_functf(sample, str, usefp, 0, comp_id, "sampler.%d", num);
294293
if (retval != 0) {
295294
rtapi_print_msg(RTAPI_MSG_ERR,
296295
"SAMPLER: ERROR: function export failed\n");

src/hal/components/siggen.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ static void calc_siggen(void *arg, long period)
277277
static int export_siggen(int num, hal_siggen_t * addr,char* prefix)
278278
{
279279
int retval;
280-
char buf[HAL_NAME_LEN + 1];
281280

282281
/* export pins */
283282
retval = hal_pin_float_newf(HAL_OUT, &(addr->square), comp_id,
@@ -342,10 +341,9 @@ static int export_siggen(int num, hal_siggen_t * addr,char* prefix)
342341
*(addr->offset) = 0.0;
343342
addr->index = 0.0;
344343
/* export function for this loop */
345-
rtapi_snprintf(buf, sizeof(buf), "%s.update", prefix);
346344
retval =
347-
hal_export_funct(buf, calc_siggen, &(siggen_array[num]), 1, 0,
348-
comp_id);
345+
hal_export_functf(calc_siggen, &(siggen_array[num]), 1, 0,
346+
comp_id, "%s.update", prefix);
349347
if (retval != 0) {
350348
rtapi_print_msg(RTAPI_MSG_ERR,
351349
"SIGGEN: ERROR: update funct export failed\n");

src/hal/components/streamer.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,7 @@ static int init_streamer(int num, streamer_t *str)
346346
pptr++;
347347
}
348348
/* export update function */
349-
rtapi_snprintf(buf, sizeof(buf), "streamer.%d", num);
350-
retval = hal_export_funct(buf, update, str, usefp, 0, comp_id);
349+
retval = hal_export_functf(update, str, usefp, 0, comp_id, "streamer.%d", num);
351350
if (retval != 0) {
352351
rtapi_print_msg(RTAPI_MSG_ERR,
353352
"STREAMER: ERROR: function export failed\n");

src/hal/components/supply.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ static void update_supply(void *arg, long l)
159159
static int export_supply(int num, hal_supply_t * addr)
160160
{
161161
int retval;
162-
char buf[HAL_NAME_LEN + 1];
163162

164163
/* export pins */
165164
retval = hal_pin_bit_newf(HAL_OUT, &(addr->q), comp_id, "supply.%d.q", num);
@@ -195,10 +194,9 @@ static int export_supply(int num, hal_supply_t * addr)
195194
*(addr->d) = 0;
196195
*(addr->value) = 0.0;
197196
/* export function for this loop */
198-
rtapi_snprintf(buf, sizeof(buf), "supply.%d.update", num);
199197
retval =
200-
hal_export_funct(buf, update_supply, &(supply_array[num]), 1, 0,
201-
comp_id);
198+
hal_export_functf(update_supply, &(supply_array[num]), 1, 0,
199+
comp_id, "supply.%d.update", num);
202200
if (retval != 0) {
203201
rtapi_print_msg(RTAPI_MSG_ERR,
204202
"SUPPLY: ERROR: update funct export failed\n");

src/hal/drivers/hal_ax5214h.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ int rtapi_app_main(void)
191191
{
192192
char *cp;
193193
char *argv[MAX_TOK];
194-
char name[HAL_NAME_LEN + 1];
195194
int n, retval;
196195

197196
/* test for config string */
@@ -235,22 +234,18 @@ int rtapi_app_main(void)
235234
}
236235
/* export functions for each board */
237236
for (n = 0; n < num_boards; n++) {
238-
/* make read function name */
239-
rtapi_snprintf(name, sizeof(name), "ax5214h.%d.read", n);
240237
/* export read function */
241-
retval = hal_export_funct(name, read_board, &(board_array[n]),
242-
0, 0, comp_id);
238+
retval = hal_export_functf(read_board, &(board_array[n]),
239+
0, 0, comp_id, "ax5214h.%d.read", n);
243240
if (retval != 0) {
244241
rtapi_print_msg(RTAPI_MSG_ERR,
245242
"AX5214H: ERROR: port %d read funct export failed\n", n);
246243
hal_exit(comp_id);
247244
return -1;
248245
}
249-
/* make write function name */
250-
rtapi_snprintf(name, sizeof(name), "ax5214h.%d.write", n);
251246
/* export write function */
252-
retval = hal_export_funct(name, write_board, &(board_array[n]),
253-
0, 0, comp_id);
247+
retval = hal_export_functf(write_board, &(board_array[n]),
248+
0, 0, comp_id, "ax5214h.%d.write", n);
254249
if (retval != 0) {
255250
rtapi_print_msg(RTAPI_MSG_ERR,
256251
"AX5214H: ERROR: port %d write funct export failed\n", n);

src/hal/drivers/hal_bb_gpio.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ int configure_gpio_port(int n) {
126126
}
127127

128128
int rtapi_app_main(void) {
129-
char name[HAL_NAME_LEN + 1];
130129
int n, retval;
131130
char *data, *token;
132131

@@ -359,16 +358,14 @@ int rtapi_app_main(void) {
359358

360359

361360
// export functions
362-
rtapi_snprintf(name, sizeof(name), "bb_gpio.write");
363-
retval = hal_export_funct(name, write_port, port_data, 0, 0, comp_id);
361+
retval = hal_export_funct("bb_gpio.write", write_port, port_data, 0, 0, comp_id);
364362
if(retval < 0) {
365363
rtapi_print_msg(RTAPI_MSG_ERR, "%s: ERROR: port %d write funct export failed\n", modname, n);
366364
hal_exit(comp_id);
367365
return -1;
368366
}
369367

370-
rtapi_snprintf(name, sizeof(name), "bb_gpio.read");
371-
retval = hal_export_funct(name, read_port, port_data, 0, 0, comp_id);
368+
retval = hal_export_funct("bb_gpio.read", read_port, port_data, 0, 0, comp_id);
372369
if(retval < 0) {
373370
rtapi_print_msg(RTAPI_MSG_ERR, "%s: ERROR: port %d read funct export failed\n", modname, n);
374371
hal_exit(comp_id);

src/hal/drivers/hal_evoreg.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ static void update_port(void *arg, long period);
134134

135135
int rtapi_app_main(void)
136136
{
137-
char name[HAL_NAME_LEN + 1];
138137
int n,i , retval, num_dac, num_enc;
139138

140139
unsigned int base=0x300;
@@ -255,9 +254,8 @@ int rtapi_app_main(void)
255254

256255

257256
/* STEP 4: export function */
258-
rtapi_snprintf(name, sizeof(name), "evoreg.%d.update", n + 1);
259-
retval = hal_export_funct(name, update_port, &(port_data_array[n]), 1, 0,
260-
comp_id);
257+
retval = hal_export_functf(update_port, &(port_data_array[n]), 1, 0,
258+
comp_id, "evoreg.%d.update", n + 1);
261259
if (retval < 0) {
262260
rtapi_print_msg(RTAPI_MSG_ERR,
263261
"EVOREG: ERROR: port %d write funct export failed\n", n + 1);

0 commit comments

Comments
 (0)