Infuse-IoT SDK API 0.0.1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Infuse-IoT application state APIs

Data Structures

struct  infuse_state_cb
 Infuse-IoT application state callback structure. More...
 

Macros

#define INFUSE_STATES_ARRAY_SIZE   ATOMIC_BITMAP_SIZE(INFUSE_STATES_END + 1)
 
#define INFUSE_STATES_ARRAY(name)
 Define a variable that can hold all Infuse-IoT application states.
 

Enumerations

enum  infuse_state {
  INFUSE_STATE_REBOOTING = 1 , INFUSE_STATE_APPLICATION_ACTIVE = 2 , INFUSE_STATE_TIME_KNOWN = 3 , INFUSE_STATE_DEVICE_STATIONARY = 4 ,
  INFUSE_STATE_HIGH_PRIORITY_UPLINK = 5 , INFUSE_STATE_DEVICE_STARTED_MOVING = 6 , INFUSE_STATE_DEVICE_STOPPED_MOVING = 7 , INFUSE_STATES_APP_START = 128 ,
  INFUSE_STATES_END = UINT8_MAX
}
 Infuse-IoT application states. More...
 

Functions

void infuse_state_register_callback (struct infuse_state_cb *cb)
 Register to be notified of state update events.
 
bool infuse_state_unregister_callback (struct infuse_state_cb *cb)
 Unregister previously registered callback structure.
 
bool infuse_state_set (enum infuse_state state)
 Set an application state.
 
bool infuse_state_set_timeout (enum infuse_state state, uint16_t timeout)
 Set an application state that times out after a duration.
 
int infuse_state_get_timeout (enum infuse_state state)
 Get the timeout associated with a state.
 
bool infuse_state_clear (enum infuse_state state)
 Clear an application state.
 
static bool infuse_state_set_to (enum infuse_state state, bool val)
 Set an application state to a specific value.
 
bool infuse_state_get (enum infuse_state state)
 Get an application state.
 
void infuse_states_snapshot (atomic_t snapshot[ATOMIC_BITMAP_SIZE(INFUSE_STATES_END+1)])
 Get a snapshot of the current application states.
 
void infuse_states_tick (atomic_t snapshot[ATOMIC_BITMAP_SIZE(INFUSE_STATES_END+1)])
 Run one tick of the state timeouts.
 

Detailed Description

Macro Definition Documentation

◆ INFUSE_STATES_ARRAY

#define INFUSE_STATES_ARRAY ( name)

#include <infuse/states.h>

Value:
#define INFUSE_STATES_ARRAY_SIZE
Definition states.h:55

Define a variable that can hold all Infuse-IoT application states.

◆ INFUSE_STATES_ARRAY_SIZE

#define INFUSE_STATES_ARRAY_SIZE   ATOMIC_BITMAP_SIZE(INFUSE_STATES_END + 1)

#include <infuse/states.h>

Enumeration Type Documentation

◆ infuse_state

#include <infuse/states.h>

Infuse-IoT application states.

1 - 127: Infuse-IoT defined states 128 - 255: Application specific states

Enumerator
INFUSE_STATE_REBOOTING 
INFUSE_STATE_APPLICATION_ACTIVE 
INFUSE_STATE_TIME_KNOWN 
INFUSE_STATE_DEVICE_STATIONARY 
INFUSE_STATE_HIGH_PRIORITY_UPLINK 
INFUSE_STATE_DEVICE_STARTED_MOVING 
INFUSE_STATE_DEVICE_STOPPED_MOVING 
INFUSE_STATES_APP_START 
INFUSE_STATES_END 

Function Documentation

◆ infuse_state_clear()

bool infuse_state_clear ( enum infuse_state state)

#include <infuse/states.h>

Clear an application state.

Parameters
stateState to clear
Returns
false if the bit was already cleared, true if it wasn't.

◆ infuse_state_get()

bool infuse_state_get ( enum infuse_state state)

#include <infuse/states.h>

Get an application state.

Parameters
stateState to query
Return values
trueApplication state is set
falseApplication state is not set

◆ infuse_state_get_timeout()

int infuse_state_get_timeout ( enum infuse_state state)

#include <infuse/states.h>

Get the timeout associated with a state.

Parameters
stateState to query timeout of
Return values
-EINVALis state is not set
0if state is set but has no timeout
timeoutseconds until the state is cleared otherwise

◆ infuse_state_register_callback()

void infuse_state_register_callback ( struct infuse_state_cb * cb)

#include <infuse/states.h>

Register to be notified of state update events.

Parameters
cbCallback struct to register

◆ infuse_state_set()

bool infuse_state_set ( enum infuse_state state)

#include <infuse/states.h>

Set an application state.

Application state will remain set until infuse_state_clear is called. Any pending timeouts from infuse_state_set_timeout will be cancelled.

Parameters
stateState to set
Returns
true if the state was already set, false if it wasn't.

◆ infuse_state_set_timeout()

bool infuse_state_set_timeout ( enum infuse_state state,
uint16_t timeout )

#include <infuse/states.h>

Set an application state that times out after a duration.

Calling this function multiple times will reschedule the timeout each time. If the state was previously set without a timeout via infuse_state_set, a timeout will be added.

Parameters
stateState to set
timeoutSeconds that state should be set for
Returns
true if the state was already set, false if it wasn't.

◆ infuse_state_set_to()

static bool infuse_state_set_to ( enum infuse_state state,
bool val )
inlinestatic

#include <infuse/states.h>

Set an application state to a specific value.

Parameters
stateState to set
valValue to set to
Returns
true if the state was previously set, false if it wasn't.

◆ infuse_state_unregister_callback()

bool infuse_state_unregister_callback ( struct infuse_state_cb * cb)

#include <infuse/states.h>

Unregister previously registered callback structure.

Parameters
cbCallback struct to unregister
Return values
trueWhen callback structure unregistered
falseWhen structure was not previously registered

◆ infuse_states_snapshot()

void infuse_states_snapshot ( atomic_t snapshot[ATOMIC_BITMAP_SIZE(INFUSE_STATES_END+1)])

#include <infuse/states.h>

Get a snapshot of the current application states.

Parameters
snapshotMemory to store snapshot in

◆ infuse_states_tick()

void infuse_states_tick ( atomic_t snapshot[ATOMIC_BITMAP_SIZE(INFUSE_STATES_END+1)])

#include <infuse/states.h>

Run one tick of the state timeouts.

The requirement to provide the snapshotted state is to prevent situations where a state is set just before this function is called, but after the consumer of the states has run. The typical concrete example of this is the task runner. This feature ensures that for a timeout of N, the state is set for N iterations of the task runner evaluation.

Note
This function must be run once and only once per second for correct operation
Parameters
snapshotStates that were present at evaluation time, from infuse_states_snapshot