用于接收器将无线介质访问到有限状态机的伪代码
此伪代码适用于尝试访问无线介质以从传感器发送和接收数据的接收器。
- set
pc = 0.01
- 发送轮询数据包
- 如果没有传感器响应轮询数据包,则设置
pc = min (pc + 0.01, 1.0)
- 如果成功接收到来自传感器的数据包传感器,将
pc
保持在当前值 - 如果两个或多个传感器之间存在冲突(如数据包损坏所示),则设置
pc = pc / 2
- 重复步骤 2
我已读过如何阅读 FSM 图 的链接,它确实对我有帮助传感器部分。但我仍然对尝试将上述伪代码转换为 FSM 感到困惑。
任何人都可以推荐一个链接或电子书,对将伪代码转换为 FSM 进行清晰的解释吗?
This pseudocode is for a sink that tries to access the wireless medium in send and receive data from sensors.
- set
pc = 0.01
- send a polling packet
- If no sensor responds to polling packet, set
pc = min (pc + 0.01, 1.0)
- If a data packet is successfully received from one of the sensors, keep
pc
at current value - If there is a collision between two or more sensors as indicated by a corrupted data packet, set
pc = pc / 2
- Repeat step 2
I have read the link by How to read a FSM diagram and it really helped me for the sensor part. But I am still confused about trying to convert the above pseudocode into an FSM.
Can anyone suggest a link or ebook that gives a clear explanation about converting the pseudocode into a FSM?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你真正在这里寻找什么;简单地编码会非常简单,而且这个问题看起来并不值得全面解决对我来说,FSM 表驱动方法。
这是一些类似 C 的伪代码:
伪代码是指我刚刚编写的代码,并且没有测试机制
它。如果你的程序变得比这复杂得多,你可能会
想要将所有
select(2)
设置封装到它自己的函数中,并且可能是处理来自传感器套接字的数据包的所有细节。
I'm not sure what you're really looking for here; coding this simply would be pretty straight forward, and this problem doesn't look like it deserves the full-blown FSM table-driven approach to me.
Here's some C-like pseudo-code:
Pseudo-code in the sense that I just wrote this and have no mechanism to test
it. If your program gets much more complicated than this, you would probably
want to encapsulate all the
select(2)
setup into a function of its own, andpossibly all the details of handling the packet from the sensor's socket.