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@19:9bc8fabeddfa, 2016-09-07 (annotated)
- Committer:
- jmarkel44
- Date:
- Wed Sep 07 19:40:17 2016 +0000
- Revision:
- 19:9bc8fabeddfa
- Parent:
- 13:c80c283f9db2
- Child:
- 20:653923c2f37a
created Load method for Timer and Setpoint controls;
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 | 12:ea87887ca7ad | 12 | // setpoint control table |
jmarkel44 | 12:ea87887ca7ad | 13 | typedef map<string, SetpointControl*> StringSetpointMap; |
jmarkel44 | 12:ea87887ca7ad | 14 | static StringSetpointMap setpointTable; |
jmarkel44 | 12:ea87887ca7ad | 15 | |
jmarkel44 | 12:ea87887ca7ad | 16 | // timer control table |
jmarkel44 | 12:ea87887ca7ad | 17 | typedef map<string, TimerControl*> StringTimerMap; |
jmarkel44 | 12:ea87887ca7ad | 18 | static StringTimerMap timerTable; |
jmarkel44 | 5:5e77a1db4d45 | 19 | |
jmarkel44 | 5:5e77a1db4d45 | 20 | // local function prototypes |
jmarkel44 | 5:5e77a1db4d45 | 21 | static int loadPersistentControls(void); |
jmarkel44 | 5:5e77a1db4d45 | 22 | |
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 | 12:ea87887ca7ad | 27 | /***************************************************************************** |
jmarkel44 | 12:ea87887ca7ad | 28 | * Function: ConfigurationHandler() |
jmarkel44 | 12:ea87887ca7ad | 29 | * Description: The ICE Configuration Handler |
jmarkel44 | 12:ea87887ca7ad | 30 | * |
jmarkel44 | 12:ea87887ca7ad | 31 | * @param args (unused) |
jmarkel44 | 12:ea87887ca7ad | 32 | * @return none |
jmarkel44 | 12:ea87887ca7ad | 33 | *****************************************************************************/ |
jmarkel44 | 0:65cfa4873284 | 34 | void ConfigurationHandler(void const *args) |
jmarkel44 | 0:65cfa4873284 | 35 | { |
jmarkel44 | 12:ea87887ca7ad | 36 | UNUSED(args); |
jmarkel44 | 5:5e77a1db4d45 | 37 | loadPersistentControls(); |
jmarkel44 | 0:65cfa4873284 | 38 | osSignalSet(mainThreadId, sig_continue); |
jmarkel44 | 5:5e77a1db4d45 | 39 | |
jmarkel44 | 3:8ea4db957749 | 40 | while ( true ) { |
jmarkel44 | 5:5e77a1db4d45 | 41 | // wait for an event |
jmarkel44 | 5:5e77a1db4d45 | 42 | osEvent evt = MailBox.get(); |
jmarkel44 | 5:5e77a1db4d45 | 43 | if (evt.status == osEventMail) { |
jmarkel44 | 5:5e77a1db4d45 | 44 | Message_t *msg = (Message_t*) evt.value.p; |
jmarkel44 | 5:5e77a1db4d45 | 45 | |
jmarkel44 | 5:5e77a1db4d45 | 46 | printf("\r%s: mes->action = %d\n", __func__, msg->action); |
jmarkel44 | 5:5e77a1db4d45 | 47 | printf("\r%s: msg->control = %d\n", __func__, msg->control); |
jmarkel44 | 5:5e77a1db4d45 | 48 | printf("\r%s: msg->controlFile = %s\n", __func__, msg->controlFile); |
jmarkel44 | 5:5e77a1db4d45 | 49 | |
jmarkel44 | 5:5e77a1db4d45 | 50 | switch ( msg->action ) { |
jmarkel44 | 5:5e77a1db4d45 | 51 | case ACTION_CREATE: { |
jmarkel44 | 5:5e77a1db4d45 | 52 | (void)createControl(msg); |
jmarkel44 | 5:5e77a1db4d45 | 53 | break; |
jmarkel44 | 5:5e77a1db4d45 | 54 | } |
jmarkel44 | 5:5e77a1db4d45 | 55 | case ACTION_MODIFY: { |
jmarkel44 | 5:5e77a1db4d45 | 56 | (void)modifyControl(msg); |
jmarkel44 | 5:5e77a1db4d45 | 57 | break; |
jmarkel44 | 5:5e77a1db4d45 | 58 | } |
jmarkel44 | 5:5e77a1db4d45 | 59 | case ACTION_DESTROY: { |
jmarkel44 | 5:5e77a1db4d45 | 60 | (void)destroyControl(msg); |
jmarkel44 | 5:5e77a1db4d45 | 61 | break; |
jmarkel44 | 5:5e77a1db4d45 | 62 | } |
jmarkel44 | 5:5e77a1db4d45 | 63 | default: |
jmarkel44 | 5:5e77a1db4d45 | 64 | break; |
jmarkel44 | 5:5e77a1db4d45 | 65 | } |
jmarkel44 | 5:5e77a1db4d45 | 66 | |
jmarkel44 | 5:5e77a1db4d45 | 67 | // free the message |
jmarkel44 | 5:5e77a1db4d45 | 68 | MailBox.free(msg); |
jmarkel44 | 5:5e77a1db4d45 | 69 | } |
jmarkel44 | 0:65cfa4873284 | 70 | } |
jmarkel44 | 0:65cfa4873284 | 71 | } |
jmarkel44 | 5:5e77a1db4d45 | 72 | |
jmarkel44 | 12:ea87887ca7ad | 73 | /***************************************************************************** |
jmarkel44 | 12:ea87887ca7ad | 74 | * Function: ConfigurationHandler_showControls() |
jmarkel44 | 13:c80c283f9db2 | 75 | * Description: show the controls |
jmarkel44 | 12:ea87887ca7ad | 76 | * |
jmarkel44 | 12:ea87887ca7ad | 77 | * @param msg |
jmarkel44 | 12:ea87887ca7ad | 78 | * @return none |
jmarkel44 | 12:ea87887ca7ad | 79 | *****************************************************************************/ |
jmarkel44 | 12:ea87887ca7ad | 80 | void ConfigurationHandler_showControls(void) |
jmarkel44 | 12:ea87887ca7ad | 81 | { |
jmarkel44 | 12:ea87887ca7ad | 82 | if ( !timerTable.empty() ) { |
jmarkel44 | 12:ea87887ca7ad | 83 | printf("\rTIMER CONTROLS\n"); |
jmarkel44 | 12:ea87887ca7ad | 84 | StringTimerMap::iterator pos; |
jmarkel44 | 12:ea87887ca7ad | 85 | for ( pos = timerTable.begin(); |
jmarkel44 | 12:ea87887ca7ad | 86 | pos != timerTable.end(); |
jmarkel44 | 12:ea87887ca7ad | 87 | ++pos ) { |
jmarkel44 | 13:c80c283f9db2 | 88 | printf("\r control file: %32s\n", pos->second->getControlFile().c_str()); |
jmarkel44 | 12:ea87887ca7ad | 89 | } |
jmarkel44 | 12:ea87887ca7ad | 90 | } |
jmarkel44 | 12:ea87887ca7ad | 91 | if ( !setpointTable.empty() ) { |
jmarkel44 | 12:ea87887ca7ad | 92 | printf("\rSETPOINT CONTROLS\n"); |
jmarkel44 | 12:ea87887ca7ad | 93 | StringSetpointMap::iterator pos; |
jmarkel44 | 12:ea87887ca7ad | 94 | for ( pos = setpointTable.begin(); |
jmarkel44 | 12:ea87887ca7ad | 95 | pos != setpointTable.end(); |
jmarkel44 | 12:ea87887ca7ad | 96 | ++pos ) { |
jmarkel44 | 13:c80c283f9db2 | 97 | printf("\r control file: %32s\n", pos->second->getControlFile().c_str()); |
jmarkel44 | 12:ea87887ca7ad | 98 | } |
jmarkel44 | 12:ea87887ca7ad | 99 | } |
jmarkel44 | 12:ea87887ca7ad | 100 | } |
jmarkel44 | 12:ea87887ca7ad | 101 | |
jmarkel44 | 12:ea87887ca7ad | 102 | /***************************************************************************** |
jmarkel44 | 12:ea87887ca7ad | 103 | * Function: loadPersistentControls() |
jmarkel44 | 12:ea87887ca7ad | 104 | * Description: load persistent controls from flash |
jmarkel44 | 12:ea87887ca7ad | 105 | * |
jmarkel44 | 12:ea87887ca7ad | 106 | * @param none |
jmarkel44 | 12:ea87887ca7ad | 107 | * @return none |
jmarkel44 | 12:ea87887ca7ad | 108 | *****************************************************************************/ |
jmarkel44 | 12:ea87887ca7ad | 109 | static int loadPersistentControls(void) |
jmarkel44 | 12:ea87887ca7ad | 110 | { |
jmarkel44 | 12:ea87887ca7ad | 111 | static bool loaded = false; |
jmarkel44 | 12:ea87887ca7ad | 112 | |
jmarkel44 | 12:ea87887ca7ad | 113 | if ( !loaded ) { // lazy protection |
jmarkel44 | 12:ea87887ca7ad | 114 | // do something |
jmarkel44 | 12:ea87887ca7ad | 115 | loaded = true; |
jmarkel44 | 12:ea87887ca7ad | 116 | } |
jmarkel44 | 12:ea87887ca7ad | 117 | return 0; |
jmarkel44 | 12:ea87887ca7ad | 118 | } |
jmarkel44 | 12:ea87887ca7ad | 119 | |
jmarkel44 | 12:ea87887ca7ad | 120 | /***************************************************************************** |
jmarkel44 | 12:ea87887ca7ad | 121 | * Function: createControl() |
jmarkel44 | 12:ea87887ca7ad | 122 | * Description: creates a new control |
jmarkel44 | 12:ea87887ca7ad | 123 | * |
jmarkel44 | 12:ea87887ca7ad | 124 | * @param none |
jmarkel44 | 12:ea87887ca7ad | 125 | * @return none |
jmarkel44 | 12:ea87887ca7ad | 126 | *****************************************************************************/ |
jmarkel44 | 5:5e77a1db4d45 | 127 | static int createControl(const Message_t *msg) |
jmarkel44 | 5:5e77a1db4d45 | 128 | { |
jmarkel44 | 5:5e77a1db4d45 | 129 | printf("\r%s invoked\n", __func__); |
jmarkel44 | 5:5e77a1db4d45 | 130 | |
jmarkel44 | 5:5e77a1db4d45 | 131 | switch (msg->control) { |
jmarkel44 | 5:5e77a1db4d45 | 132 | case CONTROL_SETPOINT: { |
jmarkel44 | 19:9bc8fabeddfa | 133 | SetpointControl *setpointControl = new SetpointControl(); |
jmarkel44 | 19:9bc8fabeddfa | 134 | bool rc = setpointControl->Load(msg->controlFile); |
jmarkel44 | 19:9bc8fabeddfa | 135 | if ( rc != true ) { |
jmarkel44 | 19:9bc8fabeddfa | 136 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
jmarkel44 | 19:9bc8fabeddfa | 137 | delete setpointControl; |
jmarkel44 | 19:9bc8fabeddfa | 138 | } else { |
jmarkel44 | 19:9bc8fabeddfa | 139 | setpointTable[msg->controlFile] = setpointControl; |
jmarkel44 | 19:9bc8fabeddfa | 140 | } |
jmarkel44 | 5:5e77a1db4d45 | 141 | break; |
jmarkel44 | 5:5e77a1db4d45 | 142 | } |
jmarkel44 | 5:5e77a1db4d45 | 143 | case CONTROL_TIMER: { |
jmarkel44 | 19:9bc8fabeddfa | 144 | TimerControl *timerControl = new TimerControl(); |
jmarkel44 | 19:9bc8fabeddfa | 145 | bool rc = timerControl->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 timerControl; |
jmarkel44 | 19:9bc8fabeddfa | 149 | } else { |
jmarkel44 | 19:9bc8fabeddfa | 150 | timerTable[msg->controlFile] = timerControl; |
jmarkel44 | 19:9bc8fabeddfa | 151 | } |
jmarkel44 | 5:5e77a1db4d45 | 152 | break; |
jmarkel44 | 5:5e77a1db4d45 | 153 | } |
jmarkel44 | 19:9bc8fabeddfa | 154 | case CONTROL_PID: |
jmarkel44 | 19:9bc8fabeddfa | 155 | case CONTROL_MANUAL: |
jmarkel44 | 19:9bc8fabeddfa | 156 | case CONTROL_COMPOSITE: |
jmarkel44 | 5:5e77a1db4d45 | 157 | default: |
jmarkel44 | 19:9bc8fabeddfa | 158 | printf("\r%s: control type %d not implemented yet...\n", |
jmarkel44 | 19:9bc8fabeddfa | 159 | __func__, msg->control); |
jmarkel44 | 5:5e77a1db4d45 | 160 | break; |
jmarkel44 | 5:5e77a1db4d45 | 161 | } |
jmarkel44 | 5:5e77a1db4d45 | 162 | return 0; |
jmarkel44 | 5:5e77a1db4d45 | 163 | } |
jmarkel44 | 12:ea87887ca7ad | 164 | |
jmarkel44 | 12:ea87887ca7ad | 165 | /***************************************************************************** |
jmarkel44 | 12:ea87887ca7ad | 166 | * Function: modifyControl() |
jmarkel44 | 12:ea87887ca7ad | 167 | * Description: modifies a control |
jmarkel44 | 12:ea87887ca7ad | 168 | * |
jmarkel44 | 12:ea87887ca7ad | 169 | * @param msg |
jmarkel44 | 12:ea87887ca7ad | 170 | * @return none |
jmarkel44 | 12:ea87887ca7ad | 171 | *****************************************************************************/ |
jmarkel44 | 5:5e77a1db4d45 | 172 | static int modifyControl(const Message_t *msg) |
jmarkel44 | 5:5e77a1db4d45 | 173 | { |
jmarkel44 | 5:5e77a1db4d45 | 174 | printf("\r%s invoked\n", __func__); |
jmarkel44 | 5:5e77a1db4d45 | 175 | return 0; |
jmarkel44 | 5:5e77a1db4d45 | 176 | |
jmarkel44 | 5:5e77a1db4d45 | 177 | } |
jmarkel44 | 12:ea87887ca7ad | 178 | |
jmarkel44 | 12:ea87887ca7ad | 179 | /***************************************************************************** |
jmarkel44 | 12:ea87887ca7ad | 180 | * Function: destroyControl() |
jmarkel44 | 12:ea87887ca7ad | 181 | * Description: destroys a controls |
jmarkel44 | 12:ea87887ca7ad | 182 | * |
jmarkel44 | 12:ea87887ca7ad | 183 | * @param msg |
jmarkel44 | 12:ea87887ca7ad | 184 | * @return none |
jmarkel44 | 12:ea87887ca7ad | 185 | *****************************************************************************/ |
jmarkel44 | 5:5e77a1db4d45 | 186 | static int destroyControl(const Message_t *msg) |
jmarkel44 | 5:5e77a1db4d45 | 187 | { |
jmarkel44 | 5:5e77a1db4d45 | 188 | printf("\r%s invoked\n", __func__); |
jmarkel44 | 12:ea87887ca7ad | 189 | |
jmarkel44 | 12:ea87887ca7ad | 190 | switch ( msg->control ) { |
jmarkel44 | 12:ea87887ca7ad | 191 | case CONTROL_SETPOINT: { |
jmarkel44 | 12:ea87887ca7ad | 192 | StringSetpointMap::iterator pos; |
jmarkel44 | 12:ea87887ca7ad | 193 | pos = setpointTable.find(msg->controlFile); |
jmarkel44 | 12:ea87887ca7ad | 194 | if ( pos != setpointTable.end() ) { |
jmarkel44 | 12:ea87887ca7ad | 195 | delete (pos->second); |
jmarkel44 | 12:ea87887ca7ad | 196 | setpointTable.erase(pos); |
jmarkel44 | 12:ea87887ca7ad | 197 | } |
jmarkel44 | 12:ea87887ca7ad | 198 | break; |
jmarkel44 | 12:ea87887ca7ad | 199 | } |
jmarkel44 | 12:ea87887ca7ad | 200 | case CONTROL_TIMER: { |
jmarkel44 | 12:ea87887ca7ad | 201 | StringTimerMap::iterator pos; |
jmarkel44 | 12:ea87887ca7ad | 202 | pos = timerTable.find(msg->controlFile); |
jmarkel44 | 12:ea87887ca7ad | 203 | if ( pos != timerTable.end() ) { |
jmarkel44 | 12:ea87887ca7ad | 204 | delete (pos->second); |
jmarkel44 | 12:ea87887ca7ad | 205 | timerTable.erase(pos); |
jmarkel44 | 12:ea87887ca7ad | 206 | } |
jmarkel44 | 12:ea87887ca7ad | 207 | break; |
jmarkel44 | 12:ea87887ca7ad | 208 | } |
jmarkel44 | 12:ea87887ca7ad | 209 | default: |
jmarkel44 | 12:ea87887ca7ad | 210 | break; |
jmarkel44 | 12:ea87887ca7ad | 211 | } |
jmarkel44 | 12:ea87887ca7ad | 212 | return 0; |
jmarkel44 | 5:5e77a1db4d45 | 213 | } |
jmarkel44 | 12:ea87887ca7ad | 214 |