discoLight
Loading...
Searching...
No Matches
SWE4211RPi::PeriodicTask Class Referenceabstract
Inheritance diagram for SWE4211RPi::PeriodicTask:
Collaboration diagram for SWE4211RPi::PeriodicTask:

Public Member Functions

 PeriodicTask (std::string threadName, uint32_t period, int priority=1)
 
virtual ~PeriodicTask ()
 
virtual void taskMethod ()=0
 
virtual void setTaskPeriod (uint32_t period) final
 
virtual uint32_t getTaskPeriod () final
 
void run () final
 
virtual void printInformation ()
 
virtual double getCPUUsageInfo ()
 
virtual void resetThreadDiagnostics ()
 
- Public Member Functions inherited from SWE4211RPi::RunnableClass
 RunnableClass (std::string threadName, int priority=0)
 
virtual ~RunnableClass ()
 
virtual pid_t getThreadID ()
 
virtual void start () final
 
virtual void setPriority (int priority) final
 
virtual int getPriority () final
 
virtual bool isShutdown () final
 
virtual bool isStarted () final
 
virtual void stopThreadExecution ()
 
virtual void waitForShutdown ()
 

Protected Member Functions

virtual void startChildRunnables () final
 
virtual void stopChildRunnables () final
 
virtual void startChildTasks ()
 
virtual void stopChildTasks ()
 

Protected Attributes

uint32_t taskPeriod = 100000
 
- Protected Attributes inherited from SWE4211RPi::RunnableClass
std::thread * myThread = NULL
 
pthread_t executingThread = 0
 
pid_t myOSThreadID = 0
 
std::string myName
 
bool keepGoing = true
 
bool runCompleted = false
 
bool runStarted = false
 
int priority = -1
 

Private Member Functions

void invokeRun ()
 
void waitForNextExecution (std::chrono::microseconds remainingSleepTime)
 
void waitForNextExecution (struct timespec sleepTime)
 

Private Attributes

long worstCaseExecutionTime = 0
 
long lastExecutionTime = 0
 
long missedDeadlineCount = 0
 
long lastWallTime = 0
 
long worstCaseWallTime = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from SWE4211RPi::RunnableClass
static void printThreads ()
 
static void resetAllThreadInformation ()
 
- Static Protected Attributes inherited from SWE4211RPi::RunnableClass
static std::list< RunnableClass * > runningThreads
 

Constructor & Destructor Documentation

◆ PeriodicTask()

PeriodicTask::PeriodicTask ( std::string  threadName,
uint32_t  period,
int  priority = 1 
)

This is the default constructor for the class.

Parameters
threadNameThis is the name of the thread in a human readable format.
periodThis is the period for the task, given in microseconds. Must be at least 100 microseconds.
Here is the call graph for this function:

◆ ~PeriodicTask()

PeriodicTask::~PeriodicTask ( )
virtual

This method will clean up from the periodic task and its execution.

Nothing to be done in the destructor.

Member Function Documentation

◆ getCPUUsageInfo()

double PeriodicTask::getCPUUsageInfo ( )
virtual

This method will obtain the CPU usage. CPU usage is the worst case measured execution time divided by the period.

Returns
The CPU usage will be returned.

This method will return the CPU usage for the given task. The usage will be as a percentage value.

Reimplemented from SWE4211RPi::RunnableClass.

Here is the caller graph for this function:

◆ getTaskPeriod()

uint32_t PeriodicTask::getTaskPeriod ( )
finalvirtual

This method will return the task period.

Returns
the Task period in microseconds will be returned.
Here is the caller graph for this function:

◆ invokeRun()

void SWE4211RPi::PeriodicTask::invokeRun ( )
private

This is a private method that will be used by start to invoke the run method.

◆ printInformation()

void PeriodicTask::printInformation ( )
virtual

This method will print out information about the given thread. The info will be dependent upon the given thread.

Reimplemented from SWE4211RPi::RunnableClass.

Here is the call graph for this function:

◆ resetThreadDiagnostics()

void PeriodicTask::resetThreadDiagnostics ( )
virtual

This method will reset thread diagnostics back to their default values. The wall times and CPU times will be set to 0.

This method will reset thread diagnostics back to their default values.

Reimplemented from SWE4211RPi::RunnableClass.

◆ run()

void PeriodicTask::run ( )
finalvirtual

This is the run method for the class.

This is a private method that will be used by start to invoke the run method.

Set keep going to be true, to indicate that the thread is to continue running.

The following gets the wall time, for determining next execution time.

Obtain the cpu time at the start of this periodic task. This is for CPU time measurement.

Now run the task. Call the task method.

Now get the end CPU time entry.

Determine where we are in terms of the worst case execution time.

Now figure out exactly what time it is to schedule the next execution.

Figure out how long to sleep.

Sleep until the next execution should occur.

Implements SWE4211RPi::RunnableClass.

Here is the call graph for this function:

◆ setTaskPeriod()

void PeriodicTask::setTaskPeriod ( uint32_t  period)
finalvirtual

This will set the period for the given task.

Parameters
periodThis is the period, given in microseconds, between executions of this task. However, it must be at least 100 microseconds (.1 ms)

Set the task period to the parameter passed in if it is greater than or equal to 100.

Here is the caller graph for this function:

◆ startChildRunnables()

void PeriodicTask::startChildRunnables ( )
finalprotectedvirtual

This method will start up any runnable objects which are contained within a class that implements the RUnnable interface. If there are no other objects that are runnable, there is no need to override this method. However, if a child class contains an instance of a runnable object, then this method must be overridden in the derived class.

Reimplemented from SWE4211RPi::RunnableClass.

Here is the call graph for this function:

◆ startChildTasks()

void PeriodicTask::startChildTasks ( )
protectedvirtual

This method will start up any runnable objects which are contained within a class that implements the RUnnable interface. If there are no other objects that are runnable, there is no need to override this method. However, if a child class contains an instance of a runnable object, then this method must be overridden in the derived class.

Here is the caller graph for this function:

◆ stopChildRunnables()

void PeriodicTask::stopChildRunnables ( )
finalprotectedvirtual

This method will stop any runnable objects which are contained within a class that implements the Runnable interface. If there are no other objects that are runnable, there is no need to override this method. However, if a child class contains an instance of a runnable object, then this method must be overridden in the derived class.

Reimplemented from SWE4211RPi::RunnableClass.

Here is the call graph for this function:

◆ stopChildTasks()

void PeriodicTask::stopChildTasks ( )
protectedvirtual

This method will stop any runnable objects which are contained within a class that implements the RUnnable interface. If there are no other objects that are runnable, there is no need to override this method. However, if a child class contains an instance of a runnable object, then this method must be overridden in the derived class.

Here is the caller graph for this function:

◆ taskMethod()

virtual void SWE4211RPi::PeriodicTask::taskMethod ( )
pure virtual

This is the task method. The task method will be invoked periodically every taskPeriod units of time.

Implemented in SWE4211RPi::PulsedGPIOPin, and LightController.

Here is the caller graph for this function:

◆ waitForNextExecution() [1/2]

void PeriodicTask::waitForNextExecution ( std::chrono::microseconds  remainingSleepTime)
private

This method will suspend execution until the next period has been reached. It will do this by blocking.

Sleep for the given amount of time.

Here is the caller graph for this function:

◆ waitForNextExecution() [2/2]

void PeriodicTask::waitForNextExecution ( struct timespec  sleepTime)
private

This method will suspend execution until the next period has been reached. It will do this by blocking.

Sleep for the given amount of time.

Member Data Documentation

◆ lastExecutionTime

long SWE4211RPi::PeriodicTask::lastExecutionTime = 0
private

This variable holds the last execution value for the CPU, showing the time it took to execute.

◆ lastWallTime

long SWE4211RPi::PeriodicTask::lastWallTime = 0
private

This variable holds the last wall time measurement for the given periodic task. The wall time is the time from the start to the end of the task running.

◆ missedDeadlineCount

long SWE4211RPi::PeriodicTask::missedDeadlineCount = 0
private

This variable will hold the count as to how many times the deadline was missed for the given system.

◆ taskPeriod

uint32_t SWE4211RPi::PeriodicTask::taskPeriod = 100000
protected

This variable sets the period for the task. The period defines the length of time from one invocation until the next invocation. The task period is given in microseconds. Default value is 100 ms or 100000 microseconds.

◆ worstCaseExecutionTime

long SWE4211RPi::PeriodicTask::worstCaseExecutionTime = 0
private

This variable stores the worst case execution time from a CPU time standpoint.

◆ worstCaseWallTime

long SWE4211RPi::PeriodicTask::worstCaseWallTime = 0
private

This variable holds the worst case wall time. This is the worst case from start to finish of the given periodic task.


The documentation for this class was generated from the following files: