roo_monitoring
API Documentation for roo_monitoring
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1#pragma once
2
3#include <Arduino.h>
4#include <stdint.h>
5
6#include <vector>
7
8#include "roo_io/fs/filesystem.h"
9
10namespace roo_monitoring {
11
12/// Number of base-4 digits used per range.
13///
14/// Default is 4 (4^4 = 256 items per range). When ROO_MONITORING_TESTING is
15/// defined, use 2 (16 items per range) to keep unit tests small but meaningful.
16#ifdef ROO_MONITORING_TESTING
17static const int kRangeLength = 2;
18#else
19static const int kRangeLength = 4;
20#endif
21/// Number of items in a range (4^(kRangeLength)).
22static const int kRangeElementCount = 1 << (kRangeLength << 1);
23
24/// Base directory for monitoring storage on the filesystem.
25extern const char* kMonitoringBasePath;
26/// Subdirectory name used for raw log files.
27extern const char* kLogSubPath;
28
29/// Converts a 0-15 value to an uppercase hex digit.
30inline constexpr char toHexDigit(int d) {
31 return (d < 10) ? d + '0' : d - 10 + 'A';
32}
33
34/// Returns a path formed by joining the base directory and subdirectory.
35String subdir(String base, const String& sub);
36/// Returns a file path for the given directory and timestamp-like value.
37String filepath(String dir, int64_t file);
38
39/// Lists timestamp-named files in the directory and returns their timestamps.
40///
41/// The timestamps are in milliseconds since Epoch and sorted ascending.
42std::vector<int64_t> listFiles(roo_io::Mount& fs, const char* dirname);
43
44/// Helper class for generating filenames corresponding to timestamps.
45class Filename {
46 public:
47 /// Creates a filename for the specified timestamp.
48 static Filename forTimestamp(int64_t nanosSinceEpoch);
49 /// Returns the generated filename as a null-terminated string.
50 const char* filename() const { return data_; }
51
52 private:
53 Filename() {}
54 char data_[13];
55};
56
57} // namespace roo_monitoring
Helper class for generating filenames corresponding to timestamps.
Definition common.h:45
const char * filename() const
Returns the generated filename as a null-terminated string.
Definition common.h:50
static Filename forTimestamp(int64_t nanosSinceEpoch)
Creates a filename for the specified timestamp.
Definition common.cpp:69
Umbrella header for the roo_monitoring module.
static const int kRangeElementCount
Number of items in a range (4^(kRangeLength)).
Definition common.h:22
const char * kLogSubPath
Subdirectory name used for raw log files.
Definition common.cpp:11
static const int kRangeLength
Number of base-4 digits used per range.
Definition common.h:19
String filepath(String dir, int64_t file)
Returns a file path for the given directory and timestamp-like value.
Definition common.cpp:19
const char * kMonitoringBasePath
Base directory for monitoring storage on the filesystem.
Definition common.cpp:10
std::vector< int64_t > listFiles(roo_io::Mount &fs, const char *dirname)
Lists timestamp-named files in the directory and returns their timestamps.
Definition common.cpp:45
constexpr char toHexDigit(int d)
Converts a 0-15 value to an uppercase hex digit.
Definition common.h:30
String subdir(String base, const String &sub)
Returns a path formed by joining the base directory and subdirectory.
Definition common.cpp:13