#pragma once #include #include #include "app.h" #include "key_value_store.h" #include "services/battery_service.h" #include "services/gnss_service.h" #include "services/radio_service.h" #include "services/storage_service.h" #include "services/wifi_service.h" #include "task_stats.h" #include "traffic.h" namespace roro { // The System App (docs/milestones/S1.md, Q117 to Q127): what the device is doing, live and // read-only. Tab moves between Overview, Tasks, Memory, Network and System. It samples once a // second and keeps two minutes of history, only while it's open (Q120). class SystemApp : public App { public: SystemApp(WifiService& wifi, BatteryService& battery, StorageService& storage, RadioService& radio, GnssService& gnss, KeyValueStore& store) : wifi_(wifi), battery_(battery), storage_(storage), radio_(radio), gnss_(gnss), store_(store) {} void onEnter() override; void onExit() override; bool onKey(const KeyEvent& e) override; void update(uint32_t nowMs) override; void draw(Canvas& c) override; private: enum class View : uint8_t { Overview, Tasks, Memory, Network, System, Count }; static constexpr size_t kHistory = 120; // seconds static constexpr int kTaskRows = 7; void sample(uint32_t nowMs); void drawOverview(Canvas& c); void drawTasks(Canvas& c); void drawMemory(Canvas& c); void drawNetwork(Canvas& c); void drawSystem(Canvas& c); void footer(Canvas& c, const char* keys); WifiService& wifi_; BatteryService& battery_; StorageService& storage_; RadioService& radio_; GnssService& gnss_; KeyValueStore& store_; View view_ = View::Overview; uint32_t sampledMs_ = 0; std::vector before_; uint32_t beforeTotal_ = 0; std::vector rows_; // the last second, sorted TaskSort sort_ = TaskSort::Share; int taskTop_ = 0; int load_[2] = {-1, -1}; History loadHistory_[2]; History heapHistory_; // free heap, KB net::Traffic traffic_[static_cast(net::User::Count)]; uint32_t rateIn_[static_cast(net::User::Count)] = {}, rateOut_[static_cast(net::User::Count)] = {}; std::vector systemLines_; int systemTop_ = 0, wrappedLines_ = 0; }; } // namespace roro