Skip to content

Instantly share code, notes, and snippets.

@ahappyforest
Created February 20, 2014 15:30
Show Gist options
  • Save ahappyforest/9116361 to your computer and use it in GitHub Desktop.
Save ahappyforest/9116361 to your computer and use it in GitHub Desktop.
mushroom serial operation
while (1) {
每次总是先发送命令, 再读取回应, 因此这里也是按照这个顺序:
把串口操作看作是一个command和一个response组成, command是一个结构体, 不但包含待发送的数据, 还包含对应的message_queue指针, 上层的请求首先会被排队, 然后这个线程从队列中取出一个command开始发送。
0. 从队列中取出一个command
1. 发送command
2. 接收ack(这里严格按照超时来做, 因为有可能因为串口原因, 收不到ack)
3. 判断ack是否正确
4. 通知上层来响应这个ack的行为(将数据打包成response, 发送给message_queue)
5. 继续回到步骤0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment