-
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
5f2f6a6
commit 310d33c
Showing
8 changed files
with
287 additions
and
22 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/** | ||
* @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 "scheduler.hpp" | ||
#include "consts.hpp" | ||
#include <cli/flog.hpp> | ||
#include <string.h> | ||
|
||
|
||
#if SCHEDULER_VERSION == CONSOLODATED_VERSION | ||
Scheduler::Scheduler(DeploymentSchedule_t schedule[]) | ||
: scheduleTable(schedule){} | ||
/** | ||
* @brief Initializes ensembles within schedule table. | ||
* | ||
*/ | ||
void Scheduler::initializeScheduler() | ||
{ | ||
DeploymentSchedule_t* pDeployment = scheduleTable; | ||
uint32_t lastEndTime = 0; | ||
tableSize = 0; | ||
while (pDeployment->init) | ||
{ | ||
tableSize++; | ||
memset(&(pDeployment->state), 0, | ||
sizeof(StateInformation)); | ||
pDeployment->state.lastMeasurementTime = UINT32_MAX; | ||
pDeployment->init(pDeployment); | ||
pDeployment++; | ||
} | ||
} | ||
|
||
|
||
|
||
/** | ||
* @brief Retrieves the next schedu2led event | ||
* | ||
* This function iterates through a schedule table to find the event that | ||
* should run next based on the current system time. | ||
* It ensures that no overlapping events are scheduled by checking with | ||
* @ref SCH_willOverlap(). | ||
* | ||
* @see tests/gtest.cpp for intended behavior | ||
* | ||
* @param scheduleTable Pointer to the first element of an array of | ||
* DeploymentSchedule_t, which contains the scheduling information. | ||
* @param p_nextEvent Pointer to a pointer where the next event to be executed | ||
* will be stored. | ||
* @param p_nextTime Pointer to where the time for the next event will | ||
* be stored. | ||
* | ||
* @return Returns SUCCESS if a suitable event is found, | ||
* TASK_SEARCH_FAIL otherwise. | ||
*/ | ||
|
||
int Scheduler::getNextTask(DeploymentSchedule_t** p_nextEvent, | ||
std::uint32_t* p_nextTime, | ||
std::uint32_t currentTime) | ||
{ | ||
uint32_t minNextTime = UINT32_MAX; | ||
DeploymentSchedule_t* nextEvent = nullptr; | ||
|
||
// Iterate through each event in the schedule table. | ||
|
||
for(int idx = tableSize - 1; idx>=0; idx--) | ||
{ | ||
bool canSet = true; | ||
DeploymentSchedule_t& currentEvent = scheduleTable[idx]; | ||
StateInformation& state = scheduleTable[idx].state; | ||
std::uint32_t runTime = state.nextRunTime; | ||
int delay = currentTime - runTime; | ||
if (delay > 0) | ||
{ | ||
runTime = currentTime; | ||
} | ||
else | ||
{ | ||
delay = 0; | ||
} | ||
if (delay == currentEvent.maxDelay) | ||
{ | ||
//send warning | ||
} | ||
int completion = runTime + currentEvent.maxDuration; | ||
int j = 0; | ||
while (j < idx && canSet) | ||
{ | ||
if (scheduleTable[j].state.nextRunTime < completion) | ||
{ | ||
canSet = false; | ||
} | ||
j++; | ||
} | ||
if (canSet) | ||
{ | ||
*p_nextEvent = ¤tEvent; | ||
state.nextRunTime = runTime + currentEvent.ensembleInterval; | ||
|
||
state.measurementCount++; | ||
*p_nextTime = runTime; | ||
if(delay>0){ | ||
FLOG_AddError(FLOG_SCHEDULER_DELAY_EXCEEDED, | ||
state.measurementCount); | ||
SF_OSAL_printf("Task %s shifted at time %zu" __NL__ , | ||
currentEvent.taskName,currentTime); | ||
} | ||
return SUCCESS; | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
return TASK_SEARCH_FAIL; | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
#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 |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/** | ||
* @file charlie_scheduler.hpp | ||
* @author Charlie Kushelevsky ([email protected]) | ||
* @brief Header file for scheduler defined in @ref scheduler.cpp | ||
* @version 1 | ||
*/ | ||
#ifndef __CONSOLODATED_SCHEDULER__HPP__ | ||
#define __CHARLIE_SCHEDULER__HPP__ | ||
#include "product.hpp" | ||
#if SCHEDULER_VERSION == CONSOLODATED_VERSION | ||
|
||
#include <stddef.h> | ||
#include <cstdint> | ||
|
||
#include "deploymentSchedule.hpp" | ||
#include "abstractScheduler.hpp" | ||
#include "cli/conio.hpp" | ||
#ifndef TEST_VERSION | ||
#include "Particle.h" | ||
#else | ||
#include "scheduler_test_system.hpp" | ||
#endif | ||
|
||
|
||
/** | ||
* @brief Ensemble function. | ||
* | ||
* This function executes once to update the ensemble state. This should update | ||
* the accumulators with a new measurement. If the accumulators have | ||
* accumulated the proper amount of data, this function should then record the | ||
* proper data. | ||
* | ||
* Essentially, this will be called every ensembleInterval ms after | ||
* ensembleDelay ms from the start of the deployment. | ||
* | ||
* @param pDeployment the schedule table | ||
*/ | ||
typedef void (*EnsembleFunction)(DeploymentSchedule_t* pDeployment); | ||
/** | ||
* @brief Ensemble initialization function. | ||
* | ||
* This function is executed once when all of the | ||
* @param pDeployment the schedule table | ||
*/ | ||
typedef void (*EnsembleInit)(DeploymentSchedule_t* pDeployment); | ||
/** | ||
* @brief contains stat information for each ensemble | ||
*/ | ||
|
||
struct StateInformation | ||
{ | ||
//! how many times ensemble was scheduled | ||
uint32_t measurementCount; | ||
|
||
//! store the next time the task should run | ||
uint32_t nextRunTime; | ||
|
||
|
||
}; | ||
/** | ||
* @brief Records and writes ensemble | ||
* @param pDeployment the schedule table | ||
*/ | ||
typedef void (*EnsembleProccess)(DeploymentSchedule_t* pDeployment); | ||
struct DeploymentSchedule_ | ||
{ | ||
|
||
EnsembleFunction measure; //!< measurement function | ||
EnsembleInit init; //!< initialization function | ||
//EnsembleProccess process; //!< processing function | ||
|
||
uint32_t measurementsToAccumulate; //!< measurements before processing | ||
uint32_t ensembleDelay; //!< delay after deployment start | ||
uint32_t ensembleInterval; //!< time between ensembles | ||
//! store max running time of measurement | ||
uint32_t maxDuration; | ||
//! maximum delay before throwing flag and resetting | ||
uint32_t maxDelay; | ||
//! task name of ensemble | ||
const char* taskName; | ||
//! state information | ||
StateInformation state; | ||
|
||
|
||
}; | ||
|
||
class Scheduler : public AbstractScheduler { | ||
private: | ||
uint32_t tableSize; | ||
public: | ||
DeploymentSchedule_t* scheduleTable; | ||
|
||
|
||
|
||
|
||
Scheduler(DeploymentSchedule_t* scheduler); | ||
|
||
/** | ||
* @brief Initializes ensemble variables | ||
* | ||
* @param scheduleTable the schedule table | ||
* @param startTime the start time of the deployment | ||
*/ | ||
void initializeScheduler(); | ||
|
||
/** | ||
* @brief Determines if a task will overlap with other scheduled tasks. | ||
* | ||
* This function checks if the proposed start and end times of a task | ||
* overlap with any other tasks in the schedule table. It ensures that | ||
* tasks are scheduled without conflicts. | ||
* | ||
* @param scheduleTable The table containing all scheduled tasks. | ||
* @param idx The index of the current task in the schedule table. | ||
* @param currentTime The current system time. | ||
* @param nextStartTime The proposed start time of the current task. | ||
* @return True if there is an overlap with another task; false otherwise. | ||
*/ | ||
int getNextTask(DeploymentSchedule_t** p_next_task, | ||
uint32_t* p_next_runtime, | ||
uint32_t current_time); | ||
|
||
bool willOverlap(uint32_t i, system_tick_t currentTime, | ||
uint32_t nextStartTime); | ||
|
||
}; | ||
|
||
typedef enum error_ | ||
{ | ||
SUCCESS, | ||
TASK_SEARCH_FAIL, | ||
}SCH_error_e; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
#endif | ||
|
||
#endif //__CHARLIE_SCHEDULER__HPP__ |
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