Multiple FSM's in same program with colliding state names have unexpected side effects
- Dominant language
- C++
- Stars
- 1.2k
- Forks
- 193
- PR merge metrics
- No merged PRs in 30d
Description
Most probably I'm missing something trivial here, but I'm unable to understand what is happening in the following case:
1. I have 2 files 'wifi_sta_manager.cpp' and 'wifi_ap_manager.cpp'
2. Both hold a 'local' tinyFSM state machine, one is WiFiStationFSM, the other one is WiFiSoftAPFSM
3. Some of the states of these FSMs have the same names: Idle, Started ...
4. Both are initialized using FSM_INITIAL_STATE(name of FSM, Idle)
This is the station FSM
```
// states forward declaration
struct Idle;
struct Started;
struct Connected;
struct BackOff;
// State Machine Base Class
struct WiFiStationFSM : tinyfsm::Fsm
{
virtual void react(const tinyfsm::Event) {}
virtual void react(const WiFiStarted &) {}
virtual void react(const WiFiConnected &) {}
virtual void react(const WiFiDisconnected &) {}
// default behaviour is to stop wifi on transition to Idle
virtual void react(const SetttingsChanged &) { transit(station_stop); }
virtual void react(const OneSecond &) {}
virtual void entry() {}
virtual void exit() {}
};
// ... state implementation to follow
// Initial state definition
FSM_INITIAL_STATE(WiFiStationFSM, Idle)
// and somewhere
WiFiStationFSM::start();
```
And again for the AP FSM:
```
// states forward declaration
struct Idle;
struct Started;
// State Machine Base Class
struct WiFiSoftAPFSM : tinyfsm::Fsm
{
virtual void react(const tinyfsm::Event) {}
virtual void react(const WiFiStarted &) {}
// default behaviour is to stop wifi on transition to Idle
virtual void react(const SetttingsChanged &) { transit(softap_stop); }
virtual void entry() {}
virtual void exit() {}
};
// Initial state definition
FSM_INITIAL_STATE(WiFiSoftAPFSM, Idle)
// and somewhere
WiFiSoftAPFSM::start();
```
The trouble is, that the AP FSM start does not enter the Idle state. If I rename the states to APIdle and APStarted it works.
None of the state structs are defined in a header file, but solely in 'their' cpp files.
What am I missing?
BTW: This is an ESP32 project (IDF 5.2.1), riscv32-esp-elf-gcc (crosstool-NG esp-13.2.0_20230928) 13.2.0
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.