FSMTools is a set of C++ library (librFSM) to load and execute rFSM LUA-based state machines and a graphical modelling tools (rfsmGui) to create, debug and execute the state machine.
Compile and Build librFSM on Linux
The installation is easy, straightforward and uses Cmake
building system.
$ sudo apt-get install lua5.X-dev
$ cd rfsmTools
$ mkdir build; cd build
$ cmake -DENABLE_RFSMGUI=OFF ../;
$ make
Sample Code
#include <iostream>
public:
std::cout<<"entry() of Configure (hello from C++)"<<std::endl;
}
std::cout<<"doo() of Configure (hello from C++)"<<std::endl;
}
std::cout<<"exit() of Configure (hello from C++)"<<std::endl;
}
} configureCallback;
std::cout<<"------------------------------------------"<<std::endl;
std::cout<<"States:";
for(
size_t i=0; i<graph.
states.size(); i++)
std::cout<<
"\t"<<graph.
states[i].name<<
"("<<graph.
states[i].type<<
")"<<std::endl;
std::cout<<"Transitions:"<<std::endl;
std::string events;
for(
size_t e=0; e<graph.
transitions[i].events.size();e++)
}
std::cout<<"------------------------------------------"<<std::endl;
}
void printEventQueue(std::vector<std::string>& equeue) {
std::string events;
for(size_t i=0; i<equeue.size(); i++)
events = events + ((events.size()) ? ", " + equeue[i] : equeue[i]);
std::cout<<"Event queue:"<<events<<std::endl;
}
int main(int argc, char** argv) {
if(argc < 2) {
std::cout<<"Usage:"<<argv[0]<<"myfsm.lua"<<std::endl;
return 0;
}
if(!
rfsm.load(argv[1])) {
std::cerr<<"Cannot load"<<argv[1]<<std::endl;
return 0;
}
rfsm.setStateCallback(
"Configure", configureCallback);
std::cout<<"Sending event 'e_true'"<<std::endl;
rfsm.sendEvent(
"e_true");
std::cout<<"Sending event 'e_true'"<<std::endl;
rfsm.sendEvent(
"e_true");
std::cout<<"Sending event 'e_interrupt'"<<std::endl;
rfsm.sendEvent(
"e_interrupt");
return 0;
}
Running Examples
$ cd build/bin
$ ./examples/rfsmTest ../examples/fsm/rfmodule_fsm.lua
- Author
- Ali Paikan