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/ControlTask/ControlTask.cpp@269:97243a7f56ba, 2016-10-26 (annotated)
- Committer:
- jmarkel44
- Date:
- Wed Oct 26 18:30:08 2016 +0000
- Revision:
- 269:97243a7f56ba
- Parent:
- 252:3c9863f951b7
general sensor error state added to failsafes
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jmarkel44 | 218:e0c05b4f470b | 1 | /****************************************************************************** |
| jmarkel44 | 218:e0c05b4f470b | 2 | * |
| jmarkel44 | 218:e0c05b4f470b | 3 | * File: ControlTask.cpp |
| jmarkel44 | 218:e0c05b4f470b | 4 | * Desciption: source for the ICE Control task |
| jmarkel44 | 218:e0c05b4f470b | 5 | * |
| jmarkel44 | 218:e0c05b4f470b | 6 | *****************************************************************************/ |
| jmarkel44 | 218:e0c05b4f470b | 7 | |
| jmarkel44 | 20:653923c2f37a | 8 | #include "ControlTask.h" |
| jmarkel44 | 20:653923c2f37a | 9 | #include <stdio.h> |
| jmarkel44 | 20:653923c2f37a | 10 | #include "rtos.h" |
| jmarkel44 | 46:4cb96ab2d1c8 | 11 | #include "ConfigurationHandler.h" |
| jmarkel44 | 46:4cb96ab2d1c8 | 12 | #include "MTSLog.h" |
| jmarkel44 | 196:78397baf0802 | 13 | #include "global.h" |
| jmarkel44 | 20:653923c2f37a | 14 | |
| jmarkel44 | 218:e0c05b4f470b | 15 | // control functions |
| jmarkel44 | 170:f9406996ff5b | 16 | static void serviceManualControls(void); |
| jmarkel44 | 170:f9406996ff5b | 17 | static void serviceTimerControls(void); |
| jmarkel44 | 170:f9406996ff5b | 18 | static void serviceSetpointControls(void); |
| jmarkel44 | 218:e0c05b4f470b | 19 | static void serviceCompositeControls(void); |
| jmarkel44 | 252:3c9863f951b7 | 20 | static void serviceFailsafeControls(void); |
| jmarkel44 | 170:f9406996ff5b | 21 | |
| jmarkel44 | 46:4cb96ab2d1c8 | 22 | /***************************************************************************** |
| jmarkel44 | 46:4cb96ab2d1c8 | 23 | * Function: ControlTask() |
| jmarkel44 | 131:a290a3934132 | 24 | * Description: This task will loop through all of the configured |
| jmarkel44 | 131:a290a3934132 | 25 | * controls |
| jmarkel44 | 46:4cb96ab2d1c8 | 26 | * |
| jmarkel44 | 46:4cb96ab2d1c8 | 27 | * @param msg |
| jmarkel44 | 46:4cb96ab2d1c8 | 28 | * @return none |
| jmarkel44 | 46:4cb96ab2d1c8 | 29 | *****************************************************************************/ |
| jmarkel44 | 20:653923c2f37a | 30 | void ControlTask(void const *args) |
| jmarkel44 | 20:653923c2f37a | 31 | { |
| jmarkel44 | 20:653923c2f37a | 32 | printf("\r%s has started...\n", __func__); |
| jmarkel44 | 20:653923c2f37a | 33 | |
| jmarkel44 | 20:653923c2f37a | 34 | while ( true ) { |
| jmarkel44 | 170:f9406996ff5b | 35 | serviceManualControls(); |
| jmarkel44 | 170:f9406996ff5b | 36 | |
| jmarkel44 | 170:f9406996ff5b | 37 | serviceTimerControls(); |
| jmarkel44 | 170:f9406996ff5b | 38 | |
| jmarkel44 | 170:f9406996ff5b | 39 | serviceSetpointControls(); |
| jmarkel44 | 170:f9406996ff5b | 40 | |
| jmarkel44 | 218:e0c05b4f470b | 41 | serviceCompositeControls(); |
| jmarkel44 | 252:3c9863f951b7 | 42 | |
| jmarkel44 | 252:3c9863f951b7 | 43 | serviceFailsafeControls(); |
| jmarkel44 | 170:f9406996ff5b | 44 | |
| jmarkel44 | 170:f9406996ff5b | 45 | Thread::wait(1000); // do we need to wait? |
| jmarkel44 | 170:f9406996ff5b | 46 | } |
| jmarkel44 | 170:f9406996ff5b | 47 | } |
| jmarkel44 | 170:f9406996ff5b | 48 | |
| jmarkel44 | 170:f9406996ff5b | 49 | /***************************************************************************** |
| jmarkel44 | 170:f9406996ff5b | 50 | * Function: serviceManualControls() |
| jmarkel44 | 170:f9406996ff5b | 51 | * Description: service the manual controls |
| jmarkel44 | 170:f9406996ff5b | 52 | * controls |
| jmarkel44 | 170:f9406996ff5b | 53 | * |
| jmarkel44 | 170:f9406996ff5b | 54 | * @param none |
| jmarkel44 | 170:f9406996ff5b | 55 | * @return none |
| jmarkel44 | 170:f9406996ff5b | 56 | *****************************************************************************/ |
| jmarkel44 | 170:f9406996ff5b | 57 | static void serviceManualControls(void) |
| jmarkel44 | 170:f9406996ff5b | 58 | { |
| jmarkel44 | 170:f9406996ff5b | 59 | // service the manual controls |
| jmarkel44 | 170:f9406996ff5b | 60 | if ( !manualTable.empty() ) { |
| jmarkel44 | 170:f9406996ff5b | 61 | StringManualMap::iterator pos; |
| jmarkel44 | 170:f9406996ff5b | 62 | for ( pos = manualTable.begin(); pos != manualTable.end(); ++pos ) { |
| jmarkel44 | 170:f9406996ff5b | 63 | pos->second->update(); |
| jmarkel44 | 97:5cf6ab71dcd0 | 64 | } |
| jmarkel44 | 170:f9406996ff5b | 65 | } |
| jmarkel44 | 170:f9406996ff5b | 66 | } |
| jmarkel44 | 170:f9406996ff5b | 67 | |
| jmarkel44 | 170:f9406996ff5b | 68 | /***************************************************************************** |
| jmarkel44 | 170:f9406996ff5b | 69 | * Function: serviceSetpointControls() |
| jmarkel44 | 170:f9406996ff5b | 70 | * Description: service the setpoint controls |
| jmarkel44 | 170:f9406996ff5b | 71 | * controls |
| jmarkel44 | 170:f9406996ff5b | 72 | * |
| jmarkel44 | 170:f9406996ff5b | 73 | * @param none |
| jmarkel44 | 170:f9406996ff5b | 74 | * @return none |
| jmarkel44 | 170:f9406996ff5b | 75 | *****************************************************************************/ |
| jmarkel44 | 170:f9406996ff5b | 76 | static void serviceSetpointControls(void) |
| jmarkel44 | 170:f9406996ff5b | 77 | { |
| jmarkel44 | 170:f9406996ff5b | 78 | // service the setpoint controls |
| jmarkel44 | 170:f9406996ff5b | 79 | if ( !setpointTable.empty() ) { |
| jmarkel44 | 170:f9406996ff5b | 80 | StringSetpointMap::iterator pos; |
| jmarkel44 | 170:f9406996ff5b | 81 | for ( pos = setpointTable.begin(); pos != setpointTable.end(); ++pos ) { |
| jmarkel44 | 170:f9406996ff5b | 82 | pos->second->update(); |
| jmarkel44 | 170:f9406996ff5b | 83 | } |
| jmarkel44 | 170:f9406996ff5b | 84 | } |
| jmarkel44 | 170:f9406996ff5b | 85 | } |
| jmarkel44 | 170:f9406996ff5b | 86 | |
| jmarkel44 | 170:f9406996ff5b | 87 | /***************************************************************************** |
| jmarkel44 | 170:f9406996ff5b | 88 | * Function: serviceTimerControls() |
| jmarkel44 | 170:f9406996ff5b | 89 | * Description: service the timer controls |
| jmarkel44 | 170:f9406996ff5b | 90 | * controls |
| jmarkel44 | 170:f9406996ff5b | 91 | * |
| jmarkel44 | 170:f9406996ff5b | 92 | * @param none |
| jmarkel44 | 170:f9406996ff5b | 93 | * @return none |
| jmarkel44 | 170:f9406996ff5b | 94 | *****************************************************************************/ |
| jmarkel44 | 170:f9406996ff5b | 95 | static void serviceTimerControls(void) |
| jmarkel44 | 170:f9406996ff5b | 96 | { |
| jmarkel44 | 170:f9406996ff5b | 97 | // service the timer controls |
| jmarkel44 | 170:f9406996ff5b | 98 | if ( !timerTable.empty() ) { |
| jmarkel44 | 170:f9406996ff5b | 99 | StringVectorTimerMap::iterator pos; |
| jmarkel44 | 170:f9406996ff5b | 100 | for ( pos = timerTable.begin(); pos != timerTable.end(); ++pos ) { |
| jmarkel44 | 170:f9406996ff5b | 101 | // the timer vector is sorted by starttime, so we only need |
| jmarkel44 | 170:f9406996ff5b | 102 | // to service the first timer |
| jmarkel44 | 170:f9406996ff5b | 103 | TimerError_t rc = pos->second.front()->update(); |
| jmarkel44 | 170:f9406996ff5b | 104 | if ( rc == TIMER_CONTROL_DESTROY ) { |
| jmarkel44 | 196:78397baf0802 | 105 | GLOBAL_mdot->deleteUserFile(pos->second.front()->getControlFile().c_str()); |
| jmarkel44 | 196:78397baf0802 | 106 | logInfo("%s: deleted %s", __func__, pos->second.front()->getControlFile().c_str()); |
| jmarkel44 | 170:f9406996ff5b | 107 | // free the memory |
| jmarkel44 | 170:f9406996ff5b | 108 | delete pos->second.front(); |
| jmarkel44 | 170:f9406996ff5b | 109 | pos->second.erase(pos->second.begin()); |
| jmarkel44 | 46:4cb96ab2d1c8 | 110 | } |
| jmarkel44 | 46:4cb96ab2d1c8 | 111 | } |
| jmarkel44 | 20:653923c2f37a | 112 | } |
| jmarkel44 | 170:f9406996ff5b | 113 | |
| jmarkel44 | 218:e0c05b4f470b | 114 | } |
| jmarkel44 | 218:e0c05b4f470b | 115 | |
| jmarkel44 | 218:e0c05b4f470b | 116 | /***************************************************************************** |
| jmarkel44 | 218:e0c05b4f470b | 117 | * Function: serviceCompositeControls() |
| jmarkel44 | 218:e0c05b4f470b | 118 | * Description: service the composite controls |
| jmarkel44 | 218:e0c05b4f470b | 119 | * controls |
| jmarkel44 | 218:e0c05b4f470b | 120 | * |
| jmarkel44 | 218:e0c05b4f470b | 121 | * @param none |
| jmarkel44 | 218:e0c05b4f470b | 122 | * @return none |
| jmarkel44 | 218:e0c05b4f470b | 123 | *****************************************************************************/ |
| jmarkel44 | 218:e0c05b4f470b | 124 | static void serviceCompositeControls(void) |
| jmarkel44 | 218:e0c05b4f470b | 125 | { |
| jmarkel44 | 221:2a5e9902003c | 126 | // service the setpoint controls |
| jmarkel44 | 221:2a5e9902003c | 127 | if ( !compositeTable.empty() ) { |
| jmarkel44 | 221:2a5e9902003c | 128 | StringCompositeMap::iterator pos; |
| jmarkel44 | 221:2a5e9902003c | 129 | for ( pos = compositeTable.begin(); pos != compositeTable.end(); ++pos ) { |
| jmarkel44 | 221:2a5e9902003c | 130 | pos->second->update(); |
| jmarkel44 | 221:2a5e9902003c | 131 | } |
| jmarkel44 | 221:2a5e9902003c | 132 | } |
| jmarkel44 | 252:3c9863f951b7 | 133 | } |
| jmarkel44 | 252:3c9863f951b7 | 134 | |
| jmarkel44 | 252:3c9863f951b7 | 135 | /***************************************************************************** |
| jmarkel44 | 269:97243a7f56ba | 136 | * Function: serviceFailsafeControls() |
| jmarkel44 | 269:97243a7f56ba | 137 | * Description: service the failsafe controls |
| jmarkel44 | 252:3c9863f951b7 | 138 | * controls |
| jmarkel44 | 252:3c9863f951b7 | 139 | * |
| jmarkel44 | 269:97243a7f56ba | 140 | * @param[in] none |
| jmarkel44 | 252:3c9863f951b7 | 141 | * @return none |
| jmarkel44 | 252:3c9863f951b7 | 142 | *****************************************************************************/ |
| jmarkel44 | 252:3c9863f951b7 | 143 | static void serviceFailsafeControls(void) |
| jmarkel44 | 252:3c9863f951b7 | 144 | { |
| jmarkel44 | 252:3c9863f951b7 | 145 | // service the setpoint controls |
| jmarkel44 | 252:3c9863f951b7 | 146 | if ( !failsafeTable.empty() ) { |
| jmarkel44 | 252:3c9863f951b7 | 147 | StringFailsafeMap::iterator pos; |
| jmarkel44 | 252:3c9863f951b7 | 148 | for ( pos = failsafeTable.begin(); pos != failsafeTable.end(); ++pos ) { |
| jmarkel44 | 252:3c9863f951b7 | 149 | pos->second->update(); |
| jmarkel44 | 252:3c9863f951b7 | 150 | } |
| jmarkel44 | 252:3c9863f951b7 | 151 | } |
| jmarkel44 | 51:66b820f203a5 | 152 | } |
