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
- Committer:
- jmarkel44
- Date:
- 2016-09-07
- Revision:
- 12:ea87887ca7ad
- Parent:
- 5:5e77a1db4d45
- Child:
- 13:c80c283f9db2
File content as of revision 12:ea87887ca7ad:
/****************************************************************************** * * File: ConfigurationHandler.cpp * Desciption: source for the ICE Configuration Handler * *****************************************************************************/ #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); static int createControl(const Message_t *msg); static int modifyControl(const Message_t *msg); static int destroyControl(const Message_t *msg); /***************************************************************************** * Function: ConfigurationHandler() * Description: The ICE Configuration Handler * * @param args (unused) * @return none *****************************************************************************/ void ConfigurationHandler(void const *args) { UNUSED(args); loadPersistentControls(); osSignalSet(mainThreadId, sig_continue); while ( true ) { // wait for an event osEvent evt = MailBox.get(); if (evt.status == osEventMail) { Message_t *msg = (Message_t*) evt.value.p; printf("\r%s: mes->action = %d\n", __func__, msg->action); printf("\r%s: msg->control = %d\n", __func__, msg->control); printf("\r%s: msg->controlFile = %s\n", __func__, msg->controlFile); switch ( msg->action ) { case ACTION_CREATE: { (void)createControl(msg); break; } case ACTION_MODIFY: { (void)modifyControl(msg); break; } case ACTION_DESTROY: { (void)destroyControl(msg); break; } default: break; } // free the message MailBox.free(msg); } } } /***************************************************************************** * 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__); switch (msg->control) { case CONTROL_SETPOINT: { SetpointControl *setpointControl = new SetpointControl(msg->controlFile); setpointTable[msg->controlFile] = setpointControl; break; } case CONTROL_TIMER: { TimerControl *timerControl = new TimerControl(msg->controlFile); timerTable[msg->controlFile] = timerControl; break; } default: break; } 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__); 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; }