【发布时间】:2014-01-21 13:12:06
【问题描述】:
我是 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 方面收到的。我不知道如何将接收到的数据(存储在数组中)转换为可用的格式。
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,但无法使其正常工作。我很感激任何帮助。
【问题讨论】:
-
我误解了你的问题,还是你在问如何将该数组转换为在 Python 中 的可用形式?因为那是微不足道的......
标签: python c struct wireless beagleboneblack