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.
Dependencies: NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed
Fork of ICE by
src/ConfigurationHandler/Controls/CompositeControl.cpp@230:11765008ff3a, 2016-10-18 (annotated)
- Committer:
- jmarkel44
- Date:
- Tue Oct 18 20:23:31 2016 +0000
- Revision:
- 230:11765008ff3a
- Parent:
- 229:0d6755d765fd
- Child:
- 231:f22901955e0c
LOCKOUT blowdown
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jmarkel44 | 164:7cecd731882e | 1 | /****************************************************************************** |
| jmarkel44 | 164:7cecd731882e | 2 | * |
| jmarkel44 | 164:7cecd731882e | 3 | * File: CompositeControl.cpp |
| jmarkel44 | 164:7cecd731882e | 4 | * Desciption: ICE Composite Control Class implementation |
| jmarkel44 | 164:7cecd731882e | 5 | * |
| jmarkel44 | 164:7cecd731882e | 6 | *****************************************************************************/ |
| jmarkel44 | 164:7cecd731882e | 7 | #include "CompositeControl.h" |
| jmarkel44 | 221:2a5e9902003c | 8 | #include "ConfigurationHandler.h" |
| jmarkel44 | 164:7cecd731882e | 9 | #include "mDot.h" |
| jmarkel44 | 164:7cecd731882e | 10 | #include "MbedJSONValue.h" |
| jmarkel44 | 164:7cecd731882e | 11 | #include "ModbusMasterApi.h" |
| jmarkel44 | 164:7cecd731882e | 12 | #include "global.h" |
| jmarkel44 | 164:7cecd731882e | 13 | #include <string> |
| jmarkel44 | 164:7cecd731882e | 14 | |
| jmarkel44 | 164:7cecd731882e | 15 | extern mDot *GLOBAL_mdot; |
| jmarkel44 | 164:7cecd731882e | 16 | |
| jmarkel44 | 221:2a5e9902003c | 17 | // |
| jmarkel44 | 221:2a5e9902003c | 18 | // method: load |
| jmarkel44 | 221:2a5e9902003c | 19 | // description: load a composite control |
| jmarkel44 | 221:2a5e9902003c | 20 | // |
| jmarkel44 | 221:2a5e9902003c | 21 | // @param none |
| jmarkel44 | 221:2a5e9902003c | 22 | // @return none |
| jmarkel44 | 221:2a5e9902003c | 23 | // |
| jmarkel44 | 220:dbe21411f962 | 24 | bool CompositeControl::load(std::string _controlFile) |
| jmarkel44 | 164:7cecd731882e | 25 | { |
| jmarkel44 | 220:dbe21411f962 | 26 | MbedJSONValue json_value; // JSON parsing element |
| jmarkel44 | 220:dbe21411f962 | 27 | controlFile = _controlFile; |
| jmarkel44 | 220:dbe21411f962 | 28 | |
| jmarkel44 | 230:11765008ff3a | 29 | |
| jmarkel44 | 220:dbe21411f962 | 30 | // open and read from the control file |
| jmarkel44 | 220:dbe21411f962 | 31 | mDot::mdot_file file = GLOBAL_mdot->openUserFile(controlFile.c_str(), mDot::FM_RDONLY); |
| jmarkel44 | 220:dbe21411f962 | 32 | if ( file.fd < 0 ) { |
| jmarkel44 | 220:dbe21411f962 | 33 | logError("%s: failed to open %s\n", __func__, controlFile.c_str()); |
| jmarkel44 | 220:dbe21411f962 | 34 | return false; |
| jmarkel44 | 220:dbe21411f962 | 35 | } |
| jmarkel44 | 220:dbe21411f962 | 36 | |
| jmarkel44 | 220:dbe21411f962 | 37 | // read the data into a buffer |
| jmarkel44 | 220:dbe21411f962 | 38 | char dataBuf[MAX_FILE_SIZE]; |
| jmarkel44 | 220:dbe21411f962 | 39 | |
| jmarkel44 | 220:dbe21411f962 | 40 | int bytes_read = GLOBAL_mdot->readUserFile(file, (void *)dataBuf, sizeof(dataBuf)); |
| jmarkel44 | 220:dbe21411f962 | 41 | if ( bytes_read != sizeof(dataBuf) ) { |
| jmarkel44 | 220:dbe21411f962 | 42 | logError("%s: failed to read %d bytes from %s", __func__, sizeof(dataBuf), controlFile.c_str()); |
| jmarkel44 | 220:dbe21411f962 | 43 | // caller should destroy the object |
| jmarkel44 | 220:dbe21411f962 | 44 | return false; |
| jmarkel44 | 220:dbe21411f962 | 45 | } |
| jmarkel44 | 220:dbe21411f962 | 46 | |
| jmarkel44 | 220:dbe21411f962 | 47 | // close the file |
| jmarkel44 | 220:dbe21411f962 | 48 | GLOBAL_mdot->closeUserFile(file); |
| jmarkel44 | 220:dbe21411f962 | 49 | |
| jmarkel44 | 220:dbe21411f962 | 50 | parse(json_value, dataBuf); |
| jmarkel44 | 220:dbe21411f962 | 51 | |
| jmarkel44 | 221:2a5e9902003c | 52 | if ( !json_value.hasMember("id") || |
| jmarkel44 | 221:2a5e9902003c | 53 | !json_value.hasMember("tag") || |
| jmarkel44 | 221:2a5e9902003c | 54 | !json_value.hasMember("priority") || |
| jmarkel44 | 221:2a5e9902003c | 55 | !json_value.hasMember("ca") || |
| jmarkel44 | 220:dbe21411f962 | 56 | !json_value.hasMember("entries") ) { |
| jmarkel44 | 220:dbe21411f962 | 57 | printf("\rComposite control is missing expected tags\n"); |
| jmarkel44 | 220:dbe21411f962 | 58 | return false; |
| jmarkel44 | 220:dbe21411f962 | 59 | } |
| jmarkel44 | 220:dbe21411f962 | 60 | |
| jmarkel44 | 221:2a5e9902003c | 61 | id = json_value ["id"].get<string>(); |
| jmarkel44 | 221:2a5e9902003c | 62 | tag = json_value ["tag"].get<string>(); |
| jmarkel44 | 220:dbe21411f962 | 63 | priority = atoi(json_value["priority"].get<string>().c_str()); |
| jmarkel44 | 221:2a5e9902003c | 64 | ca = json_value ["ca"].get<string>(); |
| jmarkel44 | 220:dbe21411f962 | 65 | |
| jmarkel44 | 230:11765008ff3a | 66 | |
| jmarkel44 | 220:dbe21411f962 | 67 | int entries = atoi(json_value["entries"].get<string>().c_str()); |
| jmarkel44 | 220:dbe21411f962 | 68 | |
| jmarkel44 | 230:11765008ff3a | 69 | // populate the outputs |
| jmarkel44 | 220:dbe21411f962 | 70 | for ( int i = 0; i < entries; ++i ) { |
| jmarkel44 | 220:dbe21411f962 | 71 | std::string tag = json_value["outputs"][i]["tag"].get<string>(); |
| jmarkel44 | 230:11765008ff3a | 72 | Thread::wait(1000); |
| jmarkel44 | 221:2a5e9902003c | 73 | std::string response = json_value["outputs"][i]["responseA"].get<string>(); |
| jmarkel44 | 230:11765008ff3a | 74 | Thread::wait(1000); |
| jmarkel44 | 220:dbe21411f962 | 75 | if ( !tag.empty() && !response.empty() ) { |
| jmarkel44 | 220:dbe21411f962 | 76 | OutputElement x = { tag, response }; |
| jmarkel44 | 220:dbe21411f962 | 77 | outputs.push_back(x); |
| jmarkel44 | 220:dbe21411f962 | 78 | } else { |
| jmarkel44 | 220:dbe21411f962 | 79 | return false; |
| jmarkel44 | 220:dbe21411f962 | 80 | } |
| jmarkel44 | 220:dbe21411f962 | 81 | } |
| jmarkel44 | 220:dbe21411f962 | 82 | |
| jmarkel44 | 164:7cecd731882e | 83 | return true; |
| jmarkel44 | 164:7cecd731882e | 84 | } |
| jmarkel44 | 164:7cecd731882e | 85 | |
| jmarkel44 | 221:2a5e9902003c | 86 | // |
| jmarkel44 | 221:2a5e9902003c | 87 | // method: start |
| jmarkel44 | 221:2a5e9902003c | 88 | // description: start the composite control |
| jmarkel44 | 221:2a5e9902003c | 89 | // |
| jmarkel44 | 221:2a5e9902003c | 90 | // @param none |
| jmarkel44 | 221:2a5e9902003c | 91 | // @return none |
| jmarkel44 | 221:2a5e9902003c | 92 | // |
| jmarkel44 | 221:2a5e9902003c | 93 | void CompositeControl::start(void) |
| jmarkel44 | 221:2a5e9902003c | 94 | { |
| jmarkel44 | 221:2a5e9902003c | 95 | currentState = STATE_START; |
| jmarkel44 | 221:2a5e9902003c | 96 | } |
| jmarkel44 | 221:2a5e9902003c | 97 | |
| jmarkel44 | 221:2a5e9902003c | 98 | // |
| jmarkel44 | 221:2a5e9902003c | 99 | // method: update |
| jmarkel44 | 221:2a5e9902003c | 100 | // description: updater for the composite control |
| jmarkel44 | 221:2a5e9902003c | 101 | // |
| jmarkel44 | 221:2a5e9902003c | 102 | // @param none |
| jmarkel44 | 221:2a5e9902003c | 103 | // @return none |
| jmarkel44 | 230:11765008ff3a | 104 | // |
| jmarkel44 | 221:2a5e9902003c | 105 | void CompositeControl::update(void) |
| jmarkel44 | 164:7cecd731882e | 106 | { |
| jmarkel44 | 221:2a5e9902003c | 107 | std::string function; |
| jmarkel44 | 221:2a5e9902003c | 108 | |
| jmarkel44 | 221:2a5e9902003c | 109 | switch ( currentState ) { |
| jmarkel44 | 221:2a5e9902003c | 110 | case STATE_INIT: |
| jmarkel44 | 221:2a5e9902003c | 111 | // do nothing |
| jmarkel44 | 221:2a5e9902003c | 112 | break; |
| jmarkel44 | 221:2a5e9902003c | 113 | case STATE_START: |
| jmarkel44 | 221:2a5e9902003c | 114 | function = executeCommand(); |
| jmarkel44 | 221:2a5e9902003c | 115 | if ( function == "responseA" ) { |
| jmarkel44 | 221:2a5e9902003c | 116 | currentState = STATE_CONTROL_ON; |
| jmarkel44 | 221:2a5e9902003c | 117 | triggerOutputs(function); |
| jmarkel44 | 221:2a5e9902003c | 118 | } else if ( function == "nothing" ) { |
| jmarkel44 | 221:2a5e9902003c | 119 | currentState = STATE_CONTROL_OFF; |
| jmarkel44 | 221:2a5e9902003c | 120 | } |
| jmarkel44 | 221:2a5e9902003c | 121 | break; |
| jmarkel44 | 221:2a5e9902003c | 122 | case STATE_CONTROL_ON: |
| jmarkel44 | 221:2a5e9902003c | 123 | function = executeCommand(); |
| jmarkel44 | 221:2a5e9902003c | 124 | if ( function == "nothing" ) { |
| jmarkel44 | 221:2a5e9902003c | 125 | currentState = STATE_CONTROL_OFF; |
| jmarkel44 | 221:2a5e9902003c | 126 | unregisterControls(); |
| jmarkel44 | 221:2a5e9902003c | 127 | } else { |
| jmarkel44 | 221:2a5e9902003c | 128 | // do nothing |
| jmarkel44 | 221:2a5e9902003c | 129 | } |
| jmarkel44 | 221:2a5e9902003c | 130 | break; |
| jmarkel44 | 221:2a5e9902003c | 131 | case STATE_CONTROL_OFF: |
| jmarkel44 | 221:2a5e9902003c | 132 | function = executeCommand(); |
| jmarkel44 | 221:2a5e9902003c | 133 | if ( function == "responseA" ) { |
| jmarkel44 | 221:2a5e9902003c | 134 | currentState = STATE_CONTROL_ON; |
| jmarkel44 | 221:2a5e9902003c | 135 | triggerOutputs(function); |
| jmarkel44 | 221:2a5e9902003c | 136 | } else { |
| jmarkel44 | 221:2a5e9902003c | 137 | // do nothing |
| jmarkel44 | 221:2a5e9902003c | 138 | } |
| jmarkel44 | 221:2a5e9902003c | 139 | break; |
| jmarkel44 | 221:2a5e9902003c | 140 | default: |
| jmarkel44 | 221:2a5e9902003c | 141 | break; |
| jmarkel44 | 221:2a5e9902003c | 142 | } |
| jmarkel44 | 221:2a5e9902003c | 143 | } |
| jmarkel44 | 221:2a5e9902003c | 144 | |
| jmarkel44 | 230:11765008ff3a | 145 | // |
| jmarkel44 | 221:2a5e9902003c | 146 | // method: executeCommand |
| jmarkel44 | 221:2a5e9902003c | 147 | // description: execute the command specified in the control algorithm |
| jmarkel44 | 221:2a5e9902003c | 148 | // |
| jmarkel44 | 221:2a5e9902003c | 149 | // @param none |
| jmarkel44 | 221:2a5e9902003c | 150 | // @return none |
| jmarkel44 | 221:2a5e9902003c | 151 | // |
| jmarkel44 | 221:2a5e9902003c | 152 | std::string CompositeControl::executeCommand(void) |
| jmarkel44 | 221:2a5e9902003c | 153 | { |
| jmarkel44 | 221:2a5e9902003c | 154 | // look up the algorithm |
| jmarkel44 | 221:2a5e9902003c | 155 | StringAlgorithmMap::iterator pos; |
| jmarkel44 | 221:2a5e9902003c | 156 | pos = algorithmTable.find(this->ca); |
| jmarkel44 | 221:2a5e9902003c | 157 | if ( pos != algorithmTable.end() ) { |
| jmarkel44 | 221:2a5e9902003c | 158 | // we found the control algorithm |
| jmarkel44 | 221:2a5e9902003c | 159 | return this->executeOperation(pos->second); |
| jmarkel44 | 221:2a5e9902003c | 160 | } |
| jmarkel44 | 221:2a5e9902003c | 161 | return "nothing"; |
| jmarkel44 | 220:dbe21411f962 | 162 | } |
| jmarkel44 | 220:dbe21411f962 | 163 | |
| jmarkel44 | 221:2a5e9902003c | 164 | // |
| jmarkel44 | 221:2a5e9902003c | 165 | // method: executeOperation |
| jmarkel44 | 221:2a5e9902003c | 166 | // description: execute an operations from the control equation |
| jmarkel44 | 221:2a5e9902003c | 167 | // |
| jmarkel44 | 221:2a5e9902003c | 168 | // @param ca -> composite control algorithm |
| jmarkel44 | 221:2a5e9902003c | 169 | // @return string to the result |
| jmarkel44 | 221:2a5e9902003c | 170 | // |
| jmarkel44 | 221:2a5e9902003c | 171 | std::string CompositeControl::executeOperation(const CompositeAlgorithm *ca) |
| jmarkel44 | 221:2a5e9902003c | 172 | { |
| jmarkel44 | 221:2a5e9902003c | 173 | // (this->tag) <op> <opr> = <result> |
| jmarkel44 | 221:2a5e9902003c | 174 | // |
| jmarkel44 | 221:2a5e9902003c | 175 | // example: |
| jmarkel44 | 221:2a5e9902003c | 176 | // this->tag = "i_flowswitch" |
| jmarkel44 | 221:2a5e9902003c | 177 | // opr = "1" |
| jmarkel44 | 221:2a5e9902003c | 178 | // op = "==" |
| jmarkel44 | 221:2a5e9902003c | 179 | // if true return "responseA" else return "nothing" |
| jmarkel44 | 221:2a5e9902003c | 180 | |
| jmarkel44 | 221:2a5e9902003c | 181 | ModbusValue value; |
| jmarkel44 | 221:2a5e9902003c | 182 | bool rc = ModbusMasterReadRegister(tag,&value); |
| jmarkel44 | 221:2a5e9902003c | 183 | if ( rc != true ) { |
| jmarkel44 | 221:2a5e9902003c | 184 | printf("\rDEBUG: %s cannot find tag\n", __func__); |
| jmarkel44 | 221:2a5e9902003c | 185 | return "nothing"; |
| jmarkel44 | 221:2a5e9902003c | 186 | } |
| jmarkel44 | 221:2a5e9902003c | 187 | |
| jmarkel44 | 230:11765008ff3a | 188 | // equal to operator |
| jmarkel44 | 221:2a5e9902003c | 189 | if ( ca->getOp() == "==" ) { |
| jmarkel44 | 230:11765008ff3a | 190 | // perform the equality operation |
| jmarkel44 | 221:2a5e9902003c | 191 | if ( value.value == atof(ca->getOpr().c_str()) ) { |
| jmarkel44 | 221:2a5e9902003c | 192 | return ca->getResultTrue(); |
| jmarkel44 | 221:2a5e9902003c | 193 | } else { |
| jmarkel44 | 221:2a5e9902003c | 194 | return ca->getResultFalse(); |
| jmarkel44 | 221:2a5e9902003c | 195 | } |
| jmarkel44 | 221:2a5e9902003c | 196 | } |
| jmarkel44 | 230:11765008ff3a | 197 | if ( ca->getOp() == ">=" ) { |
| jmarkel44 | 230:11765008ff3a | 198 | if ( value.value >= atof(ca->getOpr().c_str()) ) { |
| jmarkel44 | 230:11765008ff3a | 199 | return ca->getResultTrue(); |
| jmarkel44 | 230:11765008ff3a | 200 | } else { |
| jmarkel44 | 230:11765008ff3a | 201 | return ca->getResultFalse(); |
| jmarkel44 | 230:11765008ff3a | 202 | } |
| jmarkel44 | 230:11765008ff3a | 203 | } |
| jmarkel44 | 230:11765008ff3a | 204 | // addition operator |
| jmarkel44 | 221:2a5e9902003c | 205 | if ( ca->getOp() == "+" ) { |
| jmarkel44 | 227:7153e89b6974 | 206 | // TODO |
| jmarkel44 | 221:2a5e9902003c | 207 | } |
| jmarkel44 | 230:11765008ff3a | 208 | // multiply operator |
| jmarkel44 | 227:7153e89b6974 | 209 | if ( ca->getOp() == "*" ) { |
| jmarkel44 | 230:11765008ff3a | 210 | // TODO: |
| jmarkel44 | 227:7153e89b6974 | 211 | } |
| jmarkel44 | 230:11765008ff3a | 212 | // subtraction operator |
| jmarkel44 | 227:7153e89b6974 | 213 | if ( ca->getOp() == "-" ) { |
| jmarkel44 | 227:7153e89b6974 | 214 | // TODO: |
| jmarkel44 | 227:7153e89b6974 | 215 | } |
| jmarkel44 | 230:11765008ff3a | 216 | |
| jmarkel44 | 221:2a5e9902003c | 217 | return "nothing"; |
| jmarkel44 | 221:2a5e9902003c | 218 | } |
| jmarkel44 | 221:2a5e9902003c | 219 | |
| jmarkel44 | 221:2a5e9902003c | 220 | // |
| jmarkel44 | 221:2a5e9902003c | 221 | // method: triggerOutputs |
| jmarkel44 | 221:2a5e9902003c | 222 | // description: trigger the output(s) to do something |
| jmarkel44 | 221:2a5e9902003c | 223 | // |
| jmarkel44 | 221:2a5e9902003c | 224 | // @param result -> the result of the operation |
| jmarkel44 | 221:2a5e9902003c | 225 | // @return none |
| jmarkel44 | 221:2a5e9902003c | 226 | // |
| jmarkel44 | 221:2a5e9902003c | 227 | void CompositeControl::triggerOutputs(std::string result) |
| jmarkel44 | 221:2a5e9902003c | 228 | { |
| jmarkel44 | 221:2a5e9902003c | 229 | |
| jmarkel44 | 221:2a5e9902003c | 230 | // loop through the list |
| jmarkel44 | 221:2a5e9902003c | 231 | StringAlgorithmMap::iterator pos; |
| jmarkel44 | 221:2a5e9902003c | 232 | pos = algorithmTable.find(this->ca); |
| jmarkel44 | 221:2a5e9902003c | 233 | if ( pos != algorithmTable.end() ) { |
| jmarkel44 | 221:2a5e9902003c | 234 | std::vector<OutputElement>::iterator it; |
| jmarkel44 | 221:2a5e9902003c | 235 | for ( it = outputs.begin(); it != outputs.end(); ++it ) { |
| jmarkel44 | 221:2a5e9902003c | 236 | if ( it->response == "fixed off" ) { |
| jmarkel44 | 221:2a5e9902003c | 237 | printf("\rSending an OFF control for %s\n", it->tag.c_str()); |
| jmarkel44 | 221:2a5e9902003c | 238 | sendMail(it->tag, ACTION_CONTROL_OFF); |
| jmarkel44 | 221:2a5e9902003c | 239 | } else if ( it->response == "fixed on" ) { |
| jmarkel44 | 221:2a5e9902003c | 240 | printf("\rSending an ON request for %s\n", it->tag.c_str()); |
| jmarkel44 | 221:2a5e9902003c | 241 | sendMail(it->tag, ACTION_CONTROL_ON); |
| jmarkel44 | 221:2a5e9902003c | 242 | } |
| jmarkel44 | 221:2a5e9902003c | 243 | } |
| jmarkel44 | 221:2a5e9902003c | 244 | } else { |
| jmarkel44 | 221:2a5e9902003c | 245 | logError("%s: failed to find the control algorithm %s\n", __func__, this->ca.c_str()); |
| jmarkel44 | 221:2a5e9902003c | 246 | } |
| jmarkel44 | 221:2a5e9902003c | 247 | } |
| jmarkel44 | 221:2a5e9902003c | 248 | |
| jmarkel44 | 221:2a5e9902003c | 249 | // |
| jmarkel44 | 221:2a5e9902003c | 250 | // method: sendMail |
| jmarkel44 | 221:2a5e9902003c | 251 | // description: send mail to the output task |
| jmarkel44 | 221:2a5e9902003c | 252 | // |
| jmarkel44 | 221:2a5e9902003c | 253 | // @param io_tag -> input/output tag |
| jmarkel44 | 221:2a5e9902003c | 254 | // @param action -> ON, OFF, UNREGISTER |
| jmarkel44 | 221:2a5e9902003c | 255 | // @return none |
| jmarkel44 | 221:2a5e9902003c | 256 | // |
| jmarkel44 | 221:2a5e9902003c | 257 | void CompositeControl::sendMail(const std::string io_tag, OutputAction action) |
| jmarkel44 | 221:2a5e9902003c | 258 | { |
| jmarkel44 | 222:94ea9a091d99 | 259 | logInfo("%s: composite control attempting to send action %d\n", |
| jmarkel44 | 222:94ea9a091d99 | 260 | __func__, action); |
| jmarkel44 | 221:2a5e9902003c | 261 | |
| jmarkel44 | 221:2a5e9902003c | 262 | OutputControlMsg_t *output_mail = OutputMasterMailBox.alloc(); |
| jmarkel44 | 221:2a5e9902003c | 263 | memset(output_mail, 0, sizeof(OutputControlMsg_t)); |
| jmarkel44 | 221:2a5e9902003c | 264 | |
| jmarkel44 | 227:7153e89b6974 | 265 | output_mail->action = action; |
| jmarkel44 | 227:7153e89b6974 | 266 | output_mail->controlType = CONTROL_COMPOSITE; |
| jmarkel44 | 227:7153e89b6974 | 267 | output_mail->priority = this->priority; |
| jmarkel44 | 227:7153e89b6974 | 268 | |
| jmarkel44 | 221:2a5e9902003c | 269 | strncpy(output_mail->input_tag, this->tag.c_str(), sizeof(output_mail->input_tag)-1); |
| jmarkel44 | 221:2a5e9902003c | 270 | strncpy(output_mail->output_tag, io_tag.c_str(), sizeof(output_mail->output_tag)-1); |
| jmarkel44 | 221:2a5e9902003c | 271 | strncpy(output_mail->id, this->id.c_str(), sizeof(output_mail->id)-1); |
| jmarkel44 | 230:11765008ff3a | 272 | |
| jmarkel44 | 221:2a5e9902003c | 273 | OutputMasterMailBox.put(output_mail); |
| jmarkel44 | 221:2a5e9902003c | 274 | } |
| jmarkel44 | 221:2a5e9902003c | 275 | |
| jmarkel44 | 221:2a5e9902003c | 276 | // |
| jmarkel44 | 221:2a5e9902003c | 277 | // method: unregisterControls |
| jmarkel44 | 221:2a5e9902003c | 278 | // description: unregister the control with the output task |
| jmarkel44 | 230:11765008ff3a | 279 | // |
| jmarkel44 | 221:2a5e9902003c | 280 | // @param none |
| jmarkel44 | 221:2a5e9902003c | 281 | // @return none |
| jmarkel44 | 221:2a5e9902003c | 282 | // |
| jmarkel44 | 221:2a5e9902003c | 283 | void CompositeControl::unregisterControls(void) |
| jmarkel44 | 221:2a5e9902003c | 284 | { |
| jmarkel44 | 221:2a5e9902003c | 285 | // loop through the list |
| jmarkel44 | 221:2a5e9902003c | 286 | StringAlgorithmMap::iterator pos; |
| jmarkel44 | 221:2a5e9902003c | 287 | pos = algorithmTable.find(this->ca); |
| jmarkel44 | 221:2a5e9902003c | 288 | if ( pos != algorithmTable.end() ) { |
| jmarkel44 | 221:2a5e9902003c | 289 | std::vector<OutputElement>::iterator it; |
| jmarkel44 | 221:2a5e9902003c | 290 | for ( it = outputs.begin(); it != outputs.end(); ++it ) { |
| jmarkel44 | 221:2a5e9902003c | 291 | sendMail(it->tag, ACTION_CONTROL_UNREGISTER); |
| jmarkel44 | 221:2a5e9902003c | 292 | } |
| jmarkel44 | 221:2a5e9902003c | 293 | } else { |
| jmarkel44 | 221:2a5e9902003c | 294 | logError("%s: failed to find the control algorithm %s\n", __func__, this->ca.c_str()); |
| jmarkel44 | 221:2a5e9902003c | 295 | } |
| jmarkel44 | 221:2a5e9902003c | 296 | } |
| jmarkel44 | 221:2a5e9902003c | 297 | |
| jmarkel44 | 221:2a5e9902003c | 298 | // |
| jmarkel44 | 221:2a5e9902003c | 299 | // methid: display |
| jmarkel44 | 221:2a5e9902003c | 300 | // description: display the pertinents |
| jmarkel44 | 221:2a5e9902003c | 301 | // |
| jmarkel44 | 221:2a5e9902003c | 302 | // @param none |
| jmarkel44 | 221:2a5e9902003c | 303 | // @return none |
| jmarkel44 | 221:2a5e9902003c | 304 | // |
| jmarkel44 | 220:dbe21411f962 | 305 | void CompositeControl::display(void) |
| jmarkel44 | 220:dbe21411f962 | 306 | { |
| jmarkel44 | 221:2a5e9902003c | 307 | const char *mapper[] = { "INIT", |
| jmarkel44 | 221:2a5e9902003c | 308 | "START", |
| jmarkel44 | 221:2a5e9902003c | 309 | "CONTROL_OFF", |
| jmarkel44 | 221:2a5e9902003c | 310 | "CONTROL_ON" |
| jmarkel44 | 221:2a5e9902003c | 311 | }; |
| jmarkel44 | 230:11765008ff3a | 312 | \ |
| jmarkel44 | 220:dbe21411f962 | 313 | printf("\r control file : %s\n", controlFile.c_str()); |
| jmarkel44 | 220:dbe21411f962 | 314 | printf("\r id : %s\n", id.c_str()); |
| jmarkel44 | 221:2a5e9902003c | 315 | printf("\r tag : %s\n", tag.c_str()); |
| jmarkel44 | 220:dbe21411f962 | 316 | printf("\r priority : %u\n", priority); |
| jmarkel44 | 220:dbe21411f962 | 317 | printf("\r ca : %s\n", ca.c_str()); |
| jmarkel44 | 221:2a5e9902003c | 318 | |
| jmarkel44 | 220:dbe21411f962 | 319 | vector<OutputElement>::iterator it; |
| jmarkel44 | 220:dbe21411f962 | 320 | printf("\r outputs :\n"); |
| jmarkel44 | 220:dbe21411f962 | 321 | for ( it = outputs.begin(); it != outputs.end(); ++it ) { |
| jmarkel44 | 220:dbe21411f962 | 322 | printf("\r tag-> %s\n", (*it).tag.c_str()); |
| jmarkel44 | 220:dbe21411f962 | 323 | printf("\r response-> %s\n", (*it).response.c_str()); |
| jmarkel44 | 220:dbe21411f962 | 324 | } |
| jmarkel44 | 221:2a5e9902003c | 325 | printf("\r current state : %s\n", mapper[currentState]); |
| jmarkel44 | 220:dbe21411f962 | 326 | printf("\r\n"); |
| jmarkel44 | 164:7cecd731882e | 327 | } |
