Bluenet  5.7.0
Bluenet, firmware for nRF52 smart home devices
Loading...
Searching...
No Matches
cs_Microapp.h
Go to the documentation of this file.
1/*
2 * Author: Crownstone Team
3 * Copyright: Crownstone (https://crownstone.rocks)
4 * Date: Mar 09, 2021
5 * License: LGPLv3+, Apache License 2.0, and/or MIT (triple-licensed)
6 */
7
8#pragma once
9
12
21class Microapp : public EventListener {
22public:
24 static Microapp instance;
25 return instance;
26 }
27
32 void init(OperationMode operationMode);
33
37 bool canRunApp(uint8_t index);
38
42 void onExcessiveCallDuration(uint8_t appIndex);
43
44private:
49 Microapp(Microapp const&) = delete;
50 void operator=(Microapp const&) = delete;
51
55 microapp_state_t _states[g_MICROAPP_COUNT];
56
61 bool _started[g_MICROAPP_COUNT] = {};
62
66 bool _loaded = false;
67
74
78 bool _factoryResetMode = false;
79
80 void loadApps();
81
82 void loadState(uint8_t index);
83
89 void updateStateFromOperatingData(uint8_t index);
90
95 cs_ret_code_t validateApp(uint8_t index);
96
101 cs_ret_code_t enableApp(uint8_t index);
102
106 cs_ret_code_t startApp(uint8_t index);
107
111 void resetState(uint8_t index);
112
116 void resetTestState(uint8_t index);
117
121 cs_ret_code_t storeState(uint8_t index);
122
127 void tick();
128
139
144
149
154
162
166 void handleEvent(event_t& event);
167};
Event listener.
Definition: cs_EventListener.h:17
Class that enables the feature to run microapps on the firmware.
Definition: cs_Microapp.h:21
cs_ret_code_t checkHeader(microapp_ctrl_header_t *packet)
Checks if control command header is ok.
void resetTestState(uint8_t index)
Resets app state tests in ram only.
void resetState(uint8_t index)
Resets app state in ram only.
bool _loaded
Local flag to indicate that ram section has been loaded.
Definition: cs_Microapp.h:66
bool _started[g_MICROAPP_COUNT]
Keep up whether the microapp has been started yet.
Definition: cs_Microapp.h:61
void init(OperationMode operationMode)
Initialize storage, and load microapps in normal mode.
static Microapp & getInstance()
Definition: cs_Microapp.h:23
void loadApps()
cs_ret_code_t handleGetInfo(cs_result_t &result)
Handle control commands.
cs_ret_code_t resumeFactoryReset()
Remove next microapp and sends an event when done: EVT_MICROAPP_FACTORY_RESET_DONE.
cs_ret_code_t storeState(uint8_t index)
Store app state to flash.
void onExcessiveCallDuration(uint8_t appIndex)
To be called when a microapp took too long to yield.
void onStorageEvent(cs_async_result_t &event)
Handle microapp storage event.
void tick()
To be called every tick.
cs_ret_code_t handleDisable(microapp_ctrl_header_t *packet)
uint8_t _currentMicroappIndex
Keep up which microapp is currently being operated on.
Definition: cs_Microapp.h:73
cs_ret_code_t startApp(uint8_t index)
Start app, if it passed all tests according to cached state.
bool canRunApp(uint8_t index)
Checks app state and returns true if this app is allowed to run.
void updateStateFromOperatingData(uint8_t index)
Update state from operating data in IPC.
cs_ret_code_t handleRemove(microapp_ctrl_header_t *packet)
cs_ret_code_t handleEnable(microapp_ctrl_header_t *packet)
cs_ret_code_t enableApp(uint8_t index)
Enables app: checks sdk version.
cs_ret_code_t handleUpload(microapp_upload_internal_t *packet)
cs_ret_code_t handleMessage(microapp_message_internal_t *packet, cs_result_t &result)
cs_ret_code_t factoryReset()
Removes all microapps and sends an event when done: EVT_MICROAPP_FACTORY_RESET_DONE.
cs_ret_code_t validateApp(uint8_t index)
Validates app: compare checksum.
Microapp()
Singleton, constructor, also copy constructor, is private.
void loadState(uint8_t index)
void operator=(Microapp const &)=delete
bool _factoryResetMode
Whether we are in factory reset mode.
Definition: cs_Microapp.h:78
microapp_state_t _states[g_MICROAPP_COUNT]
The state of each microapp.
Definition: cs_Microapp.h:55
cs_ret_code_t handleValidate(microapp_ctrl_header_t *packet)
void handleEvent(event_t &event)
Handle incoming events.
Microapp(Microapp const &)=delete
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_Event.h:26
constexpr uint8_t MICROAPP_INDEX_NONE
Invalid microapp index.
Definition: cs_MicroappPackets.h:43
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
OperationMode
Definition: cs_Types.h:440
Definition: cs_PacketsInternal.h:71
Definition: cs_PacketsInternal.h:46
Definition: cs_MicroappPackets.h:67
Definition: cs_PacketsInternal.h:384
State of tests of a microapp, also stored in flash.
Definition: cs_MicroappPackets.h:108
Definition: cs_PacketsInternal.h:379