设计串行命令和数据的协议
我需要(设计?)一种通过串行连接在微处理器驱动的数据记录器和 PC(或类似设备)之间进行通信的协议。不会有控制线,设备/PC 知道它们是否已连接的唯一方法是通过它们接收的数据。连接可能随时中断并重新建立。串行连接是全双工的。 (8n1)
问题在于使用哪种类型的数据包、握手代码或类似代码。微处理器的能力极其有限,因此协议需要尽可能简单。但数据记录器将具有许多功能,例如调度记录、下载日志、设置采样率等,这些功能可能同时处于活动状态。
我的臃肿版本将是这样的:对于数据记录器和 PC,固定数据包大小为 16 字节,带有简单的 1 字节校验和,可能在开头/结尾有一个 0x00 字节以简化数据包的识别,并且一个字节表示数据包中的数据类型(命令/设置/日志数据/实时反馈值等)。为了同步,PC 可以发送一个唯一的“hello/reset”数据包(例如全零),当设备检测到该数据包时,该数据包会返回以确认同步。
如果您对这种方法有任何评论,我将不胜感激,并欢迎任何其他建议和一般性意见。
观察:我想我必须自己推出,因为我需要它尽可能轻量。我将从答案中建议的协议以及我发现的其他一些协议中获取一些零碎的内容...... 滑动, PPP 和 HLDC。
I need (to design?) a protocol for communication between a microprocessor-driven data logger, and a PC (or similar) via serial connection. There will be no control lines, the only way the device/PC can know if they're connected is by the data they're receiving. Connection might be broken and re-established at any time. The serial connection is full-duplex. (8n1)
The problem is what sort of packets to use, handshaking codes, or similar. The microprocessor is extremely limited in capability, so the protocol needs to be as simple as possible. But the data logger will have a number of features such as scheduling logging, downloading logs, setting sample rates, and so on, which may be active simultaneously.
My bloated version would go like this: For both the data logger and PC, a fixed packet size of 16 bytes with a simple 1 byte check sum, perhaps a 0x00 byte at the beginning/end to simplify recognition of packets, and one byte denoting the kind of data in the packet (command / settings / log data / live feed values etc). To synchronize, a unique "hello/reset" packet (of all zero's for example) could be sent by the PC, which when detected by the device is then returned to confirm synchronization.
I'd appreciate any comments on this approach, and welcome any other suggestions as well as general observations.
Observations: I think I will have to roll my own, since I need it to be as lightweight as possible. I'll be taking bits and pieces from protocols suggested in answers, as well as some others I've found... Slip,
PPP and HLDC.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 Google 的协议缓冲区作为数据交换格式(另请查看C 绑定 项目(如果您使用的是 C)。这是一种非常高效的格式,非常适合此类任务。
You can use Google's Protocol Buffers as a data exchange format (also check out the C bindings project if you're using C). It's a very efficient format, well suited to such tasks.
微控制器互连网络 (MIN) 正是为此目的而设计的:微型 8 位微控制器与其他设备通信。
该代码已获得 MIT 许可,并且有嵌入式 C 和 Python 实现:
https://github.com/min-protocol /分钟
Microcontroller Interconnect Network (MIN) is designed for just this purpose: tiny 8-bit microcontrollers talking to something else.
The code is MIT licensed and there's embedded C and also Python implementations:
https://github.com/min-protocol/min
我不会尝试从头开始发明一些东西,也许你可以重用过去的东西,比如 ZMODEM或者它的表兄弟之一?您提到的大多数问题都已经解决,并且可能还有许多其他情况您还没有解决。
zmodem 的详细信息:
http://www.techfest.com/hardware/modem/zmodem.htm
并且c源代码属于公共领域。
I wouldn't try to invent something from scratch, perhaps you could reuse something from the past like ZMODEM or one of its cousins? Most of the problems you mention have been solved, and there are probably a number of other cases you haven't even though of yet.
Details on zmodem:
http://www.techfest.com/hardware/modem/zmodem.htm
And the c source code is in the public domain.