From 5add1b75ebbb75abd6cfc5865cd6b4a9ce1f0030 Mon Sep 17 00:00:00 2001 From: Mario Falcao Date: Thu, 20 Sep 2018 22:23:12 +0100 Subject: [PATCH] class layout and other minor improvements --- Doxyfile | 4 +- README.md | 76 +-- extras/docs/api.md | 157 +++-- extras/docs/html/_s_p_i_f_f_s_logger_8h.html | 6 +- .../html/_s_p_i_f_f_s_logger_8h_source.html | 34 +- .../html/_s_p_i_f_f_s_logger_base_8cpp.html | 107 ++++ .../html/_s_p_i_f_f_s_logger_base_8cpp.js | 4 + .../html/_s_p_i_f_f_s_logger_base_8h.html | 97 +++ .../_s_p_i_f_f_s_logger_base_8h_source.html | 99 ++++ extras/docs/html/annotated.html | 3 +- extras/docs/html/annotated_dup.js | 3 +- .../class_s_p_i_f_f_s_logger-members.html | 35 +- .../docs/html/class_s_p_i_f_f_s_logger.html | 305 ++++++---- extras/docs/html/class_s_p_i_f_f_s_logger.js | 25 +- ...class_s_p_i_f_f_s_logger_base-members.html | 100 ++++ .../html/class_s_p_i_f_f_s_logger_base.html | 561 ++++++++++++++++++ .../html/class_s_p_i_f_f_s_logger_base.js | 16 + extras/docs/html/classes.html | 8 +- .../dir_68267d1309a1af8e8297ef4c3efbcdba.html | 6 +- .../dir_68267d1309a1af8e8297ef4c3efbcdba.js | 9 +- extras/docs/html/files.html | 4 +- extras/docs/html/functions.html | 37 +- extras/docs/html/functions_func.html | 23 +- extras/docs/html/functions_vars.html | 16 +- extras/docs/html/globals.html | 83 +++ extras/docs/html/globals_vars.html | 83 +++ extras/docs/html/hierarchy.html | 89 +++ extras/docs/html/hierarchy.js | 7 + extras/docs/html/index.html | 2 +- extras/docs/html/menudata.js | 6 +- extras/docs/html/navtreedata.js | 7 +- extras/docs/html/navtreeindex0.js | 56 +- .../struct_s_p_i_f_f_s_log_data-members.html | 2 +- .../html/struct_s_p_i_f_f_s_log_data.html | 2 +- extras/docs/xml/_s_p_i_f_f_s_logger_8h.xml | 308 +++------- .../xml/_s_p_i_f_f_s_logger_base_8cpp.xml | 161 +++++ .../docs/xml/_s_p_i_f_f_s_logger_base_8h.xml | 112 ++++ extras/docs/xml/class_s_p_i_f_f_s_logger.xml | 382 +++++++----- .../xml/class_s_p_i_f_f_s_logger_base.xml | 276 +++++++++ .../dir_68267d1309a1af8e8297ef4c3efbcdba.xml | 2 + extras/docs/xml/index.xml | 51 +- .../docs/xml/struct_s_p_i_f_f_s_log_data.xml | 6 +- library.properties | 2 +- src/SPIFFSLogger.h | 149 +---- src/SPIFFSLoggerBase.cpp | 106 ++++ src/SPIFFSLoggerBase.h | 80 +++ 46 files changed, 2875 insertions(+), 832 deletions(-) create mode 100644 extras/docs/html/_s_p_i_f_f_s_logger_base_8cpp.html create mode 100644 extras/docs/html/_s_p_i_f_f_s_logger_base_8cpp.js create mode 100644 extras/docs/html/_s_p_i_f_f_s_logger_base_8h.html create mode 100644 extras/docs/html/_s_p_i_f_f_s_logger_base_8h_source.html create mode 100644 extras/docs/html/class_s_p_i_f_f_s_logger_base-members.html create mode 100644 extras/docs/html/class_s_p_i_f_f_s_logger_base.html create mode 100644 extras/docs/html/class_s_p_i_f_f_s_logger_base.js create mode 100644 extras/docs/html/globals.html create mode 100644 extras/docs/html/globals_vars.html create mode 100644 extras/docs/html/hierarchy.html create mode 100644 extras/docs/html/hierarchy.js create mode 100644 extras/docs/xml/_s_p_i_f_f_s_logger_base_8cpp.xml create mode 100644 extras/docs/xml/_s_p_i_f_f_s_logger_base_8h.xml create mode 100644 extras/docs/xml/class_s_p_i_f_f_s_logger_base.xml create mode 100644 src/SPIFFSLoggerBase.cpp create mode 100644 src/SPIFFSLoggerBase.h diff --git a/Doxyfile b/Doxyfile index 4e5431a..254beae 100644 --- a/Doxyfile +++ b/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = SPIFFSLogger # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = v0.1.0 +PROJECT_NUMBER = v0.1.1 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a @@ -143,7 +143,7 @@ ALWAYS_DETAILED_SEC = NO # operators of the base classes will not be shown. # The default value is: NO. -INLINE_INHERITED_MEMB = NO +INLINE_INHERITED_MEMB = YES # If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path # before files name in the file list and in the header files. If set to NO the diff --git a/README.md b/README.md index e33a7e8..c17ef51 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,11 @@ Clone the library into your libraries folder, or download the zip and extract it ## class `SPIFFSLogger` +``` +class SPIFFSLogger + : public SPIFFSLoggerBase +``` + Minimal class template for binary data logging in ESP8266 SPIFFS. Makes it easy to read, write and keep logs of relevant data, such as sensor readings in an efficient way, by storing data in raw, binary format along with a time_t. One file is created per UTC day to store the respective data, and deleted once it has reached the defined maximum age. @@ -31,21 +36,22 @@ Makes it easy to read, write and keep logs of relevant data, such as sensor read Members | Descriptions --------------------------------|--------------------------------------------- `public `[`SPIFFSLogger`](#class_s_p_i_f_f_s_logger_1afa8152a5d5d29fedbb04265cb4589359)`(const char * directory,uint16_t daysToKeep,uint16_t processInterval)` | Default constructor for [SPIFFSLogger](#class_s_p_i_f_f_s_logger). -`public void `[`init`](#class_s_p_i_f_f_s_logger_1abfc7ce5e1a8022705c6704e50edf087d)`()` | Initialize the logger. -`public void `[`process`](#class_s_p_i_f_f_s_logger_1a34f24a3c6229653a31c166b899d43537)`()` | Process the file rotation and other required operations according to the defined processInterval. `public size_t `[`write`](#class_s_p_i_f_f_s_logger_1a2e914dd1884de9900288564a41bc55a4)`(const T & value)` | Write the specified value to the end of the current log file, with the current timestamp. `public size_t `[`readRows`](#class_s_p_i_f_f_s_logger_1aeceb2db3a41feb387e874f247657e19c)`(`[`SPIFFSLogData`](#struct_s_p_i_f_f_s_log_data)`< T > * output,time_t date,size_t startIdx,size_t maxCount)` | Read data from a daily logfile into a buffer. +`public size_t `[`readRowsBetween`](#class_s_p_i_f_f_s_logger_1a8d82d01f694528becba720e0612dc48d)`(`[`SPIFFSLogData`](#struct_s_p_i_f_f_s_log_data)`< T > * output,time_t fromTime,time_t toTime,size_t startIdx,size_t maxCount)` | `public size_t `[`rowCount`](#class_s_p_i_f_f_s_logger_1ac539407d1bfebe9443393ea2e4047e29)`(time_t date)` | Get the number of entries for the specified date. -`protected time_t `[`_today`](#class_s_p_i_f_f_s_logger_1a0a83d73217bc8bada843092ae7d055e8) | current date, set in the last processing run -`protected unsigned long `[`_lastProcess`](#class_s_p_i_f_f_s_logger_1ad48c3983258885410e6b7d0a299e8e69) | last processing millis() -`protected const uint16_t `[`_processInterval`](#class_s_p_i_f_f_s_logger_1a42017253e85b5f4978e4ba778960a62d) | ms between processing runs -`protected const uint16_t `[`_daysToKeep`](#class_s_p_i_f_f_s_logger_1afa47e4215bf7dc8a27704e5c10324fa8) | number of days to keep logs for -`protected bool `[`_processNow`](#class_s_p_i_f_f_s_logger_1af6227914a7bd060a26b5f83fa5641665) | force processing now, even if the processing interval hasn't passed -`protected char `[`_directory`](#class_s_p_i_f_f_s_logger_1a294e4b04bb7d26c6d63d4168d574221a) | base directory for log files -`protected char `[`_curPath`](#class_s_p_i_f_f_s_logger_1af6c68f5bf3ceccde605a89cb929bb787) | path for today's file -`protected void `[`_pathFromDate`](#class_s_p_i_f_f_s_logger_1ad366d57e6ca7b721b27164e40fb342b3)`(char * output,time_t date)` | Converts a time_t to that day's file path. -`protected void `[`_updateCurPath`](#class_s_p_i_f_f_s_logger_1ae6edbf5e924957c107068fce73554737)`()` | Updates the current path to match today's date. -`protected void `[`_runRotation`](#class_s_p_i_f_f_s_logger_1afbb2b0583a0500e3e5eae006a6740992)`()` | Deletes files older than the defined age limit. +`public void `[`init`](#class_s_p_i_f_f_s_logger_base_1ad2270960852a999b0340fa4eab50f063)`()` | Initialize the logger. +`public void `[`process`](#class_s_p_i_f_f_s_logger_base_1a22fdd2b540717853ae403edbc0ed1b7f)`()` | Process the file rotation and other required operations according to the defined processInterval. +`protected time_t `[`_today`](#class_s_p_i_f_f_s_logger_base_1a77a967ae68a680dea5a647200ba49815) | current date, set in the last processing run +`protected unsigned long `[`_lastProcess`](#class_s_p_i_f_f_s_logger_base_1ac1b33a4c97b2a45b2b178a261ebbb12c) | last processing millis() +`protected const uint16_t `[`_processInterval`](#class_s_p_i_f_f_s_logger_base_1a517fa4d3854283ba7b2dba9bf0d09c84) | ms between processing runs +`protected const uint16_t `[`_daysToKeep`](#class_s_p_i_f_f_s_logger_base_1a8feb62f012879aca79d600cf217c2098) | number of days to keep logs for +`protected bool `[`_processNow`](#class_s_p_i_f_f_s_logger_base_1a978f0a636ce4d7a7f1640df124cc25ff) | force processing now, even if the processing interval hasn't passed +`protected char `[`_directory`](#class_s_p_i_f_f_s_logger_base_1a829da5d8bf3d83ed24e608bb60fc623c) | base directory for log files +`protected char `[`_curPath`](#class_s_p_i_f_f_s_logger_base_1a7f79553c53c7b5b6c87aaaa104d5a1e3) | path for today's file +`protected void `[`_pathFromDate`](#class_s_p_i_f_f_s_logger_base_1abfba26125f8b32b4c8e2e3d29d65b31f)`(char * output,time_t date)` | Converts a time_t to that day's file path. +`protected void `[`_updateCurPath`](#class_s_p_i_f_f_s_logger_base_1aa5679e47e144e591b5fa90fb31b65cbd)`()` | Updates the current path to match today's date. +`protected void `[`_runRotation`](#class_s_p_i_f_f_s_logger_base_1a2e9e45428e1ffbe989dd7679c5def4fe)`()` | Deletes files older than the defined age limit. ### Members @@ -60,18 +66,6 @@ Default constructor for [SPIFFSLogger](#class_s_p_i_f_f_s_logger). * `processInterval` milliseconds between file directory updates and file rotation. -#### `public void `[`init`](#class_s_p_i_f_f_s_logger_1abfc7ce5e1a8022705c6704e50edf087d)`()` - -Initialize the logger. - -Should be called after initializing SPIFFS and before before any other method. - -#### `public void `[`process`](#class_s_p_i_f_f_s_logger_1a34f24a3c6229653a31c166b899d43537)`()` - -Process the file rotation and other required operations according to the defined processInterval. - -Should be called as often as possible, i.e. in loop(). - #### `public size_t `[`write`](#class_s_p_i_f_f_s_logger_1a2e914dd1884de9900288564a41bc55a4)`(const T & value)` Write the specified value to the end of the current log file, with the current timestamp. @@ -95,6 +89,8 @@ Read data from a daily logfile into a buffer. #### Returns number of entries read +#### `public size_t `[`readRowsBetween`](#class_s_p_i_f_f_s_logger_1a8d82d01f694528becba720e0612dc48d)`(`[`SPIFFSLogData`](#struct_s_p_i_f_f_s_log_data)`< T > * output,time_t fromTime,time_t toTime,size_t startIdx,size_t maxCount)` + #### `public size_t `[`rowCount`](#class_s_p_i_f_f_s_logger_1ac539407d1bfebe9443393ea2e4047e29)`(time_t date)` Get the number of entries for the specified date. @@ -105,43 +101,55 @@ Get the number of entries for the specified date. #### Returns number of entries -#### `protected time_t `[`_today`](#class_s_p_i_f_f_s_logger_1a0a83d73217bc8bada843092ae7d055e8) +#### `public void `[`init`](#class_s_p_i_f_f_s_logger_base_1ad2270960852a999b0340fa4eab50f063)`()` + +Initialize the logger. + +Should be called after initializing SPIFFS and before before any other method. + +#### `public void `[`process`](#class_s_p_i_f_f_s_logger_base_1a22fdd2b540717853ae403edbc0ed1b7f)`()` + +Process the file rotation and other required operations according to the defined processInterval. + +Should be called as often as possible, i.e. in loop(). + +#### `protected time_t `[`_today`](#class_s_p_i_f_f_s_logger_base_1a77a967ae68a680dea5a647200ba49815) current date, set in the last processing run -#### `protected unsigned long `[`_lastProcess`](#class_s_p_i_f_f_s_logger_1ad48c3983258885410e6b7d0a299e8e69) +#### `protected unsigned long `[`_lastProcess`](#class_s_p_i_f_f_s_logger_base_1ac1b33a4c97b2a45b2b178a261ebbb12c) last processing millis() -#### `protected const uint16_t `[`_processInterval`](#class_s_p_i_f_f_s_logger_1a42017253e85b5f4978e4ba778960a62d) +#### `protected const uint16_t `[`_processInterval`](#class_s_p_i_f_f_s_logger_base_1a517fa4d3854283ba7b2dba9bf0d09c84) ms between processing runs -#### `protected const uint16_t `[`_daysToKeep`](#class_s_p_i_f_f_s_logger_1afa47e4215bf7dc8a27704e5c10324fa8) +#### `protected const uint16_t `[`_daysToKeep`](#class_s_p_i_f_f_s_logger_base_1a8feb62f012879aca79d600cf217c2098) number of days to keep logs for -#### `protected bool `[`_processNow`](#class_s_p_i_f_f_s_logger_1af6227914a7bd060a26b5f83fa5641665) +#### `protected bool `[`_processNow`](#class_s_p_i_f_f_s_logger_base_1a978f0a636ce4d7a7f1640df124cc25ff) force processing now, even if the processing interval hasn't passed -#### `protected char `[`_directory`](#class_s_p_i_f_f_s_logger_1a294e4b04bb7d26c6d63d4168d574221a) +#### `protected char `[`_directory`](#class_s_p_i_f_f_s_logger_base_1a829da5d8bf3d83ed24e608bb60fc623c) base directory for log files -#### `protected char `[`_curPath`](#class_s_p_i_f_f_s_logger_1af6c68f5bf3ceccde605a89cb929bb787) +#### `protected char `[`_curPath`](#class_s_p_i_f_f_s_logger_base_1a7f79553c53c7b5b6c87aaaa104d5a1e3) path for today's file -#### `protected void `[`_pathFromDate`](#class_s_p_i_f_f_s_logger_1ad366d57e6ca7b721b27164e40fb342b3)`(char * output,time_t date)` +#### `protected void `[`_pathFromDate`](#class_s_p_i_f_f_s_logger_base_1abfba26125f8b32b4c8e2e3d29d65b31f)`(char * output,time_t date)` Converts a time_t to that day's file path. -#### `protected void `[`_updateCurPath`](#class_s_p_i_f_f_s_logger_1ae6edbf5e924957c107068fce73554737)`()` +#### `protected void `[`_updateCurPath`](#class_s_p_i_f_f_s_logger_base_1aa5679e47e144e591b5fa90fb31b65cbd)`()` Updates the current path to match today's date. -#### `protected void `[`_runRotation`](#class_s_p_i_f_f_s_logger_1afbb2b0583a0500e3e5eae006a6740992)`()` +#### `protected void `[`_runRotation`](#class_s_p_i_f_f_s_logger_base_1a2e9e45428e1ffbe989dd7679c5def4fe)`()` Deletes files older than the defined age limit. diff --git a/extras/docs/api.md b/extras/docs/api.md index eecf5a1..3555052 100644 --- a/extras/docs/api.md +++ b/extras/docs/api.md @@ -3,10 +3,16 @@ Members | Descriptions --------------------------------|--------------------------------------------- `class `[`SPIFFSLogger`](#class_s_p_i_f_f_s_logger) | Minimal class template for binary data logging in ESP8266 SPIFFS. +`class `[`SPIFFSLoggerBase`](#class_s_p_i_f_f_s_logger_base) | Base class for the [SPIFFSLogger](#class_s_p_i_f_f_s_logger) template, implementing common methods. `struct `[`SPIFFSLogData`](#struct_s_p_i_f_f_s_log_data) | Represents a data element as stored in SPIFFS, along with the creation timestamp. # class `SPIFFSLogger` +``` +class SPIFFSLogger + : public SPIFFSLoggerBase +``` + Minimal class template for binary data logging in ESP8266 SPIFFS. Makes it easy to read, write and keep logs of relevant data, such as sensor readings in an efficient way, by storing data in raw, binary format along with a time_t. One file is created per UTC day to store the respective data, and deleted once it has reached the defined maximum age. @@ -19,21 +25,22 @@ Makes it easy to read, write and keep logs of relevant data, such as sensor read Members | Descriptions --------------------------------|--------------------------------------------- `public `[`SPIFFSLogger`](#class_s_p_i_f_f_s_logger_1afa8152a5d5d29fedbb04265cb4589359)`(const char * directory,uint16_t daysToKeep,uint16_t processInterval)` | Default constructor for [SPIFFSLogger](#class_s_p_i_f_f_s_logger). -`public void `[`init`](#class_s_p_i_f_f_s_logger_1abfc7ce5e1a8022705c6704e50edf087d)`()` | Initialize the logger. -`public void `[`process`](#class_s_p_i_f_f_s_logger_1a34f24a3c6229653a31c166b899d43537)`()` | Process the file rotation and other required operations according to the defined processInterval. `public size_t `[`write`](#class_s_p_i_f_f_s_logger_1a2e914dd1884de9900288564a41bc55a4)`(const T & value)` | Write the specified value to the end of the current log file, with the current timestamp. `public size_t `[`readRows`](#class_s_p_i_f_f_s_logger_1aeceb2db3a41feb387e874f247657e19c)`(`[`SPIFFSLogData`](#struct_s_p_i_f_f_s_log_data)`< T > * output,time_t date,size_t startIdx,size_t maxCount)` | Read data from a daily logfile into a buffer. +`public size_t `[`readRowsBetween`](#class_s_p_i_f_f_s_logger_1a8d82d01f694528becba720e0612dc48d)`(`[`SPIFFSLogData`](#struct_s_p_i_f_f_s_log_data)`< T > * output,time_t fromTime,time_t toTime,size_t startIdx,size_t maxCount)` | `public size_t `[`rowCount`](#class_s_p_i_f_f_s_logger_1ac539407d1bfebe9443393ea2e4047e29)`(time_t date)` | Get the number of entries for the specified date. -`protected time_t `[`_today`](#class_s_p_i_f_f_s_logger_1a0a83d73217bc8bada843092ae7d055e8) | current date, set in the last processing run -`protected unsigned long `[`_lastProcess`](#class_s_p_i_f_f_s_logger_1ad48c3983258885410e6b7d0a299e8e69) | last processing millis() -`protected const uint16_t `[`_processInterval`](#class_s_p_i_f_f_s_logger_1a42017253e85b5f4978e4ba778960a62d) | ms between processing runs -`protected const uint16_t `[`_daysToKeep`](#class_s_p_i_f_f_s_logger_1afa47e4215bf7dc8a27704e5c10324fa8) | number of days to keep logs for -`protected bool `[`_processNow`](#class_s_p_i_f_f_s_logger_1af6227914a7bd060a26b5f83fa5641665) | force processing now, even if the processing interval hasn't passed -`protected char `[`_directory`](#class_s_p_i_f_f_s_logger_1a294e4b04bb7d26c6d63d4168d574221a) | base directory for log files -`protected char `[`_curPath`](#class_s_p_i_f_f_s_logger_1af6c68f5bf3ceccde605a89cb929bb787) | path for today's file -`protected void `[`_pathFromDate`](#class_s_p_i_f_f_s_logger_1ad366d57e6ca7b721b27164e40fb342b3)`(char * output,time_t date)` | Converts a time_t to that day's file path. -`protected void `[`_updateCurPath`](#class_s_p_i_f_f_s_logger_1ae6edbf5e924957c107068fce73554737)`()` | Updates the current path to match today's date. -`protected void `[`_runRotation`](#class_s_p_i_f_f_s_logger_1afbb2b0583a0500e3e5eae006a6740992)`()` | Deletes files older than the defined age limit. +`public void `[`init`](#class_s_p_i_f_f_s_logger_base_1ad2270960852a999b0340fa4eab50f063)`()` | Initialize the logger. +`public void `[`process`](#class_s_p_i_f_f_s_logger_base_1a22fdd2b540717853ae403edbc0ed1b7f)`()` | Process the file rotation and other required operations according to the defined processInterval. +`protected time_t `[`_today`](#class_s_p_i_f_f_s_logger_base_1a77a967ae68a680dea5a647200ba49815) | current date, set in the last processing run +`protected unsigned long `[`_lastProcess`](#class_s_p_i_f_f_s_logger_base_1ac1b33a4c97b2a45b2b178a261ebbb12c) | last processing millis() +`protected const uint16_t `[`_processInterval`](#class_s_p_i_f_f_s_logger_base_1a517fa4d3854283ba7b2dba9bf0d09c84) | ms between processing runs +`protected const uint16_t `[`_daysToKeep`](#class_s_p_i_f_f_s_logger_base_1a8feb62f012879aca79d600cf217c2098) | number of days to keep logs for +`protected bool `[`_processNow`](#class_s_p_i_f_f_s_logger_base_1a978f0a636ce4d7a7f1640df124cc25ff) | force processing now, even if the processing interval hasn't passed +`protected char `[`_directory`](#class_s_p_i_f_f_s_logger_base_1a829da5d8bf3d83ed24e608bb60fc623c) | base directory for log files +`protected char `[`_curPath`](#class_s_p_i_f_f_s_logger_base_1a7f79553c53c7b5b6c87aaaa104d5a1e3) | path for today's file +`protected void `[`_pathFromDate`](#class_s_p_i_f_f_s_logger_base_1abfba26125f8b32b4c8e2e3d29d65b31f)`(char * output,time_t date)` | Converts a time_t to that day's file path. +`protected void `[`_updateCurPath`](#class_s_p_i_f_f_s_logger_base_1aa5679e47e144e591b5fa90fb31b65cbd)`()` | Updates the current path to match today's date. +`protected void `[`_runRotation`](#class_s_p_i_f_f_s_logger_base_1a2e9e45428e1ffbe989dd7679c5def4fe)`()` | Deletes files older than the defined age limit. ## Members @@ -48,18 +55,6 @@ Default constructor for [SPIFFSLogger](#class_s_p_i_f_f_s_logger). * `processInterval` milliseconds between file directory updates and file rotation. -#### `public void `[`init`](#class_s_p_i_f_f_s_logger_1abfc7ce5e1a8022705c6704e50edf087d)`()` - -Initialize the logger. - -Should be called after initializing SPIFFS and before before any other method. - -#### `public void `[`process`](#class_s_p_i_f_f_s_logger_1a34f24a3c6229653a31c166b899d43537)`()` - -Process the file rotation and other required operations according to the defined processInterval. - -Should be called as often as possible, i.e. in loop(). - #### `public size_t `[`write`](#class_s_p_i_f_f_s_logger_1a2e914dd1884de9900288564a41bc55a4)`(const T & value)` Write the specified value to the end of the current log file, with the current timestamp. @@ -83,6 +78,8 @@ Read data from a daily logfile into a buffer. #### Returns number of entries read +#### `public size_t `[`readRowsBetween`](#class_s_p_i_f_f_s_logger_1a8d82d01f694528becba720e0612dc48d)`(`[`SPIFFSLogData`](#struct_s_p_i_f_f_s_log_data)`< T > * output,time_t fromTime,time_t toTime,size_t startIdx,size_t maxCount)` + #### `public size_t `[`rowCount`](#class_s_p_i_f_f_s_logger_1ac539407d1bfebe9443393ea2e4047e29)`(time_t date)` Get the number of entries for the specified date. @@ -93,43 +90,135 @@ Get the number of entries for the specified date. #### Returns number of entries -#### `protected time_t `[`_today`](#class_s_p_i_f_f_s_logger_1a0a83d73217bc8bada843092ae7d055e8) +#### `public void `[`init`](#class_s_p_i_f_f_s_logger_base_1ad2270960852a999b0340fa4eab50f063)`()` + +Initialize the logger. + +Should be called after initializing SPIFFS and before before any other method. + +#### `public void `[`process`](#class_s_p_i_f_f_s_logger_base_1a22fdd2b540717853ae403edbc0ed1b7f)`()` + +Process the file rotation and other required operations according to the defined processInterval. + +Should be called as often as possible, i.e. in loop(). + +#### `protected time_t `[`_today`](#class_s_p_i_f_f_s_logger_base_1a77a967ae68a680dea5a647200ba49815) current date, set in the last processing run -#### `protected unsigned long `[`_lastProcess`](#class_s_p_i_f_f_s_logger_1ad48c3983258885410e6b7d0a299e8e69) +#### `protected unsigned long `[`_lastProcess`](#class_s_p_i_f_f_s_logger_base_1ac1b33a4c97b2a45b2b178a261ebbb12c) last processing millis() -#### `protected const uint16_t `[`_processInterval`](#class_s_p_i_f_f_s_logger_1a42017253e85b5f4978e4ba778960a62d) +#### `protected const uint16_t `[`_processInterval`](#class_s_p_i_f_f_s_logger_base_1a517fa4d3854283ba7b2dba9bf0d09c84) ms between processing runs -#### `protected const uint16_t `[`_daysToKeep`](#class_s_p_i_f_f_s_logger_1afa47e4215bf7dc8a27704e5c10324fa8) +#### `protected const uint16_t `[`_daysToKeep`](#class_s_p_i_f_f_s_logger_base_1a8feb62f012879aca79d600cf217c2098) number of days to keep logs for -#### `protected bool `[`_processNow`](#class_s_p_i_f_f_s_logger_1af6227914a7bd060a26b5f83fa5641665) +#### `protected bool `[`_processNow`](#class_s_p_i_f_f_s_logger_base_1a978f0a636ce4d7a7f1640df124cc25ff) force processing now, even if the processing interval hasn't passed -#### `protected char `[`_directory`](#class_s_p_i_f_f_s_logger_1a294e4b04bb7d26c6d63d4168d574221a) +#### `protected char `[`_directory`](#class_s_p_i_f_f_s_logger_base_1a829da5d8bf3d83ed24e608bb60fc623c) base directory for log files -#### `protected char `[`_curPath`](#class_s_p_i_f_f_s_logger_1af6c68f5bf3ceccde605a89cb929bb787) +#### `protected char `[`_curPath`](#class_s_p_i_f_f_s_logger_base_1a7f79553c53c7b5b6c87aaaa104d5a1e3) path for today's file -#### `protected void `[`_pathFromDate`](#class_s_p_i_f_f_s_logger_1ad366d57e6ca7b721b27164e40fb342b3)`(char * output,time_t date)` +#### `protected void `[`_pathFromDate`](#class_s_p_i_f_f_s_logger_base_1abfba26125f8b32b4c8e2e3d29d65b31f)`(char * output,time_t date)` + +Converts a time_t to that day's file path. + +#### `protected void `[`_updateCurPath`](#class_s_p_i_f_f_s_logger_base_1aa5679e47e144e591b5fa90fb31b65cbd)`()` + +Updates the current path to match today's date. + +#### `protected void `[`_runRotation`](#class_s_p_i_f_f_s_logger_base_1a2e9e45428e1ffbe989dd7679c5def4fe)`()` + +Deletes files older than the defined age limit. + +# class `SPIFFSLoggerBase` + +Base class for the [SPIFFSLogger](#class_s_p_i_f_f_s_logger) template, implementing common methods. + +Should not be used directly. + +## Summary + + Members | Descriptions +--------------------------------|--------------------------------------------- +`public void `[`init`](#class_s_p_i_f_f_s_logger_base_1ad2270960852a999b0340fa4eab50f063)`()` | Initialize the logger. +`public void `[`process`](#class_s_p_i_f_f_s_logger_base_1a22fdd2b540717853ae403edbc0ed1b7f)`()` | Process the file rotation and other required operations according to the defined processInterval. +`protected time_t `[`_today`](#class_s_p_i_f_f_s_logger_base_1a77a967ae68a680dea5a647200ba49815) | current date, set in the last processing run +`protected unsigned long `[`_lastProcess`](#class_s_p_i_f_f_s_logger_base_1ac1b33a4c97b2a45b2b178a261ebbb12c) | last processing millis() +`protected const uint16_t `[`_processInterval`](#class_s_p_i_f_f_s_logger_base_1a517fa4d3854283ba7b2dba9bf0d09c84) | ms between processing runs +`protected const uint16_t `[`_daysToKeep`](#class_s_p_i_f_f_s_logger_base_1a8feb62f012879aca79d600cf217c2098) | number of days to keep logs for +`protected bool `[`_processNow`](#class_s_p_i_f_f_s_logger_base_1a978f0a636ce4d7a7f1640df124cc25ff) | force processing now, even if the processing interval hasn't passed +`protected char `[`_directory`](#class_s_p_i_f_f_s_logger_base_1a829da5d8bf3d83ed24e608bb60fc623c) | base directory for log files +`protected char `[`_curPath`](#class_s_p_i_f_f_s_logger_base_1a7f79553c53c7b5b6c87aaaa104d5a1e3) | path for today's file +`protected `[`SPIFFSLoggerBase`](#class_s_p_i_f_f_s_logger_base_1ace02cadd2e608c940728ae9f5242bbcc)`(const char * directory,uint16_t daysToKeep,uint16_t processInterval)` | +`protected void `[`_pathFromDate`](#class_s_p_i_f_f_s_logger_base_1abfba26125f8b32b4c8e2e3d29d65b31f)`(char * output,time_t date)` | Converts a time_t to that day's file path. +`protected void `[`_updateCurPath`](#class_s_p_i_f_f_s_logger_base_1aa5679e47e144e591b5fa90fb31b65cbd)`()` | Updates the current path to match today's date. +`protected void `[`_runRotation`](#class_s_p_i_f_f_s_logger_base_1a2e9e45428e1ffbe989dd7679c5def4fe)`()` | Deletes files older than the defined age limit. + +## Members + +#### `public void `[`init`](#class_s_p_i_f_f_s_logger_base_1ad2270960852a999b0340fa4eab50f063)`()` + +Initialize the logger. + +Should be called after initializing SPIFFS and before before any other method. + +#### `public void `[`process`](#class_s_p_i_f_f_s_logger_base_1a22fdd2b540717853ae403edbc0ed1b7f)`()` + +Process the file rotation and other required operations according to the defined processInterval. + +Should be called as often as possible, i.e. in loop(). + +#### `protected time_t `[`_today`](#class_s_p_i_f_f_s_logger_base_1a77a967ae68a680dea5a647200ba49815) + +current date, set in the last processing run + +#### `protected unsigned long `[`_lastProcess`](#class_s_p_i_f_f_s_logger_base_1ac1b33a4c97b2a45b2b178a261ebbb12c) + +last processing millis() + +#### `protected const uint16_t `[`_processInterval`](#class_s_p_i_f_f_s_logger_base_1a517fa4d3854283ba7b2dba9bf0d09c84) + +ms between processing runs + +#### `protected const uint16_t `[`_daysToKeep`](#class_s_p_i_f_f_s_logger_base_1a8feb62f012879aca79d600cf217c2098) + +number of days to keep logs for + +#### `protected bool `[`_processNow`](#class_s_p_i_f_f_s_logger_base_1a978f0a636ce4d7a7f1640df124cc25ff) + +force processing now, even if the processing interval hasn't passed + +#### `protected char `[`_directory`](#class_s_p_i_f_f_s_logger_base_1a829da5d8bf3d83ed24e608bb60fc623c) + +base directory for log files + +#### `protected char `[`_curPath`](#class_s_p_i_f_f_s_logger_base_1a7f79553c53c7b5b6c87aaaa104d5a1e3) + +path for today's file + +#### `protected `[`SPIFFSLoggerBase`](#class_s_p_i_f_f_s_logger_base_1ace02cadd2e608c940728ae9f5242bbcc)`(const char * directory,uint16_t daysToKeep,uint16_t processInterval)` + +#### `protected void `[`_pathFromDate`](#class_s_p_i_f_f_s_logger_base_1abfba26125f8b32b4c8e2e3d29d65b31f)`(char * output,time_t date)` Converts a time_t to that day's file path. -#### `protected void `[`_updateCurPath`](#class_s_p_i_f_f_s_logger_1ae6edbf5e924957c107068fce73554737)`()` +#### `protected void `[`_updateCurPath`](#class_s_p_i_f_f_s_logger_base_1aa5679e47e144e591b5fa90fb31b65cbd)`()` Updates the current path to match today's date. -#### `protected void `[`_runRotation`](#class_s_p_i_f_f_s_logger_1afbb2b0583a0500e3e5eae006a6740992)`()` +#### `protected void `[`_runRotation`](#class_s_p_i_f_f_s_logger_base_1a2e9e45428e1ffbe989dd7679c5def4fe)`()` Deletes files older than the defined age limit. diff --git a/extras/docs/html/_s_p_i_f_f_s_logger_8h.html b/extras/docs/html/_s_p_i_f_f_s_logger_8h.html index c0debd2..22c96bc 100644 --- a/extras/docs/html/_s_p_i_f_f_s_logger_8h.html +++ b/extras/docs/html/_s_p_i_f_f_s_logger_8h.html @@ -27,7 +27,7 @@
SPIFFSLogger -  v0.1.0 +  v0.1.1
A minimal library for binary data logging in ESP8266
@@ -70,9 +70,7 @@
SPIFFSLogger.h File Reference
-
#include <Arduino.h>
-#include <FS.h>
-#include <time.h>
+
#include "SPIFFSLoggerBase.h"

Go to the source code of this file.

diff --git a/extras/docs/html/_s_p_i_f_f_s_logger_8h_source.html b/extras/docs/html/_s_p_i_f_f_s_logger_8h_source.html index d95812c..552e93b 100644 --- a/extras/docs/html/_s_p_i_f_f_s_logger_8h_source.html +++ b/extras/docs/html/_s_p_i_f_f_s_logger_8h_source.html @@ -27,7 +27,7 @@ @@ -68,27 +68,17 @@
SPIFFSLogger.h
-Go to the documentation of this file.
1 /*
2 SPIFFSLogger - A minimal library for binary data logging in ESP8266
3 Copyright (C) 2018 Mario Falcao
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef __SPIFFSLOGGER_H__
20 #define __SPIFFSLOGGER_H__
21 
22 #include <Arduino.h>
23 #include <FS.h>
24 #include <time.h>
25 
26 // internal strings stored in flash for efficiency
27 static const char _logFilenameFormat[] PROGMEM = "%s/%d%02d%02d";
28 
34 template <class T>
36 {
37  time_t timestampUTC;
38  T data;
39 };
40 
50 template <class T>
52 {
53  public:
62  SPIFFSLogger(const char *directory, uint16_t daysToKeep = 7, uint16_t processInterval = 1000);
63 
67  void init();
68 
73  void process();
74 
80  size_t write(const T &value);
81 
91  size_t readRows(SPIFFSLogData<T> *output, time_t date, size_t startIdx, size_t maxCount);
92 
99  size_t rowCount(time_t date);
100 
101  protected:
102  time_t _today = 0;
103  unsigned long _lastProcess = 0;
104  const uint16_t _processInterval;
105  const uint16_t _daysToKeep;
106  bool _processNow = true;
107  char _directory[21];
108  char _curPath[32];
113  void _pathFromDate(char *output, time_t date);
114 
118  void _updateCurPath();
119 
123  void _runRotation();
124 
128  static time_t _timegm(struct tm *tm);
129 };
130 
131 template <class T>
132 SPIFFSLogger<T>::SPIFFSLogger(const char *directory, uint16_t daysToKeep, uint16_t processInterval)
133  : _daysToKeep(daysToKeep), _processInterval(processInterval)
134 {
135  strncpy(this->_directory, directory, sizeof(this->_directory) - 1);
136 }
137 
138 template <class T>
140 {
141  this->process();
142 }
143 
144 template <class T>
146 {
147  const unsigned long currentMillis = millis();
148  if (currentMillis - this->_lastProcess > this->_processInterval || this->_processNow)
149  {
150  const time_t now = time(nullptr);
151  const time_t today = now / 86400 * 86400; // remove the time part
152  if (this->_today != today)
153  { // we have switched to another day, let's run the required updates
154  this->_today = today;
155  this->_updateCurPath();
156  this->_runRotation();
157  }
158 
159  this->_lastProcess = currentMillis;
160  this->_processNow = false;
161  }
162 }
163 
164 template <class T>
165 size_t SPIFFSLogger<T>::write(const T &value)
166 {
167  struct SPIFFSLogData<T> data;
168  data.timestampUTC = time(nullptr);
169  data.data = value;
170 
171  File f = SPIFFS.open(this->_curPath, "a");
172  f.write((uint8_t *)&data, sizeof(data));
173  f.close();
174 }
175 
176 template <class T>
177 size_t SPIFFSLogger<T>::readRows(SPIFFSLogData<T> *output, time_t date, size_t startIdx, size_t maxCount)
178 {
179  char path[32];
180  this->_pathFromDate(path, date);
181 
182  if (!SPIFFS.exists(path))
183  return 0;
184 
185  File f = SPIFFS.open(path, "r");
186  maxCount = min(maxCount, f.size() / sizeof(SPIFFSLogData<T>) - startIdx);
187  f.seek(startIdx * sizeof(SPIFFSLogData<T>));
188  f.read((uint8_t *)output, maxCount * sizeof(SPIFFSLogData<T>));
189  f.close();
190  return maxCount;
191 }
192 
193 template <class T>
194 size_t SPIFFSLogger<T>::rowCount(time_t date)
195 {
196  char path[32];
197  this->_pathFromDate(path, date);
198 
199  if (!SPIFFS.exists(path))
200  return 0;
201 
202  File f = SPIFFS.open(path, "r");
203  const size_t rows = f.size() / sizeof(SPIFFSLogData<T>);
204  f.close();
205 
206  return rows;
207 }
208 
209 template <class T>
210 void SPIFFSLogger<T>::_pathFromDate(char *output, time_t date)
211 {
212  if (date <= 0)
213  date = this->_today;
214 
215  struct tm *tinfo = gmtime(&date);
216  sprintf_P(output,
217  _logFilenameFormat,
218  this->_directory,
219  1900 + tinfo->tm_year,
220  tinfo->tm_mon + 1,
221  tinfo->tm_mday);
222 }
223 
224 template <class T>
226 {
227  SPIFFSLogger::_pathFromDate(this->_curPath, this->_today);
228 }
229 
230 template <class T>
232 {
233  const uint8_t dirLen = strlen(this->_directory);
234  Dir tempDir = SPIFFS.openDir(this->_directory);
235 
236  char datePart[5] = {0};
237  while (tempDir.next())
238  {
239  struct tm tm = {0};
240  const char *dateStart = tempDir.fileName().c_str() + dirLen + 1;
241 
242  strncpy(datePart, dateStart, 4);
243  tm.tm_year = atoi(datePart) - 1900;
244 
245  strncpy(datePart, dateStart + 4, 2);
246  datePart[2] = '\0';
247  tm.tm_mon = atoi(datePart) - 1;
248 
249  strncpy(datePart, dateStart + 6, 2);
250  tm.tm_mday = atoi(datePart);
251 
252  const time_t midnight = SPIFFSLogger::_timegm(&tm) / 86400 * 86400;
253 
254  // check if file is too old and, if so, delete it
255  if (midnight < (this->_today - this->_daysToKeep * 86400))
256  SPIFFS.remove(tempDir.fileName());
257  }
258 }
259 
260 template <class T>
261 time_t SPIFFSLogger<T>::_timegm(struct tm *tm)
262 {
263  struct tm start2000 = {
264  0, // tm_sec
265  0, // tm_min
266  0, // tm_hour
267  1, // tm_mday
268  0, // tm_mon
269  100, // tm_year
270  0, // tm_wday
271  0, // tm_yday
272  0, // tm_isdst
273  };
274 
275  return mktime(tm) - (mktime(&start2000) - 946684800);
276 }
277 
278 #endif // __SPIFFSLOGGER_H__
void _pathFromDate(char *output, time_t date)
Converts a time_t to that day&#39;s file path.
Definition: SPIFFSLogger.h:210
-
Minimal class template for binary data logging in ESP8266 SPIFFS.
Definition: SPIFFSLogger.h:51
-
size_t write(const T &value)
Write the specified value to the end of the current log file, with the current timestamp.
Definition: SPIFFSLogger.h:165
-
T data
data of type T
Definition: SPIFFSLogger.h:38
-
void _updateCurPath()
Updates the current path to match today&#39;s date.
Definition: SPIFFSLogger.h:225
-
void init()
Initialize the logger.
Definition: SPIFFSLogger.h:139
-
void process()
Process the file rotation and other required operations according to the defined processInterval.
Definition: SPIFFSLogger.h:145
-
size_t rowCount(time_t date)
Get the number of entries for the specified date.
Definition: SPIFFSLogger.h:194
-
const uint16_t _daysToKeep
number of days to keep logs for
Definition: SPIFFSLogger.h:105
-
bool _processNow
force processing now, even if the processing interval hasn&#39;t passed
Definition: SPIFFSLogger.h:106
-
time_t _today
current date, set in the last processing run
Definition: SPIFFSLogger.h:102
-
Represents a data element as stored in SPIFFS, along with the creation timestamp. ...
Definition: SPIFFSLogger.h:35
-
static time_t _timegm(struct tm *tm)
Simple timegm function, since one is not available in the ESP libs.
Definition: SPIFFSLogger.h:261
-
time_t timestampUTC
creation time in UTC
Definition: SPIFFSLogger.h:37
-
SPIFFSLogger(const char *directory, uint16_t daysToKeep=7, uint16_t processInterval=1000)
Default constructor for SPIFFSLogger.
Definition: SPIFFSLogger.h:132
-
void _runRotation()
Deletes files older than the defined age limit.
Definition: SPIFFSLogger.h:231
-
char _curPath[32]
path for today&#39;s file
Definition: SPIFFSLogger.h:108
-
char _directory[21]
base directory for log files
Definition: SPIFFSLogger.h:107
-
const uint16_t _processInterval
ms between processing runs
Definition: SPIFFSLogger.h:104
-
size_t readRows(SPIFFSLogData< T > *output, time_t date, size_t startIdx, size_t maxCount)
Read data from a daily logfile into a buffer.
Definition: SPIFFSLogger.h:177
-
unsigned long _lastProcess
last processing millis()
Definition: SPIFFSLogger.h:103
+Go to the documentation of this file.
1 /*
2 SPIFFSLogger - A minimal library for binary data logging in ESP8266
3 Copyright (C) 2018 Mario Falcao
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef __SPIFFSLOGGER_H__
20 #define __SPIFFSLOGGER_H__
21 
22 #include "SPIFFSLoggerBase.h"
23 
29 template <class T>
31 {
32  time_t timestampUTC;
33  T data;
34 };
35 
45 template <class T>
47 {
48  public:
57  SPIFFSLogger(const char *directory, uint16_t daysToKeep = 7, uint16_t processInterval = 1000);
58 
64  size_t write(const T &value);
65 
75  size_t readRows(SPIFFSLogData<T> *output, time_t date, size_t startIdx, size_t maxCount);
76 
77  size_t readRowsBetween(SPIFFSLogData<T> *output, time_t fromTime, time_t toTime, size_t startIdx, size_t maxCount);
78 
85  size_t rowCount(time_t date);
86 };
87 
88 template <class T>
89 SPIFFSLogger<T>::SPIFFSLogger(const char *directory, uint16_t daysToKeep, uint16_t processInterval)
90  : SPIFFSLoggerBase(directory, daysToKeep, processInterval)
91 {
92 }
93 
94 template <class T>
95 size_t SPIFFSLogger<T>::write(const T &value)
96 {
97  struct SPIFFSLogData<T> data;
98  data.timestampUTC = time(nullptr);
99  data.data = value;
100 
101  File f = SPIFFS.open(this->_curPath, "a");
102  f.write((uint8_t *)&data, sizeof(data));
103  f.close();
104 }
105 
106 template <class T>
107 size_t SPIFFSLogger<T>::readRows(SPIFFSLogData<T> *output, time_t date, size_t startIdx, size_t maxCount)
108 {
109  char path[32];
110  this->_pathFromDate(path, date);
111 
112  if (!SPIFFS.exists(path))
113  return 0;
114 
115  File f = SPIFFS.open(path, "r");
116  maxCount = min((int32_t)maxCount, (int32_t)(f.size() / sizeof(SPIFFSLogData<T>)) - (int32_t)startIdx);
117  if (maxCount <= 0)
118  return maxCount;
119 
120  f.seek(startIdx * sizeof(SPIFFSLogData<T>));
121  f.read((uint8_t *)output, maxCount * sizeof(SPIFFSLogData<T>));
122  f.close();
123  return maxCount;
124 }
125 
126 template <class T>
127 size_t SPIFFSLogger<T>::rowCount(time_t date)
128 {
129  char path[32];
130  this->_pathFromDate(path, date);
131 
132  if (!SPIFFS.exists(path))
133  return 0;
134 
135  File f = SPIFFS.open(path, "r");
136  const size_t rows = f.size() / sizeof(SPIFFSLogData<T>);
137  f.close();
138 
139  return rows;
140 }
141 
142 #endif // __SPIFFSLOGGER_H__
Minimal class template for binary data logging in ESP8266 SPIFFS.
Definition: SPIFFSLogger.h:46
+
size_t write(const T &value)
Write the specified value to the end of the current log file, with the current timestamp.
Definition: SPIFFSLogger.h:95
+
T data
data of type T
Definition: SPIFFSLogger.h:33
+
Base class for the SPIFFSLogger template, implementing common methods.
Definition: SPIFFSLoggerBase.h:29
+
size_t readRowsBetween(SPIFFSLogData< T > *output, time_t fromTime, time_t toTime, size_t startIdx, size_t maxCount)
+
size_t rowCount(time_t date)
Get the number of entries for the specified date.
Definition: SPIFFSLogger.h:127
+ +
Represents a data element as stored in SPIFFS, along with the creation timestamp. ...
Definition: SPIFFSLogger.h:30
+
time_t timestampUTC
creation time in UTC
Definition: SPIFFSLogger.h:32
+
SPIFFSLogger(const char *directory, uint16_t daysToKeep=7, uint16_t processInterval=1000)
Default constructor for SPIFFSLogger.
Definition: SPIFFSLogger.h:89
+
size_t readRows(SPIFFSLogData< T > *output, time_t date, size_t startIdx, size_t maxCount)
Read data from a daily logfile into a buffer.
Definition: SPIFFSLogger.h:107
diff --git a/extras/docs/html/_s_p_i_f_f_s_logger_base_8cpp.html b/extras/docs/html/_s_p_i_f_f_s_logger_base_8cpp.html new file mode 100644 index 0000000..ffc1068 --- /dev/null +++ b/extras/docs/html/_s_p_i_f_f_s_logger_base_8cpp.html @@ -0,0 +1,107 @@ + + + + + + + +SPIFFSLogger: src/SPIFFSLoggerBase.cpp File Reference + + + + + + + + + + + +
+
+
SPIFFSLogger -  v0.1.0 +  v0.1.1
A minimal library for binary data logging in ESP8266
+ + + + + +
+
SPIFFSLogger +  v0.1.1 +
+
A minimal library for binary data logging in ESP8266
+
+
+ + + + + + +
+
+ +
+
+
+ +
+
+ +
+
SPIFFSLoggerBase.cpp File Reference
+
+
+
#include "SPIFFSLoggerBase.h"
+
+ + + +

+Variables

const char _logFilenameFormat [] PROGMEM = "%s/%d%02d%02d"
 
+

Variable Documentation

+ +

◆ PROGMEM

+ +
+
+ + + + +
const char _logFilenameFormat [] PROGMEM = "%s/%d%02d%02d"
+
+ +
+
+
+
+ + + + diff --git a/extras/docs/html/_s_p_i_f_f_s_logger_base_8cpp.js b/extras/docs/html/_s_p_i_f_f_s_logger_base_8cpp.js new file mode 100644 index 0000000..39c6513 --- /dev/null +++ b/extras/docs/html/_s_p_i_f_f_s_logger_base_8cpp.js @@ -0,0 +1,4 @@ +var _s_p_i_f_f_s_logger_base_8cpp = +[ + [ "PROGMEM", "_s_p_i_f_f_s_logger_base_8cpp.html#af70a7c4bf0e665786ae633f14c7b351f", null ] +]; \ No newline at end of file diff --git a/extras/docs/html/_s_p_i_f_f_s_logger_base_8h.html b/extras/docs/html/_s_p_i_f_f_s_logger_base_8h.html new file mode 100644 index 0000000..d7fbb29 --- /dev/null +++ b/extras/docs/html/_s_p_i_f_f_s_logger_base_8h.html @@ -0,0 +1,97 @@ + + + + + + + +SPIFFSLogger: src/SPIFFSLoggerBase.h File Reference + + + + + + + + + + + +
+
+ + + + + + +
+
SPIFFSLogger +  v0.1.1 +
+
A minimal library for binary data logging in ESP8266
+
+
+ + + + + + +
+
+ +
+
+
+ +
+
+ +
+
SPIFFSLoggerBase.h File Reference
+
+
+
#include <Arduino.h>
+#include <FS.h>
+#include <time.h>
+
+

Go to the source code of this file.

+ + + + + +

+Classes

class  SPIFFSLoggerBase
 Base class for the SPIFFSLogger template, implementing common methods. More...
 
+
+
+ + + + diff --git a/extras/docs/html/_s_p_i_f_f_s_logger_base_8h_source.html b/extras/docs/html/_s_p_i_f_f_s_logger_base_8h_source.html new file mode 100644 index 0000000..3a28440 --- /dev/null +++ b/extras/docs/html/_s_p_i_f_f_s_logger_base_8h_source.html @@ -0,0 +1,99 @@ + + + + + + + +SPIFFSLogger: src/SPIFFSLoggerBase.h Source File + + + + + + + + + + + +
+
+ + + + + + +
+
SPIFFSLogger +  v0.1.1 +
+
A minimal library for binary data logging in ESP8266
+
+
+ + + + + + +
+
+ +
+
+
+ +
+
+
+
SPIFFSLoggerBase.h
+
+
+Go to the documentation of this file.
1 /*
2 SPIFFSLogger - A minimal library for binary data logging in ESP8266
3 Copyright (C) 2018 Mario Falcao
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef __SPIFFSLOGGERBASE_H__
20 #define __SPIFFSLOGGERBASE_H__
21 
22 #include <Arduino.h>
23 #include <FS.h>
24 #include <time.h>
25 
30 {
31  public:
35  void init();
36 
41  void process();
42 
43  protected:
44  time_t _today = 0;
45  unsigned long _lastProcess = 0;
46  const uint16_t _processInterval;
47  const uint16_t _daysToKeep;
48  bool _processNow = true;
49  char _directory[21];
50  char _curPath[32];
52  SPIFFSLoggerBase(const char *directory, uint16_t daysToKeep, uint16_t processInterval);
53 
57  void _pathFromDate(char *output, time_t date);
58 
62  void _updateCurPath();
63 
67  void _runRotation();
68 
72  static time_t _filenameToDate(const char *filename);
73 
77  static time_t _timegm(struct tm *tm);
78 };
79 
80 #endif // __SPIFFSLOGGERBASE_H__
char _curPath[32]
path for today&#39;s file
Definition: SPIFFSLoggerBase.h:50
+
Base class for the SPIFFSLogger template, implementing common methods.
Definition: SPIFFSLoggerBase.h:29
+
char _directory[21]
base directory for log files
Definition: SPIFFSLoggerBase.h:49
+
bool _processNow
force processing now, even if the processing interval hasn&#39;t passed
Definition: SPIFFSLoggerBase.h:48
+
static time_t _filenameToDate(const char *filename)
Converts a filename in YYYYMMDD format to a time_t.
Definition: SPIFFSLoggerBase.cpp:71
+
void init()
Initialize the logger.
Definition: SPIFFSLoggerBase.cpp:12
+
static time_t _timegm(struct tm *tm)
Simple timegm function, since one is not available in the ESP libs.
Definition: SPIFFSLoggerBase.cpp:89
+
void _updateCurPath()
Updates the current path to match today&#39;s date.
Definition: SPIFFSLoggerBase.cpp:50
+
const uint16_t _processInterval
ms between processing runs
Definition: SPIFFSLoggerBase.h:46
+
const uint16_t _daysToKeep
number of days to keep logs for
Definition: SPIFFSLoggerBase.h:47
+
void _runRotation()
Deletes files older than the defined age limit.
Definition: SPIFFSLoggerBase.cpp:55
+
unsigned long _lastProcess
last processing millis()
Definition: SPIFFSLoggerBase.h:45
+
SPIFFSLoggerBase(const char *directory, uint16_t daysToKeep, uint16_t processInterval)
Definition: SPIFFSLoggerBase.cpp:6
+
void process()
Process the file rotation and other required operations according to the defined processInterval.
Definition: SPIFFSLoggerBase.cpp:17
+
time_t _today
current date, set in the last processing run
Definition: SPIFFSLoggerBase.h:44
+
void _pathFromDate(char *output, time_t date)
Converts a time_t to that day&#39;s file path.
Definition: SPIFFSLoggerBase.cpp:36
+
+
+ + + + diff --git a/extras/docs/html/annotated.html b/extras/docs/html/annotated.html index 25de67c..26a7416 100644 --- a/extras/docs/html/annotated.html +++ b/extras/docs/html/annotated.html @@ -27,7 +27,7 @@
SPIFFSLogger -  v0.1.0 +  v0.1.1
A minimal library for binary data logging in ESP8266
@@ -72,6 +72,7 @@ +
 CSPIFFSLogDataRepresents a data element as stored in SPIFFS, along with the creation timestamp
 CSPIFFSLoggerMinimal class template for binary data logging in ESP8266 SPIFFS
 CSPIFFSLoggerBaseBase class for the SPIFFSLogger template, implementing common methods
diff --git a/extras/docs/html/annotated_dup.js b/extras/docs/html/annotated_dup.js index 7c94be6..be73a4d 100644 --- a/extras/docs/html/annotated_dup.js +++ b/extras/docs/html/annotated_dup.js @@ -1,5 +1,6 @@ var annotated_dup = [ [ "SPIFFSLogData", "struct_s_p_i_f_f_s_log_data.html", "struct_s_p_i_f_f_s_log_data" ], - [ "SPIFFSLogger", "class_s_p_i_f_f_s_logger.html", "class_s_p_i_f_f_s_logger" ] + [ "SPIFFSLogger", "class_s_p_i_f_f_s_logger.html", "class_s_p_i_f_f_s_logger" ], + [ "SPIFFSLoggerBase", "class_s_p_i_f_f_s_logger_base.html", "class_s_p_i_f_f_s_logger_base" ] ]; \ No newline at end of file diff --git a/extras/docs/html/class_s_p_i_f_f_s_logger-members.html b/extras/docs/html/class_s_p_i_f_f_s_logger-members.html index df7f241..9e9fc04 100644 --- a/extras/docs/html/class_s_p_i_f_f_s_logger-members.html +++ b/extras/docs/html/class_s_p_i_f_f_s_logger-members.html @@ -27,7 +27,7 @@
SPIFFSLogger -  v0.1.0 +  v0.1.1
A minimal library for binary data logging in ESP8266
@@ -71,23 +71,26 @@

This is the complete list of members for SPIFFSLogger< T >, including all inherited members.

- - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - + +
_curPathSPIFFSLogger< T >protected
_daysToKeepSPIFFSLogger< T >protected
_directorySPIFFSLogger< T >protected
_lastProcessSPIFFSLogger< T >protected
_pathFromDate(char *output, time_t date)SPIFFSLogger< T >protected
_processIntervalSPIFFSLogger< T >protected
_processNowSPIFFSLogger< T >protected
_runRotation()SPIFFSLogger< T >protected
_timegm(struct tm *tm)SPIFFSLogger< T >protectedstatic
_todaySPIFFSLogger< T >protected
_updateCurPath()SPIFFSLogger< T >protected
init()SPIFFSLogger< T >
process()SPIFFSLogger< T >
readRows(SPIFFSLogData< T > *output, time_t date, size_t startIdx, size_t maxCount)SPIFFSLogger< T >
_curPathSPIFFSLoggerBaseprotected
_daysToKeepSPIFFSLoggerBaseprotected
_directorySPIFFSLoggerBaseprotected
_filenameToDate(const char *filename)SPIFFSLoggerBaseprotectedstatic
_lastProcessSPIFFSLoggerBaseprotected
_pathFromDate(char *output, time_t date)SPIFFSLoggerBaseprotected
_processIntervalSPIFFSLoggerBaseprotected
_processNowSPIFFSLoggerBaseprotected
_runRotation()SPIFFSLoggerBaseprotected
_timegm(struct tm *tm)SPIFFSLoggerBaseprotectedstatic
_todaySPIFFSLoggerBaseprotected
_updateCurPath()SPIFFSLoggerBaseprotected
init()SPIFFSLoggerBase
process()SPIFFSLoggerBase
readRows(SPIFFSLogData< T > *output, time_t date, size_t startIdx, size_t maxCount)SPIFFSLogger< T >
readRowsBetween(SPIFFSLogData< T > *output, time_t fromTime, time_t toTime, size_t startIdx, size_t maxCount)SPIFFSLogger< T >
rowCount(time_t date)SPIFFSLogger< T >
SPIFFSLogger(const char *directory, uint16_t daysToKeep=7, uint16_t processInterval=1000)SPIFFSLogger< T >
write(const T &value)SPIFFSLogger< T >
SPIFFSLoggerBase(const char *directory, uint16_t daysToKeep, uint16_t processInterval)SPIFFSLoggerBaseprotected
write(const T &value)SPIFFSLogger< T >
diff --git a/extras/docs/html/class_s_p_i_f_f_s_logger.html b/extras/docs/html/class_s_p_i_f_f_s_logger.html index f1ed090..1ec398c 100644 --- a/extras/docs/html/class_s_p_i_f_f_s_logger.html +++ b/extras/docs/html/class_s_p_i_f_f_s_logger.html @@ -27,7 +27,7 @@
SPIFFSLogger -  v0.1.0 +  v0.1.1
A minimal library for binary data logging in ESP8266
@@ -79,69 +79,76 @@ More...

#include <SPIFFSLogger.h>

+ +

Inherits SPIFFSLoggerBase.

- - - - - - + + + + + + + +

Public Member Functions

 SPIFFSLogger (const char *directory, uint16_t daysToKeep=7, uint16_t processInterval=1000)
 Default constructor for SPIFFSLogger. More...
 
void init ()
 Initialize the logger. More...
 
void process ()
 Process the file rotation and other required operations according to the defined processInterval. More...
 
size_t write (const T &value)
 Write the specified value to the end of the current log file, with the current timestamp. More...
 
size_t readRows (SPIFFSLogData< T > *output, time_t date, size_t startIdx, size_t maxCount)
 Read data from a daily logfile into a buffer. More...
 
size_t readRowsBetween (SPIFFSLogData< T > *output, time_t fromTime, time_t toTime, size_t startIdx, size_t maxCount)
 
size_t rowCount (time_t date)
 Get the number of entries for the specified date. More...
 
void init ()
 Initialize the logger. More...
 
void process ()
 Process the file rotation and other required operations according to the defined processInterval. More...
 
- - - - - - - - - + + + + + + + + +

Protected Member Functions

void _pathFromDate (char *output, time_t date)
 Converts a time_t to that day's file path. More...
 
void _updateCurPath ()
 Updates the current path to match today's date. More...
 
void _runRotation ()
 Deletes files older than the defined age limit. More...
 
void _pathFromDate (char *output, time_t date)
 Converts a time_t to that day's file path. More...
 
void _updateCurPath ()
 Updates the current path to match today's date. More...
 
void _runRotation ()
 Deletes files older than the defined age limit. More...
 
- - - + + + + + +

Static Protected Member Functions

static time_t _timegm (struct tm *tm)
 Simple timegm function, since one is not available in the ESP libs. More...
 
static time_t _filenameToDate (const char *filename)
 Converts a filename in YYYYMMDD format to a time_t. More...
 
static time_t _timegm (struct tm *tm)
 Simple timegm function, since one is not available in the ESP libs. More...
 
- - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + +

Protected Attributes

time_t _today = 0
 current date, set in the last processing run More...
 
unsigned long _lastProcess = 0
 last processing millis() More...
 
const uint16_t _processInterval
 ms between processing runs More...
 
const uint16_t _daysToKeep
 number of days to keep logs for More...
 
bool _processNow = true
 force processing now, even if the processing interval hasn't passed More...
 
char _directory [21]
 base directory for log files More...
 
char _curPath [32]
 path for today's file More...
 
time_t _today = 0
 current date, set in the last processing run More...
 
unsigned long _lastProcess = 0
 last processing millis() More...
 
const uint16_t _processInterval
 ms between processing runs More...
 
const uint16_t _daysToKeep
 number of days to keep logs for More...
 
bool _processNow = true
 force processing now, even if the processing interval hasn't passed More...
 
char _directory [21]
 base directory for log files More...
 
char _curPath [32]
 path for today's file More...
 

Detailed Description

template<class T>
@@ -203,19 +210,45 @@

Member Function Documentation

- -

◆ _pathFromDate()

+ +

◆ _filenameToDate()

-
-template<class T >
+ + +
- + + + + + + +
void SPIFFSLogger< T >::_pathFromDate time_t SPIFFSLoggerBase::_filenameToDate (const char * filename)
+
+staticprotectedinherited
+
+ +

Converts a filename in YYYYMMDD format to a time_t.

+ +
+
+ +

◆ _pathFromDate()

+ +
+
+ + + @@ -66,56 +66,65 @@
Here is a list of all class members with links to the classes they belong to:
@@ -65,33 +65,42 @@
 
@@ -66,25 +66,25 @@
 
+ + + @@ -234,7 +267,7 @@

-protected +protectedinherited

void SPIFFSLoggerBase::_pathFromDate ( char *  output,
@@ -243,19 +276,17 @@

-

◆ _runRotation()

+ +

◆ _runRotation()

-
-template<class T >
@@ -72,6 +72,8 @@
[detail level 12]
- + @@ -263,7 +294,7 @@

-protected +protectedinherited

void SPIFFSLogger< T >::_runRotation void SPIFFSLoggerBase::_runRotation ( )
@@ -272,19 +303,17 @@

-

◆ _timegm()

+ +

◆ _timegm()

-
-template<class T >
@@ -73,6 +73,10 @@ Files + + + +
- + @@ -293,7 +322,7 @@

-staticprotected +staticprotectedinherited

time_t SPIFFSLogger< T >::_timegm time_t SPIFFSLoggerBase::_timegm ( struct tm *  tm)
@@ -302,19 +331,17 @@

-

◆ _updateCurPath()

+ +

◆ _updateCurPath()

-
-template<class T >
@@ -71,10 +71,10 @@
- + @@ -322,7 +349,7 @@

-protected +protectedinherited

void SPIFFSLogger< T >::_updateCurPath void SPIFFSLoggerBase::_updateCurPath ( )
@@ -331,21 +358,27 @@

-

◆ init()

+ +

◆ init()

-
-template<class T >
+ + + + + +
- +
void SPIFFSLogger< T >::init void SPIFFSLoggerBase::init ( )
+
+inherited

Initialize the logger.

@@ -353,21 +386,27 @@

-

◆ process()

+ +

◆ process()

-
-template<class T >
+ + + + + +
- +
void SPIFFSLogger< T >::process void SPIFFSLoggerBase::process ( )
+
+inherited

Process the file rotation and other required operations according to the defined processInterval.

@@ -427,6 +466,54 @@

Returns
number of entries read
+

+
+ +

◆ readRowsBetween()

+ +
+
+
+template<class T >
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
size_t SPIFFSLogger< T >::readRowsBetween (SPIFFSLogData< T > * output,
time_t fromTime,
time_t toTime,
size_t startIdx,
size_t maxCount 
)
+
+
@@ -487,24 +574,22 @@

Member Data Documentation

- -

◆ _curPath

+ +

◆ _curPath

-
-template<class T >
+protectedinherited
- +
char SPIFFSLogger< T >::_curPath[32]char SPIFFSLoggerBase::_curPath[32]
-protected
@@ -513,24 +598,22 @@

-

◆ _daysToKeep

+ +

◆ _daysToKeep

-
-template<class T >
+protectedinherited
- +
const uint16_t SPIFFSLogger< T >::_daysToKeepconst uint16_t SPIFFSLoggerBase::_daysToKeep
-protected
@@ -539,24 +622,22 @@

-

◆ _directory

+ +

◆ _directory

-
-template<class T >
+protectedinherited
- +
char SPIFFSLogger< T >::_directory[21]char SPIFFSLoggerBase::_directory[21]
-protected
@@ -565,24 +646,22 @@

-

◆ _lastProcess

+ +

◆ _lastProcess

-
-template<class T >
+protectedinherited
- +
unsigned long SPIFFSLogger< T >::_lastProcess = 0unsigned long SPIFFSLoggerBase::_lastProcess = 0
-protected
@@ -591,24 +670,22 @@

-

◆ _processInterval

+ +

◆ _processInterval

-
-template<class T >
+protectedinherited
- +
const uint16_t SPIFFSLogger< T >::_processIntervalconst uint16_t SPIFFSLoggerBase::_processInterval
-protected
@@ -617,24 +694,22 @@

-

◆ _processNow

+ +

◆ _processNow

-
-template<class T >
+protectedinherited
- +
bool SPIFFSLogger< T >::_processNow = truebool SPIFFSLoggerBase::_processNow = true
-protected
@@ -643,24 +718,22 @@

-

◆ _today

+ +

◆ _today

-
-template<class T >
+protectedinherited
- +
time_t SPIFFSLogger< T >::_today = 0time_t SPIFFSLoggerBase::_today = 0
-protected
diff --git a/extras/docs/html/class_s_p_i_f_f_s_logger.js b/extras/docs/html/class_s_p_i_f_f_s_logger.js index bf3d8a8..1dc6e53 100644 --- a/extras/docs/html/class_s_p_i_f_f_s_logger.js +++ b/extras/docs/html/class_s_p_i_f_f_s_logger.js @@ -1,19 +1,20 @@ var class_s_p_i_f_f_s_logger = [ [ "SPIFFSLogger", "class_s_p_i_f_f_s_logger.html#afa8152a5d5d29fedbb04265cb4589359", null ], - [ "_pathFromDate", "class_s_p_i_f_f_s_logger.html#ad366d57e6ca7b721b27164e40fb342b3", null ], - [ "_runRotation", "class_s_p_i_f_f_s_logger.html#afbb2b0583a0500e3e5eae006a6740992", null ], - [ "_updateCurPath", "class_s_p_i_f_f_s_logger.html#ae6edbf5e924957c107068fce73554737", null ], - [ "init", "class_s_p_i_f_f_s_logger.html#abfc7ce5e1a8022705c6704e50edf087d", null ], - [ "process", "class_s_p_i_f_f_s_logger.html#a34f24a3c6229653a31c166b899d43537", null ], + [ "_pathFromDate", "class_s_p_i_f_f_s_logger.html#abfba26125f8b32b4c8e2e3d29d65b31f", null ], + [ "_runRotation", "class_s_p_i_f_f_s_logger.html#a2e9e45428e1ffbe989dd7679c5def4fe", null ], + [ "_updateCurPath", "class_s_p_i_f_f_s_logger.html#aa5679e47e144e591b5fa90fb31b65cbd", null ], + [ "init", "class_s_p_i_f_f_s_logger.html#ad2270960852a999b0340fa4eab50f063", null ], + [ "process", "class_s_p_i_f_f_s_logger.html#a22fdd2b540717853ae403edbc0ed1b7f", null ], [ "readRows", "class_s_p_i_f_f_s_logger.html#aeceb2db3a41feb387e874f247657e19c", null ], + [ "readRowsBetween", "class_s_p_i_f_f_s_logger.html#a8d82d01f694528becba720e0612dc48d", null ], [ "rowCount", "class_s_p_i_f_f_s_logger.html#ac539407d1bfebe9443393ea2e4047e29", null ], [ "write", "class_s_p_i_f_f_s_logger.html#a2e914dd1884de9900288564a41bc55a4", null ], - [ "_curPath", "class_s_p_i_f_f_s_logger.html#af6c68f5bf3ceccde605a89cb929bb787", null ], - [ "_daysToKeep", "class_s_p_i_f_f_s_logger.html#afa47e4215bf7dc8a27704e5c10324fa8", null ], - [ "_directory", "class_s_p_i_f_f_s_logger.html#a294e4b04bb7d26c6d63d4168d574221a", null ], - [ "_lastProcess", "class_s_p_i_f_f_s_logger.html#ad48c3983258885410e6b7d0a299e8e69", null ], - [ "_processInterval", "class_s_p_i_f_f_s_logger.html#a42017253e85b5f4978e4ba778960a62d", null ], - [ "_processNow", "class_s_p_i_f_f_s_logger.html#af6227914a7bd060a26b5f83fa5641665", null ], - [ "_today", "class_s_p_i_f_f_s_logger.html#a0a83d73217bc8bada843092ae7d055e8", null ] + [ "_curPath", "class_s_p_i_f_f_s_logger.html#a7f79553c53c7b5b6c87aaaa104d5a1e3", null ], + [ "_daysToKeep", "class_s_p_i_f_f_s_logger.html#a8feb62f012879aca79d600cf217c2098", null ], + [ "_directory", "class_s_p_i_f_f_s_logger.html#a829da5d8bf3d83ed24e608bb60fc623c", null ], + [ "_lastProcess", "class_s_p_i_f_f_s_logger.html#ac1b33a4c97b2a45b2b178a261ebbb12c", null ], + [ "_processInterval", "class_s_p_i_f_f_s_logger.html#a517fa4d3854283ba7b2dba9bf0d09c84", null ], + [ "_processNow", "class_s_p_i_f_f_s_logger.html#a978f0a636ce4d7a7f1640df124cc25ff", null ], + [ "_today", "class_s_p_i_f_f_s_logger.html#a77a967ae68a680dea5a647200ba49815", null ] ]; \ No newline at end of file diff --git a/extras/docs/html/class_s_p_i_f_f_s_logger_base-members.html b/extras/docs/html/class_s_p_i_f_f_s_logger_base-members.html new file mode 100644 index 0000000..a841034 --- /dev/null +++ b/extras/docs/html/class_s_p_i_f_f_s_logger_base-members.html @@ -0,0 +1,100 @@ + + + + + + + +SPIFFSLogger: Member List + + + + + + + + + + + +
+
+ + + + + + +
+
SPIFFSLogger +  v0.1.1 +
+
A minimal library for binary data logging in ESP8266
+
+
+ + + + + + +
+
+ +
+
+
+ +
+
+
+
SPIFFSLoggerBase Member List
+
+
+ +

This is the complete list of members for SPIFFSLoggerBase, including all inherited members.

+ + + + + + + + + + + + + + + + +
_curPathSPIFFSLoggerBaseprotected
_daysToKeepSPIFFSLoggerBaseprotected
_directorySPIFFSLoggerBaseprotected
_filenameToDate(const char *filename)SPIFFSLoggerBaseprotectedstatic
_lastProcessSPIFFSLoggerBaseprotected
_pathFromDate(char *output, time_t date)SPIFFSLoggerBaseprotected
_processIntervalSPIFFSLoggerBaseprotected
_processNowSPIFFSLoggerBaseprotected
_runRotation()SPIFFSLoggerBaseprotected
_timegm(struct tm *tm)SPIFFSLoggerBaseprotectedstatic
_todaySPIFFSLoggerBaseprotected
_updateCurPath()SPIFFSLoggerBaseprotected
init()SPIFFSLoggerBase
process()SPIFFSLoggerBase
SPIFFSLoggerBase(const char *directory, uint16_t daysToKeep, uint16_t processInterval)SPIFFSLoggerBaseprotected
+
+ + + + diff --git a/extras/docs/html/class_s_p_i_f_f_s_logger_base.html b/extras/docs/html/class_s_p_i_f_f_s_logger_base.html new file mode 100644 index 0000000..0a357fe --- /dev/null +++ b/extras/docs/html/class_s_p_i_f_f_s_logger_base.html @@ -0,0 +1,561 @@ + + + + + + + +SPIFFSLogger: SPIFFSLoggerBase Class Reference + + + + + + + + + + + +
+
+ + + + + + +
+
SPIFFSLogger +  v0.1.1 +
+
A minimal library for binary data logging in ESP8266
+
+
+ + + + + + +
+
+ +
+
+
+ +
+ +
+ +

Base class for the SPIFFSLogger template, implementing common methods. + More...

+ +

#include <SPIFFSLoggerBase.h>

+ +

Inherited by SPIFFSLogger< T >.

+ + + + + + + + +

+Public Member Functions

void init ()
 Initialize the logger. More...
 
void process ()
 Process the file rotation and other required operations according to the defined processInterval. More...
 
+ + + + + + + + + + + + +

+Protected Member Functions

 SPIFFSLoggerBase (const char *directory, uint16_t daysToKeep, uint16_t processInterval)
 
void _pathFromDate (char *output, time_t date)
 Converts a time_t to that day's file path. More...
 
void _updateCurPath ()
 Updates the current path to match today's date. More...
 
void _runRotation ()
 Deletes files older than the defined age limit. More...
 
+ + + + + + + +

+Static Protected Member Functions

static time_t _filenameToDate (const char *filename)
 Converts a filename in YYYYMMDD format to a time_t. More...
 
static time_t _timegm (struct tm *tm)
 Simple timegm function, since one is not available in the ESP libs. More...
 
+ + + + + + + + + + + + + + + + + + + + + + +

+Protected Attributes

time_t _today = 0
 current date, set in the last processing run More...
 
unsigned long _lastProcess = 0
 last processing millis() More...
 
const uint16_t _processInterval
 ms between processing runs More...
 
const uint16_t _daysToKeep
 number of days to keep logs for More...
 
bool _processNow = true
 force processing now, even if the processing interval hasn't passed More...
 
char _directory [21]
 base directory for log files More...
 
char _curPath [32]
 path for today's file More...
 
+

Detailed Description

+

Base class for the SPIFFSLogger template, implementing common methods.

+

Should not be used directly.

+

Constructor & Destructor Documentation

+ +

◆ SPIFFSLoggerBase()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
SPIFFSLoggerBase::SPIFFSLoggerBase (const char * directory,
uint16_t daysToKeep,
uint16_t processInterval 
)
+
+protected
+
+ +
+
+

Member Function Documentation

+ +

◆ _filenameToDate()

+ +
+
+ + + + + +
+ + + + + + + + +
time_t SPIFFSLoggerBase::_filenameToDate (const char * filename)
+
+staticprotected
+
+ +

Converts a filename in YYYYMMDD format to a time_t.

+ +
+
+ +

◆ _pathFromDate()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + +
void SPIFFSLoggerBase::_pathFromDate (char * output,
time_t date 
)
+
+protected
+
+ +

Converts a time_t to that day's file path.

+ +
+
+ +

◆ _runRotation()

+ +
+
+ + + + + +
+ + + + + + + +
void SPIFFSLoggerBase::_runRotation ()
+
+protected
+
+ +

Deletes files older than the defined age limit.

+ +
+
+ +

◆ _timegm()

+ +
+
+ + + + + +
+ + + + + + + + +
time_t SPIFFSLoggerBase::_timegm (struct tm * tm)
+
+staticprotected
+
+ +

Simple timegm function, since one is not available in the ESP libs.

+ +
+
+ +

◆ _updateCurPath()

+ +
+
+ + + + + +
+ + + + + + + +
void SPIFFSLoggerBase::_updateCurPath ()
+
+protected
+
+ +

Updates the current path to match today's date.

+ +
+
+ +

◆ init()

+ +
+
+ + + + + + + +
void SPIFFSLoggerBase::init ()
+
+ +

Initialize the logger.

+

Should be called after initializing SPIFFS and before before any other method.

+ +
+
+ +

◆ process()

+ +
+
+ + + + + + + +
void SPIFFSLoggerBase::process ()
+
+ +

Process the file rotation and other required operations according to the defined processInterval.

+

Should be called as often as possible, i.e. in loop().

+ +
+
+

Member Data Documentation

+ +

◆ _curPath

+ +
+
+ + + + + +
+ + + + +
char SPIFFSLoggerBase::_curPath[32]
+
+protected
+
+ +

path for today's file

+ +
+
+ +

◆ _daysToKeep

+ +
+
+ + + + + +
+ + + + +
const uint16_t SPIFFSLoggerBase::_daysToKeep
+
+protected
+
+ +

number of days to keep logs for

+ +
+
+ +

◆ _directory

+ +
+
+ + + + + +
+ + + + +
char SPIFFSLoggerBase::_directory[21]
+
+protected
+
+ +

base directory for log files

+ +
+
+ +

◆ _lastProcess

+ +
+
+ + + + + +
+ + + + +
unsigned long SPIFFSLoggerBase::_lastProcess = 0
+
+protected
+
+ +

last processing millis()

+ +
+
+ +

◆ _processInterval

+ +
+
+ + + + + +
+ + + + +
const uint16_t SPIFFSLoggerBase::_processInterval
+
+protected
+
+ +

ms between processing runs

+ +
+
+ +

◆ _processNow

+ +
+
+ + + + + +
+ + + + +
bool SPIFFSLoggerBase::_processNow = true
+
+protected
+
+ +

force processing now, even if the processing interval hasn't passed

+ +
+
+ +

◆ _today

+ +
+
+ + + + + +
+ + + + +
time_t SPIFFSLoggerBase::_today = 0
+
+protected
+
+ +

current date, set in the last processing run

+ +
+
+
The documentation for this class was generated from the following files: +
+
+ + + + diff --git a/extras/docs/html/class_s_p_i_f_f_s_logger_base.js b/extras/docs/html/class_s_p_i_f_f_s_logger_base.js new file mode 100644 index 0000000..e02969c --- /dev/null +++ b/extras/docs/html/class_s_p_i_f_f_s_logger_base.js @@ -0,0 +1,16 @@ +var class_s_p_i_f_f_s_logger_base = +[ + [ "SPIFFSLoggerBase", "class_s_p_i_f_f_s_logger_base.html#ace02cadd2e608c940728ae9f5242bbcc", null ], + [ "_pathFromDate", "class_s_p_i_f_f_s_logger_base.html#abfba26125f8b32b4c8e2e3d29d65b31f", null ], + [ "_runRotation", "class_s_p_i_f_f_s_logger_base.html#a2e9e45428e1ffbe989dd7679c5def4fe", null ], + [ "_updateCurPath", "class_s_p_i_f_f_s_logger_base.html#aa5679e47e144e591b5fa90fb31b65cbd", null ], + [ "init", "class_s_p_i_f_f_s_logger_base.html#ad2270960852a999b0340fa4eab50f063", null ], + [ "process", "class_s_p_i_f_f_s_logger_base.html#a22fdd2b540717853ae403edbc0ed1b7f", null ], + [ "_curPath", "class_s_p_i_f_f_s_logger_base.html#a7f79553c53c7b5b6c87aaaa104d5a1e3", null ], + [ "_daysToKeep", "class_s_p_i_f_f_s_logger_base.html#a8feb62f012879aca79d600cf217c2098", null ], + [ "_directory", "class_s_p_i_f_f_s_logger_base.html#a829da5d8bf3d83ed24e608bb60fc623c", null ], + [ "_lastProcess", "class_s_p_i_f_f_s_logger_base.html#ac1b33a4c97b2a45b2b178a261ebbb12c", null ], + [ "_processInterval", "class_s_p_i_f_f_s_logger_base.html#a517fa4d3854283ba7b2dba9bf0d09c84", null ], + [ "_processNow", "class_s_p_i_f_f_s_logger_base.html#a978f0a636ce4d7a7f1640df124cc25ff", null ], + [ "_today", "class_s_p_i_f_f_s_logger_base.html#a77a967ae68a680dea5a647200ba49815", null ] +]; \ No newline at end of file diff --git a/extras/docs/html/classes.html b/extras/docs/html/classes.html index 74ef0d0..722df40 100644 --- a/extras/docs/html/classes.html +++ b/extras/docs/html/classes.html @@ -27,7 +27,7 @@

SPIFFSLogger -  v0.1.0 +  v0.1.1
A minimal library for binary data logging in ESP8266
- - + + +
  s  
-
SPIFFSLogger   
SPIFFSLogData   
SPIFFSLogger   SPIFFSLoggerBase   
SPIFFSLogData   
diff --git a/extras/docs/html/dir_68267d1309a1af8e8297ef4c3efbcdba.html b/extras/docs/html/dir_68267d1309a1af8e8297ef4c3efbcdba.html index 95ac1b4..2f61051 100644 --- a/extras/docs/html/dir_68267d1309a1af8e8297ef4c3efbcdba.html +++ b/extras/docs/html/dir_68267d1309a1af8e8297ef4c3efbcdba.html @@ -27,7 +27,7 @@
SPIFFSLogger -  v0.1.0 +  v0.1.1
A minimal library for binary data logging in ESP8266
file  SPIFFSLogger.h [code]
 
file  SPIFFSLoggerBase.cpp
 
file  SPIFFSLoggerBase.h [code]
 
diff --git a/extras/docs/html/dir_68267d1309a1af8e8297ef4c3efbcdba.js b/extras/docs/html/dir_68267d1309a1af8e8297ef4c3efbcdba.js index 49ce28e..2c32a09 100644 --- a/extras/docs/html/dir_68267d1309a1af8e8297ef4c3efbcdba.js +++ b/extras/docs/html/dir_68267d1309a1af8e8297ef4c3efbcdba.js @@ -1,4 +1,11 @@ var dir_68267d1309a1af8e8297ef4c3efbcdba = [ - [ "SPIFFSLogger.h", "_s_p_i_f_f_s_logger_8h.html", "_s_p_i_f_f_s_logger_8h" ] + [ "SPIFFSLogger.h", "_s_p_i_f_f_s_logger_8h.html", [ + [ "SPIFFSLogData", "struct_s_p_i_f_f_s_log_data.html", "struct_s_p_i_f_f_s_log_data" ], + [ "SPIFFSLogger", "class_s_p_i_f_f_s_logger.html", "class_s_p_i_f_f_s_logger" ] + ] ], + [ "SPIFFSLoggerBase.cpp", "_s_p_i_f_f_s_logger_base_8cpp.html", "_s_p_i_f_f_s_logger_base_8cpp" ], + [ "SPIFFSLoggerBase.h", "_s_p_i_f_f_s_logger_base_8h.html", [ + [ "SPIFFSLoggerBase", "class_s_p_i_f_f_s_logger_base.html", "class_s_p_i_f_f_s_logger_base" ] + ] ] ]; \ No newline at end of file diff --git a/extras/docs/html/files.html b/extras/docs/html/files.html index 09d6824..d2fc864 100644 --- a/extras/docs/html/files.html +++ b/extras/docs/html/files.html @@ -27,7 +27,7 @@
SPIFFSLogger -  v0.1.0 +  v0.1.1
A minimal library for binary data logging in ESP8266
+ +
  src
 SPIFFSLogger.h
 SPIFFSLoggerBase.cpp
 SPIFFSLoggerBase.h
diff --git a/extras/docs/html/functions.html b/extras/docs/html/functions.html index 194f45e..0ab92fb 100644 --- a/extras/docs/html/functions.html +++ b/extras/docs/html/functions.html @@ -27,7 +27,7 @@
SPIFFSLogger -  v0.1.0 +  v0.1.1
A minimal library for binary data logging in ESP8266
SPIFFSLogger -  v0.1.0 +  v0.1.1
A minimal library for binary data logging in ESP8266
SPIFFSLogger -  v0.1.0 +  v0.1.1
A minimal library for binary data logging in ESP8266
+ + + + + +
+
SPIFFSLogger +  v0.1.1 +
+
A minimal library for binary data logging in ESP8266
+
+
+ + + + + + +
+
+ +
+
+
+ +
+
+
Here is a list of all file members with links to the files they belong to:
+
+
+ + + + diff --git a/extras/docs/html/globals_vars.html b/extras/docs/html/globals_vars.html new file mode 100644 index 0000000..15c8310 --- /dev/null +++ b/extras/docs/html/globals_vars.html @@ -0,0 +1,83 @@ + + + + + + + +SPIFFSLogger: File Members + + + + + + + + + + + +
+
+ + + + + + +
+
SPIFFSLogger +  v0.1.1 +
+
A minimal library for binary data logging in ESP8266
+
+
+ + + + + + +
+
+ +
+
+
+ +
+
+
+
+ + + + diff --git a/extras/docs/html/hierarchy.html b/extras/docs/html/hierarchy.html new file mode 100644 index 0000000..e8fd6ec --- /dev/null +++ b/extras/docs/html/hierarchy.html @@ -0,0 +1,89 @@ + + + + + + + +SPIFFSLogger: Class Hierarchy + + + + + + + + + + + +
+
+ + + + + + +
+
SPIFFSLogger +  v0.1.1 +
+
A minimal library for binary data logging in ESP8266
+
+
+ + + + + + +
+
+ +
+
+
+ +
+
+
+
Class Hierarchy
+
+
+
This inheritance list is sorted roughly, but not completely, alphabetically:
+
[detail level 12]
+ + + +
 CSPIFFSLogData< T >Represents a data element as stored in SPIFFS, along with the creation timestamp
 CSPIFFSLoggerBaseBase class for the SPIFFSLogger template, implementing common methods
 CSPIFFSLogger< T >Minimal class template for binary data logging in ESP8266 SPIFFS
+
+
+
+ + + + diff --git a/extras/docs/html/hierarchy.js b/extras/docs/html/hierarchy.js new file mode 100644 index 0000000..cc46ad4 --- /dev/null +++ b/extras/docs/html/hierarchy.js @@ -0,0 +1,7 @@ +var hierarchy = +[ + [ "SPIFFSLogData< T >", "struct_s_p_i_f_f_s_log_data.html", null ], + [ "SPIFFSLoggerBase", "class_s_p_i_f_f_s_logger_base.html", [ + [ "SPIFFSLogger< T >", "class_s_p_i_f_f_s_logger.html", null ] + ] ] +]; \ No newline at end of file diff --git a/extras/docs/html/index.html b/extras/docs/html/index.html index 31a27d6..30d1522 100644 --- a/extras/docs/html/index.html +++ b/extras/docs/html/index.html @@ -27,7 +27,7 @@
SPIFFSLogger -  v0.1.0 +  v0.1.1
A minimal library for binary data logging in ESP8266
diff --git a/extras/docs/html/menudata.js b/extras/docs/html/menudata.js index e303550..066869c 100644 --- a/extras/docs/html/menudata.js +++ b/extras/docs/html/menudata.js @@ -26,9 +26,13 @@ var menudata={children:[ {text:"Classes",url:"annotated.html",children:[ {text:"Class List",url:"annotated.html"}, {text:"Class Index",url:"classes.html"}, +{text:"Class Hierarchy",url:"hierarchy.html"}, {text:"Class Members",url:"functions.html",children:[ {text:"All",url:"functions.html"}, {text:"Functions",url:"functions_func.html"}, {text:"Variables",url:"functions_vars.html"}]}]}, {text:"Files",url:"files.html",children:[ -{text:"File List",url:"files.html"}]}]} +{text:"File List",url:"files.html"}, +{text:"File Members",url:"globals.html",children:[ +{text:"All",url:"globals.html"}, +{text:"Variables",url:"globals_vars.html"}]}]}]} diff --git a/extras/docs/html/navtreedata.js b/extras/docs/html/navtreedata.js index bf175e7..2309e23 100644 --- a/extras/docs/html/navtreedata.js +++ b/extras/docs/html/navtreedata.js @@ -27,6 +27,7 @@ var NAVTREE = [ "Classes", "annotated.html", [ [ "Class List", "annotated.html", "annotated_dup" ], [ "Class Index", "classes.html", null ], + [ "Class Hierarchy", "hierarchy.html", "hierarchy" ], [ "Class Members", "functions.html", [ [ "All", "functions.html", null ], [ "Functions", "functions_func.html", null ], @@ -34,7 +35,11 @@ var NAVTREE = ] ] ] ], [ "Files", "files.html", [ - [ "File List", "files.html", "files_dup" ] + [ "File List", "files.html", "files_dup" ], + [ "File Members", "globals.html", [ + [ "All", "globals.html", null ], + [ "Variables", "globals_vars.html", null ] + ] ] ] ] ] ] ]; diff --git a/extras/docs/html/navtreeindex0.js b/extras/docs/html/navtreeindex0.js index 60d1d3b..3513021 100644 --- a/extras/docs/html/navtreeindex0.js +++ b/extras/docs/html/navtreeindex0.js @@ -2,30 +2,52 @@ var NAVTREEINDEX0 = { "_s_p_i_f_f_s_logger_8h.html":[1,0,0,0], "_s_p_i_f_f_s_logger_8h_source.html":[1,0,0,0], +"_s_p_i_f_f_s_logger_base_8cpp.html":[1,0,0,1], +"_s_p_i_f_f_s_logger_base_8cpp.html#af70a7c4bf0e665786ae633f14c7b351f":[1,0,0,1,0], +"_s_p_i_f_f_s_logger_base_8h.html":[1,0,0,2], +"_s_p_i_f_f_s_logger_base_8h_source.html":[1,0,0,2], "annotated.html":[0,0], "class_s_p_i_f_f_s_logger.html":[0,0,1], -"class_s_p_i_f_f_s_logger.html#a0a83d73217bc8bada843092ae7d055e8":[0,0,1,15], -"class_s_p_i_f_f_s_logger.html#a294e4b04bb7d26c6d63d4168d574221a":[0,0,1,11], -"class_s_p_i_f_f_s_logger.html#a2e914dd1884de9900288564a41bc55a4":[0,0,1,8], -"class_s_p_i_f_f_s_logger.html#a34f24a3c6229653a31c166b899d43537":[0,0,1,5], -"class_s_p_i_f_f_s_logger.html#a42017253e85b5f4978e4ba778960a62d":[0,0,1,13], -"class_s_p_i_f_f_s_logger.html#abfc7ce5e1a8022705c6704e50edf087d":[0,0,1,4], -"class_s_p_i_f_f_s_logger.html#ac539407d1bfebe9443393ea2e4047e29":[0,0,1,7], -"class_s_p_i_f_f_s_logger.html#ad366d57e6ca7b721b27164e40fb342b3":[0,0,1,1], -"class_s_p_i_f_f_s_logger.html#ad48c3983258885410e6b7d0a299e8e69":[0,0,1,12], -"class_s_p_i_f_f_s_logger.html#ae6edbf5e924957c107068fce73554737":[0,0,1,3], +"class_s_p_i_f_f_s_logger.html#a22fdd2b540717853ae403edbc0ed1b7f":[0,0,1,5], +"class_s_p_i_f_f_s_logger.html#a2e914dd1884de9900288564a41bc55a4":[0,0,1,9], +"class_s_p_i_f_f_s_logger.html#a2e9e45428e1ffbe989dd7679c5def4fe":[0,0,1,2], +"class_s_p_i_f_f_s_logger.html#a517fa4d3854283ba7b2dba9bf0d09c84":[0,0,1,14], +"class_s_p_i_f_f_s_logger.html#a77a967ae68a680dea5a647200ba49815":[0,0,1,16], +"class_s_p_i_f_f_s_logger.html#a7f79553c53c7b5b6c87aaaa104d5a1e3":[0,0,1,10], +"class_s_p_i_f_f_s_logger.html#a829da5d8bf3d83ed24e608bb60fc623c":[0,0,1,12], +"class_s_p_i_f_f_s_logger.html#a8d82d01f694528becba720e0612dc48d":[0,0,1,7], +"class_s_p_i_f_f_s_logger.html#a8feb62f012879aca79d600cf217c2098":[0,0,1,11], +"class_s_p_i_f_f_s_logger.html#a978f0a636ce4d7a7f1640df124cc25ff":[0,0,1,15], +"class_s_p_i_f_f_s_logger.html#aa5679e47e144e591b5fa90fb31b65cbd":[0,0,1,3], +"class_s_p_i_f_f_s_logger.html#abfba26125f8b32b4c8e2e3d29d65b31f":[0,0,1,1], +"class_s_p_i_f_f_s_logger.html#ac1b33a4c97b2a45b2b178a261ebbb12c":[0,0,1,13], +"class_s_p_i_f_f_s_logger.html#ac539407d1bfebe9443393ea2e4047e29":[0,0,1,8], +"class_s_p_i_f_f_s_logger.html#ad2270960852a999b0340fa4eab50f063":[0,0,1,4], "class_s_p_i_f_f_s_logger.html#aeceb2db3a41feb387e874f247657e19c":[0,0,1,6], -"class_s_p_i_f_f_s_logger.html#af6227914a7bd060a26b5f83fa5641665":[0,0,1,14], -"class_s_p_i_f_f_s_logger.html#af6c68f5bf3ceccde605a89cb929bb787":[0,0,1,9], -"class_s_p_i_f_f_s_logger.html#afa47e4215bf7dc8a27704e5c10324fa8":[0,0,1,10], "class_s_p_i_f_f_s_logger.html#afa8152a5d5d29fedbb04265cb4589359":[0,0,1,0], -"class_s_p_i_f_f_s_logger.html#afbb2b0583a0500e3e5eae006a6740992":[0,0,1,2], +"class_s_p_i_f_f_s_logger_base.html":[0,0,2], +"class_s_p_i_f_f_s_logger_base.html#a22fdd2b540717853ae403edbc0ed1b7f":[0,0,2,5], +"class_s_p_i_f_f_s_logger_base.html#a2e9e45428e1ffbe989dd7679c5def4fe":[0,0,2,2], +"class_s_p_i_f_f_s_logger_base.html#a517fa4d3854283ba7b2dba9bf0d09c84":[0,0,2,10], +"class_s_p_i_f_f_s_logger_base.html#a77a967ae68a680dea5a647200ba49815":[0,0,2,12], +"class_s_p_i_f_f_s_logger_base.html#a7f79553c53c7b5b6c87aaaa104d5a1e3":[0,0,2,6], +"class_s_p_i_f_f_s_logger_base.html#a829da5d8bf3d83ed24e608bb60fc623c":[0,0,2,8], +"class_s_p_i_f_f_s_logger_base.html#a8feb62f012879aca79d600cf217c2098":[0,0,2,7], +"class_s_p_i_f_f_s_logger_base.html#a978f0a636ce4d7a7f1640df124cc25ff":[0,0,2,11], +"class_s_p_i_f_f_s_logger_base.html#aa5679e47e144e591b5fa90fb31b65cbd":[0,0,2,3], +"class_s_p_i_f_f_s_logger_base.html#abfba26125f8b32b4c8e2e3d29d65b31f":[0,0,2,1], +"class_s_p_i_f_f_s_logger_base.html#ac1b33a4c97b2a45b2b178a261ebbb12c":[0,0,2,9], +"class_s_p_i_f_f_s_logger_base.html#ace02cadd2e608c940728ae9f5242bbcc":[0,0,2,0], +"class_s_p_i_f_f_s_logger_base.html#ad2270960852a999b0340fa4eab50f063":[0,0,2,4], "classes.html":[0,1], "dir_68267d1309a1af8e8297ef4c3efbcdba.html":[1,0,0], "files.html":[1,0], -"functions.html":[0,2,0], -"functions_func.html":[0,2,1], -"functions_vars.html":[0,2,2], +"functions.html":[0,3,0], +"functions_func.html":[0,3,1], +"functions_vars.html":[0,3,2], +"globals.html":[1,1,0], +"globals_vars.html":[1,1,1], +"hierarchy.html":[0,2], "index.html":[], "pages.html":[], "struct_s_p_i_f_f_s_log_data.html":[0,0,0], diff --git a/extras/docs/html/struct_s_p_i_f_f_s_log_data-members.html b/extras/docs/html/struct_s_p_i_f_f_s_log_data-members.html index 371943a..a138fdc 100644 --- a/extras/docs/html/struct_s_p_i_f_f_s_log_data-members.html +++ b/extras/docs/html/struct_s_p_i_f_f_s_log_data-members.html @@ -27,7 +27,7 @@
SPIFFSLogger -  v0.1.0 +  v0.1.1
A minimal library for binary data logging in ESP8266
diff --git a/extras/docs/html/struct_s_p_i_f_f_s_log_data.html b/extras/docs/html/struct_s_p_i_f_f_s_log_data.html index e2c3713..9c14fc4 100644 --- a/extras/docs/html/struct_s_p_i_f_f_s_log_data.html +++ b/extras/docs/html/struct_s_p_i_f_f_s_log_data.html @@ -27,7 +27,7 @@
SPIFFSLogger -  v0.1.0 +  v0.1.1
A minimal library for binary data logging in ESP8266
diff --git a/extras/docs/xml/_s_p_i_f_f_s_logger_8h.xml b/extras/docs/xml/_s_p_i_f_f_s_logger_8h.xml index 069dc43..f8634bd 100644 --- a/extras/docs/xml/_s_p_i_f_f_s_logger_8h.xml +++ b/extras/docs/xml/_s_p_i_f_f_s_logger_8h.xml @@ -2,17 +2,25 @@ SPIFFSLogger.h - Arduino.h - FS.h - time.h + SPIFFSLoggerBase.h - + - + + + + + + + + + + + - + @@ -20,30 +28,10 @@ - - - - SPIFFSLogData SPIFFSLogger - - - const char _logFilenameFormat [] - const char _logFilenameFormat [] PROGMEM - - PROGMEM - = "%s/%d%02d%02d" - - - - - - - - - @@ -70,201 +58,85 @@ #ifndef__SPIFFSLOGGER_H__ #define__SPIFFSLOGGER_H__ -#include<Arduino.h> -#include<FS.h> -#include<time.h> - -//internalstringsstoredinflashforefficiency -staticconstchar_logFilenameFormat[]PROGMEM="%s/%d%02d%02d"; - -template<classT> -structSPIFFSLogData -{ -time_ttimestampUTC; -Tdata; -}; - -template<classT> -classSPIFFSLogger -{ -public: -SPIFFSLogger(constchar*directory,uint16_tdaysToKeep=7,uint16_tprocessInterval=1000); - -voidinit(); - -voidprocess(); - -size_twrite(constT&value); - -size_treadRows(SPIFFSLogData<T>*output,time_tdate,size_tstartIdx,size_tmaxCount); - -size_trowCount(time_tdate); +#include"SPIFFSLoggerBase.h" + +template<classT> +structSPIFFSLogData +{ +time_ttimestampUTC; +Tdata; +}; + +template<classT> +classSPIFFSLogger:publicSPIFFSLoggerBase +{ +public: +SPIFFSLogger(constchar*directory,uint16_tdaysToKeep=7,uint16_tprocessInterval=1000); + +size_twrite(constT&value); + +size_treadRows(SPIFFSLogData<T>*output,time_tdate,size_tstartIdx,size_tmaxCount); + +size_treadRowsBetween(SPIFFSLogData<T>*output,time_tfromTime,time_ttoTime,size_tstartIdx,size_tmaxCount); + +size_trowCount(time_tdate); +}; + +template<classT> +SPIFFSLogger<T>::SPIFFSLogger(constchar*directory,uint16_tdaysToKeep,uint16_tprocessInterval) +:SPIFFSLoggerBase(directory,daysToKeep,processInterval) +{ +} + +template<classT> +size_tSPIFFSLogger<T>::write(constT&value) +{ +structSPIFFSLogData<T>data; +data.timestampUTC=time(nullptr); +data.data=value; -protected: -time_t_today=0; -unsignedlong_lastProcess=0; -constuint16_t_processInterval; -constuint16_t_daysToKeep; -bool_processNow=true; -char_directory[21]; -char_curPath[32]; -void_pathFromDate(char*output,time_tdate); +Filef=SPIFFS.open(this->_curPath,"a"); +f.write((uint8_t*)&data,sizeof(data)); +f.close(); +} + +template<classT> +size_tSPIFFSLogger<T>::readRows(SPIFFSLogData<T>*output,time_tdate,size_tstartIdx,size_tmaxCount) +{ +charpath[32]; +this->_pathFromDate(path,date); + +if(!SPIFFS.exists(path)) +return0; -void_updateCurPath(); +Filef=SPIFFS.open(path,"r"); +maxCount=min((int32_t)maxCount,(int32_t)(f.size()/sizeof(SPIFFSLogData<T>))-(int32_t)startIdx); +if(maxCount<=0) +returnmaxCount; -void_runRotation(); - -statictime_t_timegm(structtm*tm); -}; - -template<classT> -SPIFFSLogger<T>::SPIFFSLogger(constchar*directory,uint16_tdaysToKeep,uint16_tprocessInterval) -:_daysToKeep(daysToKeep),_processInterval(processInterval) -{ -strncpy(this->_directory,directory,sizeof(this->_directory)-1); -} - -template<classT> -voidSPIFFSLogger<T>::init() -{ -this->process(); -} - -template<classT> -voidSPIFFSLogger<T>::process() -{ -constunsignedlongcurrentMillis=millis(); -if(currentMillis-this->_lastProcess>this->_processInterval||this->_processNow) -{ -consttime_tnow=time(nullptr); -consttime_ttoday=now/86400*86400;//removethetimepart -if(this->_today!=today) -{//wehaveswitchedtoanotherday,let'sruntherequiredupdates -this->_today=today; -this->_updateCurPath(); -this->_runRotation(); -} - -this->_lastProcess=currentMillis; -this->_processNow=false; -} -} - -template<classT> -size_tSPIFFSLogger<T>::write(constT&value) -{ -structSPIFFSLogData<T>data; -data.timestampUTC=time(nullptr); -data.data=value; - -Filef=SPIFFS.open(this->_curPath,"a"); -f.write((uint8_t*)&data,sizeof(data)); -f.close(); -} - -template<classT> -size_tSPIFFSLogger<T>::readRows(SPIFFSLogData<T>*output,time_tdate,size_tstartIdx,size_tmaxCount) -{ -charpath[32]; -this->_pathFromDate(path,date); - -if(!SPIFFS.exists(path)) -return0; - -Filef=SPIFFS.open(path,"r"); -maxCount=min(maxCount,f.size()/sizeof(SPIFFSLogData<T>)-startIdx); -f.seek(startIdx*sizeof(SPIFFSLogData<T>)); -f.read((uint8_t*)output,maxCount*sizeof(SPIFFSLogData<T>)); -f.close(); -returnmaxCount; -} - -template<classT> -size_tSPIFFSLogger<T>::rowCount(time_tdate) -{ -charpath[32]; -this->_pathFromDate(path,date); - -if(!SPIFFS.exists(path)) -return0; - -Filef=SPIFFS.open(path,"r"); -constsize_trows=f.size()/sizeof(SPIFFSLogData<T>); -f.close(); - -returnrows; -} - -template<classT> -voidSPIFFSLogger<T>::_pathFromDate(char*output,time_tdate) -{ -if(date<=0) -date=this->_today; - -structtm*tinfo=gmtime(&date); -sprintf_P(output, -_logFilenameFormat, -this->_directory, -1900+tinfo->tm_year, -tinfo->tm_mon+1, -tinfo->tm_mday); -} - -template<classT> -voidSPIFFSLogger<T>::_updateCurPath() -{ -SPIFFSLogger::_pathFromDate(this->_curPath,this->_today); -} - -template<classT> -voidSPIFFSLogger<T>::_runRotation() -{ -constuint8_tdirLen=strlen(this->_directory); -DirtempDir=SPIFFS.openDir(this->_directory); - -chardatePart[5]={0}; -while(tempDir.next()) -{ -structtmtm={0}; -constchar*dateStart=tempDir.fileName().c_str()+dirLen+1; - -strncpy(datePart,dateStart,4); -tm.tm_year=atoi(datePart)-1900; - -strncpy(datePart,dateStart+4,2); -datePart[2]='\0'; -tm.tm_mon=atoi(datePart)-1; - -strncpy(datePart,dateStart+6,2); -tm.tm_mday=atoi(datePart); - -consttime_tmidnight=SPIFFSLogger::_timegm(&tm)/86400*86400; - -//checkiffileistoooldand,ifso,deleteit -if(midnight<(this->_today-this->_daysToKeep*86400)) -SPIFFS.remove(tempDir.fileName()); -} -} - -template<classT> -time_tSPIFFSLogger<T>::_timegm(structtm*tm) -{ -structtmstart2000={ -0,//tm_sec -0,//tm_min -0,//tm_hour -1,//tm_mday -0,//tm_mon -100,//tm_year -0,//tm_wday -0,//tm_yday -0,//tm_isdst -}; - -returnmktime(tm)-(mktime(&start2000)-946684800); -} - -#endif//__SPIFFSLOGGER_H__ +f.seek(startIdx*sizeof(SPIFFSLogData<T>)); +f.read((uint8_t*)output,maxCount*sizeof(SPIFFSLogData<T>)); +f.close(); +returnmaxCount; +} + +template<classT> +size_tSPIFFSLogger<T>::rowCount(time_tdate) +{ +charpath[32]; +this->_pathFromDate(path,date); + +if(!SPIFFS.exists(path)) +return0; + +Filef=SPIFFS.open(path,"r"); +constsize_trows=f.size()/sizeof(SPIFFSLogData<T>); +f.close(); + +returnrows; +} + +#endif//__SPIFFSLOGGER_H__ diff --git a/extras/docs/xml/_s_p_i_f_f_s_logger_base_8cpp.xml b/extras/docs/xml/_s_p_i_f_f_s_logger_base_8cpp.xml new file mode 100644 index 0000000..297c5ad --- /dev/null +++ b/extras/docs/xml/_s_p_i_f_f_s_logger_base_8cpp.xml @@ -0,0 +1,161 @@ + + + + SPIFFSLoggerBase.cpp + SPIFFSLoggerBase.h + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + const char _logFilenameFormat [] + const char _logFilenameFormat [] PROGMEM + + PROGMEM + = "%s/%d%02d%02d" + + + + + + + + + + + + + + +#include"SPIFFSLoggerBase.h" + +//internalstringsstoredinflashforefficiency +constchar_logFilenameFormat[]PROGMEM="%s/%d%02d%02d"; + +SPIFFSLoggerBase::SPIFFSLoggerBase(constchar*directory,uint16_tdaysToKeep,uint16_tprocessInterval) +:_daysToKeep(daysToKeep),_processInterval(processInterval) +{ +strncpy(this->_directory,directory,sizeof(this->_directory)-1); +} + +voidSPIFFSLoggerBase::init() +{ +this->process(); +} + +voidSPIFFSLoggerBase::process() +{ +constunsignedlongcurrentMillis=millis(); +if(currentMillis-this->_lastProcess>this->_processInterval||this->_processNow) +{ +consttime_tnow=time(nullptr); +consttime_ttoday=now/86400*86400;//removethetimepart +if(this->_today!=today) +{//wehaveswitchedtoanotherday,let'sruntherequiredupdates +this->_today=today; +this->_updateCurPath(); +this->_runRotation(); +} + +this->_lastProcess=currentMillis; +this->_processNow=false; +} +} + +voidSPIFFSLoggerBase::_pathFromDate(char*output,time_tdate) +{ +if(date<=0) +date=this->_today; + +structtm*tinfo=gmtime(&date); +sprintf_P(output, +_logFilenameFormat, +this->_directory, +1900+tinfo->tm_year, +tinfo->tm_mon+1, +tinfo->tm_mday); +} + +voidSPIFFSLoggerBase::_updateCurPath() +{ +SPIFFSLoggerBase::_pathFromDate(this->_curPath,this->_today); +} + +voidSPIFFSLoggerBase::_runRotation() +{ +constuint8_tdirLen=strlen(this->_directory); +DirtempDir=SPIFFS.openDir(this->_directory); + +while(tempDir.next()) +{ +constchar*dateStart=tempDir.fileName().c_str()+dirLen+1; +consttime_tmidnight=SPIFFSLoggerBase::_filenameToDate(dateStart); + +//checkiffileistoooldand,ifso,deleteit +if(midnight<(this->_today-this->_daysToKeep*86400)) +SPIFFS.remove(tempDir.fileName()); +} +} + +time_tSPIFFSLoggerBase::_filenameToDate(constchar*filename) +{ +structtmtm={0}; +chardatePart[5]={0}; + +strncpy(datePart,filename,4); +tm.tm_year=atoi(datePart)-1900; + +strncpy(datePart,filename+4,2); +datePart[2]='\0'; +tm.tm_mon=atoi(datePart)-1; + +strncpy(datePart,filename+6,2); +tm.tm_mday=atoi(datePart); + +returnSPIFFSLoggerBase::_timegm(&tm)/86400*86400; +} + +time_tSPIFFSLoggerBase::_timegm(structtm*tm) +{ +structtmstart2000={ +0,//tm_sec +0,//tm_min +0,//tm_hour +1,//tm_mday +0,//tm_mon +100,//tm_year +0,//tm_wday +0,//tm_yday +0,//tm_isdst +}; + +returnmktime(tm)-(mktime(&start2000)-946684800); +} + + + + diff --git a/extras/docs/xml/_s_p_i_f_f_s_logger_base_8h.xml b/extras/docs/xml/_s_p_i_f_f_s_logger_base_8h.xml new file mode 100644 index 0000000..b0aacb3 --- /dev/null +++ b/extras/docs/xml/_s_p_i_f_f_s_logger_base_8h.xml @@ -0,0 +1,112 @@ + + + + SPIFFSLoggerBase.h + Arduino.h + FS.h + time.h + src/SPIFFSLogger.h + src/SPIFFSLoggerBase.cpp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SPIFFSLoggerBase + + + + + +/* +SPIFFSLogger-AminimallibraryforbinarydatalogginginESP8266 +Copyright(C)2018MarioFalcao + +Thisprogramisfreesoftware:youcanredistributeitand/ormodify +itunderthetermsoftheGNULesserGeneralPublicLicenseaspublished +bytheFreeSoftwareFoundation,eitherversion3oftheLicense,or +(atyouroption)anylaterversion. + +Thisprogramisdistributedinthehopethatitwillbeuseful, +butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof +MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe +GNUGeneralPublicLicenseformoredetails. + +YoushouldhavereceivedacopyoftheGNULesserGeneralPublicLicense +alongwiththisprogram.Ifnot,see<http://www.gnu.org/licenses/>. +*/ + +#ifndef__SPIFFSLOGGERBASE_H__ +#define__SPIFFSLOGGERBASE_H__ + +#include<Arduino.h> +#include<FS.h> +#include<time.h> + +classSPIFFSLoggerBase +{ +public: +voidinit(); + +voidprocess(); + +protected: +time_t_today=0; +unsignedlong_lastProcess=0; +constuint16_t_processInterval; +constuint16_t_daysToKeep; +bool_processNow=true; +char_directory[21]; +char_curPath[32]; +SPIFFSLoggerBase(constchar*directory,uint16_tdaysToKeep,uint16_tprocessInterval); + +void_pathFromDate(char*output,time_tdate); + +void_updateCurPath(); + +void_runRotation(); + +statictime_t_filenameToDate(constchar*filename); + +statictime_t_timegm(structtm*tm); +}; + +#endif//__SPIFFSLOGGERBASE_H__ + + + + diff --git a/extras/docs/xml/class_s_p_i_f_f_s_logger.xml b/extras/docs/xml/class_s_p_i_f_f_s_logger.xml index 1cddb30..d7e0246 100644 --- a/extras/docs/xml/class_s_p_i_f_f_s_logger.xml +++ b/extras/docs/xml/class_s_p_i_f_f_s_logger.xml @@ -2,108 +2,13 @@ SPIFFSLogger + SPIFFSLoggerBase SPIFFSLogger.h class T - - - time_t - time_t SPIFFSLogger< T >::_today - - _today - = 0 - -current date, set in the last processing run - - - - - - - - unsigned long - unsigned long SPIFFSLogger< T >::_lastProcess - - _lastProcess - = 0 - -last processing millis() - - - - - - - - const uint16_t - const uint16_t SPIFFSLogger< T >::_processInterval - - _processInterval - -ms between processing runs - - - - - - - - const uint16_t - const uint16_t SPIFFSLogger< T >::_daysToKeep - - _daysToKeep - -number of days to keep logs for - - - - - - - - bool - bool SPIFFSLogger< T >::_processNow - - _processNow - = true - -force processing now, even if the processing interval hasn't passed - - - - - - - - char - char SPIFFSLogger< T >::_directory[21] - [21] - _directory - -base directory for log files - - - - - - - - char - char SPIFFSLogger< T >::_curPath[32] - [32] - _curPath - -path for today's file - - - - - - - @@ -152,33 +57,7 @@ - - - - void - void SPIFFSLogger< T >::init - () - init - -Initialize the logger. - -Should be called after initializing SPIFFS and before before any other method. - - - - - - void - void SPIFFSLogger< T >::process - () - process - -Process the file rotation and other required operations according to the defined processInterval. - -Should be called as often as possible, i.e. in loop(). - - - + size_t @@ -203,7 +82,7 @@ - + size_t @@ -262,7 +141,40 @@ - + + + + size_t + size_t SPIFFSLogger< T >::readRowsBetween + (SPIFFSLogData< T > *output, time_t fromTime, time_t toTime, size_t startIdx, size_t maxCount) + readRowsBetween + + SPIFFSLogData< T > * + output + + + time_t + fromTime + + + time_t + toTime + + + size_t + startIdx + + + size_t + maxCount + + + + + + + + size_t @@ -288,13 +200,135 @@ - + + + + void + void SPIFFSLoggerBase::init + () + init + +Initialize the logger. + +Should be called after initializing SPIFFS and before before any other method. + + + + + + void + void SPIFFSLoggerBase::process + () + process + +Process the file rotation and other required operations according to the defined processInterval. + +Should be called as often as possible, i.e. in loop(). + + + + + + + + time_t + time_t SPIFFSLoggerBase::_today + + _today + = 0 + +current date, set in the last processing run + + + + + + + + unsigned long + unsigned long SPIFFSLoggerBase::_lastProcess + + _lastProcess + = 0 + +last processing millis() + + + + + + + + const uint16_t + const uint16_t SPIFFSLoggerBase::_processInterval + + _processInterval + +ms between processing runs + + + + + + + + const uint16_t + const uint16_t SPIFFSLoggerBase::_daysToKeep + + _daysToKeep + +number of days to keep logs for + + + + + + + + bool + bool SPIFFSLoggerBase::_processNow + + _processNow + = true + +force processing now, even if the processing interval hasn't passed + + + + + + + + char + char SPIFFSLoggerBase::_directory[21] + [21] + _directory + +base directory for log files + + + + + + + + char + char SPIFFSLoggerBase::_curPath[32] + [32] + _curPath + +path for today's file + + + + + - + void - void SPIFFSLogger< T >::_pathFromDate + void SPIFFSLoggerBase::_pathFromDate (char *output, time_t date) _pathFromDate @@ -311,11 +345,11 @@ - + - + void - void SPIFFSLogger< T >::_updateCurPath + void SPIFFSLoggerBase::_updateCurPath () _updateCurPath @@ -324,11 +358,11 @@ - + - + void - void SPIFFSLogger< T >::_runRotation + void SPIFFSLoggerBase::_runRotation () _runRotation @@ -337,13 +371,30 @@ - + - + + time_t + time_t SPIFFSLoggerBase::_filenameToDate + (const char *filename) + _filenameToDate + + const char * + filename + + +Converts a filename in YYYYMMDD format to a time_t. + + + + + + + time_t - time_t SPIFFSLogger< T >::_timegm + time_t SPIFFSLoggerBase::_timegm (struct tm *tm) _timegm @@ -356,7 +407,7 @@ - + @@ -371,24 +422,51 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + - SPIFFSLogger_curPath - SPIFFSLogger_daysToKeep - SPIFFSLogger_directory - SPIFFSLogger_lastProcess - SPIFFSLogger_pathFromDate - SPIFFSLogger_processInterval - SPIFFSLogger_processNow - SPIFFSLogger_runRotation - SPIFFSLogger_timegm - SPIFFSLogger_today - SPIFFSLogger_updateCurPath - SPIFFSLoggerinit - SPIFFSLoggerprocess + SPIFFSLogger_curPath + SPIFFSLogger_daysToKeep + SPIFFSLogger_directory + SPIFFSLogger_filenameToDate + SPIFFSLogger_lastProcess + SPIFFSLogger_pathFromDate + SPIFFSLogger_processInterval + SPIFFSLogger_processNow + SPIFFSLogger_runRotation + SPIFFSLogger_timegm + SPIFFSLogger_today + SPIFFSLogger_updateCurPath + SPIFFSLoggerinit + SPIFFSLoggerprocess SPIFFSLoggerreadRows + SPIFFSLoggerreadRowsBetween SPIFFSLoggerrowCount SPIFFSLoggerSPIFFSLogger + SPIFFSLoggerSPIFFSLoggerBase SPIFFSLoggerwrite diff --git a/extras/docs/xml/class_s_p_i_f_f_s_logger_base.xml b/extras/docs/xml/class_s_p_i_f_f_s_logger_base.xml new file mode 100644 index 0000000..6cd1207 --- /dev/null +++ b/extras/docs/xml/class_s_p_i_f_f_s_logger_base.xml @@ -0,0 +1,276 @@ + + + + SPIFFSLoggerBase + SPIFFSLogger< T > + SPIFFSLoggerBase.h + + + time_t + time_t SPIFFSLoggerBase::_today + + _today + = 0 + +current date, set in the last processing run + + + + + + + + unsigned long + unsigned long SPIFFSLoggerBase::_lastProcess + + _lastProcess + = 0 + +last processing millis() + + + + + + + + const uint16_t + const uint16_t SPIFFSLoggerBase::_processInterval + + _processInterval + +ms between processing runs + + + + + + + + const uint16_t + const uint16_t SPIFFSLoggerBase::_daysToKeep + + _daysToKeep + +number of days to keep logs for + + + + + + + + bool + bool SPIFFSLoggerBase::_processNow + + _processNow + = true + +force processing now, even if the processing interval hasn't passed + + + + + + + + char + char SPIFFSLoggerBase::_directory[21] + [21] + _directory + +base directory for log files + + + + + + + + char + char SPIFFSLoggerBase::_curPath[32] + [32] + _curPath + +path for today's file + + + + + + + + + + void + void SPIFFSLoggerBase::init + () + init + +Initialize the logger. + +Should be called after initializing SPIFFS and before before any other method. + + + + + + void + void SPIFFSLoggerBase::process + () + process + +Process the file rotation and other required operations according to the defined processInterval. + +Should be called as often as possible, i.e. in loop(). + + + + + + + + + SPIFFSLoggerBase::SPIFFSLoggerBase + (const char *directory, uint16_t daysToKeep, uint16_t processInterval) + SPIFFSLoggerBase + + const char * + directory + + + uint16_t + daysToKeep + + + uint16_t + processInterval + + + + + + + + + + + void + void SPIFFSLoggerBase::_pathFromDate + (char *output, time_t date) + _pathFromDate + + char * + output + + + time_t + date + + +Converts a time_t to that day's file path. + + + + + + + + void + void SPIFFSLoggerBase::_updateCurPath + () + _updateCurPath + +Updates the current path to match today's date. + + + + + + + + void + void SPIFFSLoggerBase::_runRotation + () + _runRotation + +Deletes files older than the defined age limit. + + + + + + + + + + time_t + time_t SPIFFSLoggerBase::_filenameToDate + (const char *filename) + _filenameToDate + + const char * + filename + + +Converts a filename in YYYYMMDD format to a time_t. + + + + + + + + time_t + time_t SPIFFSLoggerBase::_timegm + (struct tm *tm) + _timegm + + struct tm * + tm + + +Simple timegm function, since one is not available in the ESP libs. + + + + + + + + +Base class for the SPIFFSLogger template, implementing common methods. + +Should not be used directly. + + + + + + + + + + + + + + + SPIFFSLoggerBase_curPath + SPIFFSLoggerBase_daysToKeep + SPIFFSLoggerBase_directory + SPIFFSLoggerBase_filenameToDate + SPIFFSLoggerBase_lastProcess + SPIFFSLoggerBase_pathFromDate + SPIFFSLoggerBase_processInterval + SPIFFSLoggerBase_processNow + SPIFFSLoggerBase_runRotation + SPIFFSLoggerBase_timegm + SPIFFSLoggerBase_today + SPIFFSLoggerBase_updateCurPath + SPIFFSLoggerBaseinit + SPIFFSLoggerBaseprocess + SPIFFSLoggerBaseSPIFFSLoggerBase + + + diff --git a/extras/docs/xml/dir_68267d1309a1af8e8297ef4c3efbcdba.xml b/extras/docs/xml/dir_68267d1309a1af8e8297ef4c3efbcdba.xml index a8d8534..1d4378e 100644 --- a/extras/docs/xml/dir_68267d1309a1af8e8297ef4c3efbcdba.xml +++ b/extras/docs/xml/dir_68267d1309a1af8e8297ef4c3efbcdba.xml @@ -3,6 +3,8 @@ src SPIFFSLogger.h + SPIFFSLoggerBase.cpp + SPIFFSLoggerBase.h diff --git a/extras/docs/xml/index.xml b/extras/docs/xml/index.xml index 177b09e..d908b17 100644 --- a/extras/docs/xml/index.xml +++ b/extras/docs/xml/index.xml @@ -5,26 +5,49 @@ data SPIFFSLogger - _today - _lastProcess - _processInterval - _daysToKeep - _processNow - _directory - _curPath SPIFFSLogger - init - process write readRows + readRowsBetween rowCount - _pathFromDate - _updateCurPath - _runRotation - _timegm + init + process + _today + _lastProcess + _processInterval + _daysToKeep + _processNow + _directory + _curPath + _pathFromDate + _updateCurPath + _runRotation + _filenameToDate + _timegm + + SPIFFSLoggerBase + _today + _lastProcess + _processInterval + _daysToKeep + _processNow + _directory + _curPath + init + process + SPIFFSLoggerBase + _pathFromDate + _updateCurPath + _runRotation + _filenameToDate + _timegm SPIFFSLogger.h - PROGMEM + + SPIFFSLoggerBase.cpp + PROGMEM + + SPIFFSLoggerBase.h src diff --git a/extras/docs/xml/struct_s_p_i_f_f_s_log_data.xml b/extras/docs/xml/struct_s_p_i_f_f_s_log_data.xml index 7a3e429..ff11566 100644 --- a/extras/docs/xml/struct_s_p_i_f_f_s_log_data.xml +++ b/extras/docs/xml/struct_s_p_i_f_f_s_log_data.xml @@ -22,7 +22,7 @@ - + T @@ -35,7 +35,7 @@ - + @@ -50,7 +50,7 @@ - + SPIFFSLogDatadata SPIFFSLogDatatimestampUTC diff --git a/library.properties b/library.properties index 1c990fd..f5cd5ee 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SPIFFSLogger -version=0.1.0 +version=0.1.1 author=Mario Falcao maintainer=Mario Falcao sentence=A minimal library for binary data logging in ESP8266. diff --git a/src/SPIFFSLogger.h b/src/SPIFFSLogger.h index e89d215..3819d6c 100644 --- a/src/SPIFFSLogger.h +++ b/src/SPIFFSLogger.h @@ -19,12 +19,7 @@ along with this program. If not, see . #ifndef __SPIFFSLOGGER_H__ #define __SPIFFSLOGGER_H__ -#include -#include -#include - -// internal strings stored in flash for efficiency -static const char _logFilenameFormat[] PROGMEM = "%s/%d%02d%02d"; +#include "SPIFFSLoggerBase.h" /** * Represents a data element as stored in SPIFFS, along with the creation timestamp. @@ -48,7 +43,7 @@ struct SPIFFSLogData * @tparam T type to store, e.g. a struct. */ template -class SPIFFSLogger +class SPIFFSLogger : public SPIFFSLoggerBase { public: /** @@ -61,17 +56,6 @@ class SPIFFSLogger */ SPIFFSLogger(const char *directory, uint16_t daysToKeep = 7, uint16_t processInterval = 1000); - /** - * Initialize the logger. Should be called after initializing SPIFFS and before before any other method. - */ - void init(); - - /** - * Process the file rotation and other required operations according to the defined processInterval. - * Should be called as often as possible, i.e. in loop(). - */ - void process(); - /** * Write the specified value to the end of the current log file, with the current timestamp. * @@ -90,6 +74,8 @@ class SPIFFSLogger */ size_t readRows(SPIFFSLogData *output, time_t date, size_t startIdx, size_t maxCount); + size_t readRowsBetween(SPIFFSLogData *output, time_t fromTime, time_t toTime, size_t startIdx, size_t maxCount); + /** * Get the number of entries for the specified date. * @@ -97,68 +83,12 @@ class SPIFFSLogger * @return number of entries */ size_t rowCount(time_t date); - - protected: - time_t _today = 0; /**< current date, set in the last processing run */ - unsigned long _lastProcess = 0; /**< last processing millis() */ - const uint16_t _processInterval; /**< ms between processing runs */ - const uint16_t _daysToKeep; /**< number of days to keep logs for */ - bool _processNow = true; /**< force processing now, even if the processing interval hasn't passed */ - char _directory[21]; /**< base directory for log files */ - char _curPath[32]; /**< path for today's file */ - - /** - * Converts a time_t to that day's file path. - */ - void _pathFromDate(char *output, time_t date); - - /** - * Updates the current path to match today's date. - */ - void _updateCurPath(); - - /** - * Deletes files older than the defined age limit. - */ - void _runRotation(); - - /** - * Simple timegm function, since one is not available in the ESP libs. - */ - static time_t _timegm(struct tm *tm); }; template SPIFFSLogger::SPIFFSLogger(const char *directory, uint16_t daysToKeep, uint16_t processInterval) - : _daysToKeep(daysToKeep), _processInterval(processInterval) -{ - strncpy(this->_directory, directory, sizeof(this->_directory) - 1); -} - -template -void SPIFFSLogger::init() -{ - this->process(); -} - -template -void SPIFFSLogger::process() + : SPIFFSLoggerBase(directory, daysToKeep, processInterval) { - const unsigned long currentMillis = millis(); - if (currentMillis - this->_lastProcess > this->_processInterval || this->_processNow) - { - const time_t now = time(nullptr); - const time_t today = now / 86400 * 86400; // remove the time part - if (this->_today != today) - { // we have switched to another day, let's run the required updates - this->_today = today; - this->_updateCurPath(); - this->_runRotation(); - } - - this->_lastProcess = currentMillis; - this->_processNow = false; - } } template @@ -209,73 +139,4 @@ size_t SPIFFSLogger::rowCount(time_t date) return rows; } -template -void SPIFFSLogger::_pathFromDate(char *output, time_t date) -{ - if (date <= 0) - date = this->_today; - - struct tm *tinfo = gmtime(&date); - sprintf_P(output, - _logFilenameFormat, - this->_directory, - 1900 + tinfo->tm_year, - tinfo->tm_mon + 1, - tinfo->tm_mday); -} - -template -void SPIFFSLogger::_updateCurPath() -{ - SPIFFSLogger::_pathFromDate(this->_curPath, this->_today); -} - -template -void SPIFFSLogger::_runRotation() -{ - const uint8_t dirLen = strlen(this->_directory); - Dir tempDir = SPIFFS.openDir(this->_directory); - - char datePart[5] = {0}; - while (tempDir.next()) - { - struct tm tm = {0}; - const char *dateStart = tempDir.fileName().c_str() + dirLen + 1; - - strncpy(datePart, dateStart, 4); - tm.tm_year = atoi(datePart) - 1900; - - strncpy(datePart, dateStart + 4, 2); - datePart[2] = '\0'; - tm.tm_mon = atoi(datePart) - 1; - - strncpy(datePart, dateStart + 6, 2); - tm.tm_mday = atoi(datePart); - - const time_t midnight = SPIFFSLogger::_timegm(&tm) / 86400 * 86400; - - // check if file is too old and, if so, delete it - if (midnight < (this->_today - this->_daysToKeep * 86400)) - SPIFFS.remove(tempDir.fileName()); - } -} - -template -time_t SPIFFSLogger::_timegm(struct tm *tm) -{ - struct tm start2000 = { - 0, // tm_sec - 0, // tm_min - 0, // tm_hour - 1, // tm_mday - 0, // tm_mon - 100, // tm_year - 0, // tm_wday - 0, // tm_yday - 0, // tm_isdst - }; - - return mktime(tm) - (mktime(&start2000) - 946684800); -} - #endif // __SPIFFSLOGGER_H__ diff --git a/src/SPIFFSLoggerBase.cpp b/src/SPIFFSLoggerBase.cpp new file mode 100644 index 0000000..2eb0471 --- /dev/null +++ b/src/SPIFFSLoggerBase.cpp @@ -0,0 +1,106 @@ +#include "SPIFFSLoggerBase.h" + +// internal strings stored in flash for efficiency +const char _logFilenameFormat[] PROGMEM = "%s/%d%02d%02d"; + +SPIFFSLoggerBase::SPIFFSLoggerBase(const char *directory, uint16_t daysToKeep, uint16_t processInterval) + : _daysToKeep(daysToKeep), _processInterval(processInterval) +{ + strncpy(this->_directory, directory, sizeof(this->_directory) - 1); +} + +void SPIFFSLoggerBase::init() +{ + this->process(); +} + +void SPIFFSLoggerBase::process() +{ + const unsigned long currentMillis = millis(); + if (currentMillis - this->_lastProcess > this->_processInterval || this->_processNow) + { + const time_t now = time(nullptr); + const time_t today = now / 86400 * 86400; // remove the time part + if (this->_today != today) + { // we have switched to another day, let's run the required updates + this->_today = today; + this->_updateCurPath(); + this->_runRotation(); + } + + this->_lastProcess = currentMillis; + this->_processNow = false; + } +} + +void SPIFFSLoggerBase::_pathFromDate(char *output, time_t date) +{ + if (date <= 0) + date = this->_today; + + struct tm *tinfo = gmtime(&date); + sprintf_P(output, + _logFilenameFormat, + this->_directory, + 1900 + tinfo->tm_year, + tinfo->tm_mon + 1, + tinfo->tm_mday); +} + +void SPIFFSLoggerBase::_updateCurPath() +{ + SPIFFSLoggerBase::_pathFromDate(this->_curPath, this->_today); +} + +void SPIFFSLoggerBase::_runRotation() +{ + const uint8_t dirLen = strlen(this->_directory); + Dir tempDir = SPIFFS.openDir(this->_directory); + + while (tempDir.next()) + { + const char *dateStart = tempDir.fileName().c_str() + dirLen + 1; + const time_t midnight = SPIFFSLoggerBase::_filenameToDate(dateStart); + + // check if file is too old and, if so, delete it + if (midnight < (this->_today - this->_daysToKeep * 86400)) + SPIFFS.remove(tempDir.fileName()); + } +} + +time_t SPIFFSLoggerBase::_filenameToDate(const char *filename) +{ + // we do a manual conversion since strptime() acts funny with YYYYMMDD dates + // https://github.com/esp8266/Arduino/issues/5141 + struct tm tm = {0}; + char datePart[5] = {0}; + + strncpy(datePart, filename, 4); + tm.tm_year = atoi(datePart) - 1900; + + strncpy(datePart, filename + 4, 2); + datePart[2] = '\0'; + tm.tm_mon = atoi(datePart) - 1; + + strncpy(datePart, filename + 6, 2); + tm.tm_mday = atoi(datePart); + + return SPIFFSLoggerBase::_timegm(&tm) / 86400 * 86400; +} + +time_t SPIFFSLoggerBase::_timegm(struct tm *tm) +{ + struct tm start2000 = { + 0, // tm_sec + 0, // tm_min + 0, // tm_hour + 1, // tm_mday + 0, // tm_mon + 100, // tm_year + 0, // tm_wday + 0, // tm_yday + 0, // tm_isdst + }; + + return mktime(tm) - (mktime(&start2000) - 946684800); +} diff --git a/src/SPIFFSLoggerBase.h b/src/SPIFFSLoggerBase.h new file mode 100644 index 0000000..c24adfa --- /dev/null +++ b/src/SPIFFSLoggerBase.h @@ -0,0 +1,80 @@ +/* +SPIFFSLogger - A minimal library for binary data logging in ESP8266 +Copyright (C) 2018 Mario Falcao + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published +by the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see . +*/ + +#ifndef __SPIFFSLOGGERBASE_H__ +#define __SPIFFSLOGGERBASE_H__ + +#include +#include +#include + +/** + * Base class for the SPIFFSLogger template, implementing common methods. Should not be used directly. + */ +class SPIFFSLoggerBase +{ + public: + /** + * Initialize the logger. Should be called after initializing SPIFFS and before before any other method. + */ + void init(); + + /** + * Process the file rotation and other required operations according to the defined processInterval. + * Should be called as often as possible, i.e. in loop(). + */ + void process(); + + protected: + time_t _today = 0; /**< current date, set in the last processing run */ + unsigned long _lastProcess = 0; /**< last processing millis() */ + const uint16_t _processInterval; /**< ms between processing runs */ + const uint16_t _daysToKeep; /**< number of days to keep logs for */ + bool _processNow = true; /**< force processing now, even if the processing interval hasn't passed */ + char _directory[21]; /**< base directory for log files */ + char _curPath[32]; /**< path for today's file */ + + SPIFFSLoggerBase(const char *directory, uint16_t daysToKeep, uint16_t processInterval); + + /** + * Converts a time_t to that day's file path. + */ + void _pathFromDate(char *output, time_t date); + + /** + * Updates the current path to match today's date. + */ + void _updateCurPath(); + + /** + * Deletes files older than the defined age limit. + */ + void _runRotation(); + + /** + * Converts a filename in YYYYMMDD format to a time_t. + */ + static time_t _filenameToDate(const char *filename); + + /** + * Simple timegm function, since one is not available in the ESP libs. + */ + static time_t _timegm(struct tm *tm); +}; + +#endif // __SPIFFSLOGGERBASE_H__