From b28cdba46de51c68c2c2f2ad60e8b131a41dc7a9 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Thu, 25 Oct 2012 21:49:53 -0500 Subject: [PATCH] SanityCheck: Trigger sanity check code on callbacks from the appropriate settings. The only downside is that it needs to update on the TaskInfo object which means since htat updates periodically this code runs more often that really needed since the modules only start at first. However, leaving that connection out means it misses the initial set of modules. --- flight/Libraries/sanitycheck.c | 1 - flight/Modules/System/systemmod.c | 21 ++++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/flight/Libraries/sanitycheck.c b/flight/Libraries/sanitycheck.c index b716259ff..87b1e8352 100644 --- a/flight/Libraries/sanitycheck.c +++ b/flight/Libraries/sanitycheck.c @@ -29,7 +29,6 @@ #include "openpilot.h" #include #include "sanitycheck.h" -#include "hwsettings.h" #include "taskinfo.h" #include "manualcontrolsettings.h" #include "systemalarms.h" diff --git a/flight/Modules/System/systemmod.c b/flight/Modules/System/systemmod.c index bd4382500..e85ce85c6 100644 --- a/flight/Modules/System/systemmod.c +++ b/flight/Modules/System/systemmod.c @@ -43,6 +43,7 @@ #include "sanitycheck.h" #include "objectpersistence.h" #include "flightstatus.h" +#include "manualcontrolsettings.h" #include "systemstats.h" #include "systemsettings.h" #include "i2cstats.h" @@ -88,6 +89,7 @@ static bool mallocFailed; // Private functions static void objectUpdatedCb(UAVObjEvent * ev); +static void configurationUpdatedCb(UAVObjEvent * ev); static void updateStats(); static void updateSystemAlarms(); static void systemTask(void *parameters); @@ -168,14 +170,19 @@ static void systemTask(void *parameters) // Listen for SettingPersistance object updates, connect a callback function ObjectPersistenceConnectQueue(objectPersistenceQueue); + // Whenever the configuration changes, make sure it is safe to fly + SystemSettingsConnectCallback(configurationUpdatedCb); + ManualControlSettingsConnectCallback(configurationUpdatedCb); + TaskInfoConnectCallback(configurationUpdatedCb); + + // Run this initially to make sure the configuration is checked + configuration_check(); + // Main system loop while (1) { // Update the system statistics updateStats(); - // TODO: Make this only be called when configuration settings change - configuration_check(); - // Update the system alarms updateSystemAlarms(); #if defined(I2C_WDG_STATS_DIAGNOSTICS) @@ -307,6 +314,14 @@ static void objectUpdatedCb(UAVObjEvent * ev) } } +/** + * Called whenever a critical configuration component changes + */ +static void configurationUpdatedCb(UAVObjEvent * ev) +{ + configuration_check(); +} + /** * Called periodically to update the I2C statistics */