【发布时间】:2016-04-15 15:39:38
【问题描述】:
我最近开始使用this UART library 传输数据。测试用例有效,但阅读该库并不是一件轻而易举的事(至少对我而言)。
我的目标是将数据从传输控制器上的结构存储在接收微控制器上的结构中。 I thought I was close on my last implementation,但它无处可去。
我想避免犯与上次相同的错误。这是我的协议的伪代码。看起来我忽略了什么吗?
转移
1) Instance struct
2) Point at its memory location
3) For each variable in struct, write its data to the register
接收
1) Instance struct
2) Point at its memory location
3) When the register buffer is full, read register and store to struct by index
【问题讨论】:
-
结构是否包含指针?
-
其他可能的障碍:结构在每台机器上的大小可能不同;和字节序。
-
@IanAbbott 结构体本身不会,不是吗?
-
构建结构实例的字符串表示并通过 RS232(或其他方式)发送它们。解析接收站点上的字符串表示并重建您的结构实例。
-
@SensationSama 我试图阻止你做任何事情,比如“对于结构中的每个变量,将其数据写入寄存器”,天气风向标也是如此。您将通过字节流将数据从一个系统传输到另一个系统。字节流,而不是结构流或字符串流。您需要在单字节级别精确定义要发送的内容,包括明确的消息开始和消息数据,例如。由于字节顺序问题,[4 字节 int] 将不起作用。
标签: c++ c struct protocols uart