Files
pi-dashboard/components/ws_client/ws_client.h
2026-02-15 12:57:05 +09:00

66 lines
1.5 KiB
C

#ifndef WS_CLIENT_H
#define WS_CLIENT_H
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define WS_MAX_SERVICES 8
#define WS_SERVICE_NAME_LEN 16
typedef enum {
WS_STATE_DISCONNECTED = 0,
WS_STATE_CONNECTING,
WS_STATE_CONNECTED,
WS_STATE_ERROR,
} ws_state_t;
typedef struct {
char name[WS_SERVICE_NAME_LEN];
bool running;
} ws_service_t;
typedef struct {
float cpu_pct;
float mem_pct;
uint32_t mem_used_mb;
float disk_pct;
float cpu_temp;
float uptime_hrs;
float net_rx_kbps;
float net_tx_kbps;
ws_service_t services[WS_MAX_SERVICES];
uint8_t service_count;
uint32_t last_update; // timestamp from server
bool valid; // set true after first successful parse
/* Broken-down local time from Pi for RTC sync */
uint16_t time_year;
uint8_t time_month;
uint8_t time_day;
uint8_t time_hour;
uint8_t time_minute;
uint8_t time_second;
bool time_valid; // true when local_time object was parsed
} pi_stats_t;
typedef void (*ws_data_callback_t)(const pi_stats_t *stats);
typedef void (*ws_state_callback_t)(ws_state_t state);
void ws_client_init(const char *uri);
void ws_client_start(void);
void ws_client_stop(void);
ws_state_t ws_client_get_state(void);
void ws_client_get_stats(pi_stats_t *out);
void ws_client_set_data_callback(ws_data_callback_t cb);
void ws_client_set_state_callback(ws_state_callback_t cb);
#ifdef __cplusplus
}
#endif
#endif