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/Controls/TimerControl.cpp
- Revision:
- 136:6ad7ba157b70
- Parent:
- 133:c871de2d2b90
- Child:
- 141:d924caf402c2
--- a/src/ConfigurationHandler/Controls/TimerControl.cpp Tue Sep 27 15:28:59 2016 +0000 +++ b/src/ConfigurationHandler/Controls/TimerControl.cpp Tue Sep 27 18:46:10 2016 +0000 @@ -70,6 +70,16 @@ void TimerControl::start(void) { currentState = STATE_OFF; + vector<Schedule_t>::iterator pos; + + if ( schedule.empty() ) return; + #if 0 + for ( pos = schedule.begin(); pos != schedule.end(); ++pos ) { + if ( (pos->startTime + pos->duration) < time(NULL) ) { + schedule.erase(pos); + } + } + #endif } // @@ -94,10 +104,9 @@ logInfo("%s signals feed start", __func__); return true; } else { - // something is wrong here, so let's toss the schedule away - printf("\rERROR: schedule timestamp %lu has expired\n", - schedule.front().startTime); + logInfo("%s: schedule for %s has expired", __func__, id.c_str()); schedule.erase(schedule.begin()); + this->unregisterControl(); } } return false; @@ -195,6 +204,29 @@ OutputMasterMailBox.put(output_mail); } +// Method: unregisterControl +// Description: send OFF indication to Output Master for this control's +// relay +// +// @param none +// @return none +void TimerControl::unregisterControl(void) +{ + logInfo("%s: %s attempting to unregister %s\n", + __func__, controlFile.c_str()); + + OutputControlMsg_t *output_mail = OutputMasterMailBox.alloc(); + memset(output_mail, 0, sizeof(OutputControlMsg_t)); + + output_mail->action = ACTION_CONTROL_UNREGISTER; + output_mail->controlType = CONTROL_TIMER; + output_mail->priority = this->schedule.front().priority; + strncpy(output_mail->output_tag, this->output.c_str(), sizeof(output_mail->output_tag)-1); + strncpy(output_mail->id, this->id.c_str(), sizeof(output_mail->id)-1); + + OutputMasterMailBox.put(output_mail); +} + // // methid: display // description: display the elements of this timer control object @@ -216,12 +248,19 @@ std::vector<Schedule_t>::iterator pos; int counter = 0; - for ( pos = schedule.begin(); pos != schedule.end(); ++pos ) { - printf("\r Schedule %d\n", ++counter); - printf("\r priority : %u \n", pos->priority); - printf("\r start time : %lu\n", pos->startTime); - printf("\r duration : %u \n", pos->duration); + if ( schedule.empty() ) { + printf("\rNo scheduled timers\r\n"); + return; + } else { + for ( pos = schedule.begin(); pos != schedule.end(); ++pos ) { + printf("\r Schedule %d\n", ++counter); + printf("\r priority : %u \n", pos->priority); + printf("\r start time : %lu\n", pos->startTime); + printf("\r duration : %u sec\n", pos->duration); + printf("\r end time : %lu\n", pos->startTime + pos->duration); + printf("\r current time : %lu\n", time(NULL)); + printf("\r expires in : %lu sec\n", (pos->startTime + pos->duration) - time(NULL)); + } } printf("\r current State : %s\n", mapper[currentState].c_str()); - } \ No newline at end of file