Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
Microapp Class Reference

Class that enables the feature to run microapps on the firmware. More...

#include <cs_Microapp.h>

Inheritance diagram for Microapp:
Collaboration diagram for Microapp:

Public Member Functions

void init (OperationMode operationMode)
 Initialize storage, and load microapps in normal mode. More...
 
bool canRunApp (uint8_t index)
 Checks app state and returns true if this app is allowed to run. More...
 
void onExcessiveCallDuration (uint8_t appIndex)
 To be called when a microapp took too long to yield. More...
 
- Public Member Functions inherited from EventListener
 EventListener ()
 
virtual ~EventListener ()
 unregisters the listener. More...
 
virtual void handleEvent (event_t &event)=0
 Handle events. More...
 
void listen ()
 Registers this with the EventDispatcher. More...
 

Static Public Member Functions

static MicroappgetInstance ()
 

Private Member Functions

 Microapp ()
 Singleton, constructor, also copy constructor, is private. More...
 
 Microapp (Microapp const &)=delete
 
void operator= (Microapp const &)=delete
 
void loadApps ()
 
void loadState (uint8_t index)
 
void updateStateFromOperatingData (uint8_t index)
 Update state from operating data in IPC. More...
 
cs_ret_code_t validateApp (uint8_t index)
 Validates app: compare checksum. More...
 
cs_ret_code_t enableApp (uint8_t index)
 Enables app: checks sdk version. More...
 
cs_ret_code_t startApp (uint8_t index)
 Start app, if it passed all tests according to cached state. More...
 
void resetState (uint8_t index)
 Resets app state in ram only. More...
 
void resetTestState (uint8_t index)
 Resets app state tests in ram only. More...
 
cs_ret_code_t storeState (uint8_t index)
 Store app state to flash. More...
 
void tick ()
 To be called every tick. More...
 
cs_ret_code_t handleGetInfo (cs_result_t &result)
 Handle control commands. More...
 
cs_ret_code_t handleUpload (microapp_upload_internal_t *packet)
 
cs_ret_code_t handleValidate (microapp_ctrl_header_t *packet)
 
cs_ret_code_t handleRemove (microapp_ctrl_header_t *packet)
 
cs_ret_code_t handleEnable (microapp_ctrl_header_t *packet)
 
cs_ret_code_t handleDisable (microapp_ctrl_header_t *packet)
 
cs_ret_code_t handleMessage (microapp_message_internal_t *packet, cs_result_t &result)
 
cs_ret_code_t checkHeader (microapp_ctrl_header_t *packet)
 Checks if control command header is ok. More...
 
cs_ret_code_t factoryReset ()
 Removes all microapps and sends an event when done: EVT_MICROAPP_FACTORY_RESET_DONE. More...
 
cs_ret_code_t resumeFactoryReset ()
 Remove next microapp and sends an event when done: EVT_MICROAPP_FACTORY_RESET_DONE. More...
 
void onStorageEvent (cs_async_result_t &event)
 Handle microapp storage event. More...
 
void handleEvent (event_t &event)
 Handle incoming events. More...
 

Private Attributes

microapp_state_t _states [g_MICROAPP_COUNT]
 The state of each microapp. More...
 
bool _started [g_MICROAPP_COUNT] = {}
 Keep up whether the microapp has been started yet. More...
 
bool _loaded = false
 Local flag to indicate that ram section has been loaded. More...
 
uint8_t _currentMicroappIndex = MICROAPP_INDEX_NONE
 Keep up which microapp is currently being operated on. More...
 
bool _factoryResetMode = false
 Whether we are in factory reset mode. More...
 

Detailed Description

Class that enables the feature to run microapps on the firmware.

This class:

  • Handles control commands (from BLE and UART).
  • Keeps up the state of microapps.
  • Instantiates and uses classes MicroappStorage and MicroappProtocol.

Constructor & Destructor Documentation

◆ Microapp() [1/2]

Microapp::Microapp ( )
private

Singleton, constructor, also copy constructor, is private.

◆ Microapp() [2/2]

Microapp::Microapp ( Microapp const &  )
privatedelete

Member Function Documentation

◆ canRunApp()

bool Microapp::canRunApp ( uint8_t  index)

Checks app state and returns true if this app is allowed to run.

◆ checkHeader()

cs_ret_code_t Microapp::checkHeader ( microapp_ctrl_header_t packet)
private

Checks if control command header is ok.

◆ enableApp()

cs_ret_code_t Microapp::enableApp ( uint8_t  index)
private

Enables app: checks sdk version.

App state is updated in this call, make sure to store the state afterwards.

◆ factoryReset()

cs_ret_code_t Microapp::factoryReset ( )
private

Removes all microapps and sends an event when done: EVT_MICROAPP_FACTORY_RESET_DONE.

◆ getInstance()

static Microapp & Microapp::getInstance ( )
inlinestatic

◆ handleDisable()

cs_ret_code_t Microapp::handleDisable ( microapp_ctrl_header_t packet)
private

◆ handleEnable()

cs_ret_code_t Microapp::handleEnable ( microapp_ctrl_header_t packet)
private

◆ handleEvent()

void Microapp::handleEvent ( event_t event)
privatevirtual

Handle incoming events.

Implements EventListener.

◆ handleGetInfo()

cs_ret_code_t Microapp::handleGetInfo ( cs_result_t result)
private

Handle control commands.

◆ handleMessage()

cs_ret_code_t Microapp::handleMessage ( microapp_message_internal_t packet,
cs_result_t result 
)
private

◆ handleRemove()

cs_ret_code_t Microapp::handleRemove ( microapp_ctrl_header_t packet)
private

◆ handleUpload()

cs_ret_code_t Microapp::handleUpload ( microapp_upload_internal_t packet)
private

◆ handleValidate()

cs_ret_code_t Microapp::handleValidate ( microapp_ctrl_header_t packet)
private

◆ init()

void Microapp::init ( OperationMode  operationMode)

Initialize storage, and load microapps in normal mode.

Checks operation mode and only actually initializes for some modes.

◆ loadApps()

void Microapp::loadApps ( )
private

◆ loadState()

void Microapp::loadState ( uint8_t  index)
private

◆ onExcessiveCallDuration()

void Microapp::onExcessiveCallDuration ( uint8_t  appIndex)

To be called when a microapp took too long to yield.

◆ onStorageEvent()

void Microapp::onStorageEvent ( cs_async_result_t event)
private

Handle microapp storage event.

For now, this just handles CMD_RESOLVE_ASYNC_CONTROL_COMMAND. We should register an event handler instead.

◆ operator=()

void Microapp::operator= ( Microapp const &  )
privatedelete

◆ resetState()

void Microapp::resetState ( uint8_t  index)
private

Resets app state in ram only.

◆ resetTestState()

void Microapp::resetTestState ( uint8_t  index)
private

Resets app state tests in ram only.

◆ resumeFactoryReset()

cs_ret_code_t Microapp::resumeFactoryReset ( )
private

Remove next microapp and sends an event when done: EVT_MICROAPP_FACTORY_RESET_DONE.

◆ startApp()

cs_ret_code_t Microapp::startApp ( uint8_t  index)
private

Start app, if it passed all tests according to cached state.

◆ storeState()

cs_ret_code_t Microapp::storeState ( uint8_t  index)
private

Store app state to flash.

◆ tick()

void Microapp::tick ( )
private

To be called every tick.

Calls all microapps.

◆ updateStateFromOperatingData()

void Microapp::updateStateFromOperatingData ( uint8_t  index)
private

Update state from operating data in IPC.

For example, when a reboot has happened when a microapp was running, this updates the state accordingly.

◆ validateApp()

cs_ret_code_t Microapp::validateApp ( uint8_t  index)
private

Validates app: compare checksum.

App state is updated in this call, make sure to store the state afterwards.

Member Data Documentation

◆ _currentMicroappIndex

uint8_t Microapp::_currentMicroappIndex = MICROAPP_INDEX_NONE
private

Keep up which microapp is currently being operated on.

Used for factory reset. Set to MICROAPP_INDEX_NONE when not operating on anything.

◆ _factoryResetMode

bool Microapp::_factoryResetMode = false
private

Whether we are in factory reset mode.

◆ _loaded

bool Microapp::_loaded = false
private

Local flag to indicate that ram section has been loaded.

◆ _started

bool Microapp::_started[g_MICROAPP_COUNT] = {}
private

Keep up whether the microapp has been started yet.

Init to false (default bool constructor).

◆ _states

microapp_state_t Microapp::_states[g_MICROAPP_COUNT]
private

The state of each microapp.


The documentation for this class was generated from the following file: