Erick / Mbed 2 deprecated ICE-F412

Dependencies:   mbed-rtos mbed

Committer:
jmarkel44
Date:
Tue Jan 24 19:05:33 2017 +0000
Revision:
0:61364762ee0e
Port from IAR to Nucleo-F412 board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jmarkel44 0:61364762ee0e 1 #ifndef SENSORERRORCONTROL_H
jmarkel44 0:61364762ee0e 2 #define SENSORERRORCONTROL_H
jmarkel44 0:61364762ee0e 3
jmarkel44 0:61364762ee0e 4 #include <stdio.h>
jmarkel44 0:61364762ee0e 5 #include <string>
jmarkel44 0:61364762ee0e 6 #include <time.h>
jmarkel44 0:61364762ee0e 7
jmarkel44 0:61364762ee0e 8 #include "global.h"
jmarkel44 0:61364762ee0e 9
jmarkel44 0:61364762ee0e 10 typedef enum {
jmarkel44 0:61364762ee0e 11 SENSOR_ERROR_CONTROL_OK,
jmarkel44 0:61364762ee0e 12 SENSOR_ERROR_CONTROL_UNK_STATE,
jmarkel44 0:61364762ee0e 13 SENSOR_ERROR_CONTROL_ERROR,
jmarkel44 0:61364762ee0e 14 } SensorErrorControlError_t;
jmarkel44 0:61364762ee0e 15
jmarkel44 0:61364762ee0e 16 //! SensorErrorControl - implements a sensor error control by reading an input's
jmarkel44 0:61364762ee0e 17 // error flag and manipulating an output (duty-cycle style)
jmarkel44 0:61364762ee0e 18 class SensorErrorControl
jmarkel44 0:61364762ee0e 19 {
jmarkel44 0:61364762ee0e 20 private:
jmarkel44 0:61364762ee0e 21 std::string controlFile; // the control file
jmarkel44 0:61364762ee0e 22 std::string id; // unique control identifier
jmarkel44 0:61364762ee0e 23 std::string input; // sensor to read
jmarkel44 0:61364762ee0e 24 std::string output; // output to manipulate
jmarkel44 0:61364762ee0e 25 unsigned int priority; // control priority (typically 450)
jmarkel44 0:61364762ee0e 26
jmarkel44 0:61364762ee0e 27 typedef struct dutyCycle_tag {
jmarkel44 0:61364762ee0e 28 unsigned int dutyCycle; // on-time (percentage)
jmarkel44 0:61364762ee0e 29 unsigned int interval; // in minutes
jmarkel44 0:61364762ee0e 30 } dutyCycle_t;
jmarkel44 0:61364762ee0e 31
jmarkel44 0:61364762ee0e 32 dutyCycle_t dutyCycle;
jmarkel44 0:61364762ee0e 33
jmarkel44 0:61364762ee0e 34 typedef struct timer_tag {
jmarkel44 0:61364762ee0e 35 unsigned long offTime; // epoch time
jmarkel44 0:61364762ee0e 36 unsigned long expirationTime; // epoch time
jmarkel44 0:61364762ee0e 37 } Timer_t;
jmarkel44 0:61364762ee0e 38
jmarkel44 0:61364762ee0e 39 Timer_t duty_timer; // the duty timer
jmarkel44 0:61364762ee0e 40
jmarkel44 0:61364762ee0e 41 enum State {
jmarkel44 0:61364762ee0e 42 STATE_INIT, // object instantiated
jmarkel44 0:61364762ee0e 43 STATE_START, // control has been started
jmarkel44 0:61364762ee0e 44 STATE_CONTROL_OFF, // control is not above/below limit
jmarkel44 0:61364762ee0e 45 STATE_DUTY_CYCLE_ON, // in sensor error, duty-cycle ON
jmarkel44 0:61364762ee0e 46 STATE_DUTY_CYCLE_OFF, // in sensor error, duty-cycle OFF
jmarkel44 0:61364762ee0e 47 STATE_MAX
jmarkel44 0:61364762ee0e 48 };
jmarkel44 0:61364762ee0e 49
jmarkel44 0:61364762ee0e 50 State currentState; // current state
jmarkel44 0:61364762ee0e 51 bool isVirtualOutput; // output is virtual
jmarkel44 0:61364762ee0e 52
jmarkel44 0:61364762ee0e 53 bool validateControlData(const char *buf); // validate JSON control data
jmarkel44 0:61364762ee0e 54 void copyControlData(const char *buf); // copy JSON data to control data
jmarkel44 0:61364762ee0e 55
jmarkel44 0:61364762ee0e 56 bool isSensorError(void); // input sig is in sensor error
jmarkel44 0:61364762ee0e 57
jmarkel44 0:61364762ee0e 58 void startDutyTimer(void); // start the duty timer
jmarkel44 0:61364762ee0e 59 void stopDutyTimer(void); // stop the duty timer
jmarkel44 0:61364762ee0e 60
jmarkel44 0:61364762ee0e 61 bool dutyOnExpired(void); // boolean check if duty ON-time expired
jmarkel44 0:61364762ee0e 62 bool dutyOffExpired(void); // boolean check if duty OFF-time expired
jmarkel44 0:61364762ee0e 63
jmarkel44 0:61364762ee0e 64 void sendMailToOutput(OutputAction action);
jmarkel44 0:61364762ee0e 65 public:
jmarkel44 0:61364762ee0e 66 /// Create a sensor-error control instance
jmarkel44 0:61364762ee0e 67 SensorErrorControl() {
jmarkel44 0:61364762ee0e 68 currentState = STATE_INIT;
jmarkel44 0:61364762ee0e 69 isVirtualOutput = false;
jmarkel44 0:61364762ee0e 70 }
jmarkel44 0:61364762ee0e 71 /// Destroy a sensor-error control instance
jmarkel44 0:61364762ee0e 72 ~SensorErrorControl() {
jmarkel44 0:61364762ee0e 73 // "erased...from existence!" -- Doc Brown
jmarkel44 0:61364762ee0e 74 printf("\r%s invoked\n", __func__);
jmarkel44 0:61364762ee0e 75 }
jmarkel44 0:61364762ee0e 76
jmarkel44 0:61364762ee0e 77 /// load a sensor-error control instance with data from a JSON configuration file
jmarkel44 0:61364762ee0e 78 bool load(std::string filename);
jmarkel44 0:61364762ee0e 79
jmarkel44 0:61364762ee0e 80 /// start a sensor-error control instance
jmarkel44 0:61364762ee0e 81 void start(void);
jmarkel44 0:61364762ee0e 82
jmarkel44 0:61364762ee0e 83 /// update this sensor error control instance
jmarkel44 0:61364762ee0e 84 SensorErrorControlError_t update(void);
jmarkel44 0:61364762ee0e 85
jmarkel44 0:61364762ee0e 86 /// unregister a failsafe control instance
jmarkel44 0:61364762ee0e 87 void unregisterControl(void);
jmarkel44 0:61364762ee0e 88
jmarkel44 0:61364762ee0e 89 /// display the pertinent data of this sensor error control instance
jmarkel44 0:61364762ee0e 90 void display(void);
jmarkel44 0:61364762ee0e 91
jmarkel44 0:61364762ee0e 92 /// get control file
jmarkel44 0:61364762ee0e 93 std::string getControlFile() const {
jmarkel44 0:61364762ee0e 94 return controlFile;
jmarkel44 0:61364762ee0e 95 }
jmarkel44 0:61364762ee0e 96
jmarkel44 0:61364762ee0e 97 /// get control identifier
jmarkel44 0:61364762ee0e 98 std::string getId() const {
jmarkel44 0:61364762ee0e 99 return id;
jmarkel44 0:61364762ee0e 100 }
jmarkel44 0:61364762ee0e 101 };
jmarkel44 0:61364762ee0e 102
jmarkel44 0:61364762ee0e 103 #endif // SENSORERRORCONTROL_H
jmarkel44 0:61364762ee0e 104