用于嵌入式设备的有限状态机

发布于 2024-11-24 14:33:26 字数 321 浏览 5 评论 0原文

我使用 FSM 制作了几个菜单,但界面非常笨重。为了方便搬迁,我从编程中休息了一年,就在今晚重写了我的旧 FSM 代码。

可以看到 HERE

我的代码的问题是,无论何时,它都需要对 StateMachine 类和事件处理器进行大量修改。改变实施。 我无法使用 BOOST::FSM,因此我想编写自己的类,该类足够强大,可以处理菜单和编程反对数之类的事情(例如 PIC 的 ICSP 是一个简单的 FSM)

由于这是在嵌入式设备上, 你们建议我让我的状态机更有用吗?

I have made several menus using FSM's but with a VERY clunky interface. I took a year long break from programming to facilitate a relocation and just tonight re-wrote my old FSM code.

It can be seen HERE

The problem with my code is it requires heavy rework of the StateMachine class and the event processor whenever you change the implementation. As this is on an embedded device I can not use the BOOST::FSM so I want to write my own class that is robust enough to handle things like menus and programming antilogarithms (ICSP for a PIC for example is a simple FSM)

How would you guys recommend I make my state machine more useable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

↘紸啶 2024-12-01 14:33:26

如果您正在编写自己的类 - 考虑实现通用 FSM,然后用状态和事件填充它。

基本上,它将是一个简单的接口,具有类似这样的方法:

create();
addState(someState, stateFunction);
addEdge(someStateOrig, someStateDest, event);
processEvent(event);
start(startFromState);

这应该涵盖它。然后,当您创建 FSM 时,向其提供您的状态、到达该状态时要执行的函数以及使 FSM 从一种状态转移到另一种状态的事件。

然后,您只需在某个状态(即启动状态)启动 FSM,并提供事件。

如果您需要更改事件、函数或状态 - FSM 实现保持不变,您可以更改使用它的代码,因为它应该是这样。

这或多或少是 Boost.FSM 给你的,但你说你不能使用它 - 所以你自己做:-)

If you're writing your own class - consider implementing a generic FSM, and then fill it with states and events.

Basically it would be a simple interface with something like this as methods:

create();
addState(someState, stateFunction);
addEdge(someStateOrig, someStateDest, event);
processEvent(event);
start(startFromState);

That should cover it. Then, when you create the FSM - feed it with your states, and functions to execute when you reach the state, and the events that make the FSM move from one state to another.

Then you just start the FSM at some state which will be the start state, and feed the events.

If you need to change the events, functions, or states - the FSM implementation remains the same, you change the code that uses it, as it should be.

That is more or less what Boost.FSM gives you, but you said you can't use it - so do it on your own:-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文