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
Diff: src/ConfigurationHandler/ConfigurationHandler.cpp
- Revision:
- 12:ea87887ca7ad
- Parent:
- 5:5e77a1db4d45
- Child:
- 13:c80c283f9db2
--- a/src/ConfigurationHandler/ConfigurationHandler.cpp Tue Sep 06 22:09:39 2016 +0000 +++ b/src/ConfigurationHandler/ConfigurationHandler.cpp Wed Sep 07 13:22:28 2016 +0000 @@ -7,6 +7,15 @@ #include "ConfigurationHandler.h" #include "global.h" #include "SetpointControl.h" +#include "TimerControl.h" + +// setpoint control table +typedef map<string, SetpointControl*> StringSetpointMap; +static StringSetpointMap setpointTable; + +// timer control table +typedef map<string, TimerControl*> StringTimerMap; +static StringTimerMap timerTable; // local function prototypes static int loadPersistentControls(void); @@ -15,14 +24,16 @@ static int modifyControl(const Message_t *msg); static int destroyControl(const Message_t *msg); -static int loadPersistentControls(void) -{ - printf("\r%s: stubbed.\n", __func__); - return 0; -} - +/***************************************************************************** + * Function: ConfigurationHandler() + * Description: The ICE Configuration Handler + * + * @param args (unused) + * @return none + *****************************************************************************/ void ConfigurationHandler(void const *args) { + UNUSED(args); loadPersistentControls(); osSignalSet(mainThreadId, sig_continue); @@ -59,6 +70,60 @@ } } +/***************************************************************************** + * Function: ConfigurationHandler_showControls() + * Description: show the controls + * + * @param msg + * @return none + *****************************************************************************/ +void ConfigurationHandler_showControls(void) +{ + if ( !timerTable.empty() ) { + printf("\rTIMER CONTROLS\n"); + StringTimerMap::iterator pos; + for ( pos = timerTable.begin(); + pos != timerTable.end(); + ++pos ) { + printf("\r control file: %32s\n", pos->first); + } + } + if ( !setpointTable.empty() ) { + printf("\rSETPOINT CONTROLS\n"); + StringSetpointMap::iterator pos; + for ( pos = setpointTable.begin(); + pos != setpointTable.end(); + ++pos ) { + printf("\r control file: %32s\n", pos->first); + } + } +} + +/***************************************************************************** + * Function: loadPersistentControls() + * Description: load persistent controls from flash + * + * @param none + * @return none + *****************************************************************************/ +static int loadPersistentControls(void) +{ + static bool loaded = false; + + if ( !loaded ) { // lazy protection + // do something + loaded = true; + } + return 0; +} + +/***************************************************************************** + * Function: createControl() + * Description: creates a new control + * + * @param none + * @return none + *****************************************************************************/ static int createControl(const Message_t *msg) { printf("\r%s invoked\n", __func__); @@ -66,12 +131,12 @@ switch (msg->control) { case CONTROL_SETPOINT: { SetpointControl *setpointControl = new SetpointControl(msg->controlFile); - printf("\r%s: setpoint control file = %s\n", __func__, setpointControl->getControlFile().c_str()); - + setpointTable[msg->controlFile] = setpointControl; break; } case CONTROL_TIMER: { - // do something similar here + TimerControl *timerControl = new TimerControl(msg->controlFile); + timerTable[msg->controlFile] = timerControl; break; } default: @@ -79,15 +144,55 @@ } return 0; } + +/***************************************************************************** + * Function: modifyControl() + * Description: modifies a control + * + * @param msg + * @return none + *****************************************************************************/ static int modifyControl(const Message_t *msg) { printf("\r%s invoked\n", __func__); return 0; } + +/***************************************************************************** + * Function: destroyControl() + * Description: destroys a controls + * + * @param msg + * @return none + *****************************************************************************/ static int destroyControl(const Message_t *msg) { printf("\r%s invoked\n", __func__); - return 0; + + switch ( msg->control ) { + case CONTROL_SETPOINT: { + StringSetpointMap::iterator pos; + pos = setpointTable.find(msg->controlFile); + if ( pos != setpointTable.end() ) { + delete (pos->second); + setpointTable.erase(pos); + } + break; + } + case CONTROL_TIMER: { + StringTimerMap::iterator pos; + pos = timerTable.find(msg->controlFile); + if ( pos != timerTable.end() ) { + delete (pos->second); + timerTable.erase(pos); + } + break; + } + default: + break; + } + return 0; } +