-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDcard.cpp
51 lines (49 loc) · 1.03 KB
/
SDcard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "SDcard.h"
bool initSDCard(){
if (!SD.begin(15)) {
return false;
}
return true;
}
bool writeFile(fs::FS &fs, const char * path, const char * message) {
File file = fs.open(path, FILE_WRITE);
if(!file) {
return false;
}
if(file.print(message)) {
file.close();
return true;
} else {
file.close();
return false;
}
}
bool appendFile(fs::FS &fs, const char * path, const char * message) {
File file = fs.open(path, FILE_APPEND);
if(!file) {
return false;
}
if(file.print(message)) {
file.close();
return true;
} else {
file.close();
return false;
}
}
void readFile(fs::FS &fs, const char * path, String& payload){
File file = fs.open(path);
if(!file){
Serial.println("Failed to open file for reading");
return;
}
payload = file.readString();
file.close();
}
void saveTleDataToSD(String& payload){
const char* mess = &payload[0];
writeFile(SD, PATH_TLE_IN_SD, mess);
}
void updateTleDataFromSD(String& payload){
readFile(SD, PATH_TLE_IN_SD, payload);
}