Skip to content

Commit 2c32f7e

Browse files
authored
Merge pull request #2774 from heeplr/hal_export_functf
introduce hal_export_functf()
2 parents cac8b1b + 4cd038d commit 2c32f7e

28 files changed

+127
-173
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.so man3/hal_export_funct.3hal

docs/po4a.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@
264264
[type: man_def] man/man3/hal_del_funct_from_thread.3hal $lang:man/$lang/man3/hal_del_funct_from_thread.3hal
265265
[type: man_def] man/man3/hal_exit.3hal $lang:man/$lang/man3/hal_exit.3hal
266266
[type: man_def] man/man3/hal_export_funct.3hal $lang:man/$lang/man3/hal_export_funct.3hal
267+
[type: man_def] man/man3/hal_export_functf.3hal $lang:man/$lang/man3/hal_export_functf.3hal
267268
[type: man_def] man/man3/hal_float_t.3hal $lang:man/$lang/man3/hal_float_t.3hal
268269
[type: man_def] man/man3/hal_get_lock.3hal $lang:man/$lang/man3/hal_get_lock.3hal
269270
[type: man_def] man/man3/hal_init.3hal $lang:man/$lang/man3/hal_init.3hal

docs/src/hal/components.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ hal_create_thread.3hal
339339
hal_del_funct_from_thread.3hal
340340
hal_exit.3hal
341341
hal_export_funct.3hal
342+
hal_export_functf.3hal
342343
hal_float_t.3hal
343344
hal_get_lock.3hal
344345
hal_init.3hal

src/hal/components/boss_plc.c

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ typedef struct {
201201
hal_bit_t limitNeg;
202202
} Limit;
203203

204-
static int Limit_Export(Limit *this, int compId, int id, char *name, char axis);
204+
static int Limit_Export(Limit *this, int compId, int id, char axis);
205205
static void Limit_Init(Limit *this);
206206
static BOOL Limit_IsActive(Limit *this);
207207
static void Limit_Refresh(Limit *this, hal_bit_t override);
@@ -225,7 +225,7 @@ typedef struct {
225225
hal_bit_t lastEnable;
226226
} Amp;
227227

228-
static int Amp_Export(Amp *this, int compId, int id, char *name, char axis);
228+
static int Amp_Export(Amp *this, int compId, int id, char axis);
229229
static void Amp_Init(Amp *this);
230230
static void Amp_Refresh(Amp *this, long period, hal_u32_t readyDelay);
231231

@@ -313,11 +313,11 @@ typedef struct {
313313
// These methods are used for initialization.
314314
static int Plc_Init(Plc *this);
315315
static int Plc_Export(Plc *this, int compId, int id);
316-
static int Plc_ExportFeed(Plc *this, int compId, int id, char *name);
317-
static int Plc_ExportLimits(Plc *this, int compId, int id, char *name);
318-
static int Plc_ExportAmps(Plc *this, int compId, int id, char *name);
319-
static int Plc_ExportSpindle(Plc *this, int compId, int id, char *name);
320-
static int Plc_ExportJog(Plc *this, int compId, int id, char *name);
316+
static int Plc_ExportFeed(Plc *this, int compId, int id);
317+
static int Plc_ExportLimits(Plc *this, int compId, int id);
318+
static int Plc_ExportAmps(Plc *this, int compId, int id);
319+
static int Plc_ExportSpindle(Plc *this, int compId, int id);
320+
static int Plc_ExportJog(Plc *this, int compId, int id);
321321

322322
// These methods are exported to the HAL.
323323
static void Plc_Refresh(void *this, long period);
@@ -468,7 +468,6 @@ static int
468468
Plc_Export(Plc *this, int compId, int id)
469469
{
470470
int msgLevel, error;
471-
char name[HAL_NAME_LEN + 1];
472471

473472
// This function exports a lot of stuff, which results in a lot of
474473
// logging if msg_level is at INFO or ALL. So we save the current value
@@ -478,27 +477,26 @@ Plc_Export(Plc *this, int compId, int id)
478477
rtapi_set_msg_level(RTAPI_MSG_WARN);
479478

480479
// Export pins and parameters.
481-
error = Plc_ExportFeed(this, compId, id, name);
480+
error = Plc_ExportFeed(this, compId, id);
482481

483482
if(!error){
484-
error = Plc_ExportLimits(this, compId, id, name);
483+
error = Plc_ExportLimits(this, compId, id);
485484
}
486485

487486
if(!error){
488-
error = Plc_ExportAmps(this, compId, id, name);
487+
error = Plc_ExportAmps(this, compId, id);
489488
}
490489

491490
if(!error){
492-
error = Plc_ExportSpindle(this, compId, id, name);
491+
error = Plc_ExportSpindle(this, compId, id);
493492
}
494493
if(!error){
495-
error = Plc_ExportJog(this, compId, id, name);
494+
error = Plc_ExportJog(this, compId, id);
496495
}
497496

498497
// Export functions.
499498
if(!error){
500-
rtapi_snprintf(name, sizeof(name), "boss_plc.%d.refresh", id);
501-
error = hal_export_funct(name, Plc_Refresh, this, 1, 0, compId);
499+
error = hal_export_functf(Plc_Refresh, this, 1, 0, compId, "boss_plc.%d.refresh", id);
502500
}
503501

504502
// Restore saved message level.
@@ -509,7 +507,7 @@ Plc_Export(Plc *this, int compId, int id)
509507

510508

511509
static int
512-
Plc_ExportFeed(Plc *this, int compId, int id, char *name)
510+
Plc_ExportFeed(Plc *this, int compId, int id)
513511
{
514512
int error;
515513

@@ -578,7 +576,7 @@ Plc_ExportFeed(Plc *this, int compId, int id, char *name)
578576

579577

580578
static int
581-
Plc_ExportLimits(Plc *this, int compId, int id, char *name)
579+
Plc_ExportLimits(Plc *this, int compId, int id)
582580
{
583581
int error;
584582

@@ -592,11 +590,11 @@ Plc_ExportLimits(Plc *this, int compId, int id, char *name)
592590
}
593591

594592
if(!error){
595-
error = Limit_Export(&this->xLimit, compId, id, name, axisNames[0]);
593+
error = Limit_Export(&this->xLimit, compId, id, axisNames[0]);
596594
}
597595

598596
if(!error){
599-
error = Limit_Export(&this->yLimit, compId, id, name, axisNames[1]);
597+
error = Limit_Export(&this->yLimit, compId, id, axisNames[1]);
600598
}
601599

602600
if(!error){
@@ -642,7 +640,7 @@ Plc_ExportLimits(Plc *this, int compId, int id, char *name)
642640

643641

644642
static int
645-
Plc_ExportAmps(Plc *this, int compId, int id, char *name)
643+
Plc_ExportAmps(Plc *this, int compId, int id)
646644
{
647645
int error, i;
648646
Amp *pAmp;
@@ -652,15 +650,15 @@ Plc_ExportAmps(Plc *this, int compId, int id, char *name)
652650

653651
pAmp = this->amps;
654652
for(i = 0; i < NUM_AXIS && !error; i++, pAmp++){
655-
error = Amp_Export(pAmp, compId, id, name, axisNames[i]);
653+
error = Amp_Export(pAmp, compId, id, axisNames[i]);
656654
}
657655

658656
return(error);
659657
}
660658

661659

662660
static int
663-
Plc_ExportSpindle(Plc *this, int compId, int id, char *name)
661+
Plc_ExportSpindle(Plc *this, int compId, int id)
664662
{
665663
int error;
666664

@@ -742,7 +740,7 @@ Plc_ExportSpindle(Plc *this, int compId, int id, char *name)
742740

743741

744742
static int
745-
Plc_ExportJog(Plc *this, int compId, int id, char *name)
743+
Plc_ExportJog(Plc *this, int compId, int id)
746744
{
747745
int error, i;
748746

@@ -969,7 +967,7 @@ Plc_RefreshJog(Plc *this, long period)
969967
******************************************************************************/
970968

971969
static int
972-
Limit_Export(Limit *this, int compId, int id, char *name, char axis)
970+
Limit_Export(Limit *this, int compId, int id, char axis)
973971
{
974972
int error;
975973

@@ -1084,7 +1082,7 @@ Limit_Refresh(Limit *this, hal_bit_t override)
10841082
******************************************************************************/
10851083

10861084
static int
1087-
Amp_Export(Amp *this, int compId, int id, char *name, char axis)
1085+
Amp_Export(Amp *this, int compId, int id, char axis)
10881086
{
10891087
int error;
10901088

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");

0 commit comments

Comments
 (0)