我是 python 新手,一直在尝试为这个特定项目学习它。我正在做的是使用本质上是一个 arduino 克隆和一个 NRf24 收发器来无线发送以下结构。
struct SENSOR{
float sensor1;
float sensor2;
float sensor3;
};
struct HEADER{
long type;
long hops;
long src;
long ID;
SENSOR sensor;
};
我正在使用带有 NRf24 的 beaglebone black 来接收它。在 BBB 上,收发器由 python 驱动(因为 BBB 和我正在使用的收音机已经有一个(相对)大的代码库)。
在 arduino 方面,它显示结构的长度为 28,这也是我在 python 方面收到的。我不知道如何将接收到的数据(存储在数组中)转换为可用格式。
蟒蛇方面:
#Receive Data
recv_buffer = []
radio.read(recv_buffer)
这是我在 python 端收到的
[1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 51, 51, 163, 64, 51, 51, 195, 64, 51, 51, 227, 64]
并在arduino方面发送
header.type = 1;
header.hops = 2;
header.src = 3;
header.ID = 4;
header.sensor.sensor1 = 5.1;
header.sensor.sensor2 = 6.1;
header.sensor.sensor3 = 7.1;
我一直在研究 ctypes 库并可能在其上使用 unpack,但无法使其正常工作。我很感激任何帮助。