9 ms·
Show HN: µFSM – A state chart library for embedded applications
- speps 8y agoProbably worth having a look at this: https://youtu.be/c9Xt6Me3mJ4?t=4196 https://youtu.be/c9Xt6Me3mJ4?t=4196 Embedded shouldn't rhyme with "C".
- dljsjr 8y agoIt's true that embedded software doesn't need to be written in C but if you're distributing a _library_ that's aimed at embedded systems then C is still a terrific choice for a ton of reasons. The goal of a library should be to embrace the path of least resistance for adoption. And when you're working in the embedded space that means targeting the least common denominator. Are all embedded systems extremely resource constrained? No, but many are. Do all applications running on embedded platforms need to be real-time? No, but many do. Writing in C means you can get small binaries, with minimal runtimes, easy control over things like memory allocation, and if you want to use the library you don't have to write C because almost any language with any form of FFI is going to target C before it targets C++.
- rhencke 8y agoThanks for sharing this. I really like the idea of being able to extract the state machine from a higher-level spec you've included here. The DHCP client example especially is really nice.
- slig 8y agoA must read for anyone interested https://statecharts.github.io/ https://statecharts.github.io/ Also I highly recommend to check out `xstate` TypeScript library. It's a breeze to work with it.
- deleted 8y ago[deleted]
- sktrdie 8y agoCan't stress how great that resource truly is in understanding statecharts, which are state-machines but with lots of extra details that actually make them usable at scale in large projects.
- davidkpiano 8y agoThanks so much for the praise (I created `xstate`)! I'm working hard on making it fully SCXML-compatible.
- slig 8y agoThank you for your work on it!
- kuwze 8y agoOn the topic of state-machines, there are some really cool typed libraries out there. The ones that stand out are motor[0] for Haskell and ST[1] for Idris. [0]: https://hackage.haskell.org/package/motor https://hackage.haskell.org/package/motor [1]: http://docs.idris-lang.org/en/latest/st/state.html http://docs.idris-lang.org/en/latest/st/state.html
- analognoise 8y agoIt requires a paid tool (Staruml) to extract a fsm from a state chart? Regardless, this looks very cool I will dive in later.
- j0p 8y agoI've used the evaluation version
- aylons 8y agoVery nice! Anything that allows something more sophisticated than switch:case in embedded systems are welcome! Also, state machines are way too often overlooked as a proper model for embedded systems architecture. My guess is that proper implementation may become hard (specially if you want to nest them), and there are lots of hardware engineers doing firmware. In my case, when I want to use a state machine for a project, I usually go with Quantum Leaps [1] tools. Nowadays their website seems cluttered and management-focused, but the tech is solid and the tools are very robust. They also distribute a book [2] on how to use the model using their framework as an example, and I even implemented my version of it as an exercise years ago. It does not have (or did not, I haven't checked in the last few years) a tool to translate from XMI to their framework, but they have a freeware to draw the chart. Frankly, I have not even used it: I draw the state machine using some editor and it is easy enough to translate to code and maintain. Maybe not the best, but up until now, very nice to deal with the limited complexity of most embedded systems. [1] https://www.state-machine.com/doc/concepts#HSM https://www.state-machine.com/doc/concepts#HSM [2] https://www.state-machine.com/psicc2/ https://www.state-machine.com/psicc2/
- childintime 8y agoI went to the Quantum Leaps site to check out their run-to-completion scheduler(s), one of the rare RTOS alternatives out there. They seem to have an incredible vision, yet, unfortunately, the site and the books make you want to stop reading and go alone.
- aylons 8y agoThe site was not that bad a few years ago, but I guess this new structure sells better for some companies. At the time, I actually bought the book and I liked it. It was a bit dense in the beginning, and I skipped the example, but I had some good takeaways, specially on the implementation of the system, which is described in the book.
- elcritch 8y agoI second the use of statemachine for embedded systems. They’re particularly ideal for embedded systems. The limited ram in many embedded systems makes a full dynamic language difficult to fit but a state chart interpreter can be very minimal while production runs can be compiled directly to code. Memory management in state charts can often be much easier to handle. There’s also a lot of benefit to describing valid states for your system both in terms of correctness and the ability of algorithmically finding an optimal reduced state machine. Personally I am fond of SCXML as it’s fairly concise, can include code snippets, and has a relatively well documented standard easy to display by converting to Vue/React/WebComponents. XMI with its connection to UML didn’t seem appealing to me, but this project seems pretty robust!
- nsomaru 8y agoFor Django there's django-fsm[0] and django-viewflow[1]. I've used the former to implement some flow for an ecommerce website. [0] https://github.com/kmmbvnr/django-fsm/ https://github.com/kmmbvnr/django-fsm/ [1] https://github.com/viewflow/viewflow https://github.com/viewflow/viewflow
- 0x5345414e 8y agoThanks for sharing! I'm working on a device and I've been searching for a good FSM library in C with no dynamic allocation :)
- okreallywtf 8y agoSame here, I've started 2 or 3 times and not liked any of my own implementations, this might actually be useful to me tonight.
- _pmf_ 8y agoWhat do you recommend as editor? Does Papyrus work?
- j0p 8y agoI've only tested with StarUML, but the plan is to support more tools
- nrclark 8y agothis looks awesome!!
- elviejo 8y agoIs there a programming language where FSM are a first class citizen?? And not just a library??
- deleted 8y ago[deleted]
- rdtsc 8y agoYes. Erlang has http://erlang.org/doc/man/gen_statem.html http://erlang.org/doc/man/gen_statem.html It is part of the Erlang's standard library. SSH and SSL state and connection management has been re-written recently to use this built-in module. Here is a video of Raimo Niskanen, the author, describing the module: https://www.youtube.com/watch?v=f_jl6MR3kXQ https://www.youtube.com/watch?v=f_jl6MR3kXQ The title is "The tool that you never knew that you always wanted", which was borrowed from another member of the community (Jesper L. Andersen)
- samatman 8y agoI'm impressed by this and like it a lot. If you don't mind a 'drive-by' feature request: it would be fantastic if you were to support the PlantUML state DSL: http://plantuml.com/state-diagram http://plantuml.com/state-diagram That would push me from "interesting proof of concept" to figuring out how to use it in projects.
- sitkack 8y agoI'd like to see a combination of this and https://en.wikipedia.org/wiki/Subtext_(programming_language) https://en.wikipedia.org/wiki/Subtext_(programming_language) along with a visualizer debugger that could scrub forwards and backwards in time.
- mogsie 8y agoI added it to the growing list of statechart libraries in various languages: https://statecharts.github.io/resources.html#tools--libraries https://statecharts.github.io/resources.html#tools--librarie...
- solarapex 8y agoThere are so many FSM implementations. The problem is when you want to implement something like this in different platforms, one has to "change the engine" along with all the connectors. Why not to use something standard like BPMN as the base?