Erick / Mbed 2 deprecated ICE-F412

Dependencies:   mbed-rtos mbed

Committer:
jmarkel44
Date:
Tue Jan 24 19:06:45 2017 +0000
Revision:
1:b2e90cda7a5a
Parent:
0:61364762ee0e
Port from IAR F412 project

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jmarkel44 0:61364762ee0e 1 #ifndef FAILSAFECONTROL_H
jmarkel44 0:61364762ee0e 2 #define FAILSAFECONTROL_H
jmarkel44 0:61364762ee0e 3
jmarkel44 0:61364762ee0e 4 #include <stdio.h>
jmarkel44 0:61364762ee0e 5 #include <string>
jmarkel44 0:61364762ee0e 6 #include "global.h"
jmarkel44 0:61364762ee0e 7
jmarkel44 0:61364762ee0e 8 #define FAILSAFE_CONTROL_DEBUG
jmarkel44 0:61364762ee0e 9
jmarkel44 0:61364762ee0e 10 typedef enum {
jmarkel44 0:61364762ee0e 11 FAILSAFE_CONTROL_OK,
jmarkel44 0:61364762ee0e 12 FAILSAFE_CONTROL_UNK_STATE,
jmarkel44 0:61364762ee0e 13 FAILSAFE_CONTROL_ERROR,
jmarkel44 0:61364762ee0e 14 } FailsafeControlError_t;
jmarkel44 0:61364762ee0e 15
jmarkel44 0:61364762ee0e 16 //! FailsafeControl - implements a failsafe by reading values from an
jmarkel44 0:61364762ee0e 17 // input signal and manipulating an output.
jmarkel44 0:61364762ee0e 18 class FailsafeControl
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 700)
jmarkel44 0:61364762ee0e 26
jmarkel44 0:61364762ee0e 27 typedef struct hfs_tag {
jmarkel44 0:61364762ee0e 28 float value; // high-failsafe trigger value
jmarkel44 0:61364762ee0e 29 float dutyCycle; // percentage of on-time
jmarkel44 0:61364762ee0e 30 float interval; // in minutes
jmarkel44 0:61364762ee0e 31 } hfs;
jmarkel44 0:61364762ee0e 32 typedef struct lfs_tag {
jmarkel44 0:61364762ee0e 33 float value; // low-failsafe trigger value
jmarkel44 0:61364762ee0e 34 float dutyCycle; // percentag of on-time
jmarkel44 0:61364762ee0e 35 float interval; // in minutes
jmarkel44 0:61364762ee0e 36 } lfs;
jmarkel44 0:61364762ee0e 37
jmarkel44 0:61364762ee0e 38 lfs lfs_data; // Low Failsafe data
jmarkel44 0:61364762ee0e 39 hfs hfs_data; // High Failsafe data
jmarkel44 0:61364762ee0e 40
jmarkel44 0:61364762ee0e 41 typedef struct timer_tag {
jmarkel44 0:61364762ee0e 42 unsigned long offTime; // epoch time
jmarkel44 0:61364762ee0e 43 unsigned long expirationTime; // epoch time
jmarkel44 0:61364762ee0e 44 } Timer_t;
jmarkel44 0:61364762ee0e 45
jmarkel44 0:61364762ee0e 46 Timer_t duty_timer; // the duty timer
jmarkel44 0:61364762ee0e 47
jmarkel44 0:61364762ee0e 48 enum State {
jmarkel44 0:61364762ee0e 49 STATE_INIT, // object instantiated
jmarkel44 0:61364762ee0e 50 STATE_START, // control has been started
jmarkel44 0:61364762ee0e 51 STATE_CONTROL_OFF, // control is not above/below limit
jmarkel44 0:61364762ee0e 52 STATE_CONTROL_ON_LFS, // low-failsafe with output on
jmarkel44 0:61364762ee0e 53 STATE_CONTROL_OFF_LFS, // low-failsafe with output off
jmarkel44 0:61364762ee0e 54 STATE_CONTROL_ON_HFS, // high-failsafe with output on
jmarkel44 0:61364762ee0e 55 STATE_CONTROL_OFF_HFS, // high-failsafe with output off
jmarkel44 0:61364762ee0e 56 STATE_CONTROL_SENSOR_ERROR, // input sensor is faulted
jmarkel44 0:61364762ee0e 57 STATE_MAX
jmarkel44 0:61364762ee0e 58 };
jmarkel44 0:61364762ee0e 59 State currentState;
jmarkel44 0:61364762ee0e 60
jmarkel44 0:61364762ee0e 61 bool isVirtualOutput;
jmarkel44 0:61364762ee0e 62
jmarkel44 0:61364762ee0e 63 bool validateControlData(const char *buf);
jmarkel44 0:61364762ee0e 64 void copyControlData(const char *buf);
jmarkel44 0:61364762ee0e 65
jmarkel44 0:61364762ee0e 66 bool aboveHighFailsafe(void); // boolean check if above HFS watermark
jmarkel44 0:61364762ee0e 67 bool belowLowFailsafe(void); // boolean check if below LFS watermark
jmarkel44 0:61364762ee0e 68
jmarkel44 0:61364762ee0e 69 void startHfsDutyTimer(void); // start the HFS duty timer
jmarkel44 0:61364762ee0e 70 void stopHfsDutyTimer(void); // stop the HFS duty timer
jmarkel44 0:61364762ee0e 71
jmarkel44 0:61364762ee0e 72 void startLfsDutyTimer(void); // start the LFS duty timer
jmarkel44 0:61364762ee0e 73 void stopLfsDutyTimer(void); // stop the LFS duty timer
jmarkel44 0:61364762ee0e 74
jmarkel44 0:61364762ee0e 75 bool dutyOnExpired(void); // boolean check if duty ON-time expired
jmarkel44 0:61364762ee0e 76 bool dutyOffExpired(void); // boolean check if duty OFF-time expired
jmarkel44 0:61364762ee0e 77
jmarkel44 0:61364762ee0e 78 bool sensorError(void); // boolean check if input is faulted
jmarkel44 0:61364762ee0e 79
jmarkel44 0:61364762ee0e 80 void sendMailToOutput(OutputAction action);
jmarkel44 0:61364762ee0e 81
jmarkel44 0:61364762ee0e 82 public:
jmarkel44 0:61364762ee0e 83 /// Create a failsafe control instance
jmarkel44 0:61364762ee0e 84 FailsafeControl() {
jmarkel44 0:61364762ee0e 85 currentState = STATE_INIT;
jmarkel44 0:61364762ee0e 86 isVirtualOutput = false;
jmarkel44 0:61364762ee0e 87 }
jmarkel44 0:61364762ee0e 88 /// Destroy a failsafe control instance
jmarkel44 0:61364762ee0e 89 ~FailsafeControl() {
jmarkel44 0:61364762ee0e 90 // "erased...from existence!" -- Doc Brown
jmarkel44 0:61364762ee0e 91 printf("\r%s invoked\n", __func__);
jmarkel44 0:61364762ee0e 92 }
jmarkel44 0:61364762ee0e 93
jmarkel44 0:61364762ee0e 94 /// load a failsafe control instance with data from a JSON configuration file
jmarkel44 0:61364762ee0e 95 bool load(std::string filename);
jmarkel44 0:61364762ee0e 96
jmarkel44 0:61364762ee0e 97 /// start a failsafe control instance
jmarkel44 0:61364762ee0e 98 void start(void);
jmarkel44 0:61364762ee0e 99
jmarkel44 0:61364762ee0e 100 /// update a failsafe control instance
jmarkel44 0:61364762ee0e 101 FailsafeControlError_t update(void);
jmarkel44 0:61364762ee0e 102
jmarkel44 0:61364762ee0e 103 /// unregister a failsafe control instance
jmarkel44 0:61364762ee0e 104 void unregisterControl(void);
jmarkel44 0:61364762ee0e 105
jmarkel44 0:61364762ee0e 106
jmarkel44 0:61364762ee0e 107 /// display the pertinent data of a failsafe control instance
jmarkel44 0:61364762ee0e 108 void display(void);
jmarkel44 0:61364762ee0e 109
jmarkel44 0:61364762ee0e 110 /// get control identifier
jmarkel44 0:61364762ee0e 111 std::string getId() const {
jmarkel44 0:61364762ee0e 112 return id;
jmarkel44 0:61364762ee0e 113 }
jmarkel44 0:61364762ee0e 114 };
jmarkel44 0:61364762ee0e 115
jmarkel44 0:61364762ee0e 116 #endif