Skip to content

Commit

Permalink
Intial implementation of scheduler with task states
Browse files Browse the repository at this point in the history
  • Loading branch information
antara-chugh committed Jul 15, 2024
1 parent 722e78f commit 1a9dcf3
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 15 deletions.
39 changes: 38 additions & 1 deletion src/rideTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ DeploymentSchedule_t deploymentSchedule[] =
{nullptr, nullptr, 0, 0, 0, 0, 0, 0, 0, nullptr, 0, '\0'}
};

int numTask=0;

/**
* @brief initialize ride task
* Sets LEDs and initializes schedule
Expand All @@ -51,7 +53,7 @@ void RideTask::init()


this->startTime = millis();
SCH_initializeSchedule(deploymentSchedule, this->startTime);
this->tasks=SCH_initializeSchedule(deploymentSchedule, numTask, this->startTime);
pSystemDesc->pRecorder->openSession();

}
Expand All @@ -61,7 +63,41 @@ void RideTask::init()
*/
STATES_e RideTask::run(void)
{
while(1){
bool inTask=false;
if(pSystemDesc->pWaterSensor->getLastStatus() ==
WATER_SENSOR_LOW_STATE)
{
SF_OSAL_printf("Out of water!" __NL__);
return STATE_UPLOAD;
}

if(pSystemDesc->flags->batteryLow)
{
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);
}


}

}
return STATE_UPLOAD;

/*
DeploymentSchedule_t* pNextEvent = NULL;
system_tick_t nextEventTime;
Expand Down Expand Up @@ -107,6 +143,7 @@ STATES_e RideTask::run(void)
}
return STATE_UPLOAD;
*/
}


Expand Down
1 change: 1 addition & 0 deletions src/rideTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class RideTask : public Task

LEDStatus ledStatus; /**< manages led behavior*/
system_tick_t startTime; /**< start time at initialization */
Task_* tasks;

};

Expand Down
29 changes: 28 additions & 1 deletion src/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,35 @@
* @param startTime sets start time as given in RideTask.cpp
*
*/
void SCH_initializeSchedule(DeploymentSchedule_t* pDeployment,
//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];
for(int i=0; i<numTask; i++){
DeploymentSchedule_t* deployInfo=pDeployment+i;
int taskStart=startTime;
if(i!=0){
DeploymentSchedule_t* previous=deployInfo-1;
taskStart=(previous->startDelay)+(previous->maxDuration);
}
EnsembleFunction* func=deployInfo->measure;
EnsembleInit* init=deployInfo->init;
task[i]=Task_{deployInfo->taskName,taskStart, deployInfo->ensembleInterval,func, init };


/*
char taskName;
uint32_t nextRunTime;
uint32_t interval;
EnsembleFunction * measure;
EnsembleInit * init;*/


}
return task;

/*
uint32_t lastEndTime = 0;
while (pDeployment->init)
{
Expand All @@ -38,6 +64,7 @@ void SCH_initializeSchedule(DeploymentSchedule_t* pDeployment,
pDeployment->init(pDeployment);
pDeployment++;
}
*/
}


Expand Down
24 changes: 11 additions & 13 deletions src/scheduler.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file scheduler.hpp
* @author Charlie Kushelevsky (ckushelevsky@ucsd.edu)
* @author Antara Chugh ([email protected].edu)
* @brief Header file for scheduler defined in @ref scheduler.cpp
* @version 1
*/
Expand All @@ -27,12 +27,6 @@ typedef enum error_
*/








typedef struct DeploymentSchedule_ DeploymentSchedule_t;

/**
Expand Down Expand Up @@ -62,7 +56,7 @@ typedef void (*EnsembleInit)(DeploymentSchedule_t* pDeployment);
* @param pDeployment the schedule table
*/
typedef void (*EnsembleProccess)(DeploymentSchedule_t* pDeployment);
//might have to be a class

class DeploymentSchedule_
public {

Expand All @@ -72,32 +66,36 @@ public {
//EnsembleProccess process; //!< processing function

uint32_t measurementsToAccumulate; //!< measurements before processing
uint32_t ensembleDelay; //!< delay after deployment start
uint32_t startDelay; //!< delay after deployment start
uint32_t ensembleInterval; //!< time between ensembles

// State information
uint32_t nMeasurements; //!< Total number of measurements to execute
//uint32_t lastMeasurementTime; //!< last time measurement was scheduled
uint32_t deploymentStartTime; //!< when schedule was initialized
//uint32_t deploymentStartTime; //!< when schedule was initialized
//uint32_t measurementCount; //!< how many times ensemble was scheduled
void* pData; //!< Buffer to store measurements temporarily
uint32_t maxDuration; //!< store max running time of measurement
//char taskName; //!< task name of ensemble
char taskName; //!< task name of ensemble
//uint32_t nextRunTime;
};

struct Delay{
uint32_t oldRunTime;
uint32_t newRunTime;
Task_* task;

}
struct Task_{
char taskName;
uint32_t nextRunTime;
uint32_t interval;
Delay delaylist [5];
EnsembleFunction * measure;
EnsembleInit * init;


}

//allocate x amount of event nodes



Expand Down

0 comments on commit 1a9dcf3

Please sign in to comment.