SDReader provides an interface for opening and reading data from files created using the SDLogger library.
More...
#include <SDReader.hpp>
|
| SDReader () |
| Constructor initializes SD card connection and nothing more.
|
|
| SDReader (std::string filename) |
| Constructor initializes SD card and set default file to open.
|
|
| SDReader (std::string prefix, int month, int day, int year, std::string filetype) |
| Constructor initializes and sets the file name structure.
|
|
void | set_filename (string filename) |
| Manually set the filename to access.
|
|
std::string | read_line () |
| Read until next newline character into buffer and return as a string.
|
|
void | read_entry_range_from_files (TimeStamp epoch, TimeStamp terminus, vector< string > topic_filter, int page_length=5, string prefix="log", string filetype="csv") |
| Retrieve all data within the specified time range, potentially accessing multiple files.
|
|
void | read_entry_range (File f, TimeStamp epoch, TimeStamp terminus, vector< string > topic_filter, int page_length) |
| Access a single file to retrieve data in time range and publish via MQTT.
|
|
File * | open_file () |
| Open the specified file and get the file pointer.
|
|
File * | open_file (string filename) |
| Open the specified file from path provided.
|
|
void | close_file () |
| Close the open file.
|
|
|
std::string | filename = "" |
|
std::string | separator = ";" |
|
SDCard | sd |
|
bool | file_open = false |
|
File | fp |
|
SDReader provides an interface for opening and reading data from files created using the SDLogger library.
◆ SDReader() [1/2]
SDReader::SDReader |
( |
std::string |
filename | ) |
|
|
inline |
Constructor initializes SD card and set default file to open.
- Parameters
-
[in] | filename | The default file to open and read data from. |
◆ SDReader() [2/2]
SDReader::SDReader |
( |
std::string |
prefix, |
|
|
int |
month, |
|
|
int |
day, |
|
|
int |
year, |
|
|
std::string |
filetype |
|
) |
| |
|
inline |
Constructor initializes and sets the file name structure.
- Parameters
-
[in] | prefix | What is this file for? Example: log . |
[in] | month | What month did this file start collecting data in? |
[in] | day | The day starting at? |
[in] | year | What year is it? |
[in] | filetype | What filetype/extension is this? |
◆ build_json_page()
Compile collected data into a JSON "page" which can then be published via the MQTT interface.
- Parameters
-
[in] | filename | The name of the file this page came from. |
[in] | epoch | The beginning timestamp of the range this data was collected from. |
[in] | terminus | The end timestamp of the range this data was collected from. |
[in] | data | The vector of data entries collected in this page. |
- Returns
- A single JSON object string which contains fields:
file name
, epoch
, terminus
, and data
.
◆ calculate_page_size()
Calculate the size, in bytes, of the current page.
If debugging is enabled over serial port, then the page size is printed to the serial port.
- Parameters
-
[in] | page | Reference to the "page" of collected results. |
- Returns
- An integer (bytes) representing the size of the page.
◆ initialize_sd_card()
bool SDReader::initialize_sd_card |
( |
| ) |
|
|
private |
Initialize connection to SD card and return false if no connection established.
- Returns
- A boolean value:
true
if initialization successful, false
otherwise.
◆ read_entry_range()
Access a single file to retrieve data in time range and publish via MQTT.
Collect all log entries in a file that fall within the time range and match a topic in topic filter. Collected entries are counted as entries in a "page". Entries are added to the "page" until page_length
is reached. At this point the entries are uploaded via MQTT to the broker.
This process is repeated until the end of the file is reached or the entries no longer fall within the time range.
- Parameters
-
[in] | f | File object to read from. |
[in] | epoch | The beginning of the time range to collect entries from. |
[in] | terminus | The end of the time range to collect entries from. |
[in] | topic_filter | A vector list of topic strings, which if matching, should be collected. |
[in] | page_length | The maximum number of results to include in this page. |
◆ read_entry_range_from_files()
Retrieve all data within the specified time range, potentially accessing multiple files.
Collect all log entries within date range included by the topic filter. This search is conducted on all files in the SD card file system. Once a file is found which meets the criteria of time range, prefix, and filetype, read_entry_range()
is used to parse the file's entries for ones that match time range and topic filter untill the end of the file has been reached. Entries are uploaded to MQTT broker in pages which are limited in length by page_length
.
This process is repeated until all files in the file system have been checked.
- Parameters
-
[in] | epoch | The beginning of the time range to collect data from. |
[in] | terminus | The end of the time range to collect data from. |
[in] | topic_filter | The vector of topics to collect in a page. |
[in] | page_length | The maximum length of the page to construct. |
[in] | prefix | Only collect data from files whose prefix matches, for example only collect from log files. |
[in] | filetype | Match file type, this defaults to csv . |
◆ read_line()
string SDReader::read_line |
( |
| ) |
|
Read until next newline character into buffer and return as a string.
- Returns
- The next line from the file as a string.
◆ set_filename()
Manually set the filename to access.
- Parameters
-
[in] | filename | The name of the file to open. Should be a path if not in the root directory. |
◆ topic_filter_match()
Check if any of the filters match the target string return true if one of them does or filter is "", else return false.
- Parameters
-
- Returns
true
if match found, false
otherwise.
The documentation for this class was generated from the following files: