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@11:0695c1091129, 2016-09-07 (annotated)
- Committer:
- jmarkel44
- Date:
- Wed Sep 07 12:06:02 2016 +0000
- Revision:
- 11:0695c1091129
- Parent:
- 5:5e77a1db4d45
basic timer & setpoint controls (via classes) operating;
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 | 11:0695c1091129 | 10 | #include "TimerControl.h" |
jmarkel44 | 11:0695c1091129 | 11 | #include <map> |
jmarkel44 | 11:0695c1091129 | 12 | #include <algorithm> |
jmarkel44 | 11:0695c1091129 | 13 | |
jmarkel44 | 11:0695c1091129 | 14 | using namespace std; |
jmarkel44 | 5:5e77a1db4d45 | 15 | |
jmarkel44 | 5:5e77a1db4d45 | 16 | // local function prototypes |
jmarkel44 | 5:5e77a1db4d45 | 17 | static int loadPersistentControls(void); |
jmarkel44 | 5:5e77a1db4d45 | 18 | |
jmarkel44 | 5:5e77a1db4d45 | 19 | static int createControl(const Message_t *msg); |
jmarkel44 | 5:5e77a1db4d45 | 20 | static int modifyControl(const Message_t *msg); |
jmarkel44 | 5:5e77a1db4d45 | 21 | static int destroyControl(const Message_t *msg); |
jmarkel44 | 5:5e77a1db4d45 | 22 | |
jmarkel44 | 11:0695c1091129 | 23 | // dynamic control lists |
jmarkel44 | 11:0695c1091129 | 24 | typedef map<string, SetpointControl*> SetpointControlMap; |
jmarkel44 | 11:0695c1091129 | 25 | static SetpointControlMap setpointControlTable; |
jmarkel44 | 11:0695c1091129 | 26 | |
jmarkel44 | 11:0695c1091129 | 27 | typedef map<string, TimerControl *> TimerControlMap; |
jmarkel44 | 11:0695c1091129 | 28 | static TimerControlMap timerControlTable; |
jmarkel44 | 0:65cfa4873284 | 29 | |
jmarkel44 | 11:0695c1091129 | 30 | /***************************************************************************** |
jmarkel44 | 11:0695c1091129 | 31 | * Function: ConfigurationHandler() |
jmarkel44 | 11:0695c1091129 | 32 | * Description: Configuration Handler thread entry point |
jmarkel44 | 11:0695c1091129 | 33 | * |
jmarkel44 | 11:0695c1091129 | 34 | * @param none |
jmarkel44 | 11:0695c1091129 | 35 | * @return none |
jmarkel44 | 11:0695c1091129 | 36 | *****************************************************************************/ |
jmarkel44 | 0:65cfa4873284 | 37 | void ConfigurationHandler(void const *args) |
jmarkel44 | 0:65cfa4873284 | 38 | { |
jmarkel44 | 5:5e77a1db4d45 | 39 | loadPersistentControls(); |
jmarkel44 | 0:65cfa4873284 | 40 | osSignalSet(mainThreadId, sig_continue); |
jmarkel44 | 5:5e77a1db4d45 | 41 | |
jmarkel44 | 3:8ea4db957749 | 42 | while ( true ) { |
jmarkel44 | 5:5e77a1db4d45 | 43 | // wait for an event |
jmarkel44 | 5:5e77a1db4d45 | 44 | osEvent evt = MailBox.get(); |
jmarkel44 | 5:5e77a1db4d45 | 45 | if (evt.status == osEventMail) { |
jmarkel44 | 5:5e77a1db4d45 | 46 | Message_t *msg = (Message_t*) evt.value.p; |
jmarkel44 | 5:5e77a1db4d45 | 47 | |
jmarkel44 | 5:5e77a1db4d45 | 48 | printf("\r%s: mes->action = %d\n", __func__, msg->action); |
jmarkel44 | 5:5e77a1db4d45 | 49 | printf("\r%s: msg->control = %d\n", __func__, msg->control); |
jmarkel44 | 5:5e77a1db4d45 | 50 | printf("\r%s: msg->controlFile = %s\n", __func__, msg->controlFile); |
jmarkel44 | 5:5e77a1db4d45 | 51 | |
jmarkel44 | 5:5e77a1db4d45 | 52 | switch ( msg->action ) { |
jmarkel44 | 5:5e77a1db4d45 | 53 | case ACTION_CREATE: { |
jmarkel44 | 5:5e77a1db4d45 | 54 | (void)createControl(msg); |
jmarkel44 | 5:5e77a1db4d45 | 55 | break; |
jmarkel44 | 5:5e77a1db4d45 | 56 | } |
jmarkel44 | 5:5e77a1db4d45 | 57 | case ACTION_MODIFY: { |
jmarkel44 | 5:5e77a1db4d45 | 58 | (void)modifyControl(msg); |
jmarkel44 | 5:5e77a1db4d45 | 59 | break; |
jmarkel44 | 5:5e77a1db4d45 | 60 | } |
jmarkel44 | 5:5e77a1db4d45 | 61 | case ACTION_DESTROY: { |
jmarkel44 | 5:5e77a1db4d45 | 62 | (void)destroyControl(msg); |
jmarkel44 | 5:5e77a1db4d45 | 63 | break; |
jmarkel44 | 5:5e77a1db4d45 | 64 | } |
jmarkel44 | 5:5e77a1db4d45 | 65 | default: |
jmarkel44 | 5:5e77a1db4d45 | 66 | break; |
jmarkel44 | 5:5e77a1db4d45 | 67 | } |
jmarkel44 | 5:5e77a1db4d45 | 68 | |
jmarkel44 | 5:5e77a1db4d45 | 69 | // free the message |
jmarkel44 | 5:5e77a1db4d45 | 70 | MailBox.free(msg); |
jmarkel44 | 5:5e77a1db4d45 | 71 | } |
jmarkel44 | 0:65cfa4873284 | 72 | } |
jmarkel44 | 0:65cfa4873284 | 73 | } |
jmarkel44 | 5:5e77a1db4d45 | 74 | |
jmarkel44 | 11:0695c1091129 | 75 | /***************************************************************************** |
jmarkel44 | 11:0695c1091129 | 76 | * Function: loadPersistentControls() |
jmarkel44 | 11:0695c1091129 | 77 | * Description: load persistent controls from flash |
jmarkel44 | 11:0695c1091129 | 78 | * |
jmarkel44 | 11:0695c1091129 | 79 | * @param none |
jmarkel44 | 11:0695c1091129 | 80 | * @return none |
jmarkel44 | 11:0695c1091129 | 81 | *****************************************************************************/ |
jmarkel44 | 11:0695c1091129 | 82 | static int loadPersistentControls(void) |
jmarkel44 | 11:0695c1091129 | 83 | { |
jmarkel44 | 11:0695c1091129 | 84 | static bool loaded = false; |
jmarkel44 | 11:0695c1091129 | 85 | |
jmarkel44 | 11:0695c1091129 | 86 | if ( !loaded ) { // lazy protection |
jmarkel44 | 11:0695c1091129 | 87 | // load the controls from flash |
jmarkel44 | 11:0695c1091129 | 88 | printf("\r%s: stubbed.\n", __func__); |
jmarkel44 | 11:0695c1091129 | 89 | loaded = true; |
jmarkel44 | 11:0695c1091129 | 90 | } |
jmarkel44 | 11:0695c1091129 | 91 | return 0; |
jmarkel44 | 11:0695c1091129 | 92 | } |
jmarkel44 | 11:0695c1091129 | 93 | |
jmarkel44 | 11:0695c1091129 | 94 | /***************************************************************************** |
jmarkel44 | 11:0695c1091129 | 95 | * Function: createControl() |
jmarkel44 | 11:0695c1091129 | 96 | * Description: create a new control |
jmarkel44 | 11:0695c1091129 | 97 | * |
jmarkel44 | 11:0695c1091129 | 98 | * @param msg <Message_t> : message from a data handler |
jmarkel44 | 11:0695c1091129 | 99 | * @return <some error code> |
jmarkel44 | 11:0695c1091129 | 100 | *****************************************************************************/ |
jmarkel44 | 5:5e77a1db4d45 | 101 | static int createControl(const Message_t *msg) |
jmarkel44 | 5:5e77a1db4d45 | 102 | { |
jmarkel44 | 5:5e77a1db4d45 | 103 | printf("\r%s invoked\n", __func__); |
jmarkel44 | 5:5e77a1db4d45 | 104 | |
jmarkel44 | 5:5e77a1db4d45 | 105 | switch (msg->control) { |
jmarkel44 | 5:5e77a1db4d45 | 106 | case CONTROL_SETPOINT: { |
jmarkel44 | 11:0695c1091129 | 107 | SetpointControl *SPcontrol = new SetpointControl(msg->controlFile); |
jmarkel44 | 11:0695c1091129 | 108 | setpointControlTable[msg->controlFile] = SPcontrol; |
jmarkel44 | 5:5e77a1db4d45 | 109 | break; |
jmarkel44 | 5:5e77a1db4d45 | 110 | } |
jmarkel44 | 5:5e77a1db4d45 | 111 | case CONTROL_TIMER: { |
jmarkel44 | 11:0695c1091129 | 112 | TimerControl *timerControl = new TimerControl(msg->controlFile); |
jmarkel44 | 11:0695c1091129 | 113 | timerControlTable[msg->controlFile] = timerControl; |
jmarkel44 | 5:5e77a1db4d45 | 114 | break; |
jmarkel44 | 5:5e77a1db4d45 | 115 | } |
jmarkel44 | 5:5e77a1db4d45 | 116 | default: |
jmarkel44 | 5:5e77a1db4d45 | 117 | break; |
jmarkel44 | 5:5e77a1db4d45 | 118 | } |
jmarkel44 | 5:5e77a1db4d45 | 119 | return 0; |
jmarkel44 | 5:5e77a1db4d45 | 120 | } |
jmarkel44 | 11:0695c1091129 | 121 | |
jmarkel44 | 11:0695c1091129 | 122 | /***************************************************************************** |
jmarkel44 | 11:0695c1091129 | 123 | * Function: modifyControl() |
jmarkel44 | 11:0695c1091129 | 124 | * Description: modify an existing control |
jmarkel44 | 11:0695c1091129 | 125 | * |
jmarkel44 | 11:0695c1091129 | 126 | * @param none |
jmarkel44 | 11:0695c1091129 | 127 | * @return none |
jmarkel44 | 11:0695c1091129 | 128 | *****************************************************************************/ |
jmarkel44 | 5:5e77a1db4d45 | 129 | static int modifyControl(const Message_t *msg) |
jmarkel44 | 5:5e77a1db4d45 | 130 | { |
jmarkel44 | 5:5e77a1db4d45 | 131 | printf("\r%s invoked\n", __func__); |
jmarkel44 | 5:5e77a1db4d45 | 132 | return 0; |
jmarkel44 | 5:5e77a1db4d45 | 133 | |
jmarkel44 | 5:5e77a1db4d45 | 134 | } |
jmarkel44 | 11:0695c1091129 | 135 | |
jmarkel44 | 11:0695c1091129 | 136 | /***************************************************************************** |
jmarkel44 | 11:0695c1091129 | 137 | * Function: destroyControl() |
jmarkel44 | 11:0695c1091129 | 138 | * Description: destroy an existing control |
jmarkel44 | 11:0695c1091129 | 139 | * |
jmarkel44 | 11:0695c1091129 | 140 | * @param none |
jmarkel44 | 11:0695c1091129 | 141 | * @return none |
jmarkel44 | 11:0695c1091129 | 142 | *****************************************************************************/ |
jmarkel44 | 5:5e77a1db4d45 | 143 | static int destroyControl(const Message_t *msg) |
jmarkel44 | 5:5e77a1db4d45 | 144 | { |
jmarkel44 | 5:5e77a1db4d45 | 145 | printf("\r%s invoked\n", __func__); |
jmarkel44 | 11:0695c1091129 | 146 | |
jmarkel44 | 11:0695c1091129 | 147 | switch (msg->control) { |
jmarkel44 | 11:0695c1091129 | 148 | case CONTROL_SETPOINT: { |
jmarkel44 | 11:0695c1091129 | 149 | SetpointControlMap::iterator sp_iter; |
jmarkel44 | 11:0695c1091129 | 150 | sp_iter = setpointControlTable.find(msg->controlFile); |
jmarkel44 | 11:0695c1091129 | 151 | if ( sp_iter != setpointControlTable.end() ) { |
jmarkel44 | 11:0695c1091129 | 152 | // free the object and delete the entry |
jmarkel44 | 11:0695c1091129 | 153 | delete (sp_iter->second); |
jmarkel44 | 11:0695c1091129 | 154 | setpointControlTable.erase(sp_iter); |
jmarkel44 | 11:0695c1091129 | 155 | } |
jmarkel44 | 11:0695c1091129 | 156 | break; |
jmarkel44 | 11:0695c1091129 | 157 | } |
jmarkel44 | 11:0695c1091129 | 158 | case CONTROL_TIMER: { |
jmarkel44 | 11:0695c1091129 | 159 | TimerControlMap::iterator tc_iter; |
jmarkel44 | 11:0695c1091129 | 160 | tc_iter = timerControlTable.find(msg->controlFile); |
jmarkel44 | 11:0695c1091129 | 161 | if ( tc_iter != timerControlTable.end() ) { |
jmarkel44 | 11:0695c1091129 | 162 | // free the timer object and delete the entry |
jmarkel44 | 11:0695c1091129 | 163 | delete (tc_iter->second); |
jmarkel44 | 11:0695c1091129 | 164 | timerControlTable.erase(tc_iter); |
jmarkel44 | 11:0695c1091129 | 165 | } |
jmarkel44 | 11:0695c1091129 | 166 | break; |
jmarkel44 | 11:0695c1091129 | 167 | } |
jmarkel44 | 11:0695c1091129 | 168 | default: |
jmarkel44 | 11:0695c1091129 | 169 | break; |
jmarkel44 | 11:0695c1091129 | 170 | } |
jmarkel44 | 5:5e77a1db4d45 | 171 | return 0; |
jmarkel44 | 11:0695c1091129 | 172 | } |
jmarkel44 | 5:5e77a1db4d45 | 173 | |
jmarkel44 | 11:0695c1091129 | 174 | /***************************************************************************** |
jmarkel44 | 11:0695c1091129 | 175 | * Function: DisplayControlLists() |
jmarkel44 | 11:0695c1091129 | 176 | * Description: Display the control lists |
jmarkel44 | 11:0695c1091129 | 177 | * |
jmarkel44 | 11:0695c1091129 | 178 | * @param none |
jmarkel44 | 11:0695c1091129 | 179 | * @return none |
jmarkel44 | 11:0695c1091129 | 180 | *****************************************************************************/ |
jmarkel44 | 11:0695c1091129 | 181 | void DisplayControlLists(void) |
jmarkel44 | 11:0695c1091129 | 182 | { |
jmarkel44 | 11:0695c1091129 | 183 | SetpointControlMap::iterator sp_iter; |
jmarkel44 | 11:0695c1091129 | 184 | TimerControlMap::iterator tc_iter; |
jmarkel44 | 11:0695c1091129 | 185 | |
jmarkel44 | 11:0695c1091129 | 186 | printf("\rSETPOINT CONTROLS:\n"); |
jmarkel44 | 11:0695c1091129 | 187 | for ( sp_iter = setpointControlTable.begin(); |
jmarkel44 | 11:0695c1091129 | 188 | sp_iter != setpointControlTable.end(); |
jmarkel44 | 11:0695c1091129 | 189 | ++sp_iter ) { |
jmarkel44 | 11:0695c1091129 | 190 | SetpointControl *s = sp_iter->second; |
jmarkel44 | 11:0695c1091129 | 191 | printf("\r control file : %32s\n", s->getControlFile().c_str()); |
jmarkel44 | 11:0695c1091129 | 192 | } |
jmarkel44 | 11:0695c1091129 | 193 | printf("\rTIMER CONTROLS:\n"); |
jmarkel44 | 11:0695c1091129 | 194 | for ( tc_iter = timerControlTable.begin(); |
jmarkel44 | 11:0695c1091129 | 195 | tc_iter != timerControlTable.end(); |
jmarkel44 | 11:0695c1091129 | 196 | ++tc_iter) { |
jmarkel44 | 11:0695c1091129 | 197 | TimerControl *t = tc_iter->second; |
jmarkel44 | 11:0695c1091129 | 198 | printf("\r control file : %32s\n", t->getControlFile().c_str()); |
jmarkel44 | 11:0695c1091129 | 199 | } |
jmarkel44 | 5:5e77a1db4d45 | 200 | } |