Data Gator
Hardware and software documentation for the Data Gator project.
Loading...
Searching...
No Matches
SDLogger.hpp
Go to the documentation of this file.
1
8#ifndef SDLOGGER_H
9#define SDLOGGER_H
10
11#include <SD.h>
12#include "../../include/SDCard.hpp"
13
14#include <vector>
15
16#define TT_CLK 18
17#define TT_MISO 19
18#define TT_MOSI 23
19#define TT_SS 13
20
21
30class SDLogger {
31
32 private:
33
34 std::string filename; // name of the file that this SDLogger interacts with
35 std::string filetype = ".csv"; // file extension assumed for the file
36 std::string separator = ";"; // separator between CSV fields
37
38 SDCard sd;
39
40
41 public:
42
47
51 SDLogger(std::string filename);
52
56 SDLogger(std::string prefix, int month, int day, int year, std::string filetype);
57
58 // must be called before logging
59 bool initialize_sd_card();
60
64 void set_filename(std::string);
65
70 void set_filename(std::string prefix, int month, int day, int year, std::string filetype);
71
76 void write_header(std::vector<std::string> fields);
77
82 void log_absolute_mqtt(std::string time, std::string mqtt_topic, std::string mqtt_message);
83
88 void log_relative_mqtt(std::string time, int offset, std::string mqtt_topic, std::string mqtt_message);
89
94 void write_line(std::string line);
95
100 void append_line(std::string line);
101
105 void read();
106
111 File open_file(const char* mode = FILE_WRITE);
112
116 bool exists(std::string fn){return this->sd.exists(fn.c_str());}
117
121 bool exists(){return this->sd.exists(this->filename.c_str());}
122
126 void close_card();
127
128};
129
130#endif
Thin wrapper around ESP32 SD card API.
Definition SDCard.hpp:28
bool exists(const char *path)
Definition SDCard.hpp:109
Creates an interface for writing data to a log file on an SD card.
Definition SDLogger.hpp:30
void close_card()
Close card connection.
Definition SDLogger.cpp:112
SDLogger()
Default constructor that performs no initialization.
Definition SDLogger.hpp:46
void write_line(std::string line)
Write a line to the file, will overwrite the contents of the file.
Definition SDLogger.cpp:124
bool initialize_sd_card()
Call before using SD card interface. Initializes connection to SD card.
Definition SDLogger.cpp:37
void log_absolute_mqtt(std::string time, std::string mqtt_topic, std::string mqtt_message)
Append a line to the target csv file containing an absolute time stamp, mqtt topic,...
Definition SDLogger.cpp:161
bool exists(std::string fn)
File with name fn exists in SD card's filesystem.
Definition SDLogger.hpp:116
bool exists()
File with name stored in this->filename exists in SD card's filesystem.
Definition SDLogger.hpp:121
void log_relative_mqtt(std::string time, int offset, std::string mqtt_topic, std::string mqtt_message)
Append a line with a relative time stamp to the target file.
Definition SDLogger.cpp:181
File open_file(const char *mode=FILE_WRITE)
Opens the file attached to the logger object with the default mode.
Definition SDLogger.cpp:92
void read()
Not implemented
void append_line(std::string line)
Open file and append a line, add newline if needed.
Definition SDLogger.cpp:141
void set_filename(std::string)
Set the filename to write to the easiest way possible.
Definition SDLogger.cpp:59
void write_header(std::vector< std::string > fields)
Writes a header line to a file using append to prevent overwriting valuable data.
Definition SDLogger.cpp:197
int reset_count
number of resets retrieved for NVS
Definition scheduler.hpp:31