This commit is contained in:
2026-05-10 21:17:36 +02:00
parent f28cd4c31a
commit 9bd2357b96
7 changed files with 118 additions and 33 deletions

View File

@@ -1,13 +1,14 @@
#include "sys.h"
#include "utils.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/statvfs.h>
#include "sys.h"
#include "log.h"
#include "utils.h"
void sys_get_time(struct time_date_t *td) {
constexpr char months[][4] = {"sty", "lut", "mar", "kwi", "maj", "cze", "lip", "sie", "wrz", "paz", "lis", "gru"};
constexpr char wdays[][4] = {"Nie", "Pon", "Wto", "Sro", "Czw", "Pia", "Sob"};
@@ -61,10 +62,29 @@ void sys_get_network(struct network_t* network) {
clock_gettime(CLOCK_MONOTONIC, &current.ts);
fast_read_num_u64(path, "rx_bytes", buf, &current.rx, 1);
fast_read_num_u64(path, "tx_bytes", buf, &current.rx, 1);
const double ts_diff = (current.ts.tv_sec - prev.ts.tv_sec) + (current.ts.tv_nsec - prev.ts.tv_nsec) / 1000000000.0;
network->download = (current.rx - prev.rx) / ts_diff;
network->upload = (current.tx - prev.tx) / ts_diff;
fast_read_num_u64(path, "tx_bytes", buf, &current.tx, 1);
const double diff_s = (double)timespec_diff_us(&current.ts, &prev.ts) / 1000000.0;
network->download = (uint32_t)((double)(current.rx - prev.rx) / diff_s);
network->upload = (uint32_t)((double)(current.tx - prev.tx) / diff_s);
prev = current;
}
}
void sys_detect(struct syssensors_t* s, const char* platform) {
snprintf(s->hwmon, sizeof(s->hwmon), "/sys/devices/platform/%s/hwmon", platform);
const int ret = get_hwmon_dir(s->hwmon);
if (ret != 0) {
s->hwmon[0] = '\0';
applog(LOG_WRN, "Can't open system hwmon. Kernel params added? Module loaded? See README");
return;
}
applog(LOG_INF, "Detected system sensors in %s", s->hwmon);
}
void sys_update_sensors(struct syssensors_t* s) {
if (!s->hwmon[0])
return;
static char buf[8];
fast_read_num_u16(s->hwmon, "/fan2_input", buf, &s->fan_speed[0], 1);
fast_read_num_u16(s->hwmon, "/fan7_input", buf, &s->fan_speed[1], 1);
fast_read_num_i16(s->hwmon, "/temp5_input", buf, &s->t_sensor, 1000);
}