(SOLVED - maybe) How to get an underscore in a pin/parameter name?

More
14 Jun 2018 18:55 #112370 by Sparky961
Looking back, I grabbed the wrong link. Here's the one where I preprocess, modify, them compile:

forum.linuxcnc.org/24-hal-components/347...?limitstart=0#112343
More
14 Jun 2018 22:29 #112380 by AnnoyingMutt

Sparky961 wrote:

ozzyrob wrote: I'd be putting my wager on the coder doing something wrong rather than the compiler doing something wrong

...

Just cos a underscore can be used does not necessarily mean it should.


Not at all helpful.


Yes you are right in that context probably not....but you did decide to leave out this bit as to why it might be an error on the coder's part.

ozzyrob wrote: Make sure that all the component names in the file match the source file name...I got the same behavior when I copied the supply.c src to supply_2.c and didn't change any reference to supply to supply_2.

More
14 Jun 2018 23:44 #112384 by Sparky961

ozzyrob wrote: Yes you are right in that context probably not....but you did decide to leave out this bit as to why it might be an error on the coder's part.


I left it out because a few posts later my course changed and I'm not trying to compile an existing file with changed names anymore.

Keep up mate, you're getting left behind. As confusing as it may be to those who might be gracious enough to help me, I can't possibly wait helplessly for people to respond. I have to keep trying things and move forward.

As to the argument of whether or not to use an underscore, it isn't my choice. The existing component I'm trying to make a "dummy" of has names with underscores.

The present issue, also mentioned previously in this thread, is that I can't seem to get a working component through the two-step process of using halcompile to preprocess the *.comp file, then 'halcompile --install' the generated C file after changing only one character in the file - the dash to an underscore.

I'll be investigating that one after I submit this. That, or I might do something more useful since this was supposed to be yet another "quick side project".
More
15 Jun 2018 00:00 #112385 by Sparky961
So here's a thought:

Are there different versions of components, halcompile, and whatever else needed to build components for 'uspace' or for the rt-preempt kernel I installed? If so, how to I verify what I have and correct any mismatch?
More
15 Jun 2018 00:22 - 15 Jun 2018 02:23 #112386 by Sparky961
For the sake of completeness, I'll summarize the current issue.

I make a file, 'and5.comp' that's in the component generator language:
component and5 "Five-input AND gate";

pin in bit in0;
pin in bit in1;
pin in bit in2;
pin in bit in3;
pin in bit in4;
pin out bit out;

function _ nofp;

license "GPL";
;;
FUNCTION(_) { out = in0 && in1 && in2 && in3 && in4; }

Then I run the following:
linuxcnc@debian:/usr/src/linuxcnc-dev/src/hal/components$ sudo halcompile --install and5.comp
[sudo] password for linuxcnc: 
Compiling realtime and5.c
Linking and5.so
cp and5.so /usr/lib/linuxcnc/modules/

Ok, all seems well. Then I try to load it in HAL:
linuxcnc@debian:/usr/src/linuxcnc-dev/src/hal/components$ halrun
halcmd: loadrt and5
Note: Using POSIX realtime
halcmd: show
Loaded HAL Components:
ID      Type  Name                                            PID   State
     6  RT    and5                                                  ready
     4  User  halcmd3948                                       3948 ready

Component Pins:
Owner   Type  Dir         Value  Name
     6  bit   IN          FALSE  and5.0.in0
     6  bit   IN          FALSE  and5.0.in1
     6  bit   IN          FALSE  and5.0.in2
     6  bit   IN          FALSE  and5.0.in3
     6  bit   IN          FALSE  and5.0.in4
     6  bit   OUT         FALSE  and5.0.out
     6  s32   OUT             0  and5.0.time
<snip>

...ok, this also seems to be working fine.

Now when I try to do it in two steps:
component hm2_7i76e "Fake pins from 7i76e for testing without attached hardware";
param r s32 watchdog.timeout_ns = 5000000;
pin out bit out0;
pin in bit in0;
function _;
license "GPL";
;;
FUNCTION(_) {
}

Then only preprocess:
linuxcnc@debian:/usr/src/linuxcnc-dev/src/hal/components$ sudo halcompile --preprocess hm2_7i76e.comp

Results in hm2_7i76e.c being created as below:
/* Autogenerated by /usr/bin/halcompile on Thu Jun 14 20:12:52 2018 -- do not edit */
#include "rtapi.h"
#ifdef RTAPI
#include "rtapi_app.h"
#endif
#include "rtapi_string.h"
#include "rtapi_errno.h"
#include "hal.h"
#include "rtapi_math64.h"

static int comp_id;

#ifdef MODULE_INFO
MODULE_INFO(linuxcnc, "component:hm2_7i76e:Fake pins from 7i76e for testing without attached hardware");
MODULE_INFO(linuxcnc, "param:watchdog.timeout_ns:s32:0:r::5000000:None");
MODULE_INFO(linuxcnc, "pin:out0:bit:0:out::None:None");
MODULE_INFO(linuxcnc, "pin:in0:bit:0:in::None:None");
MODULE_INFO(linuxcnc, "funct:_:1:");
MODULE_INFO(linuxcnc, "license:GPL");
MODULE_LICENSE("GPL");
#endif // MODULE_INFO


struct __comp_state {
    struct __comp_state *_next;
    hal_bit_t *out0;
    hal_bit_t *in0;
    hal_s32_t watchdog_timeout_ns;
};
struct __comp_state *__comp_first_inst=0, *__comp_last_inst=0;

static void _(struct __comp_state *__comp_inst, long period);
static int __comp_get_data_size(void);
#undef TRUE
#define TRUE (1)
#undef FALSE
#define FALSE (0)
#undef true
#define true (1)
#undef false
#define false (0)

static int export(char *prefix, long extra_arg) {
    char buf[HAL_NAME_LEN + 1];
    int r = 0;
    int sz = sizeof(struct __comp_state) + __comp_get_data_size();
    struct __comp_state *inst = hal_malloc(sz);
    memset(inst, 0, sz);
    r = hal_pin_bit_newf(HAL_OUT, &(inst->out0), comp_id,
        "%s.out0", prefix);
    if(r != 0) return r;
    r = hal_pin_bit_newf(HAL_IN, &(inst->in0), comp_id,
        "%s.in0", prefix);
    if(r != 0) return r;
    r = hal_param_s32_newf(HAL_RO, &(inst->watchdog_timeout_ns), comp_id,
        "%s.watchdog.timeout-ns", prefix);
    inst->watchdog_timeout_ns = 5000000;
    if(r != 0) return r;
    rtapi_snprintf(buf, sizeof(buf), "%s", prefix);
    r = hal_export_funct(buf, (void(*)(void *inst, long))_, inst, 1, 0, comp_id);
    if(r != 0) return r;
    if(__comp_last_inst) __comp_last_inst->_next = inst;
    __comp_last_inst = inst;
    if(!__comp_first_inst) __comp_first_inst = inst;
    return 0;
}
static int default_count=1, count=0;
char *names[16] = {0,};
RTAPI_MP_INT(count, "number of hm2_7i76e");
RTAPI_MP_ARRAY_STRING(names, 16, "names of hm2_7i76e");
int rtapi_app_main(void) {
    int r = 0;
    int i;
    comp_id = hal_init("hm2_7i76e");
    if(comp_id < 0) return comp_id;
    if(count && names[0]) {
        rtapi_print_msg(RTAPI_MSG_ERR,"count= and names= are mutually exclusive\n");
        return -EINVAL;
    }
    if(!count && !names[0]) count = default_count;
    if(count) {
        for(i=0; i<count; i++) {
            char buf[HAL_NAME_LEN + 1];
            rtapi_snprintf(buf, sizeof(buf), "hm2-7i76e.%d", i);
            r = export(buf, i);
            if(r != 0) break;
       }
    } else {
        int max_names = sizeof(names)/sizeof(names[0]);
        for(i=0; (i < max_names) && names[i]; i++) {
            if (strlen(names[i]) < 1) {
                rtapi_print_msg(RTAPI_MSG_ERR, "names[%d] is invalid (empty string)\n", i);
                r = -EINVAL;
                break;
            }
            r = export(names[i], i);
            if(r != 0) break;
       }
    }
    if(r) {
        hal_exit(comp_id);
    } else {
        hal_ready(comp_id);
    }
    return r;
}

void rtapi_app_exit(void) {
    hal_exit(comp_id);
}

#undef FUNCTION
#define FUNCTION(name) static void name(struct __comp_state *__comp_inst, long period)
#undef EXTRA_SETUP
#define EXTRA_SETUP() static int extra_setup(struct __comp_state *__comp_inst, char *prefix, long extra_arg)
#undef EXTRA_CLEANUP
#define EXTRA_CLEANUP() static void extra_cleanup(void)
#undef fperiod
#define fperiod (period * 1e-9)
#undef out0
#define out0 (*__comp_inst->out0)
#undef in0
#define in0 (0+*__comp_inst->in0)
#undef watchdog_timeout_ns
#define watchdog_timeout_ns (__comp_inst->watchdog_timeout_ns)


#line 8 "hm2_7i76e.comp"
FUNCTION(_) {
}
static int __comp_get_data_size(void) { return 0; }

Now I change only the dash in the name on line 56 to an underscore and try to compile the C file:
linuxcnc@debian:/usr/src/linuxcnc-dev/src/hal/components$ sudo halcompile --install hm2_7i76e.c
Compiling realtime hm2_7i76e.c
Linking hm2_7i76e.so
cp hm2_7i76e.so /usr/lib/linuxcnc/modules/

No nasty errors. Seems like it worked.

Now, as before, I try to load the component in HAL:

Well I'll be a ...... damn. I swear that wasn't happening last night. It would try to load and never succeed.
linuxcnc@debian:/usr/src/linuxcnc-dev/src/hal/components$ halrun
halcmd: loadrt hm2_7i76e
Note: Using POSIX realtime
halcmd: show
Loaded HAL Components:
ID      Type  Name                                            PID   State
     6  RT    hm2_7i76e                                             ready
     4  User  halcmd4023                                       4023 ready

Component Pins:
Owner   Type  Dir         Value  Name
     6  bit   IN          FALSE  hm2-7i76e.0.in0
     6  bit   OUT         FALSE  hm2-7i76e.0.out0
     6  s32   OUT             0  hm2-7i76e.0.time

Pin Aliases:
 Alias                                            Original Name

Signals:
Type          Value  Name     (linked to)

Parameters:
Owner   Type  Dir         Value  Name
     6  s32   RW              0  hm2-7i76e.0.tmax
     6  bit   RO          FALSE  hm2-7i76e.0.tmax-increased
     6  s32   RO        5000000  hm2-7i76e.0.watchdog.timeout_ns

Seems I don't need help on this anymore for the time being. Unless I can reproduce the problem, it seems.
Last edit: 15 Jun 2018 02:23 by Sparky961. Reason: Missed word...
More
15 Jun 2018 01:07 #112387 by AnnoyingMutt
Apparently you can use any string for indicated in red:
r = hal_param_s32_newf(HAL_RO, &(inst->watchdog_timeout_ns), comp_id,
"%s.watchdog.timeout-ns", prefix);

As seen here in blue:
r = hal_param_s32_newf(HAL_RO, &(inst->watchdog_timeout_ns), comp_id,
"%s.foofoo.dog_woof", prefix);


halcmd: loadrt hm2_7i76e
Note: Using POSIX realtime
halcmd: show
Loaded HAL Components:
ID Type Name PID State
6 RT hm2_7i76e ready
4 User halcmd9484 9484 ready

Component Pins:
Owner Type Dir Value Name
6 bit IN FALSE hm2-7i76e.0.in0
6 bit OUT FALSE hm2-7i76e.0.out0
6 s32 OUT 0 hm2-7i76e.0.time

Pin Aliases:
Alias Original Name

Signals:
Type Value Name (linked to)

Parameters:
Owner Type Dir Value Name
6 s32 RO 5000000 hm2-7i76e.0.foofoo.dog_woof
6 s32 RW 0 hm2-7i76e.0.tmax
6 bit RO FALSE hm2-7i76e.0.tmax-increased

Parameter Aliases:
Alias Original Name

Exported Functions:
Owner CodeAddr Arg FP Users Name
00006 7f158155bcb0 7f1582d640d8 YES 0 hm2-7i76e.0

Realtime Threads:
Period FP Name ( Time, Max-Time )

halcmd: quit
Note: Using POSIX realtime
More
15 Jun 2018 09:12 #112394 by andypugh
Do you want pins "hm2_7i76" or "hm2-7i76" ?

The real HAL file with the real 7i76 will have "hm2_7i76" (maybe hm2_7i76e" I haven't seen one)
More
15 Jun 2018 10:35 #112395 by Sparky961

andypugh wrote: Do you want pins "hm2_7i76" or "hm2-7i76" ?

The real HAL file with the real 7i76 will have "hm2_7i76" (maybe hm2_7i76e" I haven't seen one)


Yes, you're right. I was so focused on the one I didn't see the other.
Time to create page: 0.155 seconds
Powered by Kunena Forum