QuantumLeaps / qm

Graphical modeling and code generation tool based on UML state machines
https://www.state-machine.com/products/qm
Other
136 stars 37 forks source link

Generate portable C code? #17

Closed gonzabrusco closed 1 year ago

gonzabrusco commented 1 year ago

Hi, I'm learning on how to use QM and so far I really like it.

Is there any way of generating portable C code? I mean, I don't want the final code to relay on the qpc framework for compilation. Even If I create the most simple state machine, it will insert calls to "Q_TRAN()" "Q_HANDLED" "Q_SUPER" and definitions like QState, that would force me add the whole framework to my git repository just to compile a blinky.

I would be nicer if you could generate working state machines independent of the framework. and If you really need something from the framework, just add it to the source file. I think that approach would nice. Even for the first compilation, running the blinky example on Windows 10, the makefile will fail to compile (I think because it's not finding the framework!).

At least this would be nice to have it as an "option".

quantum-leaps commented 1 year ago

Hi Gonzalo, Thank you for your interest in the QM modeling tool.

Your request for "working state machines independent of the framework" is frankly unrealistic. You can achieve something like this only at the cost of repeating a lot of the common boilerplate in the generated state machine code. In the end, each generated state machine would contain a copy of the "framework" leading to repetitions and code bloat. (Please see my videos about various state machine implementation techniques.) The state machine elements like QEvt, QState, Q_TRAN(), etc. need to be there in one form or another. Again, a modeling tool like QM could generate those in every generated state machine, but this is silly. Isn't it? It's much better to be consistent and put such things in the common header file. This is how C and C++ languages have been designed to work.

Please note that the "framework" parts needed to compile and execute a hierarchical state machine consist of just one header file (qp.h for QP/C or qp.hpp for QP/C++) and one source file (qep_hsm.c for QP/C and qep_hsm.cpp for QP/C++). This code has been designed for portability, so it already meets your request in this respect. So you can use only the "state machine" parts of the QP/C/C++ frameworks and discard the parts for "active objects" and real-time kernels for the execution of these active objects. This minimal configuration (with just the "state machine" part being used) is illustrated in the following examples:

At the end of the day, I suspect that your request is not about technical issues, but rather to sidestep the licensing obligations associated with the QP/C and QP/C++ frameworks. Please correct me if I'm wrong...

--MMS

gonzabrusco commented 1 year ago

Actually you are not correct. I wanted to use UML modelling for an university project but I didn't really wanted to push all the framework to the repository just for one state machine. I think I will stick to modelling with UML and then writing my own implementation.

Thanks anyway.