Skip to content

Commit

Permalink
configServer: Add CPU temperature to system status
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Jul 30, 2019
1 parent d02102b commit 657939e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
25 changes: 25 additions & 0 deletions deps/tools/configServer/src/SystemStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void SystemStatus::UpdateAll() {
UpdateMemory();
UpdateCpu();
UpdateNetwork();
UpdateTemp();
status(GetStatusJson());
writable(GetWritable());
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}
2 changes: 2 additions & 0 deletions deps/tools/configServer/src/SystemStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SystemStatus {
void UpdateMemory();
void UpdateCpu();
void UpdateNetwork();
void UpdateTemp();

DataHistory<uint64_t, 5> m_memoryFree;
DataHistory<uint64_t, 5> m_memoryAvail;
Expand All @@ -56,6 +57,7 @@ class SystemStatus {
uint64_t xmitBytes = 0;
};
DataHistory<NetworkData, 6> m_network;
DataHistory<uint64_t, 5> m_temp;
};

#endif // RPICONFIGSERVER_SYSTEMSTATUS_H_
3 changes: 2 additions & 1 deletion deps/tools/configServer/src/resources/frcvision.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ var systemStatusIds = ['systemMemoryFree1s', 'systemMemoryFree5s',
'systemCpuUser1s', 'systemCpuUser5s',
'systemCpuSystem1s', 'systemCpuSystem5s',
'systemCpuIdle1s', 'systemCpuIdle5s',
'systemNetwork1s', 'systemNetwork5s'];
'systemNetwork1s', 'systemNetwork5s',
'systemCpuTemp1s', 'systemCpuTemp5s'];

function displayDisconnected() {
displayReadOnly();
Expand Down
5 changes: 5 additions & 0 deletions deps/tools/configServer/src/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@
<td id="systemNetwork1s"></td>
<td id="systemNetwork5s"></td>
</tr>
<tr>
<th scope="row">CPU Temp (&deg;C)</th>
<td id="systemCpuTemp1s"></td>
<td id="systemCpuTemp5s"></td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-warning" id="systemRestart">
Expand Down

0 comments on commit 657939e

Please sign in to comment.