Boost SML
Boost SML is a highly expressive C++14 single header library used to implement FSM
s. We will jump straight ahead in using it by implementing the same BLE device connection FSM
. Here is the code:
#include "sml.hpp"
namespace sml = boost::sml;
struct ble_button_pressed{};
struct connection_request{};
struct timer_expired{};
constexpr auto start_advertising = [](){
printf("Action: start_advertising()\n");
};
constexpr auto stop_advertising = [](){
printf("Action: stop_advertising()\n");
};
constexpr auto disconnect = [](){
printf("Action: disconnect()\n");
};
struct ble_fsm {
auto operator()() const {
using namespace sml;
return make_transition_table(
*"idle"_s + event<ble_button_pressed>
/ start_advertising = "advertising"_s,
"advertising"_s + event<connection_request> = "connected"_s,
"advertising...