46 static int32_t
hasSeverity(SystemAlarmsAlarmOptions severity);
53 SystemAlarmsInitialize();
57 uint8_t reboot_reason = SYSTEMALARMS_REBOOTCAUSE_UNDEFINED;
61 reboot_reason = SYSTEMALARMS_REBOOTCAUSE_BROWNOUT;
64 reboot_reason = SYSTEMALARMS_REBOOTCAUSE_PINRESET;
67 reboot_reason = SYSTEMALARMS_REBOOTCAUSE_POWERONRESET;
70 reboot_reason = SYSTEMALARMS_REBOOTCAUSE_SOFTWARERESET;
73 reboot_reason = SYSTEMALARMS_REBOOTCAUSE_INDEPENDENTWATCHDOG;
76 reboot_reason = SYSTEMALARMS_REBOOTCAUSE_WINDOWWATCHDOG;
79 reboot_reason = SYSTEMALARMS_REBOOTCAUSE_LOWPOWER;
82 reboot_reason = SYSTEMALARMS_REBOOTCAUSE_UNDEFINED;
86 SystemAlarmsRebootCauseSet(&reboot_reason);
97 int32_t
AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
99 SystemAlarmsData alarms;
102 if (alarm >= SYSTEMALARMS_ALARM_NUMELEM)
111 SystemAlarmsGet(&alarms);
112 if ( alarms.Alarm[alarm] != severity )
114 alarms.Alarm[alarm] = severity;
115 SystemAlarmsSet(&alarms);
129 SystemAlarmsAlarmOptions
AlarmsGet(SystemAlarmsAlarmElem alarm)
131 SystemAlarmsData alarms;
134 if (alarm >= SYSTEMALARMS_ALARM_NUMELEM)
140 SystemAlarmsGet(&alarms);
141 return alarms.Alarm[alarm];
160 for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n)
173 return AlarmsSet(alarm, SYSTEMALARMS_ALARM_OK);
182 for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n)
221 SystemAlarmsData alarms;
228 SystemAlarmsGet(&alarms);
231 for (n = 0; n < SYSTEMALARMS_ALARM_NUMELEM; ++n)
233 if ( alarms.Alarm[n] >= severity)
246 [SYSTEMALARMS_ALARM_OUTOFMEMORY] =
"MEMORY",
247 [SYSTEMALARMS_ALARM_CPUOVERLOAD] =
"CPU",
248 [SYSTEMALARMS_ALARM_STACKOVERFLOW] =
"STACK",
249 [SYSTEMALARMS_ALARM_SYSTEMCONFIGURATION] =
"CONFIG",
250 [SYSTEMALARMS_ALARM_EVENTSYSTEM] = {0},
251 [SYSTEMALARMS_ALARM_TELEMETRY] = {0},
252 [SYSTEMALARMS_ALARM_MANUALCONTROL] =
"MANUAL",
253 [SYSTEMALARMS_ALARM_ACTUATOR] =
"ACTUATOR",
254 [SYSTEMALARMS_ALARM_ATTITUDE] =
"ATTITUDE",
255 [SYSTEMALARMS_ALARM_SENSORS] =
"SENSORS",
256 [SYSTEMALARMS_ALARM_STABILIZATION] =
"STAB",
257 [SYSTEMALARMS_ALARM_PATHFOLLOWER] =
"P-FOLLOW",
258 [SYSTEMALARMS_ALARM_PATHPLANNER] =
"P-PLAN",
259 [SYSTEMALARMS_ALARM_BATTERY] =
"BATTERY",
260 [SYSTEMALARMS_ALARM_FLIGHTTIME] =
"TIME",
261 [SYSTEMALARMS_ALARM_I2C] =
"I2C",
262 [SYSTEMALARMS_ALARM_GPS] =
"GPS",
263 [SYSTEMALARMS_ALARM_ALTITUDEHOLD] =
"A-HOLD",
264 [SYSTEMALARMS_ALARM_BOOTFAULT] =
"BOOT",
265 [SYSTEMALARMS_ALARM_GEOFENCE] =
"GEOFENCE",
266 [SYSTEMALARMS_ALARM_TEMPBARO] =
"TEMPBARO",
267 [SYSTEMALARMS_ALARM_GYROBIAS] =
"GYROBIAS",
268 [SYSTEMALARMS_ALARM_ADC] =
"ADC",
269 [SYSTEMALARMS_ALARM_GIMBAL] =
"GIMBAL",
276 [SYSTEMALARMS_CONFIGERROR_STABILIZATION] =
"CFG:STAB",
277 [SYSTEMALARMS_CONFIGERROR_MULTIROTOR] =
"CFG:MULTIROTOR",
278 [SYSTEMALARMS_CONFIGERROR_AUTOTUNE] =
"CFG:AUTOTUNE",
279 [SYSTEMALARMS_CONFIGERROR_ALTITUDEHOLD] =
"CFG:AH1",
280 [SYSTEMALARMS_CONFIGERROR_POSITIONHOLD] =
"CFG:POS-HOLD",
281 [SYSTEMALARMS_CONFIGERROR_PATHPLANNER] =
"CFG:PATHPLAN",
282 [SYSTEMALARMS_CONFIGERROR_DUPLICATEPORTCFG] =
"CFG:DUP PORT",
283 [SYSTEMALARMS_CONFIGERROR_NAVFILTER] =
"CFG:NAVFILTER",
284 [SYSTEMALARMS_CONFIGERROR_UNSAFETOARM] =
"CFG:UNSAFE",
285 [SYSTEMALARMS_CONFIGERROR_LQG] =
"CFG:LQG",
286 [SYSTEMALARMS_CONFIGERROR_UNDEFINED] =
"CFG:UNDEF",
287 [SYSTEMALARMS_CONFIGERROR_NONE] = {0},
293 [SYSTEMALARMS_MANUALCONTROL_SETTINGS] =
"MAN:SETTINGS",
294 [SYSTEMALARMS_MANUALCONTROL_NORX] =
"MAN:NO RX",
295 [SYSTEMALARMS_MANUALCONTROL_ACCESSORY] =
"MAN:ACC",
296 [SYSTEMALARMS_MANUALCONTROL_ALTITUDEHOLD] =
"MAN:A-HOLD",
297 [SYSTEMALARMS_MANUALCONTROL_PATHFOLLOWER] =
"MAN:PATH-F",
298 [SYSTEMALARMS_MANUALCONTROL_CHANNELCONFIGURATION] =
"MAN:INPUT",
299 [SYSTEMALARMS_MANUALCONTROL_UNDEFINED] =
"MAN:UNDEF",
300 [SYSTEMALARMS_MANUALCONTROL_NONE] = {0},
306 [SYSTEMALARMS_REBOOTCAUSE_BROWNOUT] =
"BOOT:BROWNOUT",
307 [SYSTEMALARMS_REBOOTCAUSE_PINRESET] =
"BOOT:PIN RESET",
308 [SYSTEMALARMS_REBOOTCAUSE_POWERONRESET] =
"BOOT:PWR ON RST",
309 [SYSTEMALARMS_REBOOTCAUSE_SOFTWARERESET] =
"BOOT:SW RESET",
310 [SYSTEMALARMS_REBOOTCAUSE_INDEPENDENTWATCHDOG] =
"BOOT:INDY WDOG",
311 [SYSTEMALARMS_REBOOTCAUSE_WINDOWWATCHDOG] =
"BOOT:WIN WDOG",
312 [SYSTEMALARMS_REBOOTCAUSE_LOWPOWER] =
"BOOT:LOW POWER",
313 [SYSTEMALARMS_REBOOTCAUSE_UNDEFINED] =
"BOOT:UNDEFINED",
316 #define LONGEST_MESSAGE 17
321 InsufficientBufferage);
324 if (reason >=
NELEMENTS(boot_reason_names)) {
325 return (
const char*)&boot_reason_names[SYSTEMALARMS_REBOOTCAUSE_UNDEFINED];
327 return (
const char*)&boot_reason_names[reason];
331 *state = SYSTEMALARMS_ALARM_OK;
338 for (
int i = 0;
i < SYSTEMALARMS_ALARM_NUMELEM;
i++) {
339 if (((alarm->Alarm[
i] == SYSTEMALARMS_ALARM_WARNING) ||
340 (alarm->Alarm[
i] == SYSTEMALARMS_ALARM_ERROR) ||
341 (alarm->Alarm[
i] == SYSTEMALARMS_ALARM_CRITICAL))) {
350 if (alarm->Alarm[i] > *state) {
351 *state = alarm->Alarm[
i];
356 case SYSTEMALARMS_ALARM_SYSTEMCONFIGURATION:
358 (
const char*)config_error_names[alarm->ConfigError],
359 sizeof(*config_error_names));
360 current_msg[
sizeof(*config_error_names)] =
'\0';
362 case SYSTEMALARMS_ALARM_MANUALCONTROL:
364 (
const char*)manual_control_names[alarm->ManualControl],
365 sizeof(*manual_control_names));
366 current_msg[
sizeof(*manual_control_names)] =
'\0';
370 current_msg[
sizeof(*alarm_names)] =
'\0';
373 int this_len = strlen(current_msg);
375 if (pos + this_len + 2 >= buflen) {
379 if ((alarm->Alarm[i] != SYSTEMALARMS_ALARM_WARNING) && !blink) {
381 while (this_len > 0) {
388 memcpy(&buf[pos], current_msg, this_len);
static int32_t hasSeverity(SystemAlarmsAlarmOptions severity)
int16_t PIOS_RESET_GetResetReason(void)
PIOS_RESET_GetResetReason Does nothing on POSIX systems.
static const char manual_control_names[][13]
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
bool PIOS_Mutex_Unlock(struct pios_mutex *mtx)
struct pios_mutex * PIOS_Mutex_Create(void)
static const char config_error_names[][15]
static const char boot_reason_names[][16]
DONT_BUILD_IF(NELEMENTS(alarm_names)!=SYSTEMALARMS_ALARM_NUMELEM, AlarmArrayMismatch)
Include file of the alarm library.
int32_t AlarmsHasCritical()
#define SYSTEMALARMS_ALARM_DEFAULT
const char * AlarmBootReason(uint8_t reason)
static struct pios_mutex * lock
Includes PiOS and core architecture components.
int32_t AlarmsClear(SystemAlarmsAlarmElem alarm)
int32_t AlarmsHasErrors()
int32_t AlarmsHasWarnings()
static const char alarm_names[][10]
int32_t AlarmString(SystemAlarmsData *alarm, char *buf, size_t buflen, bool blink, uint8_t *state)
int32_t AlarmsInitialize(void)
#define PIOS_Assert(test)
#define PIOS_MUTEX_TIMEOUT_MAX
SystemAlarmsAlarmOptions AlarmsGet(SystemAlarmsAlarmElem alarm)
bool PIOS_Mutex_Lock(struct pios_mutex *mtx, uint32_t timeout_ms)
int32_t AlarmsDefault(SystemAlarmsAlarmElem alarm)