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