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.
ICE-Application/src/ConfigurationHandler/ConfigurationHandler.cpp@0:61364762ee0e, 2017-01-24 (annotated)
- Committer:
- jmarkel44
- Date:
- Tue Jan 24 19:05:33 2017 +0000
- Revision:
- 0:61364762ee0e
Port from IAR to Nucleo-F412 board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmarkel44 | 0:61364762ee0e | 1 | /****************************************************************************** |
jmarkel44 | 0:61364762ee0e | 2 | * |
jmarkel44 | 0:61364762ee0e | 3 | * File: ConfigurationHandler.cpp |
jmarkel44 | 0:61364762ee0e | 4 | * Desciption: source for the ICE Configuration Handler |
jmarkel44 | 0:61364762ee0e | 5 | * |
jmarkel44 | 0:61364762ee0e | 6 | *****************************************************************************/ |
jmarkel44 | 0:61364762ee0e | 7 | #include "ConfigurationHandler.h" |
jmarkel44 | 0:61364762ee0e | 8 | #include "global.h" |
jmarkel44 | 0:61364762ee0e | 9 | #include "SetpointControl.h" |
jmarkel44 | 0:61364762ee0e | 10 | #include "TimerControl.h" |
jmarkel44 | 0:61364762ee0e | 11 | #include "CompositeControl.h" |
jmarkel44 | 0:61364762ee0e | 12 | #include "CompositeAlgorithm.h" |
jmarkel44 | 0:61364762ee0e | 13 | #include "SensorErrorControl.h" |
jmarkel44 | 0:61364762ee0e | 14 | #include "cJSON.h" |
jmarkel44 | 0:61364762ee0e | 15 | #include "utilities.h" |
jmarkel44 | 0:61364762ee0e | 16 | #include "ICELog.h" |
jmarkel44 | 0:61364762ee0e | 17 | #include <algorithm> |
jmarkel44 | 0:61364762ee0e | 18 | #include <stdlib.h> |
jmarkel44 | 0:61364762ee0e | 19 | |
jmarkel44 | 0:61364762ee0e | 20 | // |
jmarkel44 | 0:61364762ee0e | 21 | // The control maps |
jmarkel44 | 0:61364762ee0e | 22 | //StringPIDMap PIDTable; // PID control object table |
jmarkel44 | 0:61364762ee0e | 23 | StringSetpointMap setpointTable; // setpoint control object table |
jmarkel44 | 0:61364762ee0e | 24 | StringTimerMap timerTable; // timer control object table |
jmarkel44 | 0:61364762ee0e | 25 | StringManualMap manualTable; // manual control object table |
jmarkel44 | 0:61364762ee0e | 26 | StringCompositeMap compositeTable; // composite control object table |
jmarkel44 | 0:61364762ee0e | 27 | StringFailsafeMap failsafeTable; // failsafe control object table |
jmarkel44 | 0:61364762ee0e | 28 | StringAlgorithmMap algorithmTable; // composite control algorithms |
jmarkel44 | 0:61364762ee0e | 29 | StringSequenceMap sequenceTable; // sequence control object table |
jmarkel44 | 0:61364762ee0e | 30 | StringSensorErrorMap sensorErrorTable; // sensor error object table |
jmarkel44 | 0:61364762ee0e | 31 | |
jmarkel44 | 0:61364762ee0e | 32 | Mutex manual_mutex; |
jmarkel44 | 0:61364762ee0e | 33 | Mutex setpoint_mutex; |
jmarkel44 | 0:61364762ee0e | 34 | Mutex timer_mutex; |
jmarkel44 | 0:61364762ee0e | 35 | Mutex failsafe_mutex; |
jmarkel44 | 0:61364762ee0e | 36 | Mutex composite_mutex; |
jmarkel44 | 0:61364762ee0e | 37 | Mutex sequence_mutex; |
jmarkel44 | 0:61364762ee0e | 38 | Mutex sensorError_mutex; |
jmarkel44 | 0:61364762ee0e | 39 | |
jmarkel44 | 0:61364762ee0e | 40 | // local function prototypes |
jmarkel44 | 0:61364762ee0e | 41 | static int loadPersistentControls(void); // load the controls on flash |
jmarkel44 | 0:61364762ee0e | 42 | |
jmarkel44 | 0:61364762ee0e | 43 | // local helper functions |
jmarkel44 | 0:61364762ee0e | 44 | static int createControl(const ConfigMessage_t *msg); |
jmarkel44 | 0:61364762ee0e | 45 | static int modifyControl(const ConfigMessage_t *msg); |
jmarkel44 | 0:61364762ee0e | 46 | static int destroyControl(const ConfigMessage_t *msg); |
jmarkel44 | 0:61364762ee0e | 47 | |
jmarkel44 | 0:61364762ee0e | 48 | static unsigned int getManualControlType(const char *filename); |
jmarkel44 | 0:61364762ee0e | 49 | |
jmarkel44 | 0:61364762ee0e | 50 | /***************************************************************************** |
jmarkel44 | 0:61364762ee0e | 51 | * Function: ConfigurationHandler() |
jmarkel44 | 0:61364762ee0e | 52 | * Description: The ICE Configuration Handler |
jmarkel44 | 0:61364762ee0e | 53 | * |
jmarkel44 | 0:61364762ee0e | 54 | * @param args (unused) |
jmarkel44 | 0:61364762ee0e | 55 | * @return none |
jmarkel44 | 0:61364762ee0e | 56 | *****************************************************************************/ |
jmarkel44 | 0:61364762ee0e | 57 | void ConfigurationHandler(void const *args) |
jmarkel44 | 0:61364762ee0e | 58 | { |
jmarkel44 | 0:61364762ee0e | 59 | (void)(args); |
jmarkel44 | 0:61364762ee0e | 60 | #ifdef LOAD_PERSISTENT_CONFIGURATIONS |
jmarkel44 | 0:61364762ee0e | 61 | loadPersistentControls(); |
jmarkel44 | 0:61364762ee0e | 62 | #endif |
jmarkel44 | 0:61364762ee0e | 63 | osSignalSet(mainThreadId, sig_control_continue); |
jmarkel44 | 0:61364762ee0e | 64 | |
jmarkel44 | 0:61364762ee0e | 65 | printf("\rConfigurationHandler has started...\n"); |
jmarkel44 | 0:61364762ee0e | 66 | |
jmarkel44 | 0:61364762ee0e | 67 | while ( true ) { |
jmarkel44 | 0:61364762ee0e | 68 | // wait for an event |
jmarkel44 | 0:61364762ee0e | 69 | osEvent evt = ConfigHandlerMailBox.get(); |
jmarkel44 | 0:61364762ee0e | 70 | if (evt.status == osEventMail) { |
jmarkel44 | 0:61364762ee0e | 71 | ConfigMessage_t *msg = (ConfigMessage_t*) evt.value.p; |
jmarkel44 | 0:61364762ee0e | 72 | |
jmarkel44 | 0:61364762ee0e | 73 | logInfo("\r%s: msg->action = %d\n", __func__, msg->action); |
jmarkel44 | 0:61364762ee0e | 74 | logInfo("\r%s: msg->control = %d\n", __func__, msg->control); |
jmarkel44 | 0:61364762ee0e | 75 | logInfo("\r%s: msg->controlFile = %s\n", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 76 | |
jmarkel44 | 0:61364762ee0e | 77 | switch ( msg->action ) { |
jmarkel44 | 0:61364762ee0e | 78 | case ACTION_CREATE: { |
jmarkel44 | 0:61364762ee0e | 79 | (void)createControl(msg); |
jmarkel44 | 0:61364762ee0e | 80 | break; |
jmarkel44 | 0:61364762ee0e | 81 | } |
jmarkel44 | 0:61364762ee0e | 82 | case ACTION_MODIFY: { |
jmarkel44 | 0:61364762ee0e | 83 | (void)modifyControl(msg); |
jmarkel44 | 0:61364762ee0e | 84 | break; |
jmarkel44 | 0:61364762ee0e | 85 | } |
jmarkel44 | 0:61364762ee0e | 86 | case ACTION_DESTROY: { |
jmarkel44 | 0:61364762ee0e | 87 | (void)destroyControl(msg); |
jmarkel44 | 0:61364762ee0e | 88 | break; |
jmarkel44 | 0:61364762ee0e | 89 | } |
jmarkel44 | 0:61364762ee0e | 90 | default: |
jmarkel44 | 0:61364762ee0e | 91 | break; |
jmarkel44 | 0:61364762ee0e | 92 | } |
jmarkel44 | 0:61364762ee0e | 93 | |
jmarkel44 | 0:61364762ee0e | 94 | // free the message |
jmarkel44 | 0:61364762ee0e | 95 | ConfigHandlerMailBox.free(msg); |
jmarkel44 | 0:61364762ee0e | 96 | } |
jmarkel44 | 0:61364762ee0e | 97 | } |
jmarkel44 | 0:61364762ee0e | 98 | } |
jmarkel44 | 0:61364762ee0e | 99 | |
jmarkel44 | 0:61364762ee0e | 100 | // |
jmarkel44 | 0:61364762ee0e | 101 | // function: ConfigurationHandler_showSetpointControls |
jmarkel44 | 0:61364762ee0e | 102 | // description: display contents of the setpoint control table |
jmarkel44 | 0:61364762ee0e | 103 | // |
jmarkel44 | 0:61364762ee0e | 104 | void ConfigurationHandler_showSetpointControls(void) |
jmarkel44 | 0:61364762ee0e | 105 | { |
jmarkel44 | 0:61364762ee0e | 106 | setpoint_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 107 | if ( !setpointTable.empty() ) { |
jmarkel44 | 0:61364762ee0e | 108 | printf("\r\n"); |
jmarkel44 | 0:61364762ee0e | 109 | StringSetpointMap::const_iterator pos; |
jmarkel44 | 0:61364762ee0e | 110 | for ( pos = setpointTable.begin(); pos != setpointTable.end(); ++pos ) { |
jmarkel44 | 0:61364762ee0e | 111 | pos->second->display(); |
jmarkel44 | 0:61364762ee0e | 112 | } |
jmarkel44 | 0:61364762ee0e | 113 | } |
jmarkel44 | 0:61364762ee0e | 114 | setpoint_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 115 | } |
jmarkel44 | 0:61364762ee0e | 116 | |
jmarkel44 | 0:61364762ee0e | 117 | // |
jmarkel44 | 0:61364762ee0e | 118 | // function: ConfigurationHandler_showManualControls |
jmarkel44 | 0:61364762ee0e | 119 | // description: display contents of the manual control table |
jmarkel44 | 0:61364762ee0e | 120 | // |
jmarkel44 | 0:61364762ee0e | 121 | void ConfigurationHandler_showManualControls(void) |
jmarkel44 | 0:61364762ee0e | 122 | { |
jmarkel44 | 0:61364762ee0e | 123 | manual_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 124 | if ( !manualTable.empty() ) { |
jmarkel44 | 0:61364762ee0e | 125 | printf("\r\n"); |
jmarkel44 | 0:61364762ee0e | 126 | StringManualMap::const_iterator pos; |
jmarkel44 | 0:61364762ee0e | 127 | for ( pos = manualTable.begin(); pos != manualTable.end(); ++pos ) { |
jmarkel44 | 0:61364762ee0e | 128 | pos->second->display(); |
jmarkel44 | 0:61364762ee0e | 129 | } |
jmarkel44 | 0:61364762ee0e | 130 | } |
jmarkel44 | 0:61364762ee0e | 131 | manual_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 132 | } |
jmarkel44 | 0:61364762ee0e | 133 | |
jmarkel44 | 0:61364762ee0e | 134 | // |
jmarkel44 | 0:61364762ee0e | 135 | // function: ConfigurationHandler_showTimerControls |
jmarkel44 | 0:61364762ee0e | 136 | // description: display contents of the timer control table |
jmarkel44 | 0:61364762ee0e | 137 | // |
jmarkel44 | 0:61364762ee0e | 138 | void ConfigurationHandler_showTimerControls(void) |
jmarkel44 | 0:61364762ee0e | 139 | { |
jmarkel44 | 0:61364762ee0e | 140 | timer_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 141 | if ( !timerTable.empty() ) { |
jmarkel44 | 0:61364762ee0e | 142 | printf("\r\n"); |
jmarkel44 | 0:61364762ee0e | 143 | StringTimerMap::const_iterator pos; |
jmarkel44 | 0:61364762ee0e | 144 | for ( pos = timerTable.begin(); pos != timerTable.end(); ++pos ) { |
jmarkel44 | 0:61364762ee0e | 145 | pos->second->display(); |
jmarkel44 | 0:61364762ee0e | 146 | } |
jmarkel44 | 0:61364762ee0e | 147 | } |
jmarkel44 | 0:61364762ee0e | 148 | timer_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 149 | } |
jmarkel44 | 0:61364762ee0e | 150 | |
jmarkel44 | 0:61364762ee0e | 151 | // |
jmarkel44 | 0:61364762ee0e | 152 | // function: ConfigurationHandler_showCompositeControls |
jmarkel44 | 0:61364762ee0e | 153 | // description: display contents of the composite control table |
jmarkel44 | 0:61364762ee0e | 154 | // |
jmarkel44 | 0:61364762ee0e | 155 | void ConfigurationHandler_showCompositeControls(void ) |
jmarkel44 | 0:61364762ee0e | 156 | { |
jmarkel44 | 0:61364762ee0e | 157 | composite_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 158 | if ( !compositeTable.empty() ) { |
jmarkel44 | 0:61364762ee0e | 159 | printf("\r\n"); |
jmarkel44 | 0:61364762ee0e | 160 | StringCompositeMap::const_iterator pos; |
jmarkel44 | 0:61364762ee0e | 161 | for ( pos = compositeTable.begin(); pos != compositeTable.end(); ++pos) { |
jmarkel44 | 0:61364762ee0e | 162 | pos->second->display(); |
jmarkel44 | 0:61364762ee0e | 163 | } |
jmarkel44 | 0:61364762ee0e | 164 | } |
jmarkel44 | 0:61364762ee0e | 165 | composite_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 166 | } |
jmarkel44 | 0:61364762ee0e | 167 | |
jmarkel44 | 0:61364762ee0e | 168 | // |
jmarkel44 | 0:61364762ee0e | 169 | // function: ConfigurationHandler_showFailsafeControls |
jmarkel44 | 0:61364762ee0e | 170 | // description: display contents of the failsafe control table |
jmarkel44 | 0:61364762ee0e | 171 | // |
jmarkel44 | 0:61364762ee0e | 172 | // @param[in] none |
jmarkel44 | 0:61364762ee0e | 173 | // @param[out] none |
jmarkel44 | 0:61364762ee0e | 174 | // @return none |
jmarkel44 | 0:61364762ee0e | 175 | // |
jmarkel44 | 0:61364762ee0e | 176 | void ConfigurationHandler_showFailsafeControls(void) |
jmarkel44 | 0:61364762ee0e | 177 | { |
jmarkel44 | 0:61364762ee0e | 178 | failsafe_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 179 | if ( !failsafeTable.empty() ) { |
jmarkel44 | 0:61364762ee0e | 180 | printf("\r\n"); |
jmarkel44 | 0:61364762ee0e | 181 | StringFailsafeMap::const_iterator pos; |
jmarkel44 | 0:61364762ee0e | 182 | for ( pos = failsafeTable.begin(); pos != failsafeTable.end(); ++pos ) { |
jmarkel44 | 0:61364762ee0e | 183 | pos->second->display(); |
jmarkel44 | 0:61364762ee0e | 184 | } |
jmarkel44 | 0:61364762ee0e | 185 | } |
jmarkel44 | 0:61364762ee0e | 186 | failsafe_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 187 | } |
jmarkel44 | 0:61364762ee0e | 188 | |
jmarkel44 | 0:61364762ee0e | 189 | // |
jmarkel44 | 0:61364762ee0e | 190 | // function: ConfigurationHandler_showFailsafeControls |
jmarkel44 | 0:61364762ee0e | 191 | // description: display contents of the failsafe control table |
jmarkel44 | 0:61364762ee0e | 192 | // |
jmarkel44 | 0:61364762ee0e | 193 | // @param[in] none |
jmarkel44 | 0:61364762ee0e | 194 | // @param[out] none |
jmarkel44 | 0:61364762ee0e | 195 | // @return none |
jmarkel44 | 0:61364762ee0e | 196 | // |
jmarkel44 | 0:61364762ee0e | 197 | void ConfigurationHandler_showSensorErrorControls(void) |
jmarkel44 | 0:61364762ee0e | 198 | { |
jmarkel44 | 0:61364762ee0e | 199 | sensorError_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 200 | if ( !sensorErrorTable.empty() ) { |
jmarkel44 | 0:61364762ee0e | 201 | printf("\r\n"); |
jmarkel44 | 0:61364762ee0e | 202 | StringSensorErrorMap::const_iterator pos; |
jmarkel44 | 0:61364762ee0e | 203 | for ( pos = sensorErrorTable.begin(); pos != sensorErrorTable.end(); ++pos ) { |
jmarkel44 | 0:61364762ee0e | 204 | pos->second->display(); |
jmarkel44 | 0:61364762ee0e | 205 | } |
jmarkel44 | 0:61364762ee0e | 206 | } |
jmarkel44 | 0:61364762ee0e | 207 | sensorError_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 208 | } |
jmarkel44 | 0:61364762ee0e | 209 | |
jmarkel44 | 0:61364762ee0e | 210 | |
jmarkel44 | 0:61364762ee0e | 211 | // |
jmarkel44 | 0:61364762ee0e | 212 | // function: ConfigurationHandler_showSequenceControls() |
jmarkel44 | 0:61364762ee0e | 213 | // description: display contents of the sequence control table |
jmarkel44 | 0:61364762ee0e | 214 | // |
jmarkel44 | 0:61364762ee0e | 215 | // @param[in] none |
jmarkel44 | 0:61364762ee0e | 216 | // @param[out] none |
jmarkel44 | 0:61364762ee0e | 217 | // @return none |
jmarkel44 | 0:61364762ee0e | 218 | // |
jmarkel44 | 0:61364762ee0e | 219 | void ConfigurationHandler_showSequenceControls(void) |
jmarkel44 | 0:61364762ee0e | 220 | { |
jmarkel44 | 0:61364762ee0e | 221 | sequence_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 222 | if ( !sequenceTable.empty() ) { |
jmarkel44 | 0:61364762ee0e | 223 | printf("\r\n"); |
jmarkel44 | 0:61364762ee0e | 224 | StringSequenceMap::const_iterator pos; |
jmarkel44 | 0:61364762ee0e | 225 | for ( pos = sequenceTable.begin(); pos != sequenceTable.end(); ++pos ) { |
jmarkel44 | 0:61364762ee0e | 226 | pos->second->display(); |
jmarkel44 | 0:61364762ee0e | 227 | } |
jmarkel44 | 0:61364762ee0e | 228 | } |
jmarkel44 | 0:61364762ee0e | 229 | sequence_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 230 | } |
jmarkel44 | 0:61364762ee0e | 231 | |
jmarkel44 | 0:61364762ee0e | 232 | // |
jmarkel44 | 0:61364762ee0e | 233 | // Function: ConfigurationHandler_showControls() |
jmarkel44 | 0:61364762ee0e | 234 | // Description: show the controls |
jmarkel44 | 0:61364762ee0e | 235 | // |
jmarkel44 | 0:61364762ee0e | 236 | // @param[in] none |
jmarkel44 | 0:61364762ee0e | 237 | // @return none |
jmarkel44 | 0:61364762ee0e | 238 | // |
jmarkel44 | 0:61364762ee0e | 239 | void ConfigurationHandler_showControls(void) |
jmarkel44 | 0:61364762ee0e | 240 | { |
jmarkel44 | 0:61364762ee0e | 241 | ConfigurationHandler_showSetpointControls(); |
jmarkel44 | 0:61364762ee0e | 242 | ConfigurationHandler_showTimerControls(); |
jmarkel44 | 0:61364762ee0e | 243 | ConfigurationHandler_showManualControls(); |
jmarkel44 | 0:61364762ee0e | 244 | ConfigurationHandler_showFailsafeControls(); |
jmarkel44 | 0:61364762ee0e | 245 | ConfigurationHandler_showCompositeControls(); |
jmarkel44 | 0:61364762ee0e | 246 | ConfigurationHandler_showSequenceControls(); |
jmarkel44 | 0:61364762ee0e | 247 | ConfigurationHandler_showSensorErrorControls(); |
jmarkel44 | 0:61364762ee0e | 248 | // TODO: PID controls |
jmarkel44 | 0:61364762ee0e | 249 | } |
jmarkel44 | 0:61364762ee0e | 250 | |
jmarkel44 | 0:61364762ee0e | 251 | // |
jmarkel44 | 0:61364762ee0e | 252 | // function: ConfigurationHandler_showAlgorithms |
jmarkel44 | 0:61364762ee0e | 253 | // description: display the control algorithms |
jmarkel44 | 0:61364762ee0e | 254 | // |
jmarkel44 | 0:61364762ee0e | 255 | // @param none |
jmarkel44 | 0:61364762ee0e | 256 | // @return none |
jmarkel44 | 0:61364762ee0e | 257 | // |
jmarkel44 | 0:61364762ee0e | 258 | void ConfigurationHandler_showAlgorithms(void) |
jmarkel44 | 0:61364762ee0e | 259 | { |
jmarkel44 | 0:61364762ee0e | 260 | StringAlgorithmMap::const_iterator pos; |
jmarkel44 | 0:61364762ee0e | 261 | |
jmarkel44 | 0:61364762ee0e | 262 | for ( pos = algorithmTable.begin(); pos != algorithmTable.end(); ++pos ) { |
jmarkel44 | 0:61364762ee0e | 263 | pos->second->display(); |
jmarkel44 | 0:61364762ee0e | 264 | } |
jmarkel44 | 0:61364762ee0e | 265 | } |
jmarkel44 | 0:61364762ee0e | 266 | |
jmarkel44 | 0:61364762ee0e | 267 | /***************************************************************************** |
jmarkel44 | 0:61364762ee0e | 268 | * Function: loadPersistentControls() |
jmarkel44 | 0:61364762ee0e | 269 | * Description: load persistent controls from flash |
jmarkel44 | 0:61364762ee0e | 270 | * |
jmarkel44 | 0:61364762ee0e | 271 | * @param none |
jmarkel44 | 0:61364762ee0e | 272 | * @return none |
jmarkel44 | 0:61364762ee0e | 273 | *****************************************************************************/ |
jmarkel44 | 0:61364762ee0e | 274 | static int loadPersistentControls(void) |
jmarkel44 | 0:61364762ee0e | 275 | { |
jmarkel44 | 0:61364762ee0e | 276 | static bool loaded = false; |
jmarkel44 | 0:61364762ee0e | 277 | |
jmarkel44 | 0:61364762ee0e | 278 | if ( !loaded ) { // lazy protection |
jmarkel44 | 0:61364762ee0e | 279 | |
jmarkel44 | 0:61364762ee0e | 280 | printf("\rLoading persistent controls: \n"); |
jmarkel44 | 0:61364762ee0e | 281 | std::vector<std::string> file_list = GLOBAL_mdot->listUserFiles(); |
jmarkel44 | 0:61364762ee0e | 282 | |
jmarkel44 | 0:61364762ee0e | 283 | loaded = true; |
jmarkel44 | 0:61364762ee0e | 284 | |
jmarkel44 | 0:61364762ee0e | 285 | for (std::vector<std::string>::const_iterator i = file_list.begin(); i != file_list.end(); ++i) { |
jmarkel44 | 0:61364762ee0e | 286 | if( strncmp( i->c_str(), CONTROL_SP_STR, strlen(CONTROL_SP_STR)) == 0 ) { |
jmarkel44 | 0:61364762ee0e | 287 | // create the setpoint control |
jmarkel44 | 0:61364762ee0e | 288 | ConfigMessage_t msg; |
jmarkel44 | 0:61364762ee0e | 289 | msg.control = CONTROL_SETPOINT; |
jmarkel44 | 0:61364762ee0e | 290 | strncpy(msg.controlFile, i->c_str(), sizeof(msg.controlFile)); |
jmarkel44 | 0:61364762ee0e | 291 | int rc = createControl(&msg); |
jmarkel44 | 0:61364762ee0e | 292 | if ( rc != 0 ) { |
jmarkel44 | 0:61364762ee0e | 293 | logError("%s: failed to load %s", __func__, msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 294 | } else { |
jmarkel44 | 0:61364762ee0e | 295 | printf("\r setpoint control %s loaded.\n", msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 296 | } |
jmarkel44 | 0:61364762ee0e | 297 | } else if ( strncmp( i->c_str(), CONTROL_TM_STR, strlen(CONTROL_TM_STR)) == 0 ) { |
jmarkel44 | 0:61364762ee0e | 298 | // create the timer control |
jmarkel44 | 0:61364762ee0e | 299 | ConfigMessage_t msg; |
jmarkel44 | 0:61364762ee0e | 300 | msg.control = CONTROL_TIMER; |
jmarkel44 | 0:61364762ee0e | 301 | strncpy(msg.controlFile, i->c_str(), sizeof(msg.controlFile)); |
jmarkel44 | 0:61364762ee0e | 302 | int rc = createControl(&msg); |
jmarkel44 | 0:61364762ee0e | 303 | if ( rc != 0 ) { |
jmarkel44 | 0:61364762ee0e | 304 | logError("%s: failed to load %s", __func__, msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 305 | |
jmarkel44 | 0:61364762ee0e | 306 | } else { |
jmarkel44 | 0:61364762ee0e | 307 | printf("\r timer control %s loaded.\n", msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 308 | } |
jmarkel44 | 0:61364762ee0e | 309 | } else if ( strncmp( i->c_str(), CONTROL_COMP_STR, strlen(CONTROL_COMP_STR)) == 0 ) { |
jmarkel44 | 0:61364762ee0e | 310 | ConfigMessage_t msg; |
jmarkel44 | 0:61364762ee0e | 311 | msg.control = CONTROL_COMPOSITE; |
jmarkel44 | 0:61364762ee0e | 312 | strncpy(msg.controlFile, i->c_str(), sizeof(msg.controlFile)); |
jmarkel44 | 0:61364762ee0e | 313 | int rc = createControl(&msg); |
jmarkel44 | 0:61364762ee0e | 314 | if ( rc != 0 ) { |
jmarkel44 | 0:61364762ee0e | 315 | logError("%s: failed to load %s\n", __func__, msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 316 | } else { |
jmarkel44 | 0:61364762ee0e | 317 | printf("\r composite control %s loaded.\n", msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 318 | } |
jmarkel44 | 0:61364762ee0e | 319 | } else if ( strncmp( i->c_str(), CONTROL_CA_STR, strlen(CONTROL_CA_STR)) == 0 ) { |
jmarkel44 | 0:61364762ee0e | 320 | ConfigMessage_t msg; |
jmarkel44 | 0:61364762ee0e | 321 | msg.control = CONTROL_ALGORITHM; |
jmarkel44 | 0:61364762ee0e | 322 | strncpy(msg.controlFile, i->c_str(), sizeof(msg.controlFile)); |
jmarkel44 | 0:61364762ee0e | 323 | int rc = createControl(&msg); |
jmarkel44 | 0:61364762ee0e | 324 | if ( rc != 0 ) { |
jmarkel44 | 0:61364762ee0e | 325 | logError("%s: failed to load %s\n", __func__, msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 326 | } else { |
jmarkel44 | 0:61364762ee0e | 327 | printf("\r algorithmic control %s loaded.\n", msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 328 | } |
jmarkel44 | 0:61364762ee0e | 329 | } else if ( strncmp( i->c_str(), CONTROL_FS_STR, strlen(CONTROL_FS_STR)) == 0 ) { |
jmarkel44 | 0:61364762ee0e | 330 | ConfigMessage_t msg; |
jmarkel44 | 0:61364762ee0e | 331 | msg.control = CONTROL_FAILSAFE; |
jmarkel44 | 0:61364762ee0e | 332 | strncpy(msg.controlFile, i->c_str(), sizeof(msg.controlFile)); |
jmarkel44 | 0:61364762ee0e | 333 | int rc = createControl(&msg); |
jmarkel44 | 0:61364762ee0e | 334 | if ( rc != 0 ) { |
jmarkel44 | 0:61364762ee0e | 335 | logError("%s: failed to load %s\n", __func__, msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 336 | } else { |
jmarkel44 | 0:61364762ee0e | 337 | printf("\r failsafe control %s loaded.\n", msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 338 | } |
jmarkel44 | 0:61364762ee0e | 339 | } else if ( strncmp( i->c_str(), CONTROL_PID_STR, strlen(CONTROL_PID_STR)) == 0 ) { |
jmarkel44 | 0:61364762ee0e | 340 | // TODO: |
jmarkel44 | 0:61364762ee0e | 341 | } else if ( strncmp( i->c_str(), CONTROL_MN_STR, strlen(CONTROL_MN_STR)) == 0 ) { |
jmarkel44 | 0:61364762ee0e | 342 | // TODO: delete any timed manual control, not continuous... |
jmarkel44 | 0:61364762ee0e | 343 | if ( getManualControlType(i->c_str()) == MANUAL_CONTROL_TYPE_CONTINUOUS ) { |
jmarkel44 | 0:61364762ee0e | 344 | ConfigMessage_t msg; |
jmarkel44 | 0:61364762ee0e | 345 | msg.control = CONTROL_MANUAL; |
jmarkel44 | 0:61364762ee0e | 346 | strncpy(msg.controlFile, i->c_str(), sizeof(msg.controlFile)); |
jmarkel44 | 0:61364762ee0e | 347 | int rc = createControl(&msg); |
jmarkel44 | 0:61364762ee0e | 348 | if ( rc != 0 ) { |
jmarkel44 | 0:61364762ee0e | 349 | logError("%s: failed to load %s\n", __func__, msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 350 | } else { |
jmarkel44 | 0:61364762ee0e | 351 | printf("\r manual control %s loaded\n", msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 352 | } |
jmarkel44 | 0:61364762ee0e | 353 | } else { |
jmarkel44 | 0:61364762ee0e | 354 | GLOBAL_mdot->deleteUserFile(i->c_str()); |
jmarkel44 | 0:61364762ee0e | 355 | } |
jmarkel44 | 0:61364762ee0e | 356 | } else if ( strncmp( i->c_str(), CONTROL_SEQ_STR, strlen(CONTROL_SEQ_STR)) == 0 ) { |
jmarkel44 | 0:61364762ee0e | 357 | ConfigMessage_t msg; |
jmarkel44 | 0:61364762ee0e | 358 | msg.control = CONTROL_SEQUENCE; |
jmarkel44 | 0:61364762ee0e | 359 | strncpy(msg.controlFile, i->c_str(), sizeof(msg.controlFile)); |
jmarkel44 | 0:61364762ee0e | 360 | int rc = createControl(&msg); |
jmarkel44 | 0:61364762ee0e | 361 | if ( rc != 0 ) { |
jmarkel44 | 0:61364762ee0e | 362 | logError("%s: failed to load %s\n", __func__, msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 363 | } else { |
jmarkel44 | 0:61364762ee0e | 364 | printf("\r sequence control %s loaded.\n", msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 365 | } |
jmarkel44 | 0:61364762ee0e | 366 | } else if ( strncmp( i->c_str(), CONTROL_SE_STR, strlen(CONTROL_SE_STR)) == 0 ) { |
jmarkel44 | 0:61364762ee0e | 367 | ConfigMessage_t msg; |
jmarkel44 | 0:61364762ee0e | 368 | msg.control = CONTROL_SENSOR_ERROR; |
jmarkel44 | 0:61364762ee0e | 369 | strncpy(msg.controlFile, i->c_str(), sizeof(msg.controlFile)); |
jmarkel44 | 0:61364762ee0e | 370 | int rc = createControl(&msg); |
jmarkel44 | 0:61364762ee0e | 371 | if ( rc != 0 ) { |
jmarkel44 | 0:61364762ee0e | 372 | logError("%s: failed to load %s\n", __func__, msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 373 | } else { |
jmarkel44 | 0:61364762ee0e | 374 | printf("\r sensor error control %s loaded.\n", msg.controlFile); |
jmarkel44 | 0:61364762ee0e | 375 | } |
jmarkel44 | 0:61364762ee0e | 376 | } else { |
jmarkel44 | 0:61364762ee0e | 377 | logInfo("\rNot A Control File%s\r\n", i->c_str()); |
jmarkel44 | 0:61364762ee0e | 378 | // not a control file |
jmarkel44 | 0:61364762ee0e | 379 | } |
jmarkel44 | 0:61364762ee0e | 380 | } |
jmarkel44 | 0:61364762ee0e | 381 | } |
jmarkel44 | 0:61364762ee0e | 382 | return 0; |
jmarkel44 | 0:61364762ee0e | 383 | } |
jmarkel44 | 0:61364762ee0e | 384 | |
jmarkel44 | 0:61364762ee0e | 385 | /***************************************************************************** |
jmarkel44 | 0:61364762ee0e | 386 | * Function: createControl() |
jmarkel44 | 0:61364762ee0e | 387 | * Description: creates a new control |
jmarkel44 | 0:61364762ee0e | 388 | * |
jmarkel44 | 0:61364762ee0e | 389 | * @param none |
jmarkel44 | 0:61364762ee0e | 390 | * @return 0 on success; -1 otherwise |
jmarkel44 | 0:61364762ee0e | 391 | *****************************************************************************/ |
jmarkel44 | 0:61364762ee0e | 392 | static int createControl(const ConfigMessage_t *msg) |
jmarkel44 | 0:61364762ee0e | 393 | { |
jmarkel44 | 0:61364762ee0e | 394 | int status = 0; |
jmarkel44 | 0:61364762ee0e | 395 | |
jmarkel44 | 0:61364762ee0e | 396 | logInfo("\r%s invoked\n", __func__); |
jmarkel44 | 0:61364762ee0e | 397 | |
jmarkel44 | 0:61364762ee0e | 398 | switch (msg->control) { |
jmarkel44 | 0:61364762ee0e | 399 | case CONTROL_SETPOINT: { |
jmarkel44 | 0:61364762ee0e | 400 | SetpointControl *setpointControl = new SetpointControl; |
jmarkel44 | 0:61364762ee0e | 401 | bool rc = setpointControl->load(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 402 | if ( rc != true ) { |
jmarkel44 | 0:61364762ee0e | 403 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 404 | delete setpointControl; |
jmarkel44 | 0:61364762ee0e | 405 | GLOBAL_mdot->deleteUserFile(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 406 | status = -1; |
jmarkel44 | 0:61364762ee0e | 407 | } else { |
jmarkel44 | 0:61364762ee0e | 408 | setpoint_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 409 | setpointTable[msg->controlFile] = setpointControl; |
jmarkel44 | 0:61364762ee0e | 410 | setpoint_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 411 | setpointControl->start(); |
jmarkel44 | 0:61364762ee0e | 412 | } |
jmarkel44 | 0:61364762ee0e | 413 | break; |
jmarkel44 | 0:61364762ee0e | 414 | } |
jmarkel44 | 0:61364762ee0e | 415 | case CONTROL_TIMER: { |
jmarkel44 | 0:61364762ee0e | 416 | TimerControl *timerControl = new TimerControl; |
jmarkel44 | 0:61364762ee0e | 417 | bool rc = timerControl->load(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 418 | if ( rc != true ) { |
jmarkel44 | 0:61364762ee0e | 419 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 420 | delete timerControl; |
jmarkel44 | 0:61364762ee0e | 421 | GLOBAL_mdot->deleteUserFile(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 422 | status = -1; |
jmarkel44 | 0:61364762ee0e | 423 | } else { |
jmarkel44 | 0:61364762ee0e | 424 | timer_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 425 | timerTable[msg->controlFile] = timerControl; |
jmarkel44 | 0:61364762ee0e | 426 | timer_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 427 | timerControl->start(); |
jmarkel44 | 0:61364762ee0e | 428 | } |
jmarkel44 | 0:61364762ee0e | 429 | break; |
jmarkel44 | 0:61364762ee0e | 430 | } |
jmarkel44 | 0:61364762ee0e | 431 | case CONTROL_MANUAL: { |
jmarkel44 | 0:61364762ee0e | 432 | ManualControl *manualControl = new ManualControl; |
jmarkel44 | 0:61364762ee0e | 433 | bool rc = manualControl->load(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 434 | if ( rc != true ) { |
jmarkel44 | 0:61364762ee0e | 435 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 436 | delete manualControl; |
jmarkel44 | 0:61364762ee0e | 437 | GLOBAL_mdot->deleteUserFile(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 438 | status = -1; |
jmarkel44 | 0:61364762ee0e | 439 | |
jmarkel44 | 0:61364762ee0e | 440 | } else { |
jmarkel44 | 0:61364762ee0e | 441 | manual_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 442 | manualTable[msg->controlFile] = manualControl; |
jmarkel44 | 0:61364762ee0e | 443 | manual_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 444 | manualControl-> start(); |
jmarkel44 | 0:61364762ee0e | 445 | } |
jmarkel44 | 0:61364762ee0e | 446 | break; |
jmarkel44 | 0:61364762ee0e | 447 | } |
jmarkel44 | 0:61364762ee0e | 448 | |
jmarkel44 | 0:61364762ee0e | 449 | case CONTROL_PID: { |
jmarkel44 | 0:61364762ee0e | 450 | // TODO: PID |
jmarkel44 | 0:61364762ee0e | 451 | break; |
jmarkel44 | 0:61364762ee0e | 452 | } |
jmarkel44 | 0:61364762ee0e | 453 | case CONTROL_COMPOSITE: { |
jmarkel44 | 0:61364762ee0e | 454 | CompositeControl *compositeControl = new CompositeControl; |
jmarkel44 | 0:61364762ee0e | 455 | bool rc = compositeControl->load(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 456 | if ( rc != true ) { |
jmarkel44 | 0:61364762ee0e | 457 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 458 | delete compositeControl; |
jmarkel44 | 0:61364762ee0e | 459 | GLOBAL_mdot->deleteUserFile(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 460 | status = -1; |
jmarkel44 | 0:61364762ee0e | 461 | } else { |
jmarkel44 | 0:61364762ee0e | 462 | composite_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 463 | compositeTable[msg->controlFile] = compositeControl; |
jmarkel44 | 0:61364762ee0e | 464 | composite_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 465 | compositeControl->start(); |
jmarkel44 | 0:61364762ee0e | 466 | } |
jmarkel44 | 0:61364762ee0e | 467 | break; |
jmarkel44 | 0:61364762ee0e | 468 | } |
jmarkel44 | 0:61364762ee0e | 469 | |
jmarkel44 | 0:61364762ee0e | 470 | case CONTROL_SEQUENCE: { |
jmarkel44 | 0:61364762ee0e | 471 | SequenceControl *sequenceControl = new SequenceControl; |
jmarkel44 | 0:61364762ee0e | 472 | bool rc = sequenceControl->load(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 473 | if ( rc != true ) { |
jmarkel44 | 0:61364762ee0e | 474 | logError("%s: failed to load %s", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 475 | delete sequenceControl; |
jmarkel44 | 0:61364762ee0e | 476 | //GLOBAL_mdot->deleteUserFile(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 477 | status = -1; |
jmarkel44 | 0:61364762ee0e | 478 | } else { |
jmarkel44 | 0:61364762ee0e | 479 | sequence_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 480 | sequenceTable[msg->controlFile] = sequenceControl; |
jmarkel44 | 0:61364762ee0e | 481 | sequence_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 482 | sequenceControl->start(); |
jmarkel44 | 0:61364762ee0e | 483 | } |
jmarkel44 | 0:61364762ee0e | 484 | break; |
jmarkel44 | 0:61364762ee0e | 485 | } |
jmarkel44 | 0:61364762ee0e | 486 | case CONTROL_FAILSAFE: { |
jmarkel44 | 0:61364762ee0e | 487 | FailsafeControl *failsafeControl = new FailsafeControl; |
jmarkel44 | 0:61364762ee0e | 488 | bool rc = failsafeControl->load(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 489 | if ( rc != true ) { |
jmarkel44 | 0:61364762ee0e | 490 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 491 | delete failsafeControl; |
jmarkel44 | 0:61364762ee0e | 492 | GLOBAL_mdot->deleteUserFile(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 493 | status = -1; |
jmarkel44 | 0:61364762ee0e | 494 | } else { |
jmarkel44 | 0:61364762ee0e | 495 | failsafe_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 496 | failsafeTable[msg->controlFile] = failsafeControl; |
jmarkel44 | 0:61364762ee0e | 497 | failsafe_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 498 | failsafeControl->start(); |
jmarkel44 | 0:61364762ee0e | 499 | } |
jmarkel44 | 0:61364762ee0e | 500 | break; |
jmarkel44 | 0:61364762ee0e | 501 | } |
jmarkel44 | 0:61364762ee0e | 502 | case CONTROL_SENSOR_ERROR: { |
jmarkel44 | 0:61364762ee0e | 503 | SensorErrorControl *sensorErrorControl = new SensorErrorControl; |
jmarkel44 | 0:61364762ee0e | 504 | bool rc = sensorErrorControl->load(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 505 | if ( rc != true ) { |
jmarkel44 | 0:61364762ee0e | 506 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 507 | delete sensorErrorControl; |
jmarkel44 | 0:61364762ee0e | 508 | GLOBAL_mdot->deleteUserFile(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 509 | status = -1; |
jmarkel44 | 0:61364762ee0e | 510 | } else { |
jmarkel44 | 0:61364762ee0e | 511 | sensorError_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 512 | sensorErrorTable[msg->controlFile] = sensorErrorControl; |
jmarkel44 | 0:61364762ee0e | 513 | sensorError_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 514 | sensorErrorControl->start(); |
jmarkel44 | 0:61364762ee0e | 515 | } |
jmarkel44 | 0:61364762ee0e | 516 | break; |
jmarkel44 | 0:61364762ee0e | 517 | } |
jmarkel44 | 0:61364762ee0e | 518 | case CONTROL_ALGORITHM: { |
jmarkel44 | 0:61364762ee0e | 519 | CompositeAlgorithm *compositeAlgorithm = new CompositeAlgorithm; |
jmarkel44 | 0:61364762ee0e | 520 | bool rc = compositeAlgorithm->load(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 521 | if ( rc != true ) { |
jmarkel44 | 0:61364762ee0e | 522 | logError("%s: failed to load %s\n", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 523 | status = -1; |
jmarkel44 | 0:61364762ee0e | 524 | } else { |
jmarkel44 | 0:61364762ee0e | 525 | // add this algorithm to the table |
jmarkel44 | 0:61364762ee0e | 526 | algorithmTable[compositeAlgorithm->getId()] = compositeAlgorithm; |
jmarkel44 | 0:61364762ee0e | 527 | } |
jmarkel44 | 0:61364762ee0e | 528 | break; |
jmarkel44 | 0:61364762ee0e | 529 | } |
jmarkel44 | 0:61364762ee0e | 530 | default: |
jmarkel44 | 0:61364762ee0e | 531 | logInfo("\r%s: control type %d not implemented yet...\n", |
jmarkel44 | 0:61364762ee0e | 532 | __func__, msg->control); |
jmarkel44 | 0:61364762ee0e | 533 | break; |
jmarkel44 | 0:61364762ee0e | 534 | } |
jmarkel44 | 0:61364762ee0e | 535 | return status; |
jmarkel44 | 0:61364762ee0e | 536 | } |
jmarkel44 | 0:61364762ee0e | 537 | |
jmarkel44 | 0:61364762ee0e | 538 | /***************************************************************************** |
jmarkel44 | 0:61364762ee0e | 539 | * Function: modifyControl() |
jmarkel44 | 0:61364762ee0e | 540 | * Description: modifies a control |
jmarkel44 | 0:61364762ee0e | 541 | * |
jmarkel44 | 0:61364762ee0e | 542 | * @param msg |
jmarkel44 | 0:61364762ee0e | 543 | * @return none |
jmarkel44 | 0:61364762ee0e | 544 | *****************************************************************************/ |
jmarkel44 | 0:61364762ee0e | 545 | static int modifyControl(const ConfigMessage_t *msg) |
jmarkel44 | 0:61364762ee0e | 546 | { |
jmarkel44 | 0:61364762ee0e | 547 | logInfo("\r%s invoked\n", __func__); |
jmarkel44 | 0:61364762ee0e | 548 | |
jmarkel44 | 0:61364762ee0e | 549 | switch (msg->control) { |
jmarkel44 | 0:61364762ee0e | 550 | case CONTROL_SETPOINT: { |
jmarkel44 | 0:61364762ee0e | 551 | // find the control in the table |
jmarkel44 | 0:61364762ee0e | 552 | StringSetpointMap::const_iterator pos; |
jmarkel44 | 0:61364762ee0e | 553 | setpoint_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 554 | pos = setpointTable.find(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 555 | if ( pos != setpointTable.end() ) { |
jmarkel44 | 0:61364762ee0e | 556 | bool rc = pos->second->load(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 557 | if ( rc != true ) { |
jmarkel44 | 0:61364762ee0e | 558 | logError("\rFailed to reload the setpoint control %s\n", msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 559 | } else { |
jmarkel44 | 0:61364762ee0e | 560 | logInfo("\rReloaded the setpoint control %s\n", msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 561 | } |
jmarkel44 | 0:61364762ee0e | 562 | } |
jmarkel44 | 0:61364762ee0e | 563 | setpoint_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 564 | break; |
jmarkel44 | 0:61364762ee0e | 565 | } |
jmarkel44 | 0:61364762ee0e | 566 | case CONTROL_MANUAL: { |
jmarkel44 | 0:61364762ee0e | 567 | // find the manual control in the table |
jmarkel44 | 0:61364762ee0e | 568 | StringManualMap::const_iterator pos; |
jmarkel44 | 0:61364762ee0e | 569 | manual_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 570 | pos = manualTable.find(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 571 | if ( pos != manualTable.end() ) { |
jmarkel44 | 0:61364762ee0e | 572 | bool rc = pos->second->load(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 573 | if ( rc != true ) { |
jmarkel44 | 0:61364762ee0e | 574 | logError("\rFailed to reload the manual control %s\n", msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 575 | } else { |
jmarkel44 | 0:61364762ee0e | 576 | logInfo("\rReloaded the manual control %s\n", msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 577 | } |
jmarkel44 | 0:61364762ee0e | 578 | } |
jmarkel44 | 0:61364762ee0e | 579 | manual_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 580 | break; |
jmarkel44 | 0:61364762ee0e | 581 | } |
jmarkel44 | 0:61364762ee0e | 582 | default: |
jmarkel44 | 0:61364762ee0e | 583 | logError("%s: unknown control %d\n", __func__, msg->control); |
jmarkel44 | 0:61364762ee0e | 584 | break; |
jmarkel44 | 0:61364762ee0e | 585 | } |
jmarkel44 | 0:61364762ee0e | 586 | |
jmarkel44 | 0:61364762ee0e | 587 | return 0; |
jmarkel44 | 0:61364762ee0e | 588 | } |
jmarkel44 | 0:61364762ee0e | 589 | |
jmarkel44 | 0:61364762ee0e | 590 | /***************************************************************************** |
jmarkel44 | 0:61364762ee0e | 591 | * Function: destroyControl() |
jmarkel44 | 0:61364762ee0e | 592 | * Description: destroys a controls |
jmarkel44 | 0:61364762ee0e | 593 | * |
jmarkel44 | 0:61364762ee0e | 594 | * @param msg |
jmarkel44 | 0:61364762ee0e | 595 | * @return none |
jmarkel44 | 0:61364762ee0e | 596 | *****************************************************************************/ |
jmarkel44 | 0:61364762ee0e | 597 | static int destroyControl(const ConfigMessage_t *msg) |
jmarkel44 | 0:61364762ee0e | 598 | { |
jmarkel44 | 0:61364762ee0e | 599 | logInfo("\r%s invoked\n", __func__); |
jmarkel44 | 0:61364762ee0e | 600 | |
jmarkel44 | 0:61364762ee0e | 601 | switch ( msg->control ) { |
jmarkel44 | 0:61364762ee0e | 602 | case CONTROL_SETPOINT: { |
jmarkel44 | 0:61364762ee0e | 603 | StringSetpointMap::iterator pos; |
jmarkel44 | 0:61364762ee0e | 604 | setpoint_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 605 | pos = setpointTable.find(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 606 | if ( pos != setpointTable.end() ) { |
jmarkel44 | 0:61364762ee0e | 607 | if ( !Util_isSequenceSubControl(msg->controlFile) ) { |
jmarkel44 | 0:61364762ee0e | 608 | GLOBAL_mdot->deleteUserFile(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 609 | } |
jmarkel44 | 0:61364762ee0e | 610 | logInfo("%s: deleted %s", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 611 | pos->second->unregisterControl(); |
jmarkel44 | 0:61364762ee0e | 612 | delete (pos->second); |
jmarkel44 | 0:61364762ee0e | 613 | setpointTable.erase(pos); |
jmarkel44 | 0:61364762ee0e | 614 | } else { |
jmarkel44 | 0:61364762ee0e | 615 | logError("%s: unable to find %s\n", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 616 | } |
jmarkel44 | 0:61364762ee0e | 617 | setpoint_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 618 | break; |
jmarkel44 | 0:61364762ee0e | 619 | } |
jmarkel44 | 0:61364762ee0e | 620 | case CONTROL_TIMER: { |
jmarkel44 | 0:61364762ee0e | 621 | StringTimerMap::iterator pos; |
jmarkel44 | 0:61364762ee0e | 622 | timer_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 623 | pos = timerTable.find(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 624 | if ( pos != timerTable.end() ) { |
jmarkel44 | 0:61364762ee0e | 625 | if ( !Util_isSequenceSubControl(msg->controlFile) ) { |
jmarkel44 | 0:61364762ee0e | 626 | GLOBAL_mdot->deleteUserFile(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 627 | } |
jmarkel44 | 0:61364762ee0e | 628 | logInfo("%s: deleted %s", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 629 | pos->second->unregisterControl(); |
jmarkel44 | 0:61364762ee0e | 630 | delete (pos->second); |
jmarkel44 | 0:61364762ee0e | 631 | timerTable.erase(pos); |
jmarkel44 | 0:61364762ee0e | 632 | } else { |
jmarkel44 | 0:61364762ee0e | 633 | logError("%s: unable to find %s\n", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 634 | } |
jmarkel44 | 0:61364762ee0e | 635 | timer_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 636 | break; |
jmarkel44 | 0:61364762ee0e | 637 | } |
jmarkel44 | 0:61364762ee0e | 638 | case CONTROL_MANUAL: { |
jmarkel44 | 0:61364762ee0e | 639 | StringManualMap::iterator pos; |
jmarkel44 | 0:61364762ee0e | 640 | manual_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 641 | pos = manualTable.find(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 642 | if ( pos != manualTable.end() ) { |
jmarkel44 | 0:61364762ee0e | 643 | GLOBAL_mdot->deleteUserFile(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 644 | logInfo("%s: deleted %s", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 645 | // unregister with the output thread |
jmarkel44 | 0:61364762ee0e | 646 | pos->second->unregisterControl(); |
jmarkel44 | 0:61364762ee0e | 647 | delete (pos->second); |
jmarkel44 | 0:61364762ee0e | 648 | manualTable.erase(pos); |
jmarkel44 | 0:61364762ee0e | 649 | } else { |
jmarkel44 | 0:61364762ee0e | 650 | logError("%s: unable to find %s", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 651 | } |
jmarkel44 | 0:61364762ee0e | 652 | manual_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 653 | break; |
jmarkel44 | 0:61364762ee0e | 654 | } |
jmarkel44 | 0:61364762ee0e | 655 | case CONTROL_COMPOSITE: { |
jmarkel44 | 0:61364762ee0e | 656 | StringCompositeMap::iterator pos; |
jmarkel44 | 0:61364762ee0e | 657 | composite_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 658 | pos = compositeTable.find(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 659 | if ( pos != compositeTable.end() ) { |
jmarkel44 | 0:61364762ee0e | 660 | GLOBAL_mdot->deleteUserFile(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 661 | logInfo("%s: deleted %s", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 662 | pos->second->unregisterControls(); |
jmarkel44 | 0:61364762ee0e | 663 | delete (pos->second); |
jmarkel44 | 0:61364762ee0e | 664 | compositeTable.erase(pos); |
jmarkel44 | 0:61364762ee0e | 665 | } else { |
jmarkel44 | 0:61364762ee0e | 666 | logError("%s: unable to find %s", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 667 | } |
jmarkel44 | 0:61364762ee0e | 668 | composite_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 669 | break; |
jmarkel44 | 0:61364762ee0e | 670 | } |
jmarkel44 | 0:61364762ee0e | 671 | case CONTROL_SEQUENCE: { |
jmarkel44 | 0:61364762ee0e | 672 | StringSequenceMap::iterator pos; |
jmarkel44 | 0:61364762ee0e | 673 | sequence_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 674 | pos = sequenceTable.find(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 675 | if ( pos != sequenceTable.end() ) { |
jmarkel44 | 0:61364762ee0e | 676 | GLOBAL_mdot->deleteUserFile(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 677 | logInfo("%s: delete %s", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 678 | // TODO: |
jmarkel44 | 0:61364762ee0e | 679 | // pos->second->unregisterControls(); |
jmarkel44 | 0:61364762ee0e | 680 | delete (pos->second); |
jmarkel44 | 0:61364762ee0e | 681 | sequenceTable.erase(pos); |
jmarkel44 | 0:61364762ee0e | 682 | } else { |
jmarkel44 | 0:61364762ee0e | 683 | logError("%s: unable to find %s", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 684 | } |
jmarkel44 | 0:61364762ee0e | 685 | sequence_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 686 | break; |
jmarkel44 | 0:61364762ee0e | 687 | } |
jmarkel44 | 0:61364762ee0e | 688 | case CONTROL_SENSOR_ERROR: { |
jmarkel44 | 0:61364762ee0e | 689 | StringSensorErrorMap::iterator pos; |
jmarkel44 | 0:61364762ee0e | 690 | sensorError_mutex.lock(); |
jmarkel44 | 0:61364762ee0e | 691 | pos = sensorErrorTable.find(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 692 | if ( pos != sensorErrorTable.end() ) { |
jmarkel44 | 0:61364762ee0e | 693 | GLOBAL_mdot->deleteUserFile(msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 694 | logInfo("%s: deleted %s", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 695 | pos->second->unregisterControl(); |
jmarkel44 | 0:61364762ee0e | 696 | delete (pos->second); |
jmarkel44 | 0:61364762ee0e | 697 | sensorErrorTable.erase(pos); |
jmarkel44 | 0:61364762ee0e | 698 | } else { |
jmarkel44 | 0:61364762ee0e | 699 | logError("%s: unable to find %s", __func__, msg->controlFile); |
jmarkel44 | 0:61364762ee0e | 700 | } |
jmarkel44 | 0:61364762ee0e | 701 | sensorError_mutex.unlock(); |
jmarkel44 | 0:61364762ee0e | 702 | break; |
jmarkel44 | 0:61364762ee0e | 703 | } |
jmarkel44 | 0:61364762ee0e | 704 | case CONTROL_PID: { |
jmarkel44 | 0:61364762ee0e | 705 | // TODO: |
jmarkel44 | 0:61364762ee0e | 706 | break; |
jmarkel44 | 0:61364762ee0e | 707 | } |
jmarkel44 | 0:61364762ee0e | 708 | default: |
jmarkel44 | 0:61364762ee0e | 709 | break; |
jmarkel44 | 0:61364762ee0e | 710 | } |
jmarkel44 | 0:61364762ee0e | 711 | return 0; |
jmarkel44 | 0:61364762ee0e | 712 | } |
jmarkel44 | 0:61364762ee0e | 713 | // |
jmarkel44 | 0:61364762ee0e | 714 | // function: getManualControlType |
jmarkel44 | 0:61364762ee0e | 715 | // description: extract the manual control type (continuous or timed) |
jmarkel44 | 0:61364762ee0e | 716 | // |
jmarkel44 | 0:61364762ee0e | 717 | // @param[in] filename |
jmarkel44 | 0:61364762ee0e | 718 | // @return control type (int) |
jmarkel44 | 0:61364762ee0e | 719 | // |
jmarkel44 | 0:61364762ee0e | 720 | static unsigned int getManualControlType(const char *filename) |
jmarkel44 | 0:61364762ee0e | 721 | { |
jmarkel44 | 0:61364762ee0e | 722 | char buf[MAX_FILE_SIZE]; |
jmarkel44 | 0:61364762ee0e | 723 | unsigned int type = MANUAL_CONTROL_TYPE_NONE; |
jmarkel44 | 0:61364762ee0e | 724 | bool rc = GLOBAL_mdot->readUserFile(filename, buf, MAX_FILE_SIZE); |
jmarkel44 | 0:61364762ee0e | 725 | if ( rc != true ) { |
jmarkel44 | 0:61364762ee0e | 726 | logError("%s: failed to read %s", __func__, filename); |
jmarkel44 | 0:61364762ee0e | 727 | } else { |
jmarkel44 | 0:61364762ee0e | 728 | cJSON * root = cJSON_Parse(buf); |
jmarkel44 | 0:61364762ee0e | 729 | type = atoi(cJSON_GetObjectItem(root,"type")->valuestring); |
jmarkel44 | 0:61364762ee0e | 730 | cJSON_Delete(root); |
jmarkel44 | 0:61364762ee0e | 731 | } |
jmarkel44 | 0:61364762ee0e | 732 | return type; |
jmarkel44 | 0:61364762ee0e | 733 | } |