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:
- 156:44f87c5a83ae
- Parent:
- 153:0845c7bf236a
- Child:
- 157:0d79678ed00f
--- a/src/ConfigurationHandler/Controls/TimerControl.cpp Fri Sep 30 12:27:14 2016 +0000 +++ b/src/ConfigurationHandler/Controls/TimerControl.cpp Fri Sep 30 13:37:47 2016 +0000 @@ -47,15 +47,9 @@ controlFile = _controlFile; id = json_value["id"].get<string>(); output = json_value["output"].get<string>(); - - // create the schedule - Schedule_t s; - s.priority = atol(json_value["priority"].get<string>().c_str()); - s.startTime = atol(json_value["starttime"].get<string>().c_str()); - s.duration = atol(json_value["duration"].get<string>().c_str()); - - // push it on the list - schedule.push_back(s); + priority = atoi(json_value["priority"].get<string>().c_str()); + startTime = atol(json_value["starttime"].get<string>().c_str()); + duration = atoi(json_value["duration"].get<string>().c_str()); return true; } @@ -70,16 +64,6 @@ 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 } // @@ -92,26 +76,16 @@ // bool TimerControl::timerStart(void) { - // schedules should be sorted in order, so always check the first - if ( !schedule.empty() ) { - unsigned long currentTime = time(NULL); - // does it fit? - if ( currentTime < schedule.front().startTime ) { - return false; - } - if ( currentTime >= schedule.front().startTime && - currentTime < (schedule.front().startTime + schedule.front().duration) ) { - logInfo("%s signals feed start", __func__); - return true; - } else { - logInfo("%s: schedule for %s has expired", __func__, id.c_str()); - schedule.erase(schedule.begin()); - this->unregisterControl(); - } + unsigned long currentTime = time(NULL); + + if ( currentTime < startTime ) + return false; + + if ( currentTime >= startTime && currentTime <= (startTime + duration) ) { + return true; } return false; } - // // method: timerStop // description: determines if a running timer should has reached its duration @@ -121,9 +95,7 @@ // bool TimerControl::timerStop(void) { - // if current time is greater than start time + feed duration... - if ( time(NULL) >= (schedule.front().startTime + schedule.front().duration) ) { - logInfo("%s signals a feed stop", __func__); + if ( time(NULL) >= startTime + duration ) { return true; } return false; @@ -149,6 +121,7 @@ if ( this->timerStop() ) { currentState = STATE_OFF; this->stopFeed(); + this->unregisterControl(); } break; case STATE_DISABLED: @@ -174,7 +147,7 @@ output_mail->action = ACTION_CONTROL_ON; output_mail->controlType = CONTROL_TIMER; - output_mail->priority = this->schedule.front().priority; + output_mail->priority = 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); @@ -197,13 +170,13 @@ output_mail->action = ACTION_CONTROL_OFF; output_mail->controlType = CONTROL_TIMER; - output_mail->priority = this->schedule.front().priority; + output_mail->priority = 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); } - + // // Method: unregisterControl // Description: send OFF indication to Output Master for this control's @@ -219,13 +192,13 @@ 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; + + output_mail->action = ACTION_CONTROL_UNREGISTER; + output_mail->controlType = CONTROL_TIMER; + output_mail->priority = 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); } @@ -243,26 +216,13 @@ "DISABLED" }; - printf("\r controlFile : %s \n", controlFile.c_str()); - printf("\r id : %s \n", id.c_str()); - printf("\r output : %s \n", output.c_str()); - - std::vector<Schedule_t>::iterator pos; - - int counter = 0; - if ( schedule.empty() ) { - printf("\r *No scheduled timers\r\n\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\r\n", mapper[currentState].c_str()); + printf("\r controlFile : %s \n", controlFile.c_str()); + printf("\r id : %s \n", id.c_str()); + printf("\r output : %s \n", output.c_str()); + printf("\r priority : %d \n", priority); + printf("\r start time : %lu \n", startTime); + printf("\r duration : %u \n", duration); + printf("\r end time : %lu \n", startTime + duration); + printf("\r expires in : %lu sec \n", (startTime + duration) - time(NULL)); + printf("\r current State : %s\r\n\r\n", mapper[currentState].c_str()); } \ No newline at end of file