Skip to content

Commit

Permalink
chore: implemented changes from last review
Browse files Browse the repository at this point in the history
  • Loading branch information
charliekush committed Aug 23, 2024
1 parent d00f4b9 commit 258972f
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 191 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: add googletest
run: |
git submodule init
git submodule update
git submodule --recursive update
Expand Down
3 changes: 2 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"includePath": [
"${workspaceFolder}/src",
"${workspaceFolder}/tests",
"${workspaceFolder}/src/cli"
"${workspaceFolder}/src/cli",
"${workspaceFolder}/external/googletest/googletest/include"
],
"defines": [
"_DEBUG",
Expand Down
21 changes: 0 additions & 21 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
{
"version": "0.2.0",
"configurations": [

{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${workspaceRoot}/tests"
},
{
"name": "Semantic Release",
"type": "debugpy",
"request": "launch",
"program": "semantic_release_prepare.py",
"console": "integratedTerminal",
"args": [
"1.2.3",
"37-feat-semver",
"src/vers.hpp"
]
},
{
"type": "cortex-debug",
"request": "attach",
Expand Down
1 change: 1 addition & 0 deletions src/abstractScheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstdint>
#include <cstdint>
#include <cli/flog.hpp>

#include "deploymentSchedule.hpp"

typedef enum error_
Expand Down
14 changes: 7 additions & 7 deletions src/rideTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
* @brief Contains definitions for functions defined in @ref rideTask.hpp
* @version 1
*/


#include "rideTask.hpp"
#include "Particle.h"
#include <time.h>
#include "cli/conio.hpp"
#include "consts.hpp"

#include "system.hpp"
#include "sleepTask.hpp"
#include "cli/conio.hpp"
#include "util.hpp"
#include "vers.hpp"
#include "ensembles.hpp"
#include "cli/flog.hpp"
#include "charlie_scheduler.hpp"
#include "antara_scheduler.hpp"
#include "system.hpp"
#include "sleepTask.hpp"
#include "scheduler.hpp"

#include <time.h>

/**
* @brief creates file name for log
* @todo implement RIDE_setFileName
Expand Down
9 changes: 6 additions & 3 deletions src/rideTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
#ifndef __RIDE_HPP__
#define __RIDE_HPP__
#include "task.hpp"

#include "Particle.h"
#include "product.hpp"


#include <Particle.h>


/**
* @class RideTask
* @brief Manages deployment of measurements and recording
Expand All @@ -33,8 +35,9 @@ class RideTask : public Task
*/
void exit(void);
private:
//! TODO: implement LEDStatus
//LEDStatus ledStatus; //!< manages led behavior

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

};
Expand Down
139 changes: 75 additions & 64 deletions src/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,49 @@
* @author Charlie Kushelevsky ([email protected])
* @version 1
*/
#include "scheduler.hpp"
#include "cli/conio.hpp"
#include "ensembles.hpp"
#include "consts.hpp"
#include "cli/flog.hpp"

#include <cstdint>
#include <string.h>

#ifndef TEST_VERSION
#include "Particle.h"
#else
#include "scheduler_test_system.hpp"
#endif
#include <cstdint>
#include "cli/conio.hpp"
#include "ensembles.hpp"
#include "scheduler.hpp"
#include "consts.hpp"
#include <cli/flog.hpp>
#include <string.h>


/**
* @brief constructor for scheduler
*
* @param schedule the schedule table
*/
Scheduler::Scheduler(DeploymentSchedule_t schedule[])
: scheduleTable(schedule){}
/**
* @brief Initializes ensembles within schedule table.
*
*/
: scheduleTable(schedule) {}
/**
* @brief Initializes ensembles within schedule table.
*
*/
void Scheduler::initializeScheduler()
{
DeploymentSchedule_t* pDeployment = scheduleTable;
uint32_t lastEndTime = 0;
DeploymentSchedule_t* pDeployment = this->scheduleTable;
std::uint32_t lastEndTime = 0;
tableSize = 0;
if (this->scheduleTable == nullptr)
{
return;
}
while (pDeployment->init)
{
tableSize++;
memset(&(pDeployment->state), 0,
sizeof(StateInformation));

memset(&(pDeployment->state), 0,
sizeof(StateInformation));

pDeployment->init(pDeployment);
tableSize++;
pDeployment++;
}
}
Expand All @@ -49,36 +59,35 @@ void Scheduler::initializeScheduler()
* 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
* @see tests/googletests.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.
*
* @param currentTime The current system time
* @return Returns SUCCESS if a suitable event is found,
* TASK_SEARCH_FAIL otherwise.
*/

SCH_error_e Scheduler::getNextTask(DeploymentSchedule_t** p_nextEvent,
SCH_error_e Scheduler::getNextTask(DeploymentSchedule_t** p_nextEvent,
std::uint32_t* p_nextTime,
std::uint32_t currentTime)
{
uint32_t minNextTime = UINT32_MAX;
std::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--)

// Iterate through each event in the schedule table in reverse order.

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;
StateInformation& currentEventState = scheduleTable[idx].state;
std::uint32_t runTime = currentEventState.nextRunTime;
int delay = currentTime - runTime;
if (delay > 0)
{
Expand All @@ -90,58 +99,60 @@ SCH_error_e Scheduler::getNextTask(DeploymentSchedule_t** p_nextEvent,
}
if (delay >= currentEvent.maxDelay)
{
//send warning
//! TODO: send warning
}
int completion = runTime + currentEvent.maxDuration;
int expected_completion = runTime + currentEvent.maxDuration;
int j = 0;
while (j < idx && canSet)
for (int j = 0; (j < idx) && canSet; j++)
{
if (scheduleTable[j].state.nextRunTime < completion)
if (scheduleTable[j].state.nextRunTime < expected_completion)
{
canSet = false;
}
j++;
}
if (canSet)
{
*p_nextEvent = &currentEvent;
state.nextRunTime = runTime + currentEvent.ensembleInterval;

state.measurementCount++;
*p_nextTime = runTime;
if(delay>0){
currentEventState.nextRunTime = runTime +
currentEvent.ensembleInterval;

currentEventState.measurementCount++;

if (delay > 0)
{
FLOG_AddError(FLOG_SCHEDULER_DELAY_EXCEEDED,
state.measurementCount);
#ifdef TEST_VERSION
std::ofstream logfile;
if (currentTime == 0)
{
logfile = std::ofstream("scheduler.log");
}
else
{
logfile = std::ofstream("scheduler.log", std::ios::app);
}
if (logfile.is_open())
{
logfile << currentEvent.taskName
<< "|"
<< state.measurementCount
<<"\n";
logfile.close();
}
#endif
currentEventState.measurementCount);
#ifdef TEST_VERSION
std::ofstream logfile;
if (currentTime == 0)
{
logfile = std::ofstream("scheduler.log");

}
else
{
logfile = std::ofstream("scheduler.log", std::ios::app);
}
if (logfile.is_open())
{
logfile << currentEvent.taskName
<< "|"
<< currentEventState.measurementCount
<< "\n";
logfile.close();
}
#endif

}
return SCHEDULER_SUCCESS;
}





}

return TASK_SEARCH_FAIL;
return TASK_SEARCH_FAIL;

}

Expand Down
Loading

0 comments on commit 258972f

Please sign in to comment.