如何从 rp_remote_acquire 访问数据?

How do I access the data from rp_remote_acquire?

我目前有一个 python 程序(非常慢)通过递归调用从 Red Pitaya 板接收数据: redpitaya_scpi.scpi(192.169.1.100).rx_txt()

我想使用 rp_remote_acquire 通过环形缓冲区实现更高的吞吐量。

我能够在 Red Pitaya(服务器)和 linux 机器(客户端)上执行 ./rp_remote_acquire thanks to Whosebug

每次我在红火龙果上执行以下命令时,我都会在/tmp/out中得到一些独特的内容(这表明服务器上的程序可以从其硬件访问数据)。

rm /tmp/out
./rp_remote_acquire -m 3
cat /tmp/out

为了将数据从 Red Pitaya(客户端)传输到 linux 机器(服务器),我使用以下参数启动 ./rp_remote_acquire

服务器(192.169.1.100): ./rp_remote_acquire -m 2 -a 192.169.1.102 -p 14000

客户(192.169.1.102): ./rp_remote_acquire -m 1 -a 192.169.1.100 -p 14000

其中:

-m  --mode <(1|client)|(2|server)|(3|file)>
        operating mode (default client)

-a  --address <ip_address>
        target address in client mode (default empty)

-p  --port <port_num>
        port number in client and server mode (default 14000)

两台机器都能相互 ping 通,并且机器能够建立连接(即。int connection_start(option_fields_t *options, struct handles *handles) at transfer.c:251 returns 零)。

客户端最终从 transfer.c

执行以下代码片段
533     while (!size || transferred < size) {
(gdb) n
534         if (pos == buf_size)
(gdb) n
539         if (pos + CHUNK <= curr) {
(gdb) n
552         memcpy(buf, mapped_base + pos, len);
(gdb) n
554         if (handles->sock >= 0) {
(gdb) n
552         memcpy(buf, mapped_base + pos, len);
(gdb) n
554         if (handles->sock >= 0) {
(gdb) n
555             if (send_buffer(handles->sock, options, buf, len) < 0) {
(gdb) n
569         pos += len;
(gdb) n
533     while (!size || transferred < size) {

似乎客户端实际上只是在执行以下操作(默认情况下请注意 size = 0):

533     while (!size || transferred < size) {
552         memcpy(buf, mapped_base + pos, len);
552         memcpy(buf, mapped_base + pos, len);
569         pos += len;
        }

这种行为似乎是程序员的意图,因为一旦服务器停止,客户端就会停止:

554         if (handles->sock >= 0) {
(gdb) 
556                 if (!interrupted)

当我更改 size 使其不等于零(=> 更小的数据包?)时,程序不会卡在这个循环中。

我希望能够访问(希望)从 Red Pitaya(服务器)发送到 linux 机器(客户端)的数据,并以某种方式使这些数据可用于 python 客户端机器上的程序。

我的问题:

The solution 非常简单。

在服务器模式下 运行 正确时,rp_remote_acquire 将数据写入套接字:

/*
 * transfers samples to socket via read() call on rpad_scope
 */
static u_int64_t transfer_readwrite(struct scope_parameter *param,
                                    option_fields_t *options, struct handles *handles)

在客户端模式下,它从套接字读取数据并对其进行处理。

因为我们在这里使用套接字,所以我们不需要关心 rp_remote_acquire 在客户端模式下做了什么。我们可以简单地使用 python 脚本创建我们自己的套接字并在脚本中接收数据(这是我想要数据的地方)。

这是来自 @otobrzo 的示例:

import socket
import numpy as np
import matplotlib.pyplot as plt


client  = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

ip=socket.gethostbyname("XX.XX.XX.XX") # IP of redpitaya in server mode: 

# run cat ddrdump.bit > /dev/xdevcfg
#compiled and run on redpitay  ./rp_remote_acquire -m 2 -k 0 -c 0 -d 0


port=14000 # default port for TCP 

address=(ip,port)
client.connect(address)  

Nl = 10000

#while True:
for x in range(0, Nl):
#    print("test1")
    bytes_data = client.recv(1024) # set the amount data transferred

    if x == 0: 
        data = np.frombuffer(bytes_data, dtype=np.int16) # from 16bit data to int16 
        data = np.array(data, dtype=float)
        data_all = data
    else: 
        data = np.frombuffer(bytes_data, dtype=np.int16) # from 16bit data to int16 
        data = np.array(data, dtype=float)  
        data_all= np.hstack((data_all,data)) 

#%%
FPS = 125e6        
time = np.arange(0,np.size(data_all))/FPS

plt.plot(time,data_all)