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.
ICE-Application/src/ConfigurationHandler/Controls/CompositeControl.h@0:61364762ee0e, 2017-01-24 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmarkel44 | 0:61364762ee0e | 1 | /****************************************************************************** |
jmarkel44 | 0:61364762ee0e | 2 | * |
jmarkel44 | 0:61364762ee0e | 3 | * File: CompositeControl.h |
jmarkel44 | 0:61364762ee0e | 4 | * Desciption: ICE Composite Control Class |
jmarkel44 | 0:61364762ee0e | 5 | * |
jmarkel44 | 0:61364762ee0e | 6 | *****************************************************************************/ |
jmarkel44 | 0:61364762ee0e | 7 | #ifndef COMPOSITECONTROL_H |
jmarkel44 | 0:61364762ee0e | 8 | #define COMPOSITECONTROL_H |
jmarkel44 | 0:61364762ee0e | 9 | |
jmarkel44 | 0:61364762ee0e | 10 | #include <string> |
jmarkel44 | 0:61364762ee0e | 11 | #include <vector> |
jmarkel44 | 0:61364762ee0e | 12 | #include <stdio.h> |
jmarkel44 | 0:61364762ee0e | 13 | #include <stdlib.h> |
jmarkel44 | 0:61364762ee0e | 14 | #include "global.h" |
jmarkel44 | 0:61364762ee0e | 15 | #include "./Algorithms/CompositeAlgorithm.h" |
jmarkel44 | 0:61364762ee0e | 16 | |
jmarkel44 | 0:61364762ee0e | 17 | typedef enum { |
jmarkel44 | 0:61364762ee0e | 18 | COMPOSITE_CONTROL_OK, |
jmarkel44 | 0:61364762ee0e | 19 | COMPOSITE_CONTROL_UNK_STATE, |
jmarkel44 | 0:61364762ee0e | 20 | COMPOSITE_CONTROL_ERROR, |
jmarkel44 | 0:61364762ee0e | 21 | COMPOSITE_CONTROL_DESTROY |
jmarkel44 | 0:61364762ee0e | 22 | } CompositeControlError_t; |
jmarkel44 | 0:61364762ee0e | 23 | |
jmarkel44 | 0:61364762ee0e | 24 | //! Composite Control - used to implement a composite control |
jmarkel44 | 0:61364762ee0e | 25 | class CompositeControl |
jmarkel44 | 0:61364762ee0e | 26 | { |
jmarkel44 | 0:61364762ee0e | 27 | private: |
jmarkel44 | 0:61364762ee0e | 28 | typedef struct oe_tag { |
jmarkel44 | 0:61364762ee0e | 29 | std::string tag; |
jmarkel44 | 0:61364762ee0e | 30 | std::string response; |
jmarkel44 | 0:61364762ee0e | 31 | } OutputElement; |
jmarkel44 | 0:61364762ee0e | 32 | |
jmarkel44 | 0:61364762ee0e | 33 | std::string controlFile; // the control file |
jmarkel44 | 0:61364762ee0e | 34 | std::string id; // composite identifier |
jmarkel44 | 0:61364762ee0e | 35 | std::string tag; // i/o tag to evaluate |
jmarkel44 | 0:61364762ee0e | 36 | unsigned int priority; // control priority |
jmarkel44 | 0:61364762ee0e | 37 | std::string ca; // control algorithm |
jmarkel44 | 0:61364762ee0e | 38 | std::vector<OutputElement> outputs; // (virtual) output(s) |
jmarkel44 | 0:61364762ee0e | 39 | |
jmarkel44 | 0:61364762ee0e | 40 | enum State { |
jmarkel44 | 0:61364762ee0e | 41 | STATE_INIT, |
jmarkel44 | 0:61364762ee0e | 42 | STATE_START, |
jmarkel44 | 0:61364762ee0e | 43 | STATE_CONTROL_OFF, |
jmarkel44 | 0:61364762ee0e | 44 | STATE_CONTROL_ON, |
jmarkel44 | 0:61364762ee0e | 45 | STATE_MAX |
jmarkel44 | 0:61364762ee0e | 46 | }; |
jmarkel44 | 0:61364762ee0e | 47 | State currentState; // current state |
jmarkel44 | 0:61364762ee0e | 48 | |
jmarkel44 | 0:61364762ee0e | 49 | bool validateControlData(const char *buf); |
jmarkel44 | 0:61364762ee0e | 50 | void copyControlData(const char *buf); |
jmarkel44 | 0:61364762ee0e | 51 | |
jmarkel44 | 0:61364762ee0e | 52 | std::string executeCommand(void); |
jmarkel44 | 0:61364762ee0e | 53 | std::string executeOperation(const CompositeAlgorithm*); |
jmarkel44 | 0:61364762ee0e | 54 | void triggerOutputs(std::string result); |
jmarkel44 | 0:61364762ee0e | 55 | void sendMail(std::string io_tag, OutputAction action); |
jmarkel44 | 0:61364762ee0e | 56 | |
jmarkel44 | 0:61364762ee0e | 57 | public: |
jmarkel44 | 0:61364762ee0e | 58 | /// constructor |
jmarkel44 | 0:61364762ee0e | 59 | CompositeControl() { } |
jmarkel44 | 0:61364762ee0e | 60 | |
jmarkel44 | 0:61364762ee0e | 61 | /// destructor |
jmarkel44 | 0:61364762ee0e | 62 | ~CompositeControl() { |
jmarkel44 | 0:61364762ee0e | 63 | printf("\r%s invoked\n", __func__); |
jmarkel44 | 0:61364762ee0e | 64 | } |
jmarkel44 | 0:61364762ee0e | 65 | |
jmarkel44 | 0:61364762ee0e | 66 | /// load a composite control from a JSON configuration file |
jmarkel44 | 0:61364762ee0e | 67 | bool load(std::string controlFile); |
jmarkel44 | 0:61364762ee0e | 68 | |
jmarkel44 | 0:61364762ee0e | 69 | /// start a composite control instance |
jmarkel44 | 0:61364762ee0e | 70 | void start(void); |
jmarkel44 | 0:61364762ee0e | 71 | |
jmarkel44 | 0:61364762ee0e | 72 | /// update a composite control instance |
jmarkel44 | 0:61364762ee0e | 73 | CompositeControlError_t update(void); |
jmarkel44 | 0:61364762ee0e | 74 | |
jmarkel44 | 0:61364762ee0e | 75 | /// unregister a composite control(s) instance |
jmarkel44 | 0:61364762ee0e | 76 | void unregisterControls(); |
jmarkel44 | 0:61364762ee0e | 77 | |
jmarkel44 | 0:61364762ee0e | 78 | /// get the composite control's control filename |
jmarkel44 | 0:61364762ee0e | 79 | std::string getControlFile(void) const { |
jmarkel44 | 0:61364762ee0e | 80 | return controlFile; |
jmarkel44 | 0:61364762ee0e | 81 | } |
jmarkel44 | 0:61364762ee0e | 82 | |
jmarkel44 | 0:61364762ee0e | 83 | /// get the composite control's identifier |
jmarkel44 | 0:61364762ee0e | 84 | std::string getId(void) const { |
jmarkel44 | 0:61364762ee0e | 85 | return id; |
jmarkel44 | 0:61364762ee0e | 86 | } |
jmarkel44 | 0:61364762ee0e | 87 | |
jmarkel44 | 0:61364762ee0e | 88 | /// get the composite control's current state |
jmarkel44 | 0:61364762ee0e | 89 | State getState(void) const { |
jmarkel44 | 0:61364762ee0e | 90 | return currentState; |
jmarkel44 | 0:61364762ee0e | 91 | } |
jmarkel44 | 0:61364762ee0e | 92 | |
jmarkel44 | 0:61364762ee0e | 93 | /// get the composite control's tag |
jmarkel44 | 0:61364762ee0e | 94 | std::string getTag(void) const { |
jmarkel44 | 0:61364762ee0e | 95 | return tag; |
jmarkel44 | 0:61364762ee0e | 96 | } |
jmarkel44 | 0:61364762ee0e | 97 | |
jmarkel44 | 0:61364762ee0e | 98 | /// get a list of a composite control's outputs |
jmarkel44 | 0:61364762ee0e | 99 | std::vector<std::string> getOutputs(void) const; |
jmarkel44 | 0:61364762ee0e | 100 | |
jmarkel44 | 0:61364762ee0e | 101 | void display(void); |
jmarkel44 | 0:61364762ee0e | 102 | }; |
jmarkel44 | 0:61364762ee0e | 103 | |
jmarkel44 | 0:61364762ee0e | 104 | #endif |