Fast data transfer from RP to an external linux

Applications, development tools, FPGA, C, WEB
Post Reply
grafzahl
Posts: 11
Joined: Mon Mar 02, 2015 2:34 pm

Fast data transfer from RP to an external linux

Post by grafzahl » Tue Mar 17, 2015 3:04 pm

We want to read out a RP with 20 to 100 Hz.
We used the SDK to build and copied a C File on to the RP.
The program should run all the time.
Our plan is to save a text file with the data on the RP and read out the text file over SSH.
Is there a better way? Perhaps a TCPIP port, which can stay open unlike SSH.

Karri Kaksonen
Posts: 24
Joined: Mon Dec 29, 2014 7:09 am

Re: Fast data transfer from RP to an external linux

Post by Karri Kaksonen » Wed Mar 18, 2015 10:59 am

You could send the data to an UDP socket.

Initialise port:

Code: Select all

#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/uio.h>

    const char* hostname="desktop"; 
    const char* portname="redpitaya";
    struct addrinfo hints;
    memset(&hints,0,sizeof(hints));
    hints.ai_family=AF_UNSPEC;
    hints.ai_socktype=SOCK_DGRAM;
    hints.ai_protocol=0;
    hints.ai_flags=AI_ADDRCONFIG;
    struct addrinfo* res=0;
    int err=getaddrinfo(hostname,portname,&hints,&res);
    if (err!=0) {
        fprintf(stderr, "failed to resolve remote socket address (err=%d)",err);
    }
    int fd=socket(res->ai_family,res->ai_socktype,res->ai_protocol);
    if (fd==-1) {
        fprintf(stderr, "%s",strerror(errno));
    }
Use the port:

Code: Select all

        if (sendto(fd,tbuff,sizeof(tbuff),0,res->ai_addr,res->ai_addrlen)==-1) {
            fprintf(stderr, "%s",strerror(errno));
        }
After this you still need to take a connection to redpitaya and do:

rw
cd /opt/etc
echo 192.168.xxx.xxx desktop >> hosts
echo redpitaya 10000/udp >> services
reboot

Then you should get a nice UDP stream directly to your host computer "desktop" through the port 10000/udp

Without programming you can view the text files as they arrive using socat.

socat -u udp-recv:10000 -

grafzahl
Posts: 11
Joined: Mon Mar 02, 2015 2:34 pm

Re: Fast data transfer from RP to an external linux

Post by grafzahl » Thu Mar 19, 2015 9:02 am

Thanks!

Your solution gave us the idea for a tcp connection which we will use now:
On RP we used something like www.linuxhowtos.org/data/6/client.c
And on desktop we installed with Qt a TCP Server.
50 Hz seems to be no problem.

Karri Kaksonen
Posts: 24
Joined: Mon Dec 29, 2014 7:09 am

Re: Fast data transfer from RP to an external linux

Post by Karri Kaksonen » Thu Mar 19, 2015 9:07 am

Nice.

TCP has re-sending of missed/failed packets. If your receiver hangs then you may end up having a lot of traffic waiting to be sent. This may affect you acquisition also.

UDP does not care if nobody listens to the transmissions. Of course if you miss an UDP packet it is lost forever.

Sorry. I just read you code. If you do it like in the example TCP works ok. If the receiver hangs the code exits.

--
Karri

grafzahl
Posts: 11
Joined: Mon Mar 02, 2015 2:34 pm

Re: Fast data transfer from RP to an external linux

Post by grafzahl » Thu Mar 19, 2015 12:31 pm

Thanks for the answer.

The problem of UDP would be, like you said, that we could loose packages and do not notice it.
with tcp we will implement a checksum, which is send and replied.

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 24 guests