Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: ICE-Application/src/ConfigurationHandler/Controls/SensorErrorControl.h
- Revision:
- 0:61364762ee0e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ICE-Application/src/ConfigurationHandler/Controls/SensorErrorControl.h Tue Jan 24 19:05:33 2017 +0000
@@ -0,0 +1,104 @@
+#ifndef SENSORERRORCONTROL_H
+#define SENSORERRORCONTROL_H
+
+#include <stdio.h>
+#include <string>
+#include <time.h>
+
+#include "global.h"
+
+typedef enum {
+ SENSOR_ERROR_CONTROL_OK,
+ SENSOR_ERROR_CONTROL_UNK_STATE,
+ SENSOR_ERROR_CONTROL_ERROR,
+} SensorErrorControlError_t;
+
+//! SensorErrorControl - implements a sensor error control by reading an input's
+// error flag and manipulating an output (duty-cycle style)
+class SensorErrorControl
+{
+private:
+ std::string controlFile; // the control file
+ std::string id; // unique control identifier
+ std::string input; // sensor to read
+ std::string output; // output to manipulate
+ unsigned int priority; // control priority (typically 450)
+
+ typedef struct dutyCycle_tag {
+ unsigned int dutyCycle; // on-time (percentage)
+ unsigned int interval; // in minutes
+ } dutyCycle_t;
+
+ dutyCycle_t dutyCycle;
+
+ typedef struct timer_tag {
+ unsigned long offTime; // epoch time
+ unsigned long expirationTime; // epoch time
+ } Timer_t;
+
+ Timer_t duty_timer; // the duty timer
+
+ enum State {
+ STATE_INIT, // object instantiated
+ STATE_START, // control has been started
+ STATE_CONTROL_OFF, // control is not above/below limit
+ STATE_DUTY_CYCLE_ON, // in sensor error, duty-cycle ON
+ STATE_DUTY_CYCLE_OFF, // in sensor error, duty-cycle OFF
+ STATE_MAX
+ };
+
+ State currentState; // current state
+ bool isVirtualOutput; // output is virtual
+
+ bool validateControlData(const char *buf); // validate JSON control data
+ void copyControlData(const char *buf); // copy JSON data to control data
+
+ bool isSensorError(void); // input sig is in sensor error
+
+ void startDutyTimer(void); // start the duty timer
+ void stopDutyTimer(void); // stop the duty timer
+
+ bool dutyOnExpired(void); // boolean check if duty ON-time expired
+ bool dutyOffExpired(void); // boolean check if duty OFF-time expired
+
+ void sendMailToOutput(OutputAction action);
+public:
+ /// Create a sensor-error control instance
+ SensorErrorControl() {
+ currentState = STATE_INIT;
+ isVirtualOutput = false;
+ }
+ /// Destroy a sensor-error control instance
+ ~SensorErrorControl() {
+ // "erased...from existence!" -- Doc Brown
+ printf("\r%s invoked\n", __func__);
+ }
+
+ /// load a sensor-error control instance with data from a JSON configuration file
+ bool load(std::string filename);
+
+ /// start a sensor-error control instance
+ void start(void);
+
+ /// update this sensor error control instance
+ SensorErrorControlError_t update(void);
+
+ /// unregister a failsafe control instance
+ void unregisterControl(void);
+
+ /// display the pertinent data of this sensor error control instance
+ void display(void);
+
+ /// get control file
+ std::string getControlFile() const {
+ return controlFile;
+ }
+
+ /// get control identifier
+ std::string getId() const {
+ return id;
+ }
+};
+
+#endif // SENSORERRORCONTROL_H
+