From 657939e6a8a242ddbc06d54745ca30d064c0a00d Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 29 Jul 2019 00:18:40 -0700 Subject: [PATCH] configServer: Add CPU temperature to system status --- deps/tools/configServer/src/SystemStatus.cpp | 25 +++++++++++++++++++ deps/tools/configServer/src/SystemStatus.h | 2 ++ .../configServer/src/resources/frcvision.js | 3 ++- .../configServer/src/resources/index.html | 5 ++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/deps/tools/configServer/src/SystemStatus.cpp b/deps/tools/configServer/src/SystemStatus.cpp index a2bf261e68..8874b8262a 100644 --- a/deps/tools/configServer/src/SystemStatus.cpp +++ b/deps/tools/configServer/src/SystemStatus.cpp @@ -23,6 +23,7 @@ void SystemStatus::UpdateAll() { UpdateMemory(); UpdateCpu(); UpdateNetwork(); + UpdateTemp(); status(GetStatusJson()); writable(GetWritable()); } @@ -89,6 +90,15 @@ wpi::json SystemStatus::GetStatusJson() { } } + // temperature + { + uint64_t first; + if (m_temp.GetFirstLast(&first, nullptr, &qty)) { + j["systemCpuTemp1s"] = first / 1000; + if (qty >= 5) j["systemCpuTemp5s"] = m_temp.GetTotal() / qty / 1000; + } + } + return j; } @@ -207,3 +217,18 @@ void SystemStatus::UpdateNetwork() { m_network.Add(data); } + +void SystemStatus::UpdateTemp() { + std::error_code ec; + wpi::raw_fd_istream is("/sys/class/thermal/thermal_zone0/temp", ec); + if (ec) return; + wpi::SmallString<256> lineBuf; + while (!is.has_error()) { + wpi::StringRef line = is.getline(lineBuf, 256).trim(); + if (line.empty()) break; + + uint64_t amt; + if (line.getAsInteger(10, amt)) continue; + m_temp.Add(amt); + } +} diff --git a/deps/tools/configServer/src/SystemStatus.h b/deps/tools/configServer/src/SystemStatus.h index d5f81a35cd..cdaf957641 100644 --- a/deps/tools/configServer/src/SystemStatus.h +++ b/deps/tools/configServer/src/SystemStatus.h @@ -40,6 +40,7 @@ class SystemStatus { void UpdateMemory(); void UpdateCpu(); void UpdateNetwork(); + void UpdateTemp(); DataHistory m_memoryFree; DataHistory m_memoryAvail; @@ -56,6 +57,7 @@ class SystemStatus { uint64_t xmitBytes = 0; }; DataHistory m_network; + DataHistory m_temp; }; #endif // RPICONFIGSERVER_SYSTEMSTATUS_H_ diff --git a/deps/tools/configServer/src/resources/frcvision.js b/deps/tools/configServer/src/resources/frcvision.js index 21f10117b7..80dbade883 100644 --- a/deps/tools/configServer/src/resources/frcvision.js +++ b/deps/tools/configServer/src/resources/frcvision.js @@ -56,7 +56,8 @@ var systemStatusIds = ['systemMemoryFree1s', 'systemMemoryFree5s', 'systemCpuUser1s', 'systemCpuUser5s', 'systemCpuSystem1s', 'systemCpuSystem5s', 'systemCpuIdle1s', 'systemCpuIdle5s', - 'systemNetwork1s', 'systemNetwork5s']; + 'systemNetwork1s', 'systemNetwork5s', + 'systemCpuTemp1s', 'systemCpuTemp5s']; function displayDisconnected() { displayReadOnly(); diff --git a/deps/tools/configServer/src/resources/index.html b/deps/tools/configServer/src/resources/index.html index a64e6ef539..f3910a7114 100644 --- a/deps/tools/configServer/src/resources/index.html +++ b/deps/tools/configServer/src/resources/index.html @@ -111,6 +111,11 @@ + + CPU Temp (°C) + + +