Monorepo for Aesthetic.Computer aesthetic.computer
at main 47 lines 1.7 kB view raw
1#pragma once 2 3// AC Machines — system-level remote monitoring daemon 4// Runs in the main loop, independent of which piece is loaded. 5// Connects to wss://session-server.aesthetic.computer/machines 6 7#include "ws-client.h" 8#include "wifi.h" 9 10#define MACHINES_HEARTBEAT_FRAMES 1800 // ~30s at 60fps 11#define MACHINES_RECONNECT_FRAMES 300 // ~5s 12#define MACHINES_SEND_QUEUE_SIZE 16 13#define MACHINES_SEND_MSG_SIZE 16384 14 15typedef struct { 16 ACWs *ws; 17 int connected; // 1 after register sent 18 int reconnect_frame; // frame to attempt reconnect (0 = none) 19 int last_heartbeat_frame; 20 char current_piece[64]; 21 char device_token[512]; // from /mnt/.device-token 22 23 // Send queue (ws_send is single-slot, we may queue multiple on connect) 24 char send_queue[MACHINES_SEND_QUEUE_SIZE][MACHINES_SEND_MSG_SIZE]; 25 int sq_head; 26 int sq_tail; 27 int sq_count; 28 29 // Pending command from server → forwarded to JS runtime 30 volatile int cmd_pending; 31 char cmd_type[32]; // "jump", "reboot", "update", "request-logs" 32 char cmd_target[128]; // e.g. piece name for "jump" 33 char cmd_id[32]; // commandId for ack 34} ACMachines; 35 36// Call once at startup (after init_machine_id, before main loop) 37void machines_init(ACMachines *m); 38 39// Call once per frame from the main loop 40void machines_tick(ACMachines *m, ACWifi *wifi, int frame, int fps, 41 const char *current_piece); 42 43// Flush final logs before shutdown (blocking drain of send queue) 44void machines_flush_logs(ACMachines *m); 45 46// Call at shutdown 47void machines_destroy(ACMachines *m);