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@51:66b820f203a5, 2016-09-13 (annotated)
- Committer:
- jmarkel44
- Date:
- Tue Sep 13 21:29:24 2016 +0000
- Revision:
- 51:66b820f203a5
- Parent:
- 46:4cb96ab2d1c8
- Child:
- 72:3754b352f156
committing;
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 | 12:ea87887ca7ad | 11 | |
jmarkel44 | 46:4cb96ab2d1c8 | 12 | StringSetpointMap setpointTable; // setpoint control object table |
jmarkel44 | 46:4cb96ab2d1c8 | 13 | StringTimerMap timerTable; // timer control object table |
jmarkel44 | 46:4cb96ab2d1c8 | 14 | //StringManualMap manualTable; // manual control object table |
jmarkel44 | 5:5e77a1db4d45 | 15 | |
jmarkel44 | 5:5e77a1db4d45 | 16 | // local function prototypes |
jmarkel44 | 5:5e77a1db4d45 | 17 | static int loadPersistentControls(void); |
jmarkel44 | 5:5e77a1db4d45 | 18 | |
jmarkel44 | 46:4cb96ab2d1c8 | 19 | // local helper functions |
jmarkel44 | 5:5e77a1db4d45 | 20 | static int createControl(const Message_t *msg); |
jmarkel44 | 5:5e77a1db4d45 | 21 | static int modifyControl(const Message_t *msg); |
jmarkel44 | 5:5e77a1db4d45 | 22 | static int destroyControl(const Message_t *msg); |
jmarkel44 | 5:5e77a1db4d45 | 23 | |
jmarkel44 | 12:ea87887ca7ad | 24 | /***************************************************************************** |
jmarkel44 | 12:ea87887ca7ad | 25 | * Function: ConfigurationHandler() |
jmarkel44 | 12:ea87887ca7ad | 26 | * Description: The ICE Configuration Handler |
jmarkel44 | 12:ea87887ca7ad | 27 | * |
jmarkel44 | 12:ea87887ca7ad | 28 | * @param args (unused) |
jmarkel44 | 12:ea87887ca7ad | 29 | * @return none |
jmarkel44 | 12:ea87887ca7ad | 30 | *****************************************************************************/ |
jmarkel44 | 0:65cfa4873284 | 31 | void ConfigurationHandler(void const *args) |
jmarkel44 | 0:65cfa4873284 | 32 | { |
jmarkel44 | 12:ea87887ca7ad | 33 | UNUSED(args); |
jmarkel44 | 5:5e77a1db4d45 | 34 | loadPersistentControls(); |
jmarkel44 | 0:65cfa4873284 | 35 | osSignalSet(mainThreadId, sig_continue); |
jmarkel44 | 5:5e77a1db4d45 | 36 | |
jmarkel44 | 3:8ea4db957749 | 37 | while ( true ) { |
jmarkel44 | 5:5e77a1db4d45 | 38 | // wait for an event |
jmarkel44 | 5:5e77a1db4d45 | 39 | osEvent evt = MailBox.get(); |
jmarkel44 | 5:5e77a1db4d45 | 40 | if (evt.status == osEventMail) { |
jmarkel44 | 5:5e77a1db4d45 | 41 | Message_t *msg = (Message_t*) evt.value.p; |
jmarkel44 | 5:5e77a1db4d45 | 42 | |
jmarkel44 | 37:7e6986b77f01 | 43 | logInfo("\r%s: mes->action = %d\n", __func__, msg->action); |
jmarkel44 | 37:7e6986b77f01 | 44 | logInfo("\r%s: msg->control = %d\n", __func__, msg->control); |
jmarkel44 | 37:7e6986b77f01 | 45 | logInfo("\r%s: msg->controlFile = %s\n", __func__, msg->controlFile); |
jmarkel44 | 5:5e77a1db4d45 | 46 | |
jmarkel44 | 5:5e77a1db4d45 | 47 | switch ( msg->action ) { |
jmarkel44 | 5:5e77a1db4d45 | 48 | case ACTION_CREATE: { |
jmarkel44 | 5:5e77a1db4d45 | 49 | (void)createControl(msg); |
jmarkel44 | 5:5e77a1db4d45 | 50 | break; |
jmarkel44 | 5:5e77a1db4d45 | 51 | } |
jmarkel44 | 5:5e77a1db4d45 | 52 | case ACTION_MODIFY: { |
jmarkel44 | 5:5e77a1db4d45 | 53 | (void)modifyControl(msg); |
jmarkel44 | 5:5e77a1db4d45 | 54 | break; |
jmarkel44 | 5:5e77a1db4d45 | 55 | } |
jmarkel44 | 5:5e77a1db4d45 | 56 | case ACTION_DESTROY: { |
jmarkel44 | 5:5e77a1db4d45 | 57 | (void)destroyControl(msg); |
jmarkel44 | 5:5e77a1db4d45 | 58 | break; |
jmarkel44 | 5:5e77a1db4d45 | 59 | } |
jmarkel44 | 5:5e77a1db4d45 | 60 | default: |
jmarkel44 | 5:5e77a1db4d45 | 61 | break; |
jmarkel44 | 5:5e77a1db4d45 | 62 | } |
jmarkel44 | 5:5e77a1db4d45 | 63 | |
jmarkel44 | 5:5e77a1db4d45 | 64 | // free the message |
jmarkel44 | 5:5e77a1db4d45 | 65 | MailBox.free(msg); |
jmarkel44 | 5:5e77a1db4d45 | 66 | } |
jmarkel44 | 0:65cfa4873284 | 67 | } |
jmarkel44 | 0:65cfa4873284 | 68 | } |
jmarkel44 | 5:5e77a1db4d45 | 69 | |
jmarkel44 | 12:ea87887ca7ad | 70 | /***************************************************************************** |
jmarkel44 | 12:ea87887ca7ad | 71 | * Function: ConfigurationHandler_showControls() |
jmarkel44 | 13:c80c283f9db2 | 72 | * Description: show the controls |
jmarkel44 | 12:ea87887ca7ad | 73 | * |
jmarkel44 | 12:ea87887ca7ad | 74 | * @param msg |
jmarkel44 | 12:ea87887ca7ad | 75 | * @return none |
jmarkel44 | 12:ea87887ca7ad | 76 | *****************************************************************************/ |
jmarkel44 | 12:ea87887ca7ad | 77 | void ConfigurationHandler_showControls(void) |
jmarkel44 | 12:ea87887ca7ad | 78 | { |
jmarkel44 | 12:ea87887ca7ad | 79 | if ( !timerTable.empty() ) { |
jmarkel44 | 12:ea87887ca7ad | 80 | printf("\rTIMER CONTROLS\n"); |
jmarkel44 | 12:ea87887ca7ad | 81 | StringTimerMap::iterator pos; |
jmarkel44 | 46:4cb96ab2d1c8 | 82 | for ( pos = timerTable.begin(); pos != timerTable.end(); ++pos ) { |
jmarkel44 | 46:4cb96ab2d1c8 | 83 | printf("\r control file: %32s\n", |
jmarkel44 | 46:4cb96ab2d1c8 | 84 | pos->second->getControlFile().c_str()); |
jmarkel44 | 12:ea87887ca7ad | 85 | } |
jmarkel44 | 12:ea87887ca7ad | 86 | } |
jmarkel44 | 46:4cb96ab2d1c8 | 87 | |
jmarkel44 | 12:ea87887ca7ad | 88 | if ( !setpointTable.empty() ) { |
jmarkel44 | 12:ea87887ca7ad | 89 | printf("\rSETPOINT CONTROLS\n"); |
jmarkel44 | 12:ea87887ca7ad | 90 | StringSetpointMap::iterator pos; |
jmarkel44 | 12:ea87887ca7ad | 91 | for ( pos = setpointTable.begin(); |
jmarkel44 | 12:ea87887ca7ad | 92 | pos != setpointTable.end(); |
jmarkel44 | 12:ea87887ca7ad | 93 | ++pos ) { |
jmarkel44 | 28:c410a61238bb | 94 | printf("\r controlFile : %s \n", pos->second->getControlFile().c_str()); |
jmarkel44 | 28:c410a61238bb | 95 | printf("\r id : %s \n", pos->second->getId().c_str()); |
jmarkel44 | 28:c410a61238bb | 96 | printf("\r name : %s \n", pos->second->getName().c_str()); |
jmarkel44 | 28:c410a61238bb | 97 | printf("\r priority : %d \n", pos->second->getPriority()); |
jmarkel44 | 28:c410a61238bb | 98 | printf("\r input : %s \n", pos->second->getInput().c_str()); |
jmarkel44 | 28:c410a61238bb | 99 | printf("\r output : %s \n", pos->second->getOutput().c_str()); |
jmarkel44 | 28:c410a61238bb | 100 | printf("\r prodfact : %0.2f\n", pos->second->getProductFactor()); |
jmarkel44 | 28:c410a61238bb | 101 | printf("\r halert : %0.2f\n", pos->second->getHighAlert()); |
jmarkel44 | 28:c410a61238bb | 102 | printf("\r lalert : %0.2f\n", pos->second->getLowAlert()); |
jmarkel44 | 28:c410a61238bb | 103 | printf("\r hfs : %0.2f\n", pos->second->getHighFailsafe()); |
jmarkel44 | 28:c410a61238bb | 104 | printf("\r lfs : %0.2f\n", pos->second->getLowFailsafe()); |
jmarkel44 | 28:c410a61238bb | 105 | printf("\r tol : %0.2f\n", pos->second->getTol()); |
jmarkel44 | 28:c410a61238bb | 106 | printf("\r\n"); |
jmarkel44 | 51:66b820f203a5 | 107 | printf("\r currentState: %u\n", pos->second->getCurrentState()); |
jmarkel44 | 51:66b820f203a5 | 108 | printf("\r\n"); |
jmarkel44 | 12:ea87887ca7ad | 109 | } |
jmarkel44 | 12:ea87887ca7ad | 110 | } |
jmarkel44 | 12:ea87887ca7ad | 111 | } |
jmarkel44 | 12:ea87887ca7ad | 112 | |
jmarkel44 | 12:ea87887ca7ad | 113 | /***************************************************************************** |
jmarkel44 | 12:ea87887ca7ad | 114 | * Function: loadPersistentControls() |
jmarkel44 | 12:ea87887ca7ad | 115 | * Description: load persistent controls from flash |
jmarkel44 | 12:ea87887ca7ad | 116 | * |
jmarkel44 | 12:ea87887ca7ad | 117 | * @param none |
jmarkel44 | 12:ea87887ca7ad | 118 | * @return none |
jmarkel44 | 12:ea87887ca7ad | 119 | *****************************************************************************/ |
jmarkel44 | 12:ea87887ca7ad | 120 | static int loadPersistentControls(void) |
jmarkel44 | 12:ea87887ca7ad | 121 | { |
jmarkel44 | 12:ea87887ca7ad | 122 | static bool loaded = false; |
jmarkel44 | 12:ea87887ca7ad | 123 | |
jmarkel44 | 12:ea87887ca7ad | 124 | if ( !loaded ) { // lazy protection |
jmarkel44 | 12:ea87887ca7ad | 125 | // do something |
jmarkel44 | 12:ea87887ca7ad | 126 | loaded = true; |
jmarkel44 | 12:ea87887ca7ad | 127 | } |
jmarkel44 | 12:ea87887ca7ad | 128 | return 0; |
jmarkel44 | 12:ea87887ca7ad | 129 | } |
jmarkel44 | 12:ea87887ca7ad | 130 | |
jmarkel44 | 12:ea87887ca7ad | 131 | /***************************************************************************** |
jmarkel44 | 12:ea87887ca7ad | 132 | * Function: createControl() |
jmarkel44 | 12:ea87887ca7ad | 133 | * Description: creates a new control |
jmarkel44 | 12:ea87887ca7ad | 134 | * |
jmarkel44 | 12:ea87887ca7ad | 135 | * @param none |
jmarkel44 | 12:ea87887ca7ad | 136 | * @return none |
jmarkel44 | 12:ea87887ca7ad | 137 | *****************************************************************************/ |
jmarkel44 | 5:5e77a1db4d45 | 138 | static int createControl(const Message_t *msg) |
jmarkel44 | 5:5e77a1db4d45 | 139 | { |
jmarkel44 | 37:7e6986b77f01 | 140 | logInfo("\r%s invoked\n", __func__); |
jmarkel44 | 5:5e77a1db4d45 | 141 | |
jmarkel44 | 5:5e77a1db4d45 | 142 | switch (msg->control) { |
jmarkel44 | 5:5e77a1db4d45 | 143 | case CONTROL_SETPOINT: { |
jmarkel44 | 46:4cb96ab2d1c8 | 144 | SetpointControl *setpointControl = new SetpointControl; |
jmarkel44 | 28:c410a61238bb | 145 | bool rc = setpointControl->load(msg->controlFile); |
jmarkel44 | 19:9bc8fabeddfa | 146 | if ( rc != true ) { |
jmarkel44 | 19:9bc8fabeddfa | 147 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
jmarkel44 | 19:9bc8fabeddfa | 148 | delete setpointControl; |
jmarkel44 | 19:9bc8fabeddfa | 149 | } else { |
jmarkel44 | 19:9bc8fabeddfa | 150 | setpointTable[msg->controlFile] = setpointControl; |
jmarkel44 | 51:66b820f203a5 | 151 | // start the setpoint control |
jmarkel44 | 51:66b820f203a5 | 152 | setpointControl->start(); |
jmarkel44 | 19:9bc8fabeddfa | 153 | } |
jmarkel44 | 5:5e77a1db4d45 | 154 | break; |
jmarkel44 | 5:5e77a1db4d45 | 155 | } |
jmarkel44 | 5:5e77a1db4d45 | 156 | case CONTROL_TIMER: { |
jmarkel44 | 46:4cb96ab2d1c8 | 157 | TimerControl *timerControl = new TimerControl; |
jmarkel44 | 28:c410a61238bb | 158 | bool rc = timerControl->load(msg->controlFile); |
jmarkel44 | 19:9bc8fabeddfa | 159 | if ( rc != true ) { |
jmarkel44 | 19:9bc8fabeddfa | 160 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
jmarkel44 | 19:9bc8fabeddfa | 161 | delete timerControl; |
jmarkel44 | 19:9bc8fabeddfa | 162 | } else { |
jmarkel44 | 19:9bc8fabeddfa | 163 | timerTable[msg->controlFile] = timerControl; |
jmarkel44 | 19:9bc8fabeddfa | 164 | } |
jmarkel44 | 5:5e77a1db4d45 | 165 | break; |
jmarkel44 | 5:5e77a1db4d45 | 166 | } |
jmarkel44 | 46:4cb96ab2d1c8 | 167 | case CONTROL_MANUAL: { |
jmarkel44 | 46:4cb96ab2d1c8 | 168 | #if 0 |
jmarkel44 | 46:4cb96ab2d1c8 | 169 | ManualControl *manualControl = new ManualControl; |
jmarkel44 | 46:4cb96ab2d1c8 | 170 | bool rc = manualControl->load(msg->controlFile); |
jmarkel44 | 46:4cb96ab2d1c8 | 171 | if ( rc != true ) { |
jmarkel44 | 46:4cb96ab2d1c8 | 172 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
jmarkel44 | 46:4cb96ab2d1c8 | 173 | delete manualControl; |
jmarkel44 | 46:4cb96ab2d1c8 | 174 | } else { |
jmarkel44 | 46:4cb96ab2d1c8 | 175 | manualTable[msg->controlFile] = manualControl; |
jmarkel44 | 46:4cb96ab2d1c8 | 176 | } |
jmarkel44 | 46:4cb96ab2d1c8 | 177 | #endif |
jmarkel44 | 46:4cb96ab2d1c8 | 178 | break; |
jmarkel44 | 46:4cb96ab2d1c8 | 179 | } |
jmarkel44 | 19:9bc8fabeddfa | 180 | case CONTROL_PID: |
jmarkel44 | 19:9bc8fabeddfa | 181 | case CONTROL_COMPOSITE: |
jmarkel44 | 5:5e77a1db4d45 | 182 | default: |
jmarkel44 | 46:4cb96ab2d1c8 | 183 | logInfo("\r%s: control type %d not implemented yet...\n", |
jmarkel44 | 46:4cb96ab2d1c8 | 184 | __func__, msg->control); |
jmarkel44 | 5:5e77a1db4d45 | 185 | break; |
jmarkel44 | 5:5e77a1db4d45 | 186 | } |
jmarkel44 | 5:5e77a1db4d45 | 187 | return 0; |
jmarkel44 | 5:5e77a1db4d45 | 188 | } |
jmarkel44 | 12:ea87887ca7ad | 189 | |
jmarkel44 | 12:ea87887ca7ad | 190 | /***************************************************************************** |
jmarkel44 | 12:ea87887ca7ad | 191 | * Function: modifyControl() |
jmarkel44 | 12:ea87887ca7ad | 192 | * Description: modifies a control |
jmarkel44 | 12:ea87887ca7ad | 193 | * |
jmarkel44 | 12:ea87887ca7ad | 194 | * @param msg |
jmarkel44 | 12:ea87887ca7ad | 195 | * @return none |
jmarkel44 | 12:ea87887ca7ad | 196 | *****************************************************************************/ |
jmarkel44 | 5:5e77a1db4d45 | 197 | static int modifyControl(const Message_t *msg) |
jmarkel44 | 5:5e77a1db4d45 | 198 | { |
jmarkel44 | 37:7e6986b77f01 | 199 | logInfo("\r%s invoked\n", __func__); |
jmarkel44 | 46:4cb96ab2d1c8 | 200 | |
jmarkel44 | 46:4cb96ab2d1c8 | 201 | // TODO: can we delete the current object and start a new one? |
jmarkel44 | 5:5e77a1db4d45 | 202 | return 0; |
jmarkel44 | 5:5e77a1db4d45 | 203 | |
jmarkel44 | 5:5e77a1db4d45 | 204 | } |
jmarkel44 | 12:ea87887ca7ad | 205 | |
jmarkel44 | 12:ea87887ca7ad | 206 | /***************************************************************************** |
jmarkel44 | 12:ea87887ca7ad | 207 | * Function: destroyControl() |
jmarkel44 | 12:ea87887ca7ad | 208 | * Description: destroys a controls |
jmarkel44 | 12:ea87887ca7ad | 209 | * |
jmarkel44 | 12:ea87887ca7ad | 210 | * @param msg |
jmarkel44 | 12:ea87887ca7ad | 211 | * @return none |
jmarkel44 | 12:ea87887ca7ad | 212 | *****************************************************************************/ |
jmarkel44 | 5:5e77a1db4d45 | 213 | static int destroyControl(const Message_t *msg) |
jmarkel44 | 5:5e77a1db4d45 | 214 | { |
jmarkel44 | 37:7e6986b77f01 | 215 | logInfo("\r%s invoked\n", __func__); |
jmarkel44 | 12:ea87887ca7ad | 216 | |
jmarkel44 | 12:ea87887ca7ad | 217 | switch ( msg->control ) { |
jmarkel44 | 12:ea87887ca7ad | 218 | case CONTROL_SETPOINT: { |
jmarkel44 | 12:ea87887ca7ad | 219 | StringSetpointMap::iterator pos; |
jmarkel44 | 12:ea87887ca7ad | 220 | pos = setpointTable.find(msg->controlFile); |
jmarkel44 | 12:ea87887ca7ad | 221 | if ( pos != setpointTable.end() ) { |
jmarkel44 | 12:ea87887ca7ad | 222 | delete (pos->second); |
jmarkel44 | 12:ea87887ca7ad | 223 | setpointTable.erase(pos); |
jmarkel44 | 12:ea87887ca7ad | 224 | } |
jmarkel44 | 12:ea87887ca7ad | 225 | break; |
jmarkel44 | 12:ea87887ca7ad | 226 | } |
jmarkel44 | 12:ea87887ca7ad | 227 | case CONTROL_TIMER: { |
jmarkel44 | 12:ea87887ca7ad | 228 | StringTimerMap::iterator pos; |
jmarkel44 | 12:ea87887ca7ad | 229 | pos = timerTable.find(msg->controlFile); |
jmarkel44 | 12:ea87887ca7ad | 230 | if ( pos != timerTable.end() ) { |
jmarkel44 | 12:ea87887ca7ad | 231 | delete (pos->second); |
jmarkel44 | 12:ea87887ca7ad | 232 | timerTable.erase(pos); |
jmarkel44 | 12:ea87887ca7ad | 233 | } |
jmarkel44 | 12:ea87887ca7ad | 234 | break; |
jmarkel44 | 12:ea87887ca7ad | 235 | } |
jmarkel44 | 46:4cb96ab2d1c8 | 236 | case CONTROL_MANUAL: { |
jmarkel44 | 46:4cb96ab2d1c8 | 237 | #if 0 |
jmarkel44 | 46:4cb96ab2d1c8 | 238 | StringManualMap::iterator pos; |
jmarkel44 | 46:4cb96ab2d1c8 | 239 | pos = manualTable.find(msg->controlFile); |
jmarkel44 | 46:4cb96ab2d1c8 | 240 | if ( pos != manualTable.end() ) { |
jmarkel44 | 46:4cb96ab2d1c8 | 241 | delete (pos->second); |
jmarkel44 | 46:4cb96ab2d1c8 | 242 | manualTable.erase(pos); |
jmarkel44 | 46:4cb96ab2d1c8 | 243 | } |
jmarkel44 | 46:4cb96ab2d1c8 | 244 | #endif |
jmarkel44 | 46:4cb96ab2d1c8 | 245 | break; |
jmarkel44 | 46:4cb96ab2d1c8 | 246 | } |
jmarkel44 | 12:ea87887ca7ad | 247 | default: |
jmarkel44 | 12:ea87887ca7ad | 248 | break; |
jmarkel44 | 12:ea87887ca7ad | 249 | } |
jmarkel44 | 12:ea87887ca7ad | 250 | return 0; |
jmarkel44 | 20:653923c2f37a | 251 | } |