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