58#define FACTORY_RESET_STATE_NORMAL 0
59#define FACTORY_RESET_STATE_LOWTX 1
60#define FACTORY_RESET_STATE_RESET 2
92 std::vector<cs_state_id_t>*
ids;
151 static State instance;
BaseClass.
Definition: cs_BaseClass.h:15
Event listener.
Definition: cs_EventListener.h:17
Stores state values in RAM and/or FLASH.
Definition: cs_State.h:145
cs_ret_code_t loadFromRam(cs_state_data_t &data)
Copies from ram to target buffer.
cs_ret_code_t storeInRam(const cs_state_data_t &data, size16_t &index_in_ram)
Stores state variable in ram.
cs_ret_code_t getViaPointer(cs_state_data_t &data, const PersistenceMode mode=PersistenceMode::STRATEGY1)
Get pointer to state value.
bool handleFactoryResetResult(cs_ret_code_t retCode)
Handle factory reset result.
State(State const &)
State copy constructor, singleton, thus made private.
cs_ret_code_t removeFromFlash(const CS_TYPE &type, const cs_state_id_t id)
Remove given id of given type from flash.
void startWritesToFlash()
After calling this, state is allowed to write to flash.
cs_ret_code_t findInRam(const CS_TYPE &type, cs_state_id_t id, size16_t &index_in_ram)
Find given type in ram.
cs_ret_code_t set(const CS_TYPE type, void *value, size16_t size)
Convenience function for set().
cs_state_data_t & addToRam(const CS_TYPE &type, cs_state_id_t id, size16_t size)
Adds a new state_data struct to ram.
cs_ret_code_t setDelayed(const cs_state_data_t &data, uint8_t delay)
Set the state to a new value, but delay the write to flash.
cs_ret_code_t verifySizeForSet(const cs_state_data_t &data)
Verify size of user data for setting a state.
cs_ret_code_t removeInternal(const CS_TYPE &type, cs_state_id_t id, const PersistenceMode mode)
std::vector< cs_id_list_t > _idsCache
Stores list of existing ids for certain types.
Definition: cs_State.h:464
cs_ret_code_t cleanUp()
Clean up persistent storage.
cs_ret_code_t get(cs_state_data_t &data, const PersistenceMode mode=PersistenceMode::STRATEGY1)
Get copy of a state value.
bool _startedWritingToFlash
Definition: cs_State.h:471
cs_ret_code_t get(const CS_TYPE type, void *value, size16_t size)
Convenience function for get() with id 0.
cs_ret_code_t addToQueue(StateQueueOp operation, const CS_TYPE &type, cs_state_id_t id, uint32_t delayMs, const StateQueueMode mode)
Add an operation to queue.
cs_ret_code_t verifySizeForGet(const cs_state_data_t &data)
Verify size of user data for getting a state.
void handleEvent(event_t &event)
Handle (crownstone) events.
cs_ret_code_t set(const cs_state_data_t &data, PersistenceMode mode=PersistenceMode::STRATEGY1)
Set state to new value, via copy.
void handleStorageError(cs_storage_operation_t operation, CS_TYPE type, cs_state_id_t id)
Internal usage.
cs_ret_code_t removeFromRam(const CS_TYPE &type, cs_state_id_t id)
Removed a state variable from ram.
cs_ret_code_t remId(const CS_TYPE &type, cs_state_id_t id)
Remove ID from list of cached IDs.
cs_ret_code_t storeInFlash(size16_t &index_in_ram)
Writes state variable in ram to flash.
cs_ret_code_t setViaPointer(CS_TYPE type)
Update state value.
void operator=(State const &)
Assignment operator, singleton, thus made private.
cs_ret_code_t addId(const CS_TYPE &type, cs_state_id_t id)
Add ID to list of cached IDs.
void factoryReset()
Erase all used persistent storage.
State()
State constructor, singleton, thus made private.
boards_config_t * _boardsConfig
Definition: cs_State.h:343
cs_ret_code_t compareWithRam(const cs_state_data_t &data, uint32_t &cmp_result)
Check a particular value with the value currently in ram.
cs_ret_code_t getDefaultValue(cs_state_data_t &data)
std::vector< cs_state_data_t > _ram_data_register
Stores state data structs with pointers to state data.
Definition: cs_State.h:459
static State & getInstance()
Get a reference to the State object.
Definition: cs_State.h:150
cs_ret_code_t storeInRam(const cs_state_data_t &data)
Convenience function, in case you're not interested in index in ram.
void init(boards_config_t *boardsConfig)
Initialize the State object with the board configuration.
cs_ret_code_t setThrottled(const cs_state_data_t &data, uint32_t period)
Write variable to flash in a throttled mode.
cs_ret_code_t remove(const CS_TYPE &type, cs_state_id_t id, const PersistenceMode mode=PersistenceMode::STRATEGY1)
Remove a state variable.
Storage * _storage
Definition: cs_State.h:341
bool _performingFactoryReset
Definition: cs_State.h:473
cs_ret_code_t getIds(CS_TYPE type, std::vector< cs_state_id_t > *&ids)
Get a list of IDs for given type.
cs_ret_code_t setInternal(const cs_state_data_t &data, PersistenceMode mode)
cs_ret_code_t getIdsFromFlash(const CS_TYPE &type, std::vector< cs_state_id_t > *&ids)
Get and cache all IDs with given type from flash.
cs_ret_code_t allocate(cs_state_data_t &data)
bool isTrue(CS_TYPE type, const PersistenceMode mode=PersistenceMode::STRATEGY1)
Shorthand for get() for boolean data types, and id 0.
std::vector< cs_state_store_queue_t > _store_queue
Stores the queue of flash operations.
Definition: cs_State.h:469
Class to store items persistently in flash (persistent) memory.
Definition: cs_Storage.h:57
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_Event.h:26
PersistenceMode
Store values in FLASH or RAM.
Definition: cs_StateData.h:70
constexpr int ValidMode(OperationMode const &mode)
Definition: cs_State.h:35
constexpr const char * operationModeName(OperationMode const &mode)
These strings end up in the firmware, even with binary logging.
Definition: cs_State.h:23
StateQueueOp
Definition: cs_State.h:62
@ CS_STATE_QUEUE_OP_GC
Definition: cs_State.h:66
@ CS_STATE_QUEUE_OP_REM_ONE_ID_OF_TYPE
Definition: cs_State.h:64
@ CS_STATE_QUEUE_OP_WRITE
Definition: cs_State.h:63
@ CS_STATE_QUEUE_OP_FACTORY_RESET
Definition: cs_State.h:65
constexpr OperationMode getOperationMode(uint8_t mode)
Definition: cs_State.h:48
const uint32_t CS_STATE_QUEUE_DELAY_SECONDS_MAX
Definition: cs_State.h:88
StateQueueMode
Definition: cs_State.h:56
cs_storage_operation_t
Definition: cs_Storage.h:18
uint16_t size16_t
Definition: cs_Typedefs.h:25
uint8_t cs_state_id_t
Definition: cs_Typedefs.h:28
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
OperationMode
Definition: cs_Types.h:440
@ OPERATION_MODE_FACTORY_RESET
@ OPERATION_MODE_UNINITIALIZED
CS_TYPE
Types:
Definition: cs_Types.h:79
Board configuration.
Definition: cs_Boards.h:169
Definition: cs_State.h:90
cs_id_list_t(CS_TYPE type, std::vector< cs_state_id_t > *ids)
Definition: cs_State.h:93
std::vector< cs_state_id_t > * ids
Definition: cs_State.h:92
CS_TYPE type
Definition: cs_State.h:91
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_StateData.h:22
Struct for queuing operations.
Definition: cs_State.h:79
uint32_t counter
Definition: cs_State.h:83
uint32_t init_counter
Definition: cs_State.h:84
CS_TYPE type
Definition: cs_State.h:81
cs_state_id_t id
Definition: cs_State.h:82
StateQueueOp operation
Definition: cs_State.h:80
bool execute
Definition: cs_State.h:85