diff --git a/src/rideTask.cpp b/src/rideTask.cpp index 6a50b0d8..acdd947b 100644 --- a/src/rideTask.cpp +++ b/src/rideTask.cpp @@ -34,7 +34,7 @@ DeploymentSchedule_t deploymentSchedule[] = {nullptr, nullptr, 0, 0, 0, 0, 0, 0, 0, nullptr, 0, '\0'} }; -int numTask=0; + /** * @brief initialize ride task @@ -53,7 +53,9 @@ void RideTask::init() this->startTime = millis(); - this->tasks=SCH_initializeSchedule(deploymentSchedule, numTask, this->startTime); + numTask=3; //does this need to be changed? + s=Scheduler(deploymentSchedule, numTask, startTime); + pSystemDesc->pRecorder->openSession(); } @@ -65,6 +67,7 @@ STATES_e RideTask::run(void) { while(1){ bool inTask=false; + if(pSystemDesc->pWaterSensor->getLastStatus() == WATER_SENSOR_LOW_STATE) { @@ -77,22 +80,8 @@ STATES_e RideTask::run(void) SF_OSAL_printf("Low Battery!" __NL__); return STATE_DEEP_SLEEP; } - for(int i=0;inextRunTime){ - inTask=true; - &(task->measure); - task->nextRunTime+=task->interval; - } - if(millis()>task->nextRunTime){ - inTask=true; - int delay=millis()-(task->nextRunTime); - Delay delay={task->nextRunTime, millis(), task}; - task->nextRunTime+=(task->interval + delay); - } - - - } + SCH_runSchedule(tasks, numTask); + s.SCH_runSchedule(); } return STATE_UPLOAD; diff --git a/src/rideTask.hpp b/src/rideTask.hpp index 09345544..1b9a4736 100644 --- a/src/rideTask.hpp +++ b/src/rideTask.hpp @@ -36,7 +36,8 @@ class RideTask : public Task LEDStatus ledStatus; /**< manages led behavior*/ system_tick_t startTime; /**< start time at initialization */ - Task_* tasks; + int numTask; + Scheduler s; }; diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 723285a3..35e84310 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -25,32 +25,78 @@ * */ //pDeployment is pointer to array with deployment schedules for all tasks, ordered by priority -Task_* SCH_initializeSchedule(DeploymentSchedule_t* pDeployment, int numTask; - system_tick_t startTime) -{ - Task_ task[numTask]; +Scheduler::Scheduler(DeploymentSchedule_ d[], int num, int startTime){ + numTask=num; for(int i=0; istartDelay)+(previous->maxDuration); + DeploymentSchedule_t previous=d[i-1]; + taskStart=(previous.startDelay)+(previous.maxDuration); } - EnsembleFunction* func=deployInfo->measure; - EnsembleInit* init=deployInfo->init; - task[i]=Task_{deployInfo->taskName,taskStart, deployInfo->ensembleInterval,func, init }; + EnsembleFunction* func=deployInfo.measure; + EnsembleInit* init=deployInfo.init; + task[i]=Task_{deployInfo.taskName,taskStart, deployInfo.ensembleInterval,func, init}; + } + numDelays=0; + totalDelay=0; + +} +void Scheduler::SCH_runSchedule(){ + for(int i=0;i=(int)millis()){ + int n=i-1; + //check for an overlap, can change to only check for IMU + while(n>=0){ + if(((int)millis()+ task.interval)>task[n].nextRunTime){ + break; + } + n--; + + } + if(n>0){ + break; + } + if((int)millis()==task.nextRunTime){ + inTask=true; + &(task.measure); //change + task.nextRunTime+=task.interval; + }else if((int)millis()>task.nextRunTime){ + inTask=true; + int delay=(int)millis()-(task.nextRunTime); + //set FLOG + task.nextRunTime+=(task.interval + delay); + numDelays++; + totalDelay+=(unsigned long)delay; + } + } + + + } - /* - char taskName; - uint32_t nextRunTime; - uint32_t interval; - EnsembleFunction * measure; - EnsembleInit * init;*/ + +} + +void SCH_initializeSchedule(DeploymentSchedule_t pDeployment[], int numTask, Task_ task[], + system_tick_t startTime) +{ + + for(int i=0; i=(int)millis()){ + int n=i-1; + //check for an overlap, can change to only check for IMU + while(n>=0){ + if(((int)millis()+ task.interval)>tasks[n].nextRunTime){ + break; + } + n--; + + } + if(n>0){ + break; + } + if((int)millis()==task.nextRunTime){ + inTask=true; + &(task.measure); //change + task.nextRunTime+=task.interval; + }else if((int)millis()>task.nextRunTime){ + inTask=true; + int delay=(int)millis()-(task.nextRunTime); + //set FLOG + task.nextRunTime+=(task.interval + delay); + } + } + + + } + + + + +} + + + /** @@ -90,7 +174,7 @@ Task_* SCH_initializeSchedule(DeploymentSchedule_t* pDeployment, int numTask; * TASK_SEARCH_FAIL otherwise. */ -uint32_t SCH_getNextEvent(DeploymentSchedule_t* scheduleTable, +/*uint32_t SCH_getNextEvent(DeploymentSchedule_t* scheduleTable, DeploymentSchedule_t** p_nextEvent, system_tick_t* p_nextTime, system_tick_t currentTime) { @@ -208,7 +292,7 @@ uint32_t SCH_getNextEvent(DeploymentSchedule_t* scheduleTable, * @param nextStartTime The proposed start time of the current task. * @return True if there is an overlap with another task; false otherwise. */ -bool SCH_willOverlap(DeploymentSchedule_t* scheduleTable, int idx, +/*bool SCH_willOverlap(DeploymentSchedule_t* scheduleTable, int idx, system_tick_t currentTime, uint32_t nextStartTime) { DeploymentSchedule_t& currentEvent = scheduleTable[idx]; @@ -233,5 +317,5 @@ bool SCH_willOverlap(DeploymentSchedule_t* scheduleTable, int idx, } return false; -} +} */ diff --git a/src/scheduler.hpp b/src/scheduler.hpp index 15d0dc87..562172d2 100644 --- a/src/scheduler.hpp +++ b/src/scheduler.hpp @@ -57,8 +57,8 @@ typedef void (*EnsembleInit)(DeploymentSchedule_t* pDeployment); */ typedef void (*EnsembleProccess)(DeploymentSchedule_t* pDeployment); -class DeploymentSchedule_ -public { +struct DeploymentSchedule_ + { int priority; EnsembleFunction measure; //!< measurement function @@ -96,6 +96,22 @@ struct Task_{ } +class Scheduler{ + + public: + Scheduler(DeploymentSchedule_ d[], int num, int startTime); + + void SCH_runSchedule(); + + private: + int numTasks; + Tasks_ task[numTask]; + int numDelays; + unsigned long totalDelay; + + +} + @@ -107,6 +123,7 @@ struct Task_{ */ void SCH_initializeSchedule(DeploymentSchedule_t* scheduleTable, system_tick_t startTime); +void SCH_runSchedule(Tasks_ tasks[], int numTask); /** * @brief sets next scheduled task and time @@ -140,5 +157,6 @@ uint32_t SCH_getNextEvent(DeploymentSchedule_t* scheduleTable, */ bool SCH_willOverlap(DeploymentSchedule_t* scheduleTable, int i, system_tick_t currentTime, uint32_t nextStartTime); + #endif //__SCHEDULER__HPP_