StorageHelperRK
Public Member Functions
StorageHelperRK::PersistentDataRetained Class Reference

Class for persistent data stored in retained memory. More...

#include <StorageHelperRK.h>

Inheritance diagram for StorageHelperRK::PersistentDataRetained:
StorageHelperRK::PersistentDataBase StorageHelperRK::CustomRecursiveMutex

Public Member Functions

 PersistentDataRetained (SavedDataHeader *savedDataHeader, size_t savedDataSize, uint32_t savedDataMagic, uint16_t savedDataVersion)
 Class for persistent data saved in retained memory. More...
 
- Public Member Functions inherited from StorageHelperRK::PersistentDataBase
 PersistentDataBase (SavedDataHeader *savedDataHeader, size_t savedDataSize, uint32_t savedDataMagic, uint16_t savedDataVersion)
 Base class for persistent data saved in file or RAM. More...
 
PersistentDataBasewithSaveDelayMs (uint32_t value)
 Sets the wait to save delay. Default is 1000 milliseconds. More...
 
virtual void setup ()
 Initialize this object for use in StorageHelperRK. More...
 
virtual bool load ()
 Load the persistent data file. You normally do not need to call this; it will be loaded automatically. More...
 
virtual void save ()
 Save the persistent data file. You normally do not need to call this; it will be saved automatically. More...
 
virtual void flush (bool force)
 Write the settings to disk if changed and the wait to save time has expired. More...
 
virtual void saveOrDefer ()
 Either saves data or immediately, or defers until later, based on saveDelayMs. More...
 
template<class T >
getValue (size_t offset) const
 Templated class for getting integral values (uint32_t, float, double, etc.) More...
 
template<class T >
void setValue (size_t offset, T value)
 Templated class for setting integral values (uint32_t, float, double, etc.) More...
 
bool getValueString (size_t offset, size_t size, String &value) const
 Get the value of a string. More...
 
bool setValueString (size_t offset, size_t size, const char *value)
 Set the value of a string. More...
 
uint32_t getHash () const
 Get the hash valid for data integrity checking.
 
- Public Member Functions inherited from StorageHelperRK::CustomRecursiveMutex
 CustomRecursiveMutex (os_mutex_recursive_t handle)
 Construct a CustomRecursiveMutex wrapper object from an existing recursive mutex. More...
 
 CustomRecursiveMutex ()
 Default constructor with no mutex - one will be created on first lock.
 
 ~CustomRecursiveMutex ()
 Destroys the underlying mutex object.
 
void dispose ()
 Destroys the mutex object.
 
void lock () const
 Locks the mutex. Creates a new recursive mutex object if it does not exist yet. More...
 
bool trylock () const
 Attempts to lock the mutex. Creates a new recursive mutex object if it does not exist yet. More...
 
bool try_lock () const
 Attempts to lock the mutex. Creates a new recursive mutex object if it does not exist yet. More...
 
void unlock () const
 Unlocks the mutex. More...
 

Additional Inherited Members

- Static Public Attributes inherited from StorageHelperRK::PersistentDataBase
static const uint32_t HASH_SEED = 0x851c2a3f
 Murmur32 hash seed value (randomly generated)
 
- Protected Member Functions inherited from StorageHelperRK::PersistentDataBase
 PersistentDataBase (const PersistentDataBase &)=delete
 
PersistentDataBaseoperator= (const PersistentDataBase &)=delete
 
virtual bool validate (size_t dataSize)
 Used to validate the saved data structure. Used internally by load(). More...
 
virtual void initialize ()
 Used to allow subclasses to initialize the saved data structure. Called internally by load(). More...
 
- Protected Attributes inherited from StorageHelperRK::PersistentDataBase
SavedDataHeadersavedDataHeader = 0
 Pointer to the saved data header, which is followed by the data.
 
uint32_t savedDataSize = 0
 Size of the saved data (header + actual data)
 
uint32_t savedDataMagic
 Magic bytes for the saved data.
 
uint16_t savedDataVersion
 Version number for the saved data.
 
uint32_t lastUpdate = 0
 Last time the file was updated. 0 = file has not changed since writing to disk.
 
uint32_t saveDelayMs = 1000
 How long to wait to save before writing file to disk. Set to 0 to write immediately.
 

Detailed Description

Class for persistent data stored in retained memory.

Retained memory (backup RAM, SRAM) is supported on Gen 2 and Gen 3 devices and is around 3K bytes in size. It's preserved across system reset and sometimes across flashing new code. On some Gen 2 devices an external battery or supercap can be added to preserve data on power-down.

Retained memory is not supported on the P2 or Photon 2.

Constructor & Destructor Documentation

◆ PersistentDataRetained()

StorageHelperRK::PersistentDataRetained::PersistentDataRetained ( SavedDataHeader savedDataHeader,
size_t  savedDataSize,
uint32_t  savedDataMagic,
uint16_t  savedDataVersion 
)
inline

Class for persistent data saved in retained memory.

Parameters
savedDataHeaderPointer to the saved data header in retained memory (backup RAM, SRAM)
savedDataSizesize of the whole structure, including the user data after it
savedDataMagicMagic bytes to use for this data
savedDataVersionVersion to use for this data

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