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