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

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

问题描述

我的工作与使用RS232(通过USB RS232)连接到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><长度GT;<二进制数据><&CRC GT;

但我不希望推倒重来。

注意说:我正在考虑相当受限设备:内存,内核没有,也没有标准C的lib 4KB

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)?

如果您code自己的解决方案确实有任何的最佳做法?

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


  • 请您使用魔法字节还包的结束?

  • 也许是更好地利用时间空隙,而不是分隔符的?

  • 你怎么找到的包开始流中的二进制数据?

  • 也许是更好地使用文字协议?

更新:
请重新阅读的问题。我不应该问库,但良好做法。

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

推荐答案

请参阅this答案我给了一个非常类似的问题就的简单协议的细节。

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

要您的具体问题作出回应:

To respond to your specific points:


  1. 魔术师在数据包的最后字节不造成任何伤害,但他们是多余的,如果你已经知道该数据包应该有多长须,并有CRC。

  2. 它可以是明智的specifiy超时时间,所以如果有一个数据包中的字节之间过大的差距,那么一个错误标记。有使用的Modbus 的,我不相信使用基于时间的分隔符别处的价值。

  3. 你的意思是,你是怎么找到数据包的开始二进制数据流?如果是这样,也许指定的包之间的最小间隙,和/或所需要的接受者每个分组之后acknolwedge

  4. 使得能够更容易进行调试,并且不需要在PC上的任何特殊的软件,但不是非常有效的。当然,如果可用性比效率更重要的是,超过一个基于文本的系统是完全适当的。

  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天全站免登陆