-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e42fc03
commit 22eddf5
Showing
15 changed files
with
192 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,93 @@ | ||
/** | ||
* @file scheduler.cpp | ||
* @brief Contains definitions for functions defined in @ref scheduler.hpp | ||
* @author Charlie Kushelevsky ([email protected]) | ||
* @version 1 | ||
*/ | ||
|
||
#ifndef TEST_VERSION | ||
#include "Particle.h" | ||
#else | ||
#include "scheduler_test_system.hpp" | ||
#endif | ||
#include "cli/conio.hpp" | ||
|
||
#include "ensembles.hpp" | ||
#include "antara_scheduler.hpp" | ||
#include "consts.hpp" | ||
#include "product.hpp" | ||
#include <cli/flog.hpp> | ||
#include <string.h> | ||
|
||
|
||
#if SCHEDULER_VERSION == ANTARA_VERSION | ||
Scheduler:: Scheduler(DeploymentSchedule_t schedule[]){ | ||
Scheduler::Scheduler(DeploymentSchedule_t schedule[], int numTasks) | ||
{ | ||
SF_OSAL_printf("Using Antara's Version\n"); | ||
tasks=schedule; | ||
|
||
int i=0; | ||
for(; tasks[i].measure; i++){ | ||
if(i=0){ | ||
tasks[i].startDelay=0; | ||
}else { | ||
if(i!=0){ | ||
tasks[i].startDelay=(tasks[i-1].startDelay)+(tasks[i-1].maxDuration); | ||
tasks = schedule; | ||
this->numTasks = numTasks; | ||
|
||
for (int i = 0; i < numTasks; i++) | ||
{ | ||
if (i == 0) | ||
{ | ||
tasks[i].startDelay = 0; | ||
} | ||
else | ||
{ | ||
tasks[i].startDelay = tasks[i - 1].startDelay + tasks[i - 1].maxDuration; | ||
} | ||
|
||
} | ||
int numTasks=i-1; | ||
|
||
} | ||
|
||
|
||
int Scheduler:: getNextTask(const DeploymentSchedule_t* p_next_task, std::uint32_t* p_next_runtime, std::uint32_t current_time){ | ||
|
||
//check in reverse order, return if possible | ||
int i=numTasks; | ||
|
||
while(i>0){ | ||
bool canSet=true; | ||
int runTime=tasks[i].nextRunTime; | ||
int delay=current_time-tasks[i].nextRunTime; | ||
if(delay>0){ | ||
runTime=current_time; | ||
}else{ | ||
delay=0; | ||
} | ||
if(delay==tasks[i].maxDelay){ | ||
p_next_task=&(tasks[i]); | ||
tasks[i].nextRunTime+=delay+tasks[i].ensembleInterval; | ||
return runTime; | ||
} | ||
int completion=runTime+tasks[i].ensembleInterval; | ||
int j=0; | ||
while(j<i && canSet){ | ||
if(tasks[j].nextRunTime<completion){ | ||
canSet=false; | ||
} | ||
j++; | ||
|
||
} | ||
if(canSet){ | ||
p_next_task=&(tasks[i]); | ||
tasks[i].nextRunTime+=delay+tasks[i].ensembleInterval; | ||
return runTime; | ||
|
||
int Scheduler::getNextTask(DeploymentSchedule_t **p_next_task, std::uint32_t *p_next_runtime, std::uint32_t current_time) | ||
{ | ||
int i = numTasks - 1; | ||
|
||
while (i >= 0) | ||
{ | ||
bool canSet = true; | ||
int runTime = tasks[i].nextRunTime; | ||
int delay = current_time - tasks[i].nextRunTime; | ||
if (delay > 0) | ||
{ | ||
runTime = current_time; | ||
} | ||
else | ||
{ | ||
delay = 0; | ||
} | ||
if (delay == tasks[i].maxDelay) | ||
{ | ||
*p_next_task = &(tasks[i]); | ||
tasks[i].nextRunTime += delay + tasks[i].ensembleInterval; | ||
return runTime; | ||
} | ||
int completion = runTime + tasks[i].ensembleInterval; | ||
int j = 0; | ||
while (j < i && canSet) | ||
{ | ||
if (tasks[j].nextRunTime < completion) | ||
{ | ||
canSet = false; | ||
} | ||
|
||
|
||
i--; | ||
|
||
j++; | ||
} | ||
if (canSet) | ||
{ | ||
*p_next_task = &(tasks[i]); | ||
tasks[i].nextRunTime += delay + tasks[i].ensembleInterval; | ||
return runTime; | ||
} | ||
|
||
p_next_task=&(tasks[0]); | ||
int runTime=tasks[0].nextRunTime; | ||
int delay=current_time-(tasks[0].nextRunTime); | ||
if(delay>0){ | ||
runTime=current_time; | ||
}else{ | ||
delay=0; | ||
} | ||
tasks[0].nextRunTime+=delay+tasks[0].ensembleInterval; | ||
|
||
return runTime; | ||
i--; | ||
} | ||
|
||
*p_next_task = &(tasks[0]); | ||
int runTime = tasks[0].nextRunTime; | ||
int delay = current_time - (tasks[0].nextRunTime); | ||
if (delay > 0) | ||
{ | ||
runTime = current_time; | ||
} | ||
else | ||
{ | ||
delay = 0; | ||
} | ||
tasks[0].nextRunTime += delay + tasks[0].ensembleInterval; | ||
|
||
return runTime; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
#include "product.hpp" | ||
#if SCHEDULER_VERSION == ANTARA_VERSION | ||
#ifndef __SCHEDULER__HPP__ | ||
#define __SCHEDULER__HPP__ | ||
#include "abstractScheduler.hpp" | ||
#include "deploymentSchedule.hpp" | ||
struct DeploymentSchedule_ | ||
{ | ||
// Ensemble properties | ||
int priority; | ||
void (*measure)(); //!< measurement function | ||
void (*init)(); //!< initialization function | ||
// EnsembleProccess process; //!< processing function | ||
uint32_t startDelay; //!< delay after deployment start | ||
uint32_t ensembleInterval; //!< time between ensembles | ||
// void* pData; //!< Buffer to store measurements temporarily | ||
uint32_t maxDuration; //!< store max running time of measurement | ||
char taskName; //!< task name of ensemble | ||
uint32_t maxDelay; | ||
|
||
class Scheduler : public AbstractScheduler{ | ||
// State Information | ||
uint32_t nextRunTime; | ||
}; | ||
|
||
DeploymentSchedule_t * tasks; | ||
int numTasks; | ||
public: | ||
Scheduler(DeploymentSchedule_t schedule[]); | ||
int getNextTask(const DeploymentSchedule_t* p_next_task, | ||
std::uint32_t* p_next_runtime, | ||
std::uint32_t current_time); | ||
class Scheduler : public AbstractScheduler | ||
{ | ||
DeploymentSchedule_t *tasks; | ||
int numTasks; | ||
|
||
}; | ||
public: | ||
Scheduler(DeploymentSchedule_t schedule[], int numTasks); | ||
int getNextTask(DeploymentSchedule_t **p_next_task, | ||
std::uint32_t *p_next_runtime, | ||
std::uint32_t current_time); | ||
}; | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.