#include "storage_monitor.h" namespace roro { void StorageMonitor::update(bool present, uint64_t totalBytes, uint64_t usedBytes) { StorageState next; next.present = present && totalBytes > 0; if (next.present) { next.totalBytes = totalBytes; next.usedBytes = usedBytes; next.usedPercent = static_cast(usedBytes * 100 / totalBytes); bool full = totalBytes - usedBytes < kFullReserveBytes || usedBytes >= totalBytes; next.level = full ? 100 : next.usedPercent >= 90 ? 90 : next.usedPercent >= 80 ? 80 : 0; next.logsAllowed = next.level < 90; next.capturesAllowed = next.level < 100; } bool levelChanged = next.present && (next.level != state_.level || !state_.present); bool firstReading = !state_.present; state_ = next; if (levelChanged && !(firstReading && next.level == 0)) bus_.publish(Event::withValues(EventType::StorageThreshold, next.usedPercent, next.level)); if (next.present && next.level >= 80 && !warned_) { warned_ = true; bus_.publish(Event::withText(EventType::Notification, "SD card over 80% full", static_cast(NotificationLevel::Warning))); } } } // namespace roro