/* Copyright (c) 2025 Rodrigo Arias Mallo * SPDX-License-Identifier: GPL-3.0-or-later */ #include #include "overheat.h" #include "thermostat.h" #include "heater.h" /* Read a CSV from the stdin in the format * * skipping the first row (header). * * Outputs overheat state. */ #define MAX_LINE 1024 int main(void) { char buf[MAX_LINE]; fgets(buf, MAX_LINE, stdin); float t, temp; int st; struct overheat ovh = { 0 }; struct thermostat th = { 0 }; struct heater heater = { 0 }; overheat_init(&ovh); for (int i = 0; scanf("%f %d %f", &t, &st, &temp) == 3; i++) { if (i == 0) thermostat_set(&th, 60.0); unsigned long t_ms = t * 1000; overheat_input(&ovh, t_ms, temp); float delta = overheat_delta(&ovh); float speed = overheat_speed(&ovh); float u = thermostat_state(&th, temp, speed); heater_on(&heater, t_ms, u); int h = heater_state(&heater, t_ms); int panic = overheat_panic(&ovh); printf("%8.3f %2d %6.2f %6.1f %8.3f %8.3f %d %s\n", t, st, temp, delta, speed, u, h, panic ? "PANIC" : "OK"); } return 0; }