Erick / Mbed 2 deprecated ICE_BLE_TEST

Dependencies:   NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed

Fork of ICE by Erick

Committer:
jmarkel44
Date:
Fri Sep 09 18:59:39 2016 +0000
Revision:
37:7e6986b77f01
Parent:
28:c410a61238bb
Child:
46:4cb96ab2d1c8
added commands "cif" and "cof";

Who changed what in which revision?

UserRevisionLine numberNew 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 37:7e6986b77f01 46 logInfo("\r%s: mes->action = %d\n", __func__, msg->action);
jmarkel44 37:7e6986b77f01 47 logInfo("\r%s: msg->control = %d\n", __func__, msg->control);
jmarkel44 37:7e6986b77f01 48 logInfo("\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 28:c410a61238bb 88 printf("\r control file: %32s\n",
jmarkel44 28:c410a61238bb 89 pos->second->getControlFile().c_str());
jmarkel44 12:ea87887ca7ad 90 }
jmarkel44 12:ea87887ca7ad 91 }
jmarkel44 12:ea87887ca7ad 92 if ( !setpointTable.empty() ) {
jmarkel44 12:ea87887ca7ad 93 printf("\rSETPOINT CONTROLS\n");
jmarkel44 12:ea87887ca7ad 94 StringSetpointMap::iterator pos;
jmarkel44 12:ea87887ca7ad 95 for ( pos = setpointTable.begin();
jmarkel44 12:ea87887ca7ad 96 pos != setpointTable.end();
jmarkel44 12:ea87887ca7ad 97 ++pos ) {
jmarkel44 28:c410a61238bb 98 printf("\r controlFile : %s \n", pos->second->getControlFile().c_str());
jmarkel44 28:c410a61238bb 99 printf("\r id : %s \n", pos->second->getId().c_str());
jmarkel44 28:c410a61238bb 100 printf("\r name : %s \n", pos->second->getName().c_str());
jmarkel44 28:c410a61238bb 101 printf("\r priority : %d \n", pos->second->getPriority());
jmarkel44 28:c410a61238bb 102 printf("\r input : %s \n", pos->second->getInput().c_str());
jmarkel44 28:c410a61238bb 103 printf("\r output : %s \n", pos->second->getOutput().c_str());
jmarkel44 28:c410a61238bb 104 printf("\r prodfact : %0.2f\n", pos->second->getProductFactor());
jmarkel44 28:c410a61238bb 105 printf("\r halert : %0.2f\n", pos->second->getHighAlert());
jmarkel44 28:c410a61238bb 106 printf("\r lalert : %0.2f\n", pos->second->getLowAlert());
jmarkel44 28:c410a61238bb 107 printf("\r hfs : %0.2f\n", pos->second->getHighFailsafe());
jmarkel44 28:c410a61238bb 108 printf("\r lfs : %0.2f\n", pos->second->getLowFailsafe());
jmarkel44 28:c410a61238bb 109 printf("\r tol : %0.2f\n", pos->second->getTol());
jmarkel44 28:c410a61238bb 110 printf("\r\n");
jmarkel44 12:ea87887ca7ad 111 }
jmarkel44 12:ea87887ca7ad 112 }
jmarkel44 12:ea87887ca7ad 113 }
jmarkel44 12:ea87887ca7ad 114
jmarkel44 12:ea87887ca7ad 115 /*****************************************************************************
jmarkel44 12:ea87887ca7ad 116 * Function: loadPersistentControls()
jmarkel44 12:ea87887ca7ad 117 * Description: load persistent controls from flash
jmarkel44 12:ea87887ca7ad 118 *
jmarkel44 12:ea87887ca7ad 119 * @param none
jmarkel44 12:ea87887ca7ad 120 * @return none
jmarkel44 12:ea87887ca7ad 121 *****************************************************************************/
jmarkel44 12:ea87887ca7ad 122 static int loadPersistentControls(void)
jmarkel44 12:ea87887ca7ad 123 {
jmarkel44 12:ea87887ca7ad 124 static bool loaded = false;
jmarkel44 12:ea87887ca7ad 125
jmarkel44 12:ea87887ca7ad 126 if ( !loaded ) { // lazy protection
jmarkel44 12:ea87887ca7ad 127 // do something
jmarkel44 12:ea87887ca7ad 128 loaded = true;
jmarkel44 12:ea87887ca7ad 129 }
jmarkel44 12:ea87887ca7ad 130 return 0;
jmarkel44 12:ea87887ca7ad 131 }
jmarkel44 12:ea87887ca7ad 132
jmarkel44 12:ea87887ca7ad 133 /*****************************************************************************
jmarkel44 12:ea87887ca7ad 134 * Function: createControl()
jmarkel44 12:ea87887ca7ad 135 * Description: creates a new control
jmarkel44 12:ea87887ca7ad 136 *
jmarkel44 12:ea87887ca7ad 137 * @param none
jmarkel44 12:ea87887ca7ad 138 * @return none
jmarkel44 12:ea87887ca7ad 139 *****************************************************************************/
jmarkel44 5:5e77a1db4d45 140 static int createControl(const Message_t *msg)
jmarkel44 5:5e77a1db4d45 141 {
jmarkel44 37:7e6986b77f01 142 logInfo("\r%s invoked\n", __func__);
jmarkel44 5:5e77a1db4d45 143
jmarkel44 5:5e77a1db4d45 144 switch (msg->control) {
jmarkel44 5:5e77a1db4d45 145 case CONTROL_SETPOINT: {
jmarkel44 19:9bc8fabeddfa 146 SetpointControl *setpointControl = new SetpointControl();
jmarkel44 28:c410a61238bb 147 bool rc = setpointControl->load(msg->controlFile);
jmarkel44 19:9bc8fabeddfa 148 if ( rc != true ) {
jmarkel44 19:9bc8fabeddfa 149 logError("%s: failed to load %s\n", __func__, msg->controlFile);
jmarkel44 19:9bc8fabeddfa 150 delete setpointControl;
jmarkel44 19:9bc8fabeddfa 151 } else {
jmarkel44 19:9bc8fabeddfa 152 setpointTable[msg->controlFile] = setpointControl;
jmarkel44 19:9bc8fabeddfa 153 }
jmarkel44 5:5e77a1db4d45 154 break;
jmarkel44 5:5e77a1db4d45 155 }
jmarkel44 5:5e77a1db4d45 156 case CONTROL_TIMER: {
jmarkel44 19:9bc8fabeddfa 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 19:9bc8fabeddfa 167 case CONTROL_PID:
jmarkel44 19:9bc8fabeddfa 168 case CONTROL_MANUAL:
jmarkel44 19:9bc8fabeddfa 169 case CONTROL_COMPOSITE:
jmarkel44 5:5e77a1db4d45 170 default:
jmarkel44 37:7e6986b77f01 171 logInfo("\r%s: control type %d not implemented yet...\n",
jmarkel44 19:9bc8fabeddfa 172 __func__, msg->control);
jmarkel44 5:5e77a1db4d45 173 break;
jmarkel44 5:5e77a1db4d45 174 }
jmarkel44 5:5e77a1db4d45 175 return 0;
jmarkel44 5:5e77a1db4d45 176 }
jmarkel44 12:ea87887ca7ad 177
jmarkel44 12:ea87887ca7ad 178 /*****************************************************************************
jmarkel44 12:ea87887ca7ad 179 * Function: modifyControl()
jmarkel44 12:ea87887ca7ad 180 * Description: modifies a control
jmarkel44 12:ea87887ca7ad 181 *
jmarkel44 12:ea87887ca7ad 182 * @param msg
jmarkel44 12:ea87887ca7ad 183 * @return none
jmarkel44 12:ea87887ca7ad 184 *****************************************************************************/
jmarkel44 5:5e77a1db4d45 185 static int modifyControl(const Message_t *msg)
jmarkel44 5:5e77a1db4d45 186 {
jmarkel44 37:7e6986b77f01 187 logInfo("\r%s invoked\n", __func__);
jmarkel44 5:5e77a1db4d45 188 return 0;
jmarkel44 5:5e77a1db4d45 189
jmarkel44 5:5e77a1db4d45 190 }
jmarkel44 12:ea87887ca7ad 191
jmarkel44 12:ea87887ca7ad 192 /*****************************************************************************
jmarkel44 12:ea87887ca7ad 193 * Function: destroyControl()
jmarkel44 12:ea87887ca7ad 194 * Description: destroys a controls
jmarkel44 12:ea87887ca7ad 195 *
jmarkel44 12:ea87887ca7ad 196 * @param msg
jmarkel44 12:ea87887ca7ad 197 * @return none
jmarkel44 12:ea87887ca7ad 198 *****************************************************************************/
jmarkel44 5:5e77a1db4d45 199 static int destroyControl(const Message_t *msg)
jmarkel44 5:5e77a1db4d45 200 {
jmarkel44 37:7e6986b77f01 201 logInfo("\r%s invoked\n", __func__);
jmarkel44 12:ea87887ca7ad 202
jmarkel44 12:ea87887ca7ad 203 switch ( msg->control ) {
jmarkel44 12:ea87887ca7ad 204 case CONTROL_SETPOINT: {
jmarkel44 12:ea87887ca7ad 205 StringSetpointMap::iterator pos;
jmarkel44 12:ea87887ca7ad 206 pos = setpointTable.find(msg->controlFile);
jmarkel44 12:ea87887ca7ad 207 if ( pos != setpointTable.end() ) {
jmarkel44 12:ea87887ca7ad 208 delete (pos->second);
jmarkel44 12:ea87887ca7ad 209 setpointTable.erase(pos);
jmarkel44 12:ea87887ca7ad 210 }
jmarkel44 12:ea87887ca7ad 211 break;
jmarkel44 12:ea87887ca7ad 212 }
jmarkel44 12:ea87887ca7ad 213 case CONTROL_TIMER: {
jmarkel44 12:ea87887ca7ad 214 StringTimerMap::iterator pos;
jmarkel44 12:ea87887ca7ad 215 pos = timerTable.find(msg->controlFile);
jmarkel44 12:ea87887ca7ad 216 if ( pos != timerTable.end() ) {
jmarkel44 12:ea87887ca7ad 217 delete (pos->second);
jmarkel44 12:ea87887ca7ad 218 timerTable.erase(pos);
jmarkel44 12:ea87887ca7ad 219 }
jmarkel44 12:ea87887ca7ad 220 break;
jmarkel44 12:ea87887ca7ad 221 }
jmarkel44 12:ea87887ca7ad 222 default:
jmarkel44 12:ea87887ca7ad 223 break;
jmarkel44 12:ea87887ca7ad 224 }
jmarkel44 12:ea87887ca7ad 225 return 0;
jmarkel44 20:653923c2f37a 226 }