Commit 002aa4ca authored by Alessandro Rubini's avatar Alessandro Rubini

syslog: report over-temperature situations and recover

The threshold and the repeat interval is set by Kconfig.
The temperatures are read using the temperature framework.

Tested in host environment:

   wrc# faketemp 90 80 10
   wrc# faketemp 90 40 20
   wrc# faketemp 20 30 40

   Jan  1 10:32:09 192.168.16.7 Temperature high: \
                                  roof:90.0000 core:80.0000 case:10.0000
   Jan  1 10:33:09 192.168.16.7 Temperature high: \
                                  roof:90.0000 core:40.0000 case:20.0000
   Jan  1 10:33:18 192.168.16.7 Temperature ok: \
                                  roof:20.0000 core:30.0000 case:40.0000
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent f3ab1f70
......@@ -211,6 +211,16 @@ config TEMP_POLL_INTERVAL
depends on DEVELOPER && WR_NODE
int "Poll interval, in seconds, for temperature sensors"
config TEMP_HIGH_THRESHOLD
depends on DEVELOPER && WR_NODE && SYSLOG
default 70
int "Threshold for temperature: tell syslog if higher"
config TEMP_HIGH_RAPPEL
depends on DEVELOPER && WR_NODE && SYSLOG
default 60
int "Remember over-temperature every that many seconds"
config CMD_LL
depends on DEVELOPER && EMBEDDED_NODE
bool "Build low-level commands for development/testing"
......
#include <string.h>
#include <wrc.h>
#include <wrpc.h>
#include <temperature.h>
#include "endpoint.h"
#include "minic.h"
#include "shell.h"
......@@ -78,6 +79,10 @@ int syslog_poll(void)
unsigned char ip[4];
static uint32_t down_tics;
int len = 0;
uint32_t now;
/* for temperature state */
static uint32_t next_temp_report, next_temp_check;
/* for servo-state (accesses ppsi internal variables */
extern struct pp_instance *ppi;
......@@ -153,6 +158,36 @@ int syslog_poll(void)
goto send;
}
if (!next_temp_check) {
next_temp_check = now + 1000;
next_temp_report = 0;
}
if (time_after_eq(now, next_temp_check)) {
struct wrc_onetemp *t = NULL;
int over_t = 0;
next_temp_check += 1000;
while ( (t = wrc_temp_getnext(t)) )
over_t += (t->t > (CONFIG_TEMP_HIGH_THRESHOLD << 16));
/* report if over temp, and first report or rappel time */
if (over_t && (!next_temp_report
|| time_after_eq(now, next_temp_report))) {
next_temp_report = now + 1000 * CONFIG_TEMP_HIGH_RAPPEL;
len = syslog_header(buf, SYSLOG_DEFAULT_LEVEL, ip);
len += pp_sprintf(buf + len, "Temperature high: ");
len += wrc_temp_format(buf + len, sizeof(buf) - len);
goto send;
}
if (!over_t && next_temp_report) {
next_temp_report = 0;
len = syslog_header(buf, SYSLOG_DEFAULT_LEVEL, ip);
len += pp_sprintf(buf + len, "Temperature ok: ");
len += wrc_temp_format(buf + len, sizeof(buf) - len);
goto send;
}
}
return 0;
send:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment