一种在嵌入式设备上将C89中的字节流转换为数据包流的方法 [英] A way to convert byte stream to packet stream in C89 on an embedded device

查看:171
本文介绍了一种在嵌入式设备上将C89中的字节流转换为数据包流的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用rs232(rs232 over USB)连接到PC的嵌入式设备。

I’m working on with an embedded device that is connected to PC using rs232 (rs232 over USB).

我正在考虑开发自己的协议:

I’m thinking about developing my own protocol:

< MAGIC>< LENGTH>< BINARY DATA>< CRC>

但我不想重新发明。

注意:我考虑相当受限的设备:4kb的RAM,没有内核,也没有标准的C lib。

Please note that: I'm thinking about quite restricted device: 4kb of RAM, no kernel, nor standard C lib.

你能想到一个标准的方法(也许是开源库)?

Can you think about a standard way to do this (maybe open source library)?

如果您编写自己的解决方案确实有最佳做法?

If you code your own solution do have any best practices?


  • 您也可以在包裹的末尾使用MAGIC字节?

  • 也许最好使用时间间隔而不是分隔符?

  • 如何找到开始包中的流二进制数据?

  • 也许最好使用文本协议?

  • Do you use MAGIC bytes also at the end of packages?
  • Maybe it is better to use time gaps instead of delimiters?
  • How do you find the beginning of packages in a stream binary data?
  • Maybe it is better to use text protocols?

更新:
请重新阅读Stion的。

UPDATE: Please re read the question. I shouldn't ask for library but for good practices.

推荐答案

请参阅这个答案我给了一个非常相似的问题关于一个简单的协议的细节。

See this answer I gave to a very similar question regarding details of a simple protocol.

要回应您的具体要点:


  1. 数据包末尾的魔术字节不有任何伤害,但如果您已经知道数据包应该是多长时间,并且有CRC,则它们是多余的。

  2. 指定超时时间是明智的,所以如果有一个数据包中字节之间的差距太大,则会出现错误。使用 Modbus 后,我不相信在其他地方使用基于时间的分隔符的价值。

  3. 您的意思是如何在二进制数据流中找到数据包的开头?如果是这样,可以指定数据包之间的最小间隙,和/或要求收件人在每个数据包之后进行确认。

  4. 使调试更容易,不需要任何特殊的软件电脑,但不是很有效率。当然,如果可用性比效率更重要,那么基于文本的系统是完全合适的。

  1. "Magic" bytes at the end of packets don't do any harm, but they're redundant if you already know how long the packet is supposed to be, and have a CRC.
  2. It can be sensible to specifiy timeout times, so if there's too big a gap between bytes within one packet, then an error is flagged. Having used Modbus, I'm not convinced of the value of using time-based delimiters elsewhere.
  3. Do you mean, "how do you find the beginning of packets in a stream of binary data"? If so, maybe specify a minimum gap between packets, and/or require the recipient to acknolwedge after every packet.
  4. Makes it easier for debugging, and doesn't require any special software on the PC, but not very efficient. Of course, if usability is more important than efficiency, than a text-based system is entirely appropriate.

这篇关于一种在嵌入式设备上将C89中的字节流转换为数据包流的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆