Data Gator
Hardware and software documentation for the Data Gator project.
Loading...
Searching...
No Matches
SDReader.hpp
Go to the documentation of this file.
1
7#include <SD.h>
8#include <vector>
9#include <string>
10
11#include "../../include/SDCard.hpp"
12#include "SDLogger.hpp"
13#include "TimeStamp.hpp"
14#include "MQTTMailer.hpp"
15
16#ifndef SDREADER_HPP
17#define SDREADER_HPP
18
19
20using namespace std;
21
22// must have an mqtt_client connected to publish data
23// to
25extern const bool USB_DEBUG;
26
31class SDReader {
32
33 private:
34
35 std::string filename = "";
36 std::string separator = ";";
37
38 SDCard sd; // default sd interface passed to constructor
39
40 bool initialize_sd_card();
41
42 bool file_open = false;
43 File fp;
44
46
47 string build_json_page(
48 string filename,
49 long int epoch,
50 long int terminus,
51 vector<string> &data);
52
54
55 public:
56
61
67 SDReader(std::string filename){
68 this->filename = filename;
70 }
71
81 SDReader(std::string prefix,
82 int month,
83 int day,
84 int year,
85 std::string filetype){
86
87 this->filename = prefix + "_" +
88 to_string(month) + "-" +
89 to_string(day) + "-" +
90 to_string(year) + "." + filetype;
91
93 }
94
100 void set_filename(string filename){this->filename = filename;}
101
106 std::string read_line();
107
114 int page_length=5,
115 string prefix="log",
116 string filetype="csv");
117
121 void read_entry_range(File f,
125 int page_length);
126
130 File* open_file(){
131 if(filename == "") return NULL;
132 this->fp = (sd.open(this->filename.c_str(), "r"));
133 this->file_open = true;
134 return &(this->fp);
135 }
136
140 File* open_file(string filename){
141 this->fp = sd.open(filename.c_str(), "r");
142 this->file_open = true;
143 return &(this->fp);
144 }
145
150 this->file_open = false;
151 this->fp.close();
152 }
153
154};
155
156#endif
Implements an interface for using SPI, SDLogger, for reading and writing to files on an SD card.
const bool USB_DEBUG
USB serial debugging enabled.
Definition main.cpp:62
Thin wrapper around ESP32 SD card API.
Definition SDCard.hpp:28
File open(const char *path, const char *mode=FILE_READ, const bool create=false)
Definition SDCard.hpp:92
SDReader provides an interface for opening and reading data from files created using the SDLogger lib...
Definition SDReader.hpp:31
string build_json_page(string filename, long int epoch, long int terminus, vector< string > &data)
Compile collected data into a JSON "page" which can then be published via the MQTT interface.
Definition SDReader.cpp:54
bool initialize_sd_card()
Initialize connection to SD card and return false if no connection established.
Definition SDReader.cpp:114
void set_filename(string filename)
Manually set the filename to access.
Definition SDReader.hpp:100
SDReader(std::string filename)
Constructor initializes SD card and set default file to open.
Definition SDReader.hpp:67
void close_file()
Close the open file.
Definition SDReader.hpp:149
SDReader(std::string prefix, int month, int day, int year, std::string filetype)
Constructor initializes and sets the file name structure.
Definition SDReader.hpp:81
File * open_file()
Open the specified file and get the file pointer.
Definition SDReader.hpp:130
SDReader()
Constructor initializes SD card connection and nothing more.
Definition SDReader.hpp:60
int calculate_page_size(vector< string > &page)
Calculate the size, in bytes, of the current page.
Definition SDReader.cpp:86
std::string read_line()
Read until next newline character into buffer and return as a string.
Definition SDReader.cpp:133
File * open_file(string filename)
Open the specified file from path provided.
Definition SDReader.hpp:140
bool topic_filter_match(vector< string > filter, string target)
Check if any of the filters match the target string return true if one of them does or filter is "",...
Definition SDReader.cpp:27
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.
Definition SDReader.cpp:167
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.
Definition SDReader.cpp:224
Definition TimeStamp.hpp:14
int reset_count
number of resets retrieved for NVS
Definition scheduler.hpp:31
PubSubClient mqtt_client
MQTT client object for logging.