DeviceInfoLedger
|
#include <DeviceInfoLedger.h>
Public Member Functions | |
DeviceInfoLedger & | withInfoLedgerName (const char *infoLedgerName) |
Change the device to cloud ledger that holds the device information. | |
DeviceInfoLedger & | withRetainedBuffer (uint8_t *retainedBuffer, size_t retainedBufferSize) |
Retained buffer for use mainly to save log information in a circular buffer. | |
DeviceInfoLedger & | withLocalConfigLogLevel (LogLevel level=LOG_LEVEL_INFO, LogCategoryFilters filters={}) |
Set the local config log filters from a static array of LogCategoryFilter. | |
void | setup () |
Perform setup operations; call this from global application setup() | |
void | loop () |
Perform application loop operations; call this from global application loop() | |
int | getConfigConnectionLog () const |
Get the connectionLog (int) configuration setting from local settings or cloud configuration (default or device override) | |
DeviceInfoLedger & | withLocalConfigConnectionLog (int value) |
Set a local configuration setting for connectionLog (log size). Default is 0 (disabled). | |
int | getConfigLastRunLog () const |
Get the lastRunLog (int) configuration setting from local settings or cloud configuration (default or device override) | |
DeviceInfoLedger & | withLocalConfigLastRunLog (int value) |
Set a local configuration setting for lastRunLog (log size). Default is 0 (disabled). | |
bool | getConfigLogAllConnections () const |
Get the logAllConnections (bool) configuration setting from local settings or cloud configuration (default or device override) | |
DeviceInfoLedger & | withLocalConfigLogAllConnections (bool value) |
Set a local configuration setting for logAllConnections. Default is false. | |
bool | getConfigIncludeGeneral () const |
Get the includeGeneral (bool) configuration setting from local settings or cloud configuration (default or device override) | |
DeviceInfoLedger & | withLocalConfigIncludeGeneral (bool value) |
Set a local configuration setting for includeGeneral. Default is false. | |
bool | getConfigIncludeDiag () const |
Get the includeDiag (bool) configuration setting from local settings or cloud configuration (default or device override) | |
DeviceInfoLedger & | withLocalConfigIncludeDiag (bool value) |
Set a local configuration setting for includeDiag. Default is false. | |
bool | getConfigIncludeTower () const |
Get the includeTower (bool) configuration setting from local settings or cloud configuration (default or device override) | |
DeviceInfoLedger & | withLocalConfigIncludeTower (bool value) |
Set a local configuration setting for includeTower. Default is false. | |
LogLevel | stringToLogLevel (const char *levelStr) const |
Convert a string like LOG_LEVEL_INFO into its numeric equivalent. | |
const char * | logLevelToString (LogLevel level) const |
Convert a log level value (like LOG_LEVEL_INFO) to a string. | |
void | getLogLevelFilters (LogLevel &level, LogCategoryFilters &filters) const |
Get the log level settings. | |
void | write (uint8_t c) |
Called by DeviceInfoLedgerLogHandler to handle log messages. | |
![]() | |
bool | getConfigBool (const char *key, bool defaultValue=false) const |
Get a bool (boolean) configuration setting from local settings or cloud configuration (default or device override) | |
bool | setLocalConfigBool (const char *key, bool value) |
Set a local config setting using a bool. | |
int | getConfigInt (const char *key, int defaultValue=0) const |
Get an int (32-bit signed integer) configuration setting from local settings or cloud configuration (default or device override) | |
bool | setLocalConfigInt (const char *key, int value) |
Set a local config setting using an int (signed 32-bit integer) | |
double | getConfigDouble (const char *key, double defaultValue=0.0) const |
Get a double (64-bit floating point) configuration setting from local settings or cloud configuration (default or device override) | |
bool | setLocalConfigDouble (const char *key, double value) |
Set a local config setting using a double (64-bit floating point) | |
String | getConfigString (const char *key, const char *defaultValue="") const |
Get a String configuration setting from local settings or cloud configuration (default or device override) | |
bool | setLocalConfigString (const char *key, const char *value) |
Set a local config setting using a c-string (null-terminated UTF-8, const char *) | |
Variant | getConfigVariant (const char *key, Variant defaultValue={}) const |
Get a configuration setting from local settings or cloud configuration (default or device override) | |
bool | setLocalConfigVariant (const char *key, Variant value) |
Set a local config setting using a Variant. | |
Static Public Member Functions | |
static DeviceInfoLedger & | instance () |
Gets the singleton instance of this class, allocating it if necessary. | |
Static Public Attributes | |
static const uint32_t | retainedMagicBytes = 0xde8e46cc |
Magic bytes at the beginning of the RetainedBufferHeader. | |
Protected Member Functions | |
DeviceInfoLedger () | |
The constructor is protected because the class is a singleton. | |
virtual | ~DeviceInfoLedger () |
The destructor is protected because the class is a singleton and cannot be deleted. | |
DeviceInfoLedger (const DeviceInfoLedger &)=delete | |
DeviceInfoLedger & | operator= (const DeviceInfoLedger &)=delete |
void | configureLogHandler () |
Configure the log handler with the current settings in logLevel and logFilter. | |
virtual void | onCloudConnection () |
Called on the any cloud connection completed. | |
void | updateConfig () |
Called at setup and when the configuration is updated. | |
Protected Attributes | |
String | infoLedgerName = "device-info" |
Name of the info ledger. | |
uint8_t * | retainedBuffer = nullptr |
Retained buffer for lastRunLog and other purposes. | |
size_t | retainedBufferSize = 0 |
Retained buffer size for lastRunLog and other purposes. | |
char * | lastRunLog = nullptr |
lastRunLog, set during setup(), cleared when uploaded | |
uint8_t * | connectionLogBuffer = nullptr |
Buffer for connectionLog, allocated during updateConfig() | |
size_t | connectionLogSize = 0 |
Size of buffer for connectionLog, set during updateConfig() | |
std::atomic< uint32_t > | connectionLogOffset |
Offset for writing to connectionLog. Written in write(). | |
bool | writeToConnectionLog = true |
Whether to save data to the connection log. | |
bool | isCellularConnected = false |
Internal state, true if Cellular.ready() returned true. | |
bool | isWiFiConnected = false |
Internal state, true if WiFi.ready() returned true. | |
bool | isNetworkConnected = false |
Internal state, true if Network.ready() returned true. | |
bool | isCloudConnected = false |
Internal state, true if Particle.connected() returned true. | |
int | connectionCount = 0 |
Internal state, number of times Particle.connected() has transitioned to trye. | |
bool | setupComplete = false |
Internal state, true if setup has been called and completed. | |
RetainedBufferHeader * | retainedHdr = nullptr |
Convenience pointer into retainedBuffer. Set during setup. | |
uint8_t * | retainedData = nullptr |
Convenience pointer into retainedBuffer for retained log data. Set during setup. | |
size_t | retainedDataSize = 0 |
Amount of spaces for retained log data. Set during setup. | |
int | resetReason = RESET_REASON_NONE |
Reset reason, saved at the beginning of setup. | |
uint32_t | resetReasonData = 0 |
Reset reason data, saved at the beginning of setup if RESET_REASON_USER. | |
Ledger | infoLedger |
Ledger object for device information, initialized during setup. | |
DeviceInfoLedgerLogHandler * | logHandler = nullptr |
The StreamLogHandler object. | |
Static Protected Attributes | |
static DeviceInfoLedger * | _instance |
Singleton instance of this class. | |
This class is a singleton; you do not create one as a global, on the stack, or with new.
From global application setup you must call: DeviceInfoLedger::instance().setup();
From global application loop you must call: DeviceInfoLedger::instance().loop();
|
protected |
The constructor is protected because the class is a singleton.
Use DeviceInfoLedger::instance() to instantiate the singleton.
|
protecteddelete |
This class is a singleton and cannot be copied
|
inline |
Get the connectionLog (int) configuration setting from local settings or cloud configuration (default or device override)
The ledger has a maximum size of 16 Kbytes, and could be lower on some devices due to RAM limitations. Be sure to make this field and others small enough that the ledger fits. A normal value would be 2048 bytes.
|
inline |
Get the includeDiag (bool) configuration setting from local settings or cloud configuration (default or device override)
|
inline |
Get the includeGeneral (bool) configuration setting from local settings or cloud configuration (default or device override)
|
inline |
Get the includeTower (bool) configuration setting from local settings or cloud configuration (default or device override)
|
inline |
Get the lastRunLog (int) configuration setting from local settings or cloud configuration (default or device override)
The ledger has a maximum size of 16 Kbytes, and could be lower on some devices due to RAM limitations. Be sure to make this field and others small enough that the ledger fits. A normal value would be 2048 bytes.
This is also limited by the amount of retained memory passed to withRetainedBuffer.
|
inline |
Get the logAllConnections (bool) configuration setting from local settings or cloud configuration (default or device override)
void DeviceInfoLedger::getLogLevelFilters | ( | LogLevel & | level, |
LogCategoryFilters & | filters ) const |
Get the log level settings.
level | |
filters |
|
static |
Gets the singleton instance of this class, allocating it if necessary.
Use DeviceInfoLedger::instance() to instantiate the singleton.
const char * DeviceInfoLedger::logLevelToString | ( | LogLevel | level | ) | const |
Convert a log level value (like LOG_LEVEL_INFO) to a string.
level |
void DeviceInfoLedger::loop | ( | ) |
Perform application loop operations; call this from global application loop()
You typically use DeviceInfoLedger::instance().loop();
The DeviceInfoLedger needs loop time to process the connectivity changes; the configuration library does not need a loop call.
|
protecteddelete |
This class is a singleton and cannot be copied
void DeviceInfoLedger::setup | ( | ) |
Perform setup operations; call this from global application setup()
You typically use DeviceInfoLedger::instance().setup();
This must only be called once at boot and not again. You cannot use this to reconfigure settings!
LogLevel DeviceInfoLedger::stringToLogLevel | ( | const char * | levelStr | ) | const |
Convert a string like LOG_LEVEL_INFO into its numeric equivalent.
levelStr | The string (case-sensitive) |
Note that it really only searches for case-sensitive "INFO", "TRACE", etc.
|
inline |
Change the device to cloud ledger that holds the device information.
infoLedgerName | New name to use. |
Default is "device-info".
Must be called before setup().
|
inline |
Set a local configuration setting for connectionLog (log size). Default is 0 (disabled).
value | to set |
|
inline |
Set a local configuration setting for includeDiag. Default is false.
value | to set |
|
inline |
Set a local configuration setting for includeGeneral. Default is false.
value | to set |
|
inline |
Set a local configuration setting for includeTower. Default is false.
value | to set |
|
inline |
Set a local configuration setting for lastRunLog (log size). Default is 0 (disabled).
value | to set |
|
inline |
Set a local configuration setting for logAllConnections. Default is false.
value | to set |
DeviceInfoLedger & DeviceInfoLedger::withLocalConfigLogLevel | ( | LogLevel | level = LOG_LEVEL_INFO, |
LogCategoryFilters | filters = {} ) |
Set the local config log filters from a static array of LogCategoryFilter.
level | |
filters |
|
inline |
Retained buffer for use mainly to save log information in a circular buffer.
retainedBuffer | |
retainedBufferSize |
This log may be useful for debugging problems that cause a device panic, or similar issues that occur before a device reboot.
Because of the way retained memory works on RTL872x devices (P2/Photon 2), this log may be missing the latest data written to the log.
This does not need to match the cloud setting, but the cloud setting can't be used to store more than the size of the retained buffer. Thus you will probably want to make the retained buffer as large as is reasonable for your application.
Must be called before setup().
void DeviceInfoLedger::write | ( | uint8_t | c | ) |
Called by DeviceInfoLedgerLogHandler to handle log messages.
c | A character written to the logger |
|
staticprotected |
Singleton instance of this class.
The object pointer to this class is stored here. It's NULL at system boot.
|
protected |
Name of the info ledger.
Change name using withInfoLedgerName() (before setup).
|
protected |
The StreamLogHandler object.
Allocated during setup() and when the configuration changes.
|
protected |
Retained buffer for lastRunLog and other purposes.
Set using withRetainedBuffer() before setup.
|
protected |
Retained buffer size for lastRunLog and other purposes.
Set using withRetainedBuffer() before setup.
|
static |
Magic bytes at the beginning of the RetainedBufferHeader.
This is used to see if the structure has been initialized.