Files
roro9stack/src/services/clock_service.h
T
twislaandClaude Opus 5.5 b7aed8e91c F1 steps 2-6: the Storage App, its viewers, and Maintenance moved in (#3)
The Storage App browses the SD card: folders first with sizes and dates,
three sorts, one item at a time with a clipboard (c, x, v), rename, delete
after counting what's inside, new folder, details. A listing holds 256
entries and says when a folder has more.

FileOps does the card's work for the App and the console alike, one
operation at a time on the storage task in turns of about 150 ms, so Logs
and Captures are still written during a long copy. A copy shows progress,
can be cancelled (what it wrote is taken back) and compares sizes after.
The read-only rules are checked there: the firmware's top-level folders,
/gemini/cache, and files being written (a Track, a Capture, an upload,
today's IRC Logs). A listing reads the folder straight from FatFs: through
the Arduino File, 329 entries took over two seconds.

Viewers by type: text read a screen at a time whatever the file's size
(logs open at the end), a hex dump, a Capture's packets as the LoRa Scanner
lists them, a Track's summary, and an Update File checked as an install
would check it, without writing anything. Tab shows any file as hex or text.

Settings > Storage is gone: usage, Storage Clean-up and Erase are the App's
Maintenance, behind a warning. The Storage Warning points there.

The Clock sets the system time whatever its source, so files are dated
correctly with a GNSS Fix alone (Q137).

Console: cp, mv, mkdir, du, cancel; rm takes folders and follows the rules;
ls shows dates; Debug Builds get `sd fill`.

424 host tests. Checked on the device: docs/milestones/F1.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
2026-10-06 08:45:43 +02:00

57 lines
2.0 KiB
C++

#pragma once
#include <Arduino.h>
#include <sys/time.h>
#include "clock_model.h"
#include "event_bus.h"
#include "service.h"
#include "settings.h"
namespace roro {
// Holds wall-clock time. Sources (GNSS in M2, NTP in M1, mesh in M4) call set().
class ClockService : public Service {
public:
ClockService(const Settings& settings, EventBus& bus) : settings_(settings) {
bus.subscribe(EventType::SettingChanged, [this](const Event& e) {
if (e.a == static_cast<int32_t>(Setting::Timezone)) applyTimezone();
});
}
const char* name() const override { return "clock"; }
void start() override { applyTimezone(); }
bool set(int64_t utcSeconds, TimeSource source) {
if (!model_.set(utcSeconds, source, millis())) return false;
// The system's own clock too (F1, Q137): the card's files are dated from it, and NTP was
// the only thing setting it. NTP has just done so itself.
if (source != TimeSource::Ntp) {
timeval now = {static_cast<time_t>(utcSeconds), 0};
settimeofday(&now, nullptr);
}
return true;
}
const ClockModel& model() const { return model_; }
// UTC seconds, or -1 if the clock isn't set.
int64_t utcNow() const { return model_.isSet() ? model_.utcNow(millis()) : -1; }
// Local "YYYY-MM-DD" once set; otherwise empty (Logs then go to undated files).
std::string localDate() const { return model_.isSet() ? ClockModel::formatLocalDate(model_.utcNow(millis())) : ""; }
// Days since 1970-01-01 (UTC), or -1 if the clock isn't set.
int today() const { return model_.isSet() ? static_cast<int>(model_.utcNow(millis()) / 86400) : -1; }
// "14:05" once set; otherwise "--:--".
std::string displayTime() const {
return model_.isSet() ? ClockModel::formatLocalTime(model_.utcNow(millis())) : "--:--";
}
private:
void applyTimezone() { ClockModel::applyTimezone(settings_.getString(Setting::Timezone).c_str()); }
const Settings& settings_;
ClockModel model_;
};
} // namespace roro