Skip to content

Commit

Permalink
Merge pull request #177 from RobertGawron/feature/storage_implementation
Browse files Browse the repository at this point in the history
add dev and ut for measurement data handling
  • Loading branch information
RobertGawron authored Dec 17, 2024
2 parents 06e4110 + 918f014 commit 4dd73a0
Show file tree
Hide file tree
Showing 34 changed files with 1,015 additions and 179 deletions.
9 changes: 7 additions & 2 deletions DevOps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,18 @@ Note: If using Windows, [MobaXterm](https://mobaxterm.mobatek.net/download-home-

cd /workspace/build/ && cmake .. && make -j24

cd /workspace/Test/SystemTests
cd /workspace/Test/System
python3 -m venv /workspace/venv
pytest test_display.py -s --html=report.html


after:
cd /workspace/build/ && cmake .. && make -j24 && cd /workspace/Test/SystemTests && pytest test_display.py -s --html=report.html
cd /workspace/build/ && cmake .. && make -j24 && cd /workspace/Test/System && pytest test_display.py -s --html=report.html



cd /workspace/build/ && cmake .. && make -j24 && cd /workspace/Test/System && pytest test_pulse_counter.py -s --html=report.html




Expand Down
24 changes: 24 additions & 0 deletions Documentation/Diagrams/TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@startuml
state "Idle" as IDLE
state "Initialize" as INIT
state "Run" as RUN
state "Sleep" as SLEEP
state "Fault" as FAULT
state "Power Off" as POWER_OFF

[*] --> IDLE : Power On
IDLE --> INIT : onInitialize()
INIT --> RUN : Initialization Complete

RUN --> SLEEP : onStop()
SLEEP --> RUN : onStart()

RUN --> FAULT : Fault Detected
FAULT --> INIT : Recover and Reinitialize

RUN --> POWER_OFF : onPowerOff()
SLEEP --> POWER_OFF : onPowerOff()
FAULT --> POWER_OFF : Emergency Shutdown

POWER_OFF --> [*] : Power Down Complete
@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@

#include "Driver/Interfaces/IPulseCounterDriver.hpp"

extern "C"
{
void incrementPulseCounter(std::uint8_t counterId);
}

namespace Driver
{
class PulseCounterDriverStub : public IPulseCounterDriver
{
public:
static const std::uint8_t PULSE_COUNTER_AMOUNT = 4u;

explicit PulseCounterDriverStub(PulseCounterIdentifier id);

explicit PulseCounterDriverStub();

virtual ~PulseCounterDriverStub() = default;
Expand All @@ -17,6 +26,9 @@ namespace Driver
PulseCounterDriverStub(const PulseCounterDriverStub &) = delete;
PulseCounterDriverStub &operator=(const PulseCounterDriverStub &) = delete;

IPulseCounterDriver::CounterSizeType getMeasurement() override;
void clearMeasurement() override;

bool onInitialize() override;

bool onStart() override;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
#include "PulseCounterDriverStub.hpp"

#include <cstdint>
#include <array>

#include <stdio.h>

// Declare a std::array to store pulse counts
static std::array<Driver::PulseCounterDriverStub::CounterSizeType, Driver::PulseCounterDriverStub::PULSE_COUNTER_AMOUNT> pulseCounters = {0};

// Expose the array pointer for C compatibility
extern "C"
{

// C-compatible function to increment a specific counter
void incrementPulseCounter(std::uint8_t counterId)
{
if (counterId < Driver::PulseCounterDriverStub::PULSE_COUNTER_AMOUNT)
{
pulseCounters[counterId]++;
}
}
}

namespace Driver
{
PulseCounterDriverStub::PulseCounterDriverStub()
Expand All @@ -25,4 +47,15 @@ namespace Driver
{
return true;
}

IPulseCounterDriver::CounterSizeType PulseCounterDriverStub::getMeasurement()
{
// printf("PulseCounterDriverStub::getMeasurement()\n");
return 5;
}

void PulseCounterDriverStub::clearMeasurement()
{
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "UartDriverStub.hpp"
#include <stdio.h>
#include <cstddef>

namespace Driver
{
Expand All @@ -25,9 +27,12 @@ namespace Driver

UartExchangeStatus UartDriverStub::transmit(std::uint8_t *data, std::uint16_t size, std::uint32_t timeout)
{
(void)data; // Mark data as unused
(void)size; // Mark size as unused
(void)timeout; // Mark timeout as unused

for (std::size_t i = 0u; i < size; i++)
{
printf("TX %d ", data[i]);
}
printf("\n");

return UartExchangeStatus::Ok;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#ifndef MeasurementCoordinator_h
#define MeasurementCoordinator_h

#include <cstdint>
#include "Device/Interfaces/IMeasurementSource.hpp"
#include "BusinessLogic/Inc/MeasurementDataStore.hpp"
#include "BusinessLogic/Interfaces/IMeasurementDataStore.hpp"
#include "BusinessLogic/Inc/SaferArray.hpp"
#include "Device/Interfaces/IMeasurementSource.hpp"
#include <cstdint>

namespace BusinessLogic
{
Expand All @@ -32,7 +32,7 @@ namespace BusinessLogic
*
* @param storage Reference to a MeasurementDataStore object that handles the storage of measurement data.
*/
explicit MeasurementCoordinator(MeasurementDataStore &storage);
explicit MeasurementCoordinator(IMeasurementDataStore &storage);

/**
* @brief Deleted default constructor to prevent instantiation without a storage reference.
Expand Down Expand Up @@ -75,14 +75,6 @@ namespace BusinessLogic
*/
virtual bool tick();

/**
* @brief Updates measurements from all registered input devices.
*
* This function queries all registered measurement sources for new data, processes it,
* and ensures the data is ready to be stored.
*/
void updateMeasurements();

/**
* @brief Registers an input device observer to be periodically queried for measurement data.
*
Expand All @@ -107,6 +99,14 @@ namespace BusinessLogic
bool removeObserver(Device::IMeasurementSource &observer);

private:
/**
* @brief Updates measurements from all registered input devices.
*
* This function queries all registered measurement sources for new data, processes it,
* and ensures the data is ready to be stored.
*/
void updateMeasurements();

/** @brief Maximum number of observers that can be registered. */
static const std::uint8_t MaxObservers{5u};

Expand All @@ -118,7 +118,7 @@ namespace BusinessLogic
*
* This member is responsible for notifying the storage objects when new measurement data is ready.
*/
MeasurementDataStore &storage;
IMeasurementDataStore &storage;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#ifndef MeasurementDataStore_H_
#define MeasurementDataStore_H_

#include "Device/Interfaces/IMeasurementRecorder.hpp"
#include "BusinessLogic/Interfaces/IMeasurementDataStore.hpp"
#include "BusinessLogic/Inc/SaferArray.hpp"
#include "Device/Interfaces/IMeasurementRecorder.hpp"
#include <cstdint>

namespace BusinessLogic
Expand All @@ -22,7 +23,7 @@ namespace BusinessLogic
* It is responsible for initializing and notifying all registered observers when new
* measurement data is ready.
*/
class MeasurementDataStore
class MeasurementDataStore : public IMeasurementDataStore
{
public:
/**
Expand All @@ -33,7 +34,7 @@ namespace BusinessLogic
/**
* @brief Destructor for MeasurementDataStore.
*/
~MeasurementDataStore() = default;
~MeasurementDataStore() override = default;

/**
* @brief Deleted copy constructor to prevent copying.
Expand All @@ -55,7 +56,7 @@ namespace BusinessLogic
* @param observer Reference to an object that implements IMeasurementRecorder.
* @return True if the observer was successfully added; false otherwise.
*/
bool addObserver(Device::IMeasurementRecorder &observer);
bool addObserver(Device::IMeasurementRecorder &observer) override;

/**
* @brief Removes an observer that records measurement data.
Expand All @@ -67,7 +68,7 @@ namespace BusinessLogic
* @return True if the observer was successfully removed; false otherwise.
* @note Removing the observer does not automatically deinitialize it.
*/
bool removeObserver(Device::IMeasurementRecorder &observer);
bool removeObserver(Device::IMeasurementRecorder &observer) override;

/**
* @brief Initializes the MeasurementDataStore and all registered observers.
Expand All @@ -78,7 +79,7 @@ namespace BusinessLogic
* @return True if initialization was successful; false otherwise.
* @note Observers should not be initialized manually in other classes such as ApplicationBuilder.
*/
bool initialize();
bool initialize() override;

/**
* @brief Starts the MeasurementDataStore and all registered observers.
Expand All @@ -88,15 +89,15 @@ namespace BusinessLogic
*
* @return True if start was successful; false otherwise.
*/
bool start();
bool start() override;

/**
* @brief Notifies all registered observers that new measurement data is ready to be stored.
*
* This function iterates through the list of registered observers and notifies each one
* that new measurement data is available for storage.
*/
void notifyObservers();
bool notifyObservers(Device::MeasurementType measurement) override;

private:
/** @brief Maximum number of observers that can be registered. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* @file IMeasurementDataStore.hpp
* @brief Defines the IMeasurementDataStore class which manages the storage of measurement data
* using the observer pattern.
*/

#ifndef IMeasurementDataStore_H_
#define IMeasurementDataStore_H_

#include "BusinessLogic/Inc/SaferArray.hpp"
#include "Device/Interfaces/IMeasurementRecorder.hpp"
#include "Device/Interfaces/IMeasurementSource.hpp"
#include <cstdint>

namespace BusinessLogic
{
/**
* @class IMeasurementDataStore
* @brief Implements the observer pattern to manage a collection of measurement recorders.
*
* This class allows clients to add or remove observers that store measurement data.
* Observers can represent different storage methods such as SD card, Wi-Fi, UART, etc.
* It is responsible for initializing and notifying all registered observers when new
* measurement data is ready.
*/
class IMeasurementDataStore
{
public:
/**
* @brief Default constructor for IMeasurementDataStore.
*/
explicit IMeasurementDataStore() = default;

/**
* @brief Destructor for IMeasurementDataStore.
*/
virtual ~IMeasurementDataStore() = default;

/**
* @brief Deleted copy constructor to prevent copying.
*/
IMeasurementDataStore(const IMeasurementDataStore &) = delete;

/**
* @brief Deleted assignment operator to prevent assignment.
* @return IMeasurementDataStore& The assigned object.
*/
IMeasurementDataStore &operator=(const IMeasurementDataStore &) = delete;

/**
* @brief Adds an observer that records measurement data.
*
* The observer should implement the IMeasurementRecorder interface, and this method will
* add it to the list of observers managed by the IMeasurementDataStore.
*
* @param observer Reference to an object that implements IMeasurementRecorder.
* @return True if the observer was successfully added; false otherwise.
*/
virtual bool addObserver(Device::IMeasurementRecorder &observer) = 0;

/**
* @brief Removes an observer that records measurement data.
*
* This method removes an observer from the list of registered observers, stopping it
* from receiving updates about new measurement data.
*
* @param observer Reference to an object that implements IMeasurementRecorder.
* @return True if the observer was successfully removed; false otherwise.
* @note Removing the observer does not automatically deinitialize it.
*/
virtual bool removeObserver(Device::IMeasurementRecorder &observer) = 0;

/**
* @brief Initializes the IMeasurementDataStore and all registered observers.
*
* This function initializes the IMeasurementDataStore and all the objects
* registered via addObserver().
*
* @return True if initialization was successful; false otherwise.
* @note Observers should not be initialized manually in other classes such as ApplicationBuilder.
*/
virtual bool initialize() = 0;

/**
* @brief Starts the IMeasurementDataStore and all registered observers.
*
* This function starts the IMeasurementDataStore and prepares all registered observers to start
* recording measurement data.
*
* @return True if start was successful; false otherwise.
*/
virtual bool start() = 0;

/**
* @brief Notifies all registered observers that new measurement data is ready to be stored.
*
* This function iterates through the list of registered observers and notifies each one
* that new measurement data is available for storage.
*/
virtual bool notifyObservers(Device::MeasurementType measurement) = 0;
};
}

#endif // IMeasurementDataStore_H_
Loading

0 comments on commit 4dd73a0

Please sign in to comment.