-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
60 lines (47 loc) · 1.49 KB
/
test.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
52
53
54
55
56
57
58
59
60
#include <cstdio>
#include <cstdlib>
#include <cstddef>
#include <cstring>
#include <string>
#include "Arduino.h"
#include "sd_raw.h"
#include "fkfs.h"
static constexpr uint8_t FKFS_FILE_LOG = 0;
static constexpr uint8_t FKFS_FILE_DATA = 1;
static constexpr uint8_t FKFS_FILE_PRIORITY_LOWEST = 255;
static constexpr uint8_t FKFS_FILE_PRIORITY_HIGHEST = 0;
int main(int argc, const char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <image>\n", argv[0]);
return 2;
}
fkfs_t fs;
if (!fkfs_create(&fs)) {
return 2;
}
if (!sd_raw_file_initialize(&fs.sd, argv[1])) {
fprintf(stderr, "error: Unable to open file.\n");
return 2;
}
if (!fkfs_initialize_file(&fs, FKFS_FILE_LOG, FKFS_FILE_PRIORITY_LOWEST, true, "FK.LOG")) {
fprintf(stderr, "error: Unable to initialize file.\n");
return 2;
}
if (!fkfs_initialize_file(&fs, FKFS_FILE_DATA, FKFS_FILE_PRIORITY_HIGHEST, true, "DATA.BIN")) {
fprintf(stderr, "error: Unable to initialize file.\n");
return 2;
}
if (!fkfs_initialize(&fs, false)) {
fprintf(stderr, "error: Unable to initialize fkfs.\n");
return 2;
}
fkfs_log_statistics(&fs);
const char *buffer = "Hello, world!";
if (!fkfs_file_append(&fs, FKFS_FILE_LOG, strlen(buffer), (uint8_t *)buffer)) {
fprintf(stderr, "error: Unable to append to file.\n");
return 0;
}
fkfs_flush(&fs);
sd_raw_file_close(&fs.sd);
return 0;
}