These are chat archives for machinekit/machinekit

21st
Oct 2016
zhivko
@zhivko
Oct 21 2016 10:40 UTC
Hey guys!
I wanna use #include <string> in icomp... and I get:
Compiling realtime udp.c
./components/udp.icomp:26:18: fatal error: string: No such file or directory
compilation terminated.
I want to split my custom parameters by "=" separator in:
loadrt udp count=1 ip=192.168.1.115 port=1234
Any c guru here ?
Bas de Bruijn
@luminize
Oct 21 2016 13:27 UTC
no c guru, but I think there's no support for that for instcomp. http://www.machinekit.io/docs/hal/instcomp/#instanceparams
that means you'll have to write one in C
ArcEye
@ArcEye
Oct 21 2016 14:14 UTC

Try loadrt udp count=1 --- ip=192.168.1.115 port=1234

Then in your .icomp file use option extra_inst_setup yes`
http://www.machinekit.io/docs/hal/instcomp/#options

You should then be able to access the extra args before entering the user_mainloop() from the argc, argv passed to the extra_inst_setup() function
ie. static int extra_inst_setup(struct inst_data* ip, const char *name, int argc, const char**argv)

As far as #include <string> goes, that is a C++ header std::string, do you have it installed?

zhivko
@zhivko
Oct 21 2016 14:15 UTC
Oh Hi! @ArcEye good to see you here in this chat room
I was chatting in #linuxcnc...
And made some progress
Now I know I would need to have UDP server in my component that will listen for UDP client that sends data (actuallaser sensor sending distance).
BUT...
trying to instcomp i get:
machinekit@beaglebone:~$ instcomp --install ./components/udp.icomp
Compiling realtime udp.c
Linking udp.so
cp udp.so /home/machinekit/git/machinekit/rtlib/xenomai/
machinekit@beaglebone:~$ instcomp --install ./components/udp.icomp
Compiling realtime udp.c
./components/udp.icomp: In function ‘threadFunc’:
udp.c:166:19: error: expected ‘)’ before ‘->’ token
 #define sockfd (ip->sockfd)
                   ^
./components/udp.icomp:55:7: note: in expansion of macro ‘sockfd’
udp.c:166:17: error: ‘ip’ undeclared (first use in this function)
 #define sockfd (ip->sockfd)
                 ^
./components/udp.icomp:69:3: note: in expansion of macro ‘sockfd’
udp.c:166:17: note: each undeclared identifier is reported only once for each function it appears in
 #define sockfd (ip->sockfd)
                 ^
./components/udp.icomp:69:3: note: in expansion of macro ‘sockfd’
/home/machinekit/git/machinekit/src/Makefile.modinc:123: recipe for target 'udp.o' failed
make: *** [udp.o] Error 1
machinekit@beaglebone:~$ instcomp --install ./components/udp.icomp
Compiling realtime udp.c
./components/udp.icomp: In function ‘threadFunc’:
udp.c:166:19: error: expected ‘)’ before ‘->’ token
 #define sockfd (ip->sockfd)
                   ^
./components/udp.icomp:55:7: note: in expansion of macro ‘sockfd’
udp.c:166:17: error: ‘ip’ undeclared (first use in this function)
 #define sockfd (ip->sockfd)
                 ^
./components/udp.icomp:69:3: note: in expansion of macro ‘sockfd’
udp.c:166:17: note: each undeclared identifier is reported only once for each function it appears in
 #define sockfd (ip->sockfd)
                 ^
./components/udp.icomp:69:3: note: in expansion of macro ‘sockfd’
/home/machinekit/git/machinekit/src/Makefile.modinc:123: recipe for target 'udp.o' failed
make: *** [udp.o] Error 1
ArcEye
@ArcEye
Oct 21 2016 14:20 UTC
Without seeing the code, no way to tell. Runinstcomp udp.icomp and post the .c file it produces.
You are obviously not copying the inst_struct to ip.
zhivko
@zhivko
Oct 21 2016 14:21 UTC
here it is:
a
ah
this is old one
.c is not even produced
oh sorry
here it is again:
zhivko
@zhivko
Oct 21 2016 14:28 UTC
If I delete body of void threadFunc(void arg) - than it is compiled OK...
Bas de Bruijn
@luminize
Oct 21 2016 14:28 UTC
:point_up: October 21, 2016 4:14 PM ah, should have read further
zhivko
@zhivko
Oct 21 2016 14:29 UTC
@luminize thanks - I got this solved before... I am step further I think
I mean hal comp instantiation...
I have problem compiling icomp now.
It blews when it gets to:
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
ArcEye
@ArcEye
Oct 21 2016 14:34 UTC
There are all sorts of things
The main one is probably that #define sockfd (ip->sockfd) appears above your function, but then you use the same name for a local variable in your threadFunc()
You also have pincount=6, but there are no arrays of pins with pincount as the index, so that is meaningless.
zhivko
@zhivko
Oct 21 2016 14:35 UTC
Thanks im in car now. Will check when im back ...
ArcEye
@ArcEye
Oct 21 2016 14:39 UTC
I would try getting it working in C as a userspace program, with some external trigger, before putting it into an .icomp
Might make things a lot easier
zhivko
@zhivko
Oct 21 2016 14:42 UTC
Would python comp be much slower than c?
@ArcEye where are you from?
Bas de Bruijn
@luminize
Oct 21 2016 15:12 UTC
python is ok for a userland component, not for a realtime component.
zhivko
@zhivko
Oct 21 2016 15:17 UTC
OK will try to fix c comp
oh what a silly mistake
deleting global sockfd line fixed it :)
zhivko
@zhivko
Oct 21 2016 16:27 UTC
I'm trying to build this comp on my ubuntu pc and now I get this error:
18:26:54 **** Incremental Build of configuration Debug for project UdpComp ****
make all 
Building target: UdpComp
Invoking: GCC C++ Linker
g++  -o "UdpComp"  ./UdpComp.o   
./UdpComp.o: In function `EXTRA_INST_SETUP':
/home/klemen/workspace-cdt/UdpComp/Debug/../UdpComp.c:172: undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
make: *** [UdpComp] Error 1
makefile:44: recipe for target 'UdpComp' failed

18:26:55 Build Finished (took 127ms)
zhivko
@zhivko
Oct 21 2016 17:03 UTC
OK -pthread linker option was missing...
zhivko
@zhivko
Oct 21 2016 19:04 UTC
Is there a function that is called when component is destroyed? I would need this to end the udp server thread properly... ? And do clean up..
zhivko
@zhivko
Oct 21 2016 23:22 UTC
EXTRA_CLEANUP() and option extra_cleanup yes;