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/ConfigurationHandler.cpp@250:1cd8ec63e9e9, 2016-10-21 (annotated)
- Committer:
- jmarkel44
- Date:
- Fri Oct 21 11:42:24 2016 +0000
- Revision:
- 250:1cd8ec63e9e9
- Parent:
- 232:8a86b5bf38f7
working on failsafes;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jmarkel44 | 0:65cfa4873284 | 1 | /****************************************************************************** |
| jmarkel44 | 0:65cfa4873284 | 2 | * |
| jmarkel44 | 0:65cfa4873284 | 3 | * File: ConfigurationHandler.cpp |
| jmarkel44 | 0:65cfa4873284 | 4 | * Desciption: source for the ICE Configuration Handler |
| jmarkel44 | 0:65cfa4873284 | 5 | * |
| jmarkel44 | 0:65cfa4873284 | 6 | *****************************************************************************/ |
| jmarkel44 | 3:8ea4db957749 | 7 | #include "ConfigurationHandler.h" |
| jmarkel44 | 0:65cfa4873284 | 8 | #include "global.h" |
| jmarkel44 | 5:5e77a1db4d45 | 9 | #include "SetpointControl.h" |
| jmarkel44 | 12:ea87887ca7ad | 10 | #include "TimerControl.h" |
| jmarkel44 | 220:dbe21411f962 | 11 | #include "CompositeControl.h" |
| jmarkel44 | 221:2a5e9902003c | 12 | #include "CompositeAlgorithm.h" |
| jmarkel44 | 156:44f87c5a83ae | 13 | #include <algorithm> |
| jmarkel44 | 12:ea87887ca7ad | 14 | |
| jmarkel44 | 156:44f87c5a83ae | 15 | StringSetpointMap setpointTable; // setpoint control object table |
| jmarkel44 | 156:44f87c5a83ae | 16 | StringVectorTimerMap timerTable; // timer control object table |
| jmarkel44 | 156:44f87c5a83ae | 17 | StringManualMap manualTable; // manual control object table |
| jmarkel44 | 220:dbe21411f962 | 18 | StringCompositeMap compositeTable; // composite control object table |
| jmarkel44 | 250:1cd8ec63e9e9 | 19 | StringFailsafeMap failsafeTable; // failsafe control object table |
| jmarkel44 | 230:11765008ff3a | 20 | StringAlgorithmMap algorithmTable; // composite control algorithms |
| jmarkel44 | 5:5e77a1db4d45 | 21 | |
| jmarkel44 | 5:5e77a1db4d45 | 22 | // local function prototypes |
| jmarkel44 | 5:5e77a1db4d45 | 23 | static int loadPersistentControls(void); |
| jmarkel44 | 5:5e77a1db4d45 | 24 | |
| jmarkel44 | 74:03ccf04998b5 | 25 | // local helper functions |
| jmarkel44 | 5:5e77a1db4d45 | 26 | static int createControl(const Message_t *msg); |
| jmarkel44 | 5:5e77a1db4d45 | 27 | static int modifyControl(const Message_t *msg); |
| jmarkel44 | 5:5e77a1db4d45 | 28 | static int destroyControl(const Message_t *msg); |
| jmarkel44 | 5:5e77a1db4d45 | 29 | |
| jmarkel44 | 205:3c84af5f711f | 30 | // sort function for timer controls |
| jmarkel44 | 205:3c84af5f711f | 31 | bool compareStartTime(const TimerControl *lhs, const TimerControl *rhs) |
| jmarkel44 | 205:3c84af5f711f | 32 | { |
| jmarkel44 | 156:44f87c5a83ae | 33 | return (lhs->getStartTime() < rhs->getStartTime()); |
| jmarkel44 | 156:44f87c5a83ae | 34 | } |
| jmarkel44 | 156:44f87c5a83ae | 35 | |
| jmarkel44 | 12:ea87887ca7ad | 36 | /***************************************************************************** |
| jmarkel44 | 12:ea87887ca7ad | 37 | * Function: ConfigurationHandler() |
| jmarkel44 | 12:ea87887ca7ad | 38 | * Description: The ICE Configuration Handler |
| jmarkel44 | 12:ea87887ca7ad | 39 | * |
| jmarkel44 | 12:ea87887ca7ad | 40 | * @param args (unused) |
| jmarkel44 | 12:ea87887ca7ad | 41 | * @return none |
| jmarkel44 | 12:ea87887ca7ad | 42 | *****************************************************************************/ |
| jmarkel44 | 0:65cfa4873284 | 43 | void ConfigurationHandler(void const *args) |
| jmarkel44 | 0:65cfa4873284 | 44 | { |
| jmarkel44 | 12:ea87887ca7ad | 45 | UNUSED(args); |
| jmarkel44 | 5:5e77a1db4d45 | 46 | loadPersistentControls(); |
| jmarkel44 | 75:96512ccc0443 | 47 | osSignalSet(mainThreadId, sig_config_continue); |
| jmarkel44 | 5:5e77a1db4d45 | 48 | |
| jmarkel44 | 3:8ea4db957749 | 49 | while ( true ) { |
| jmarkel44 | 5:5e77a1db4d45 | 50 | // wait for an event |
| jmarkel44 | 5:5e77a1db4d45 | 51 | osEvent evt = MailBox.get(); |
| jmarkel44 | 5:5e77a1db4d45 | 52 | if (evt.status == osEventMail) { |
| jmarkel44 | 5:5e77a1db4d45 | 53 | Message_t *msg = (Message_t*) evt.value.p; |
| jmarkel44 | 5:5e77a1db4d45 | 54 | |
| jmarkel44 | 217:d5a2ff093319 | 55 | logInfo("\r%s: msg->action = %d\n", __func__, msg->action); |
| jmarkel44 | 37:7e6986b77f01 | 56 | logInfo("\r%s: msg->control = %d\n", __func__, msg->control); |
| jmarkel44 | 37:7e6986b77f01 | 57 | logInfo("\r%s: msg->controlFile = %s\n", __func__, msg->controlFile); |
| jmarkel44 | 5:5e77a1db4d45 | 58 | |
| jmarkel44 | 5:5e77a1db4d45 | 59 | switch ( msg->action ) { |
| jmarkel44 | 5:5e77a1db4d45 | 60 | case ACTION_CREATE: { |
| jmarkel44 | 5:5e77a1db4d45 | 61 | (void)createControl(msg); |
| jmarkel44 | 5:5e77a1db4d45 | 62 | break; |
| jmarkel44 | 5:5e77a1db4d45 | 63 | } |
| jmarkel44 | 5:5e77a1db4d45 | 64 | case ACTION_MODIFY: { |
| jmarkel44 | 5:5e77a1db4d45 | 65 | (void)modifyControl(msg); |
| jmarkel44 | 5:5e77a1db4d45 | 66 | break; |
| jmarkel44 | 5:5e77a1db4d45 | 67 | } |
| jmarkel44 | 5:5e77a1db4d45 | 68 | case ACTION_DESTROY: { |
| jmarkel44 | 5:5e77a1db4d45 | 69 | (void)destroyControl(msg); |
| jmarkel44 | 5:5e77a1db4d45 | 70 | break; |
| jmarkel44 | 5:5e77a1db4d45 | 71 | } |
| jmarkel44 | 5:5e77a1db4d45 | 72 | default: |
| jmarkel44 | 5:5e77a1db4d45 | 73 | break; |
| jmarkel44 | 5:5e77a1db4d45 | 74 | } |
| jmarkel44 | 5:5e77a1db4d45 | 75 | |
| jmarkel44 | 5:5e77a1db4d45 | 76 | // free the message |
| jmarkel44 | 5:5e77a1db4d45 | 77 | MailBox.free(msg); |
| jmarkel44 | 5:5e77a1db4d45 | 78 | } |
| jmarkel44 | 0:65cfa4873284 | 79 | } |
| jmarkel44 | 0:65cfa4873284 | 80 | } |
| jmarkel44 | 5:5e77a1db4d45 | 81 | |
| jmarkel44 | 12:ea87887ca7ad | 82 | /***************************************************************************** |
| jmarkel44 | 12:ea87887ca7ad | 83 | * Function: ConfigurationHandler_showControls() |
| jmarkel44 | 13:c80c283f9db2 | 84 | * Description: show the controls |
| jmarkel44 | 12:ea87887ca7ad | 85 | * |
| jmarkel44 | 12:ea87887ca7ad | 86 | * @param msg |
| jmarkel44 | 12:ea87887ca7ad | 87 | * @return none |
| jmarkel44 | 12:ea87887ca7ad | 88 | *****************************************************************************/ |
| jmarkel44 | 12:ea87887ca7ad | 89 | void ConfigurationHandler_showControls(void) |
| jmarkel44 | 12:ea87887ca7ad | 90 | { |
| jmarkel44 | 12:ea87887ca7ad | 91 | if ( !timerTable.empty() ) { |
| jmarkel44 | 205:3c84af5f711f | 92 | printf("\r\n"); |
| jmarkel44 | 156:44f87c5a83ae | 93 | StringVectorTimerMap::iterator pos; |
| jmarkel44 | 46:4cb96ab2d1c8 | 94 | for ( pos = timerTable.begin(); pos != timerTable.end(); ++pos ) { |
| jmarkel44 | 156:44f87c5a83ae | 95 | vector<TimerControl *>::iterator it; |
| jmarkel44 | 156:44f87c5a83ae | 96 | for ( it = pos->second.begin(); it != pos->second.end(); ++it ) { |
| jmarkel44 | 156:44f87c5a83ae | 97 | (*it)->display(); |
| jmarkel44 | 156:44f87c5a83ae | 98 | } |
| jmarkel44 | 12:ea87887ca7ad | 99 | } |
| jmarkel44 | 12:ea87887ca7ad | 100 | } |
| jmarkel44 | 250:1cd8ec63e9e9 | 101 | |
| jmarkel44 | 12:ea87887ca7ad | 102 | if ( !setpointTable.empty() ) { |
| jmarkel44 | 205:3c84af5f711f | 103 | printf("\r\n"); |
| jmarkel44 | 12:ea87887ca7ad | 104 | StringSetpointMap::iterator pos; |
| jmarkel44 | 93:1553fb156915 | 105 | for ( pos = setpointTable.begin(); pos != setpointTable.end(); ++pos ) { |
| jmarkel44 | 93:1553fb156915 | 106 | pos->second->display(); |
| jmarkel44 | 12:ea87887ca7ad | 107 | } |
| jmarkel44 | 12:ea87887ca7ad | 108 | } |
| jmarkel44 | 121:650205ffa656 | 109 | |
| jmarkel44 | 97:5cf6ab71dcd0 | 110 | if ( !manualTable.empty() ) { |
| jmarkel44 | 205:3c84af5f711f | 111 | printf("\r\n"); |
| jmarkel44 | 97:5cf6ab71dcd0 | 112 | StringManualMap::iterator pos; |
| jmarkel44 | 97:5cf6ab71dcd0 | 113 | for ( pos = manualTable.begin(); pos != manualTable.end(); ++pos ) { |
| jmarkel44 | 97:5cf6ab71dcd0 | 114 | pos->second->display(); |
| jmarkel44 | 97:5cf6ab71dcd0 | 115 | } |
| jmarkel44 | 97:5cf6ab71dcd0 | 116 | } |
| jmarkel44 | 230:11765008ff3a | 117 | |
| jmarkel44 | 220:dbe21411f962 | 118 | if ( !compositeTable.empty() ) { |
| jmarkel44 | 220:dbe21411f962 | 119 | printf("\r\n"); |
| jmarkel44 | 220:dbe21411f962 | 120 | StringCompositeMap::iterator pos; |
| jmarkel44 | 220:dbe21411f962 | 121 | for ( pos = compositeTable.begin(); pos != compositeTable.end(); ++pos ) { |
| jmarkel44 | 220:dbe21411f962 | 122 | pos->second->display(); |
| jmarkel44 | 220:dbe21411f962 | 123 | } |
| jmarkel44 | 220:dbe21411f962 | 124 | } |
| jmarkel44 | 250:1cd8ec63e9e9 | 125 | |
| jmarkel44 | 250:1cd8ec63e9e9 | 126 | if ( !failsafeTable.empty() ) { |
| jmarkel44 | 250:1cd8ec63e9e9 | 127 | printf("\r\n"); |
| jmarkel44 | 250:1cd8ec63e9e9 | 128 | StringFailsafeMap::iterator pos; |
| jmarkel44 | 250:1cd8ec63e9e9 | 129 | for ( pos = failsafeTable.begin(); pos != failsafeTable.end(); ++pos ) { |
| jmarkel44 | 250:1cd8ec63e9e9 | 130 | pos->second->display(); |
| jmarkel44 | 250:1cd8ec63e9e9 | 131 | } |
| jmarkel44 | 250:1cd8ec63e9e9 | 132 | } |
| jmarkel44 | 12:ea87887ca7ad | 133 | } |
| jmarkel44 | 12:ea87887ca7ad | 134 | |
| jmarkel44 | 250:1cd8ec63e9e9 | 135 | // |
| jmarkel44 | 250:1cd8ec63e9e9 | 136 | // function: ConfigurationHandler_showAlgorithms |
| jmarkel44 | 250:1cd8ec63e9e9 | 137 | // description: display the control algorithms |
| jmarkel44 | 250:1cd8ec63e9e9 | 138 | // |
| jmarkel44 | 250:1cd8ec63e9e9 | 139 | // @param none |
| jmarkel44 | 250:1cd8ec63e9e9 | 140 | // @return none |
| jmarkel44 | 250:1cd8ec63e9e9 | 141 | // |
| jmarkel44 | 221:2a5e9902003c | 142 | void ConfigurationHandler_showAlgorithms(void) |
| jmarkel44 | 221:2a5e9902003c | 143 | { |
| jmarkel44 | 221:2a5e9902003c | 144 | StringAlgorithmMap::iterator pos; |
| jmarkel44 | 230:11765008ff3a | 145 | |
| jmarkel44 | 221:2a5e9902003c | 146 | for ( pos = algorithmTable.begin(); pos != algorithmTable.end(); ++pos ) { |
| jmarkel44 | 221:2a5e9902003c | 147 | pos->second->display(); |
| jmarkel44 | 221:2a5e9902003c | 148 | } |
| jmarkel44 | 221:2a5e9902003c | 149 | } |
| jmarkel44 | 221:2a5e9902003c | 150 | |
| jmarkel44 | 12:ea87887ca7ad | 151 | /***************************************************************************** |
| jmarkel44 | 12:ea87887ca7ad | 152 | * Function: loadPersistentControls() |
| jmarkel44 | 12:ea87887ca7ad | 153 | * Description: load persistent controls from flash |
| jmarkel44 | 12:ea87887ca7ad | 154 | * |
| jmarkel44 | 12:ea87887ca7ad | 155 | * @param none |
| jmarkel44 | 12:ea87887ca7ad | 156 | * @return none |
| jmarkel44 | 12:ea87887ca7ad | 157 | *****************************************************************************/ |
| jmarkel44 | 12:ea87887ca7ad | 158 | static int loadPersistentControls(void) |
| jmarkel44 | 12:ea87887ca7ad | 159 | { |
| jmarkel44 | 12:ea87887ca7ad | 160 | static bool loaded = false; |
| jmarkel44 | 12:ea87887ca7ad | 161 | |
| jmarkel44 | 12:ea87887ca7ad | 162 | if ( !loaded ) { // lazy protection |
| jmarkel44 | 121:650205ffa656 | 163 | |
| jmarkel44 | 77:43e0a3d9e536 | 164 | printf("\rLoading persistent controls: \n"); |
| jmarkel44 | 74:03ccf04998b5 | 165 | std::vector<mDot::mdot_file> file_list = GLOBAL_mdot->listUserFiles(); |
| jmarkel44 | 156:44f87c5a83ae | 166 | |
| jmarkel44 | 126:c85ac6a8e9af | 167 | loaded = true; |
| jmarkel44 | 74:03ccf04998b5 | 168 | |
| jmarkel44 | 74:03ccf04998b5 | 169 | for (std::vector<mDot::mdot_file>::iterator i = file_list.begin(); i != file_list.end(); ++i) { |
| jmarkel44 | 74:03ccf04998b5 | 170 | if( strncmp( i->name, CONTROL_SP_STR, strlen(CONTROL_SP_STR)) == 0 ) { |
| jmarkel44 | 77:43e0a3d9e536 | 171 | // create the setpoint control |
| jmarkel44 | 74:03ccf04998b5 | 172 | Message_t msg; |
| jmarkel44 | 74:03ccf04998b5 | 173 | msg.control = CONTROL_SETPOINT; |
| jmarkel44 | 74:03ccf04998b5 | 174 | strncpy(msg.controlFile, i->name, sizeof(msg.controlFile)); |
| jmarkel44 | 74:03ccf04998b5 | 175 | int rc = createControl(&msg); |
| jmarkel44 | 74:03ccf04998b5 | 176 | if ( rc != 0 ) { |
| jmarkel44 | 121:650205ffa656 | 177 | logError("%s: failed to load %s", __func__, msg.controlFile); |
| jmarkel44 | 74:03ccf04998b5 | 178 | } else { |
| jmarkel44 | 74:03ccf04998b5 | 179 | printf("\r control %s loaded.\n", msg.controlFile); |
| jmarkel44 | 74:03ccf04998b5 | 180 | } |
| jmarkel44 | 74:03ccf04998b5 | 181 | } else if ( strncmp( i->name, CONTROL_TM_STR, strlen(CONTROL_TM_STR)) == 0 ) { |
| jmarkel44 | 121:650205ffa656 | 182 | // create the timer control |
| jmarkel44 | 74:03ccf04998b5 | 183 | Message_t msg; |
| jmarkel44 | 74:03ccf04998b5 | 184 | msg.control = CONTROL_TIMER; |
| jmarkel44 | 74:03ccf04998b5 | 185 | strncpy(msg.controlFile, i->name, sizeof(msg.controlFile)); |
| jmarkel44 | 74:03ccf04998b5 | 186 | int rc = createControl(&msg); |
| jmarkel44 | 74:03ccf04998b5 | 187 | if ( rc != 0 ) { |
| jmarkel44 | 121:650205ffa656 | 188 | logError("%s: failed to load %s", __func__, msg.controlFile); |
| jmarkel44 | 121:650205ffa656 | 189 | |
| jmarkel44 | 74:03ccf04998b5 | 190 | } else { |
| jmarkel44 | 74:03ccf04998b5 | 191 | printf("\r control %s loaded.\n", msg.controlFile); |
| jmarkel44 | 74:03ccf04998b5 | 192 | } |
| jmarkel44 | 230:11765008ff3a | 193 | } else if ( strncmp( i->name, CONTROL_COMP_STR, strlen(CONTROL_COMP_STR)) == 0 ) { |
| jmarkel44 | 230:11765008ff3a | 194 | Message_t msg; |
| jmarkel44 | 230:11765008ff3a | 195 | msg.control = CONTROL_COMPOSITE; |
| jmarkel44 | 230:11765008ff3a | 196 | strncpy(msg.controlFile, i->name, sizeof(msg.controlFile)); |
| jmarkel44 | 230:11765008ff3a | 197 | int rc = createControl(&msg); |
| jmarkel44 | 230:11765008ff3a | 198 | if ( rc != 0 ) { |
| jmarkel44 | 230:11765008ff3a | 199 | logError("%s: failed to load %s\n", __func__, msg.controlFile); |
| jmarkel44 | 230:11765008ff3a | 200 | } else { |
| jmarkel44 | 230:11765008ff3a | 201 | printf("\r control %s loaded.\n", msg.controlFile); |
| jmarkel44 | 230:11765008ff3a | 202 | } |
| jmarkel44 | 230:11765008ff3a | 203 | } else if ( strncmp( i->name, CONTROL_CA_STR, strlen(CONTROL_CA_STR)) == 0 ) { |
| jmarkel44 | 230:11765008ff3a | 204 | Message_t msg; |
| jmarkel44 | 230:11765008ff3a | 205 | msg.control = CONTROL_ALGORITHM; |
| jmarkel44 | 230:11765008ff3a | 206 | strncpy(msg.controlFile, i->name, sizeof(msg.controlFile)); |
| jmarkel44 | 230:11765008ff3a | 207 | int rc = createControl(&msg); |
| jmarkel44 | 230:11765008ff3a | 208 | if ( rc != 0 ) { |
| jmarkel44 | 230:11765008ff3a | 209 | logError("%s: failed to load %s\n", __func__, msg.controlFile); |
| jmarkel44 | 230:11765008ff3a | 210 | } else { |
| jmarkel44 | 230:11765008ff3a | 211 | printf("\r control %s loaded.\n", msg.controlFile); |
| jmarkel44 | 230:11765008ff3a | 212 | } |
| jmarkel44 | 250:1cd8ec63e9e9 | 213 | } else if ( strncmp( i->name, CONTROL_FS_STR, strlen(CONTROL_FS_STR)) == 0 ) { |
| jmarkel44 | 250:1cd8ec63e9e9 | 214 | Message_t msg; |
| jmarkel44 | 250:1cd8ec63e9e9 | 215 | msg.control = CONTROL_FAILSAFE; |
| jmarkel44 | 250:1cd8ec63e9e9 | 216 | strncpy(msg.controlFile, i->name, sizeof(msg.controlFile)); |
| jmarkel44 | 250:1cd8ec63e9e9 | 217 | int rc = createControl(&msg); |
| jmarkel44 | 250:1cd8ec63e9e9 | 218 | if ( rc != 0 ) { |
| jmarkel44 | 250:1cd8ec63e9e9 | 219 | logError("%s: failed to load %s\n", __func__, msg.controlFile); |
| jmarkel44 | 250:1cd8ec63e9e9 | 220 | } else { |
| jmarkel44 | 250:1cd8ec63e9e9 | 221 | printf("\r control %s loaded.\n", msg.controlFile); |
| jmarkel44 | 250:1cd8ec63e9e9 | 222 | } |
| jmarkel44 | 74:03ccf04998b5 | 223 | } else if ( strncmp( i->name, CONTROL_MN_STR, strlen(CONTROL_MN_STR)) == 0 ) { |
| jmarkel44 | 126:c85ac6a8e9af | 224 | // TODO: delete any timed manual control, not continuous... |
| jmarkel44 | 126:c85ac6a8e9af | 225 | GLOBAL_mdot->deleteUserFile(i->name); |
| jmarkel44 | 74:03ccf04998b5 | 226 | } else { |
| jmarkel44 | 195:21df85341cb3 | 227 | logInfo("\rNot A Control File%s\r\n",i->name); |
| jmarkel44 | 74:03ccf04998b5 | 228 | // not a control file |
| jmarkel44 | 74:03ccf04998b5 | 229 | } |
| jmarkel44 | 74:03ccf04998b5 | 230 | } |
| jmarkel44 | 12:ea87887ca7ad | 231 | } |
| jmarkel44 | 12:ea87887ca7ad | 232 | return 0; |
| jmarkel44 | 12:ea87887ca7ad | 233 | } |
| jmarkel44 | 12:ea87887ca7ad | 234 | |
| jmarkel44 | 12:ea87887ca7ad | 235 | /***************************************************************************** |
| jmarkel44 | 12:ea87887ca7ad | 236 | * Function: createControl() |
| jmarkel44 | 12:ea87887ca7ad | 237 | * Description: creates a new control |
| jmarkel44 | 12:ea87887ca7ad | 238 | * |
| jmarkel44 | 12:ea87887ca7ad | 239 | * @param none |
| jmarkel44 | 12:ea87887ca7ad | 240 | * @return none |
| jmarkel44 | 12:ea87887ca7ad | 241 | *****************************************************************************/ |
| jmarkel44 | 5:5e77a1db4d45 | 242 | static int createControl(const Message_t *msg) |
| jmarkel44 | 5:5e77a1db4d45 | 243 | { |
| jmarkel44 | 37:7e6986b77f01 | 244 | logInfo("\r%s invoked\n", __func__); |
| jmarkel44 | 5:5e77a1db4d45 | 245 | |
| jmarkel44 | 5:5e77a1db4d45 | 246 | switch (msg->control) { |
| jmarkel44 | 5:5e77a1db4d45 | 247 | case CONTROL_SETPOINT: { |
| jmarkel44 | 46:4cb96ab2d1c8 | 248 | SetpointControl *setpointControl = new SetpointControl; |
| jmarkel44 | 28:c410a61238bb | 249 | bool rc = setpointControl->load(msg->controlFile); |
| jmarkel44 | 19:9bc8fabeddfa | 250 | if ( rc != true ) { |
| jmarkel44 | 19:9bc8fabeddfa | 251 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
| jmarkel44 | 19:9bc8fabeddfa | 252 | delete setpointControl; |
| jmarkel44 | 19:9bc8fabeddfa | 253 | } else { |
| jmarkel44 | 19:9bc8fabeddfa | 254 | setpointTable[msg->controlFile] = setpointControl; |
| jmarkel44 | 74:03ccf04998b5 | 255 | // start the setpoint control |
| jmarkel44 | 74:03ccf04998b5 | 256 | setpointControl->start(); |
| jmarkel44 | 19:9bc8fabeddfa | 257 | } |
| jmarkel44 | 5:5e77a1db4d45 | 258 | break; |
| jmarkel44 | 5:5e77a1db4d45 | 259 | } |
| jmarkel44 | 5:5e77a1db4d45 | 260 | case CONTROL_TIMER: { |
| jmarkel44 | 46:4cb96ab2d1c8 | 261 | TimerControl *timerControl = new TimerControl; |
| jmarkel44 | 28:c410a61238bb | 262 | bool rc = timerControl->load(msg->controlFile); |
| jmarkel44 | 19:9bc8fabeddfa | 263 | if ( rc != true ) { |
| jmarkel44 | 19:9bc8fabeddfa | 264 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
| jmarkel44 | 19:9bc8fabeddfa | 265 | delete timerControl; |
| jmarkel44 | 19:9bc8fabeddfa | 266 | } else { |
| jmarkel44 | 156:44f87c5a83ae | 267 | timerTable[timerControl->getOutput()].push_back(timerControl); |
| jmarkel44 | 156:44f87c5a83ae | 268 | sort(timerTable[timerControl->getOutput()].begin(), |
| jmarkel44 | 156:44f87c5a83ae | 269 | timerTable[timerControl->getOutput()].end(), |
| jmarkel44 | 156:44f87c5a83ae | 270 | compareStartTime); |
| jmarkel44 | 126:c85ac6a8e9af | 271 | timerControl->start(); |
| jmarkel44 | 19:9bc8fabeddfa | 272 | } |
| jmarkel44 | 5:5e77a1db4d45 | 273 | break; |
| jmarkel44 | 5:5e77a1db4d45 | 274 | } |
| jmarkel44 | 46:4cb96ab2d1c8 | 275 | case CONTROL_MANUAL: { |
| jmarkel44 | 46:4cb96ab2d1c8 | 276 | ManualControl *manualControl = new ManualControl; |
| jmarkel44 | 46:4cb96ab2d1c8 | 277 | bool rc = manualControl->load(msg->controlFile); |
| jmarkel44 | 46:4cb96ab2d1c8 | 278 | if ( rc != true ) { |
| jmarkel44 | 46:4cb96ab2d1c8 | 279 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
| jmarkel44 | 46:4cb96ab2d1c8 | 280 | delete manualControl; |
| jmarkel44 | 46:4cb96ab2d1c8 | 281 | } else { |
| jmarkel44 | 46:4cb96ab2d1c8 | 282 | manualTable[msg->controlFile] = manualControl; |
| jmarkel44 | 97:5cf6ab71dcd0 | 283 | // start the manual control |
| jmarkel44 | 221:2a5e9902003c | 284 | manualControl-> start(); |
| jmarkel44 | 46:4cb96ab2d1c8 | 285 | } |
| jmarkel44 | 46:4cb96ab2d1c8 | 286 | break; |
| jmarkel44 | 46:4cb96ab2d1c8 | 287 | } |
| jmarkel44 | 220:dbe21411f962 | 288 | case CONTROL_COMPOSITE: { |
| jmarkel44 | 220:dbe21411f962 | 289 | CompositeControl *compositeControl = new CompositeControl; |
| jmarkel44 | 220:dbe21411f962 | 290 | bool rc = compositeControl->load(msg->controlFile); |
| jmarkel44 | 220:dbe21411f962 | 291 | if ( rc != true ) { |
| jmarkel44 | 220:dbe21411f962 | 292 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
| jmarkel44 | 220:dbe21411f962 | 293 | delete compositeControl; |
| jmarkel44 | 220:dbe21411f962 | 294 | } else { |
| jmarkel44 | 220:dbe21411f962 | 295 | compositeTable[msg->controlFile] = compositeControl; |
| jmarkel44 | 221:2a5e9902003c | 296 | compositeControl->start(); |
| jmarkel44 | 221:2a5e9902003c | 297 | } |
| jmarkel44 | 221:2a5e9902003c | 298 | break; |
| jmarkel44 | 221:2a5e9902003c | 299 | } |
| jmarkel44 | 250:1cd8ec63e9e9 | 300 | case CONTROL_FAILSAFE: { |
| jmarkel44 | 250:1cd8ec63e9e9 | 301 | FailsafeControl *failsafeControl = new FailsafeControl; |
| jmarkel44 | 250:1cd8ec63e9e9 | 302 | bool rc = failsafeControl->load(msg->controlFile); |
| jmarkel44 | 250:1cd8ec63e9e9 | 303 | if ( rc != true ) { |
| jmarkel44 | 250:1cd8ec63e9e9 | 304 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
| jmarkel44 | 250:1cd8ec63e9e9 | 305 | delete failsafeControl; |
| jmarkel44 | 250:1cd8ec63e9e9 | 306 | } else { |
| jmarkel44 | 250:1cd8ec63e9e9 | 307 | failsafeTable[msg->controlFile] = failsafeControl; |
| jmarkel44 | 250:1cd8ec63e9e9 | 308 | failsafeControl->start(); |
| jmarkel44 | 250:1cd8ec63e9e9 | 309 | } |
| jmarkel44 | 250:1cd8ec63e9e9 | 310 | break; |
| jmarkel44 | 250:1cd8ec63e9e9 | 311 | } |
| jmarkel44 | 221:2a5e9902003c | 312 | case CONTROL_ALGORITHM: { |
| jmarkel44 | 221:2a5e9902003c | 313 | CompositeAlgorithm *compositeAlgorithm = new CompositeAlgorithm; |
| jmarkel44 | 221:2a5e9902003c | 314 | bool rc = compositeAlgorithm->load(msg->controlFile); |
| jmarkel44 | 221:2a5e9902003c | 315 | if ( rc != true ) { |
| jmarkel44 | 221:2a5e9902003c | 316 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
| jmarkel44 | 221:2a5e9902003c | 317 | } else { |
| jmarkel44 | 230:11765008ff3a | 318 | // add this algorithm to the table |
| jmarkel44 | 221:2a5e9902003c | 319 | algorithmTable[compositeAlgorithm->getId()] = compositeAlgorithm; |
| jmarkel44 | 220:dbe21411f962 | 320 | } |
| jmarkel44 | 220:dbe21411f962 | 321 | break; |
| jmarkel44 | 220:dbe21411f962 | 322 | } |
| jmarkel44 | 19:9bc8fabeddfa | 323 | case CONTROL_PID: |
| jmarkel44 | 5:5e77a1db4d45 | 324 | default: |
| jmarkel44 | 46:4cb96ab2d1c8 | 325 | logInfo("\r%s: control type %d not implemented yet...\n", |
| jmarkel44 | 46:4cb96ab2d1c8 | 326 | __func__, msg->control); |
| jmarkel44 | 5:5e77a1db4d45 | 327 | break; |
| jmarkel44 | 5:5e77a1db4d45 | 328 | } |
| jmarkel44 | 5:5e77a1db4d45 | 329 | return 0; |
| jmarkel44 | 5:5e77a1db4d45 | 330 | } |
| jmarkel44 | 12:ea87887ca7ad | 331 | |
| jmarkel44 | 12:ea87887ca7ad | 332 | /***************************************************************************** |
| jmarkel44 | 12:ea87887ca7ad | 333 | * Function: modifyControl() |
| jmarkel44 | 12:ea87887ca7ad | 334 | * Description: modifies a control |
| jmarkel44 | 12:ea87887ca7ad | 335 | * |
| jmarkel44 | 12:ea87887ca7ad | 336 | * @param msg |
| jmarkel44 | 12:ea87887ca7ad | 337 | * @return none |
| jmarkel44 | 12:ea87887ca7ad | 338 | *****************************************************************************/ |
| jmarkel44 | 5:5e77a1db4d45 | 339 | static int modifyControl(const Message_t *msg) |
| jmarkel44 | 5:5e77a1db4d45 | 340 | { |
| jmarkel44 | 37:7e6986b77f01 | 341 | logInfo("\r%s invoked\n", __func__); |
| jmarkel44 | 46:4cb96ab2d1c8 | 342 | |
| jmarkel44 | 207:55aabde2d4bf | 343 | switch (msg->control) { |
| jmarkel44 | 207:55aabde2d4bf | 344 | case CONTROL_SETPOINT: { |
| jmarkel44 | 207:55aabde2d4bf | 345 | // find the control in the table |
| jmarkel44 | 207:55aabde2d4bf | 346 | StringSetpointMap::iterator pos; |
| jmarkel44 | 207:55aabde2d4bf | 347 | pos = setpointTable.find(msg->controlFile); |
| jmarkel44 | 207:55aabde2d4bf | 348 | if ( pos != setpointTable.end() ) { |
| jmarkel44 | 207:55aabde2d4bf | 349 | int rc = pos->second->load(msg->controlFile); |
| jmarkel44 | 207:55aabde2d4bf | 350 | if ( rc != true ) { |
| jmarkel44 | 208:784c46652863 | 351 | logError("\rFailed to reload the setpoint control %s\n", msg->controlFile); |
| jmarkel44 | 207:55aabde2d4bf | 352 | } else { |
| jmarkel44 | 208:784c46652863 | 353 | logInfo("\rReloaded the setpoint control %s\n", msg->controlFile); |
| jmarkel44 | 208:784c46652863 | 354 | } |
| jmarkel44 | 208:784c46652863 | 355 | } |
| jmarkel44 | 208:784c46652863 | 356 | break; |
| jmarkel44 | 208:784c46652863 | 357 | } |
| jmarkel44 | 208:784c46652863 | 358 | case CONTROL_MANUAL: { |
| jmarkel44 | 208:784c46652863 | 359 | // find the manual control in the table |
| jmarkel44 | 208:784c46652863 | 360 | StringManualMap::iterator pos; |
| jmarkel44 | 208:784c46652863 | 361 | pos = manualTable.find(msg->controlFile); |
| jmarkel44 | 208:784c46652863 | 362 | if ( pos != manualTable.end() ) { |
| jmarkel44 | 208:784c46652863 | 363 | int rc = pos->second->load(msg->controlFile); |
| jmarkel44 | 208:784c46652863 | 364 | if ( rc != true ) { |
| jmarkel44 | 208:784c46652863 | 365 | logError("\rFailed to reload the manual control %s\n", msg->controlFile); |
| jmarkel44 | 208:784c46652863 | 366 | } else { |
| jmarkel44 | 208:784c46652863 | 367 | logInfo("\rReloaded the manual control %s\n", msg->controlFile); |
| jmarkel44 | 207:55aabde2d4bf | 368 | } |
| jmarkel44 | 207:55aabde2d4bf | 369 | } |
| jmarkel44 | 207:55aabde2d4bf | 370 | break; |
| jmarkel44 | 207:55aabde2d4bf | 371 | } |
| jmarkel44 | 207:55aabde2d4bf | 372 | default: |
| jmarkel44 | 207:55aabde2d4bf | 373 | logError("%s: unknown control %d\n", __func__, msg->control); |
| jmarkel44 | 207:55aabde2d4bf | 374 | break; |
| jmarkel44 | 207:55aabde2d4bf | 375 | } |
| jmarkel44 | 207:55aabde2d4bf | 376 | |
| jmarkel44 | 5:5e77a1db4d45 | 377 | return 0; |
| jmarkel44 | 5:5e77a1db4d45 | 378 | } |
| jmarkel44 | 12:ea87887ca7ad | 379 | |
| jmarkel44 | 12:ea87887ca7ad | 380 | /***************************************************************************** |
| jmarkel44 | 12:ea87887ca7ad | 381 | * Function: destroyControl() |
| jmarkel44 | 12:ea87887ca7ad | 382 | * Description: destroys a controls |
| jmarkel44 | 12:ea87887ca7ad | 383 | * |
| jmarkel44 | 12:ea87887ca7ad | 384 | * @param msg |
| jmarkel44 | 12:ea87887ca7ad | 385 | * @return none |
| jmarkel44 | 12:ea87887ca7ad | 386 | *****************************************************************************/ |
| jmarkel44 | 5:5e77a1db4d45 | 387 | static int destroyControl(const Message_t *msg) |
| jmarkel44 | 5:5e77a1db4d45 | 388 | { |
| jmarkel44 | 37:7e6986b77f01 | 389 | logInfo("\r%s invoked\n", __func__); |
| jmarkel44 | 12:ea87887ca7ad | 390 | |
| jmarkel44 | 12:ea87887ca7ad | 391 | switch ( msg->control ) { |
| jmarkel44 | 12:ea87887ca7ad | 392 | case CONTROL_SETPOINT: { |
| jmarkel44 | 12:ea87887ca7ad | 393 | StringSetpointMap::iterator pos; |
| jmarkel44 | 12:ea87887ca7ad | 394 | pos = setpointTable.find(msg->controlFile); |
| jmarkel44 | 12:ea87887ca7ad | 395 | if ( pos != setpointTable.end() ) { |
| jmarkel44 | 196:78397baf0802 | 396 | GLOBAL_mdot->deleteUserFile(msg->controlFile); |
| jmarkel44 | 196:78397baf0802 | 397 | logInfo("%s: deleted %s", __func__, msg->controlFile); |
| jmarkel44 | 74:03ccf04998b5 | 398 | pos->second->unregisterControl(); |
| jmarkel44 | 12:ea87887ca7ad | 399 | delete (pos->second); |
| jmarkel44 | 12:ea87887ca7ad | 400 | setpointTable.erase(pos); |
| jmarkel44 | 195:21df85341cb3 | 401 | } else { |
| jmarkel44 | 195:21df85341cb3 | 402 | logError("%s: unable to find %s\n", __func__, msg->controlFile); |
| jmarkel44 | 12:ea87887ca7ad | 403 | } |
| jmarkel44 | 12:ea87887ca7ad | 404 | break; |
| jmarkel44 | 12:ea87887ca7ad | 405 | } |
| jmarkel44 | 12:ea87887ca7ad | 406 | case CONTROL_TIMER: { |
| jmarkel44 | 164:7cecd731882e | 407 | StringVectorTimerMap::iterator pos; |
| jmarkel44 | 205:3c84af5f711f | 408 | #if 0 |
| jmarkel44 | 12:ea87887ca7ad | 409 | pos = timerTable.find(msg->controlFile); |
| jmarkel44 | 12:ea87887ca7ad | 410 | if ( pos != timerTable.end() ) { |
| jmarkel44 | 196:78397baf0802 | 411 | delete ((*pos)->second); |
| jmarkel44 | 12:ea87887ca7ad | 412 | timerTable.erase(pos); |
| jmarkel44 | 12:ea87887ca7ad | 413 | } |
| jmarkel44 | 205:3c84af5f711f | 414 | #endif |
| jmarkel44 | 12:ea87887ca7ad | 415 | break; |
| jmarkel44 | 12:ea87887ca7ad | 416 | } |
| jmarkel44 | 46:4cb96ab2d1c8 | 417 | case CONTROL_MANUAL: { |
| jmarkel44 | 46:4cb96ab2d1c8 | 418 | StringManualMap::iterator pos; |
| jmarkel44 | 46:4cb96ab2d1c8 | 419 | pos = manualTable.find(msg->controlFile); |
| jmarkel44 | 46:4cb96ab2d1c8 | 420 | if ( pos != manualTable.end() ) { |
| jmarkel44 | 196:78397baf0802 | 421 | GLOBAL_mdot->deleteUserFile(msg->controlFile); |
| jmarkel44 | 196:78397baf0802 | 422 | logInfo("%s: deleted %s", __func__, msg->controlFile); |
| jmarkel44 | 97:5cf6ab71dcd0 | 423 | pos->second->unregisterControl(); |
| jmarkel44 | 46:4cb96ab2d1c8 | 424 | delete (pos->second); |
| jmarkel44 | 46:4cb96ab2d1c8 | 425 | manualTable.erase(pos); |
| jmarkel44 | 195:21df85341cb3 | 426 | } else { |
| jmarkel44 | 195:21df85341cb3 | 427 | logError("%s: unable to find %s", __func__, msg->controlFile); |
| jmarkel44 | 46:4cb96ab2d1c8 | 428 | } |
| jmarkel44 | 46:4cb96ab2d1c8 | 429 | break; |
| jmarkel44 | 46:4cb96ab2d1c8 | 430 | } |
| jmarkel44 | 12:ea87887ca7ad | 431 | default: |
| jmarkel44 | 12:ea87887ca7ad | 432 | break; |
| jmarkel44 | 12:ea87887ca7ad | 433 | } |
| jmarkel44 | 12:ea87887ca7ad | 434 | return 0; |
| jmarkel44 | 20:653923c2f37a | 435 | } |
