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

Returns

Source


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

Returns

Source


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

Returns

Source


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

Source


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

Source


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

Returns

Source