-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSdPositionsConfig.cpp
More file actions
80 lines (60 loc) · 1.51 KB
/
SdPositionsConfig.cpp
File metadata and controls
80 lines (60 loc) · 1.51 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "Config.h"
#if BACKUP_ENABLE_SDCARD
#include "SdPositionsConfig.h"
#include "SdCard.h"
#include "Logging.h"
namespace config {
#define CURRENT_LOGGER "config::backup::sd"
namespace backup {
namespace sd {
SdPositionConfig_t value;
File configFile;
namespace details {
void ensureOpened() {
if (!configFile.isOpen()) {
hardware::sdcard::filesystem.chdir();
configFile.open(POSITIONS_CONFIG_FILENAME, O_RDWR | O_CREAT);
}
configFile.rewind();
}
void read() {
#define CURRENT_LOGGER_FUNCTION "read"
VERBOSE;
ensureOpened();
configFile.read((void*)&value, sizeof(value));
if (value.seed != POSITIONS_CONFIG_SEED) reset();
}
void write() {
#define CURRENT_LOGGER_FUNCTION "write"
VERBOSE;
ensureOpened();
configFile.write((void*)&value, sizeof(value));
}
}
SdPositionConfig_t get() {
if (value.seed != POSITIONS_CONFIG_SEED) details::read();
return value;
}
void set(SdPositionConfig_t config) {
value = config;
details::write();
}
void reset() {
#define CURRENT_LOGGER_FUNCTION "reset"
VERBOSE;
SdPositionConfig_t config = {
POSITIONS_CONFIG_SEED,
POSITIONS_CONFIG_SAVE_THRESHOLD,
POSITIONS_CONFIG_MAX_RECORDS_PER_FILE,
0xFFFF,
0,
0,
0
};
value = config;
details::write();
}
}
}
}
#endif