Skip to content

Commit

Permalink
Finished run schedule logic, reorganized code, need to set delays to …
Browse files Browse the repository at this point in the history
…FLOG and test
  • Loading branch information
antara-chugh committed Jul 16, 2024
1 parent 1a9dcf3 commit d4a88bf
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 41 deletions.
25 changes: 7 additions & 18 deletions src/rideTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

}
Expand All @@ -65,6 +67,7 @@ STATES_e RideTask::run(void)
{
while(1){
bool inTask=false;

if(pSystemDesc->pWaterSensor->getLastStatus() ==
WATER_SENSOR_LOW_STATE)
{
Expand All @@ -77,22 +80,8 @@ STATES_e RideTask::run(void)
SF_OSAL_printf("Low Battery!" __NL__);
return STATE_DEEP_SLEEP;
}
for(int i=0;i<numTask; i++){
Task_* task= tasks+i;
if(millis()==task->nextRunTime){
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;
Expand Down
3 changes: 2 additions & 1 deletion src/rideTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

};

Expand Down
124 changes: 104 additions & 20 deletions src/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<numTask; i++){
DeploymentSchedule_t* deployInfo=pDeployment+i;
DeploymentSchedule_t deployInfo=d[i];
int taskStart=startTime;
if(i!=0){
DeploymentSchedule_t* previous=deployInfo-1;
taskStart=(previous->startDelay)+(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<numTask; i++){
Task_ task=task[i];
if(task.nextRunTime>=(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<numTask; i++){
DeploymentSchedule_t deployInfo=pDeployment[i];
int taskStart=startTime;
if(i!=0){
DeploymentSchedule_t previous=pDeployment[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};


}
return task;


/*
uint32_t lastEndTime = 0;
Expand All @@ -67,6 +113,44 @@ Task_* SCH_initializeSchedule(DeploymentSchedule_t* pDeployment, int numTask;
*/
}

void SCH_runSchedule(Tasks_ tasks[], int numTask){
for(int i=0;i<numTask; i++){
Task_ task=tasks[i];
if(task.nextRunTime>=(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);
}
}


}




}





/**
Expand All @@ -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)
{
Expand Down Expand Up @@ -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];
Expand All @@ -233,5 +317,5 @@ bool SCH_willOverlap(DeploymentSchedule_t* scheduleTable, int idx,
}
return false;
}
} */

22 changes: 20 additions & 2 deletions src/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;


}




Expand All @@ -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
Expand Down Expand Up @@ -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_

0 comments on commit d4a88bf

Please sign in to comment.