Hierarchical State Machine (HSM) API
#include "src/btstack_hsm.h"
btstack_hsm_transit
btstack_hsm_state_t btstack_hsm_transit(btstack_hsm_t * const me, btstack_hsm_state_handler_t const target);
@title: Hierarchical State Machine (HSM)
/
ifndef BTSTACK_HSM_H
define BTSTACK_HSM_H
if defined __cplusplus
extern "C" {
endif
include
typedef uint16_t btstack_hsm_signal_t; enum btstack_hsm_reserved_signals_e { BTSTACK_HSM_EMPTY_SIG, BTSTACK_HSM_INIT_SIG, BTSTACK_HSM_ENTRY_SIG, BTSTACK_HSM_EXIT_SIG, BTSTACK_HSM_USER_SIG };
typedef struct { btstack_hsm_signal_t sig; } btstack_hsm_event_t; typedef struct btstack_hsm_s btstack_hsm_t; typedef enum { BTSTACK_HSM_TRAN_STATUS, BTSTACK_HSM_SUPER_STATUS, BTSTACK_HSM_HANDLED_STATUS, BTSTACK_HSM_UNHANDLED_STATUS, BTSTACK_HSM_IGNORED_STATUS } btstack_hsm_state_t;
typedef btstack_hsm_state_t (*btstack_hsm_state_handler_t)(btstack_hsm_t * const me, btstack_hsm_event_t const * const e);
struct btstack_hsm_s { btstack_hsm_state_handler_t state; btstack_hsm_state_handler_t temp; btstack_hsm_state_handler_t *path; int_fast8_t depth; };
/* API_START */
/*
Request the transition from the current state to the given new state
Parameters
- me: the current state machine
- target: the new state to transit to
Returns
- btstack_hsm_state_t: transition status
btstack_hsm_super
btstack_hsm_state_t btstack_hsm_super(btstack_hsm_t * const me, btstack_hsm_state_handler_t const target);
@title: Hierarchical State Machine (HSM)
/
ifndef BTSTACK_HSM_H
define BTSTACK_HSM_H
if defined __cplusplus
extern "C" {
endif
include
typedef uint16_t btstack_hsm_signal_t; enum btstack_hsm_reserved_signals_e { BTSTACK_HSM_EMPTY_SIG, BTSTACK_HSM_INIT_SIG, BTSTACK_HSM_ENTRY_SIG, BTSTACK_HSM_EXIT_SIG, BTSTACK_HSM_USER_SIG };
typedef struct { btstack_hsm_signal_t sig; } btstack_hsm_event_t; typedef struct btstack_hsm_s btstack_hsm_t; typedef enum { BTSTACK_HSM_TRAN_STATUS, BTSTACK_HSM_SUPER_STATUS, BTSTACK_HSM_HANDLED_STATUS, BTSTACK_HSM_UNHANDLED_STATUS, BTSTACK_HSM_IGNORED_STATUS } btstack_hsm_state_t;
typedef btstack_hsm_state_t (*btstack_hsm_state_handler_t)(btstack_hsm_t * const me, btstack_hsm_event_t const * const e);
struct btstack_hsm_s { btstack_hsm_state_handler_t state; btstack_hsm_state_handler_t temp; btstack_hsm_state_handler_t *path; int_fast8_t depth; };
/* API_START */
/*
Request the transition from the current state to the given new state
Specifies the upper state in a state hierarchy
Parameters
- me: the current state machine
- target: the new state to transit to
- me: the current state machine
- target: the next parent state in the hierarchy
Returns
- btstack_hsm_state_t: transition status / btstack_hsm_state_t btstack_hsm_transit(btstack_hsm_t * const me, btstack_hsm_state_handler_t const target); /* transition status
btstack_hsm_top
btstack_hsm_state_t btstack_hsm_top(btstack_hsm_t * const me, btstack_hsm_event_t const * const e);
@title: Hierarchical State Machine (HSM)
/
ifndef BTSTACK_HSM_H
define BTSTACK_HSM_H
if defined __cplusplus
extern "C" {
endif
include
typedef uint16_t btstack_hsm_signal_t; enum btstack_hsm_reserved_signals_e { BTSTACK_HSM_EMPTY_SIG, BTSTACK_HSM_INIT_SIG, BTSTACK_HSM_ENTRY_SIG, BTSTACK_HSM_EXIT_SIG, BTSTACK_HSM_USER_SIG };
typedef struct { btstack_hsm_signal_t sig; } btstack_hsm_event_t; typedef struct btstack_hsm_s btstack_hsm_t; typedef enum { BTSTACK_HSM_TRAN_STATUS, BTSTACK_HSM_SUPER_STATUS, BTSTACK_HSM_HANDLED_STATUS, BTSTACK_HSM_UNHANDLED_STATUS, BTSTACK_HSM_IGNORED_STATUS } btstack_hsm_state_t;
typedef btstack_hsm_state_t (*btstack_hsm_state_handler_t)(btstack_hsm_t * const me, btstack_hsm_event_t const * const e);
struct btstack_hsm_s { btstack_hsm_state_handler_t state; btstack_hsm_state_handler_t temp; btstack_hsm_state_handler_t *path; int_fast8_t depth; };
/* API_START */
/*
Request the transition from the current state to the given new state
Specifies the upper state in a state hierarchy
Placeholder state to mark the top most state in a state hierarchy, the root state. Ignores all events.
Parameters
- me: the current state machine
- target: the new state to transit to
- me: the current state machine
- target: the next parent state in the hierarchy
- me: the current state machine
- e: event
Returns
- btstack_hsm_state_t: transition status / btstack_hsm_state_t btstack_hsm_transit(btstack_hsm_t * const me, btstack_hsm_state_handler_t const target); /* transition status / btstack_hsm_state_t btstack_hsm_super(btstack_hsm_t * const me, btstack_hsm_state_handler_t const target); /* ignored status
btstack_hsm_constructor
void btstack_hsm_constructor(btstack_hsm_t * const me, btstack_hsm_state_handler_t initial, btstack_hsm_state_handler_t path[], int8_t depth);
@title: Hierarchical State Machine (HSM)
/
ifndef BTSTACK_HSM_H
define BTSTACK_HSM_H
if defined __cplusplus
extern "C" {
endif
include
typedef uint16_t btstack_hsm_signal_t; enum btstack_hsm_reserved_signals_e { BTSTACK_HSM_EMPTY_SIG, BTSTACK_HSM_INIT_SIG, BTSTACK_HSM_ENTRY_SIG, BTSTACK_HSM_EXIT_SIG, BTSTACK_HSM_USER_SIG };
typedef struct { btstack_hsm_signal_t sig; } btstack_hsm_event_t; typedef struct btstack_hsm_s btstack_hsm_t; typedef enum { BTSTACK_HSM_TRAN_STATUS, BTSTACK_HSM_SUPER_STATUS, BTSTACK_HSM_HANDLED_STATUS, BTSTACK_HSM_UNHANDLED_STATUS, BTSTACK_HSM_IGNORED_STATUS } btstack_hsm_state_t;
typedef btstack_hsm_state_t (*btstack_hsm_state_handler_t)(btstack_hsm_t * const me, btstack_hsm_event_t const * const e);
struct btstack_hsm_s { btstack_hsm_state_handler_t state; btstack_hsm_state_handler_t temp; btstack_hsm_state_handler_t *path; int_fast8_t depth; };
/* API_START */
/*
Request the transition from the current state to the given new state
Specifies the upper state in a state hierarchy
Placeholder state to mark the top most state in a state hierarchy, the root state. Ignores all events.
Constructs a new hierarchical state machine, with storage for maximum hierarchy depth.
Parameters
- me: the current state machine
- target: the new state to transit to
- me: the current state machine
- target: the next parent state in the hierarchy
- me: the current state machine
- e: event
- me: non-NULL state machine storage
- initial: non-NULL initial state
- path: non-NULL array of btstack_hsm_state_handler_t elements
- depth: positive number of elements in path, at least the maximum number of nested state machines
btstack_hsm_init
void btstack_hsm_init(btstack_hsm_t * const me, btstack_hsm_event_t const * const e);
@title: Hierarchical State Machine (HSM)
/
ifndef BTSTACK_HSM_H
define BTSTACK_HSM_H
if defined __cplusplus
extern "C" {
endif
include
typedef uint16_t btstack_hsm_signal_t; enum btstack_hsm_reserved_signals_e { BTSTACK_HSM_EMPTY_SIG, BTSTACK_HSM_INIT_SIG, BTSTACK_HSM_ENTRY_SIG, BTSTACK_HSM_EXIT_SIG, BTSTACK_HSM_USER_SIG };
typedef struct { btstack_hsm_signal_t sig; } btstack_hsm_event_t; typedef struct btstack_hsm_s btstack_hsm_t; typedef enum { BTSTACK_HSM_TRAN_STATUS, BTSTACK_HSM_SUPER_STATUS, BTSTACK_HSM_HANDLED_STATUS, BTSTACK_HSM_UNHANDLED_STATUS, BTSTACK_HSM_IGNORED_STATUS } btstack_hsm_state_t;
typedef btstack_hsm_state_t (*btstack_hsm_state_handler_t)(btstack_hsm_t * const me, btstack_hsm_event_t const * const e);
struct btstack_hsm_s { btstack_hsm_state_handler_t state; btstack_hsm_state_handler_t temp; btstack_hsm_state_handler_t *path; int_fast8_t depth; };
/* API_START */
/*
Request the transition from the current state to the given new state
Specifies the upper state in a state hierarchy
Placeholder state to mark the top most state in a state hierarchy, the root state. Ignores all events.
Constructs a new hierarchical state machine, with storage for maximum hierarchy depth.
Takes the initial transition of the state machine and sending it a BTSTACK_HSM_INIT_SIG
Parameters
- me: the current state machine
- target: the new state to transit to
- me: the current state machine
- target: the next parent state in the hierarchy
- me: the current state machine
- e: event
- me: non-NULL state machine storage
- initial: non-NULL initial state
- path: non-NULL array of btstack_hsm_state_handler_t elements
- depth: positive number of elements in path, at least the maximum number of nested state machines / void btstack_hsm_constructor(btstack_hsm_t * const me, btstack_hsm_state_handler_t initial, btstack_hsm_state_handler_t path[], int8_t depth); /*
- me: the current state machine
- e: event
btstack_hsm_dispatch
btstack_hsm_state_t btstack_hsm_dispatch(btstack_hsm_t * const me, btstack_hsm_event_t const * const e);
@title: Hierarchical State Machine (HSM)
/
ifndef BTSTACK_HSM_H
define BTSTACK_HSM_H
if defined __cplusplus
extern "C" {
endif
include
typedef uint16_t btstack_hsm_signal_t; enum btstack_hsm_reserved_signals_e { BTSTACK_HSM_EMPTY_SIG, BTSTACK_HSM_INIT_SIG, BTSTACK_HSM_ENTRY_SIG, BTSTACK_HSM_EXIT_SIG, BTSTACK_HSM_USER_SIG };
typedef struct { btstack_hsm_signal_t sig; } btstack_hsm_event_t; typedef struct btstack_hsm_s btstack_hsm_t; typedef enum { BTSTACK_HSM_TRAN_STATUS, BTSTACK_HSM_SUPER_STATUS, BTSTACK_HSM_HANDLED_STATUS, BTSTACK_HSM_UNHANDLED_STATUS, BTSTACK_HSM_IGNORED_STATUS } btstack_hsm_state_t;
typedef btstack_hsm_state_t (*btstack_hsm_state_handler_t)(btstack_hsm_t * const me, btstack_hsm_event_t const * const e);
struct btstack_hsm_s { btstack_hsm_state_handler_t state; btstack_hsm_state_handler_t temp; btstack_hsm_state_handler_t *path; int_fast8_t depth; };
/* API_START */
/*
Request the transition from the current state to the given new state
Specifies the upper state in a state hierarchy
Placeholder state to mark the top most state in a state hierarchy, the root state. Ignores all events.
Constructs a new hierarchical state machine, with storage for maximum hierarchy depth.
Takes the initial transition of the state machine and sending it a BTSTACK_HSM_INIT_SIG
Dispatches the given event to the state machine, if a transition is requested, leave the old states and enter the new on. Honoring the hierarchy and handling entering/exiting all states on the way.
Parameters
- me: the current state machine
- target: the new state to transit to
- me: the current state machine
- target: the next parent state in the hierarchy
- me: the current state machine
- e: event
- me: non-NULL state machine storage
- initial: non-NULL initial state
- path: non-NULL array of btstack_hsm_state_handler_t elements
- depth: positive number of elements in path, at least the maximum number of nested state machines / void btstack_hsm_constructor(btstack_hsm_t * const me, btstack_hsm_state_handler_t initial, btstack_hsm_state_handler_t path[], int8_t depth); /*
- me: the current state machine
- e: event / void btstack_hsm_init(btstack_hsm_t * const me, btstack_hsm_event_t const * const e); /*
- me: the current state machine
- e: event
Returns
- btstack_hsm_state_t: transition status / btstack_hsm_state_t btstack_hsm_transit(btstack_hsm_t * const me, btstack_hsm_state_handler_t const target); /* transition status / btstack_hsm_state_t btstack_hsm_super(btstack_hsm_t * const me, btstack_hsm_state_handler_t const target); /* ignored status / btstack_hsm_state_t btstack_hsm_top(btstack_hsm_t * const me, btstack_hsm_event_t const * const e); /*