-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCacheMeasurementRecorder.hpp
105 lines (85 loc) · 3.52 KB
/
CacheMeasurementRecorder.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef CacheMeasurementRecorder_H_
#define CacheMeasurementRecorder_H_
#include "Device/Interfaces/IMeasurementRecorder.hpp"
#include "Device/Interfaces/IMeasurementReader.hpp"
#include "Device/Inc/MeasurementDeviceId.hpp"
#include <array>
#include <cstdint>
namespace Device
{
class CacheMeasurementRecorder : public IMeasurementRecorder, public IMeasurementReader
{
public:
/**
* @brief Deleted default constructor to prevent instantiation without a driver.
*/
CacheMeasurementRecorder() = default;
/**
* @brief Default destructor for CacheMeasurementRecorder.
*/
~CacheMeasurementRecorder() override = default;
/**
* @brief Deleted copy constructor to prevent copying.
*/
CacheMeasurementRecorder(const CacheMeasurementRecorder &) = delete;
/**
* @brief Deleted assignment operator to prevent assignment.
* @return CacheMeasurementRecorder& The assigned object.
*/
CacheMeasurementRecorder &operator=(const CacheMeasurementRecorder &) = delete;
/**
* @brief Notifies the recorder to process new data.
*
* This method is called to notify the recorder that new measurement data is available and
* should be sent to the ESP module via UART.
*/
bool notify(Device::MeasurementType &measurement) override;
protected:
/**
* @brief Initializes the CacheMeasurementRecorder.
*
* This method is responsible for initializing the recorder, preparing it for operation.
* @return True if initialization was successful, false otherwise.
*/
bool onInitialize() override;
/**
* @brief Starts the CacheMeasurementRecorder.
*
* This method starts the recorder, enabling it to begin sending measurement data via UART.
* @return True if the recorder started successfully, false otherwise.
*/
bool onStart() override;
/**
* @brief Stops the CacheMeasurementRecorder.
*
* This method stops the recorder, halting any further transmission of measurement data.
* @return True if the recorder stopped successfully, false otherwise.
*/
bool onStop() override;
/**
* @brief Resets the CacheMeasurementRecorder.
*
* This method resets the recorder, clearing any internal state or buffers.
* @return True if the recorder was reset successfully, false otherwise.
*/
bool onReset() override;
/**
* @brief Flushes any remaining data to the ESP module.
*
* This method ensures that any remaining measurement data is sent to the ESP module via UART.
*/
bool flush() override;
[[nodiscard]] std::uint32_t getLatestMeasurement(Device::MeasurementDeviceId source) const override;
private:
/**
* @brief Writes the measurement data to the ESP module via UART.
*
* This method sends the prepared measurement data to the ESP module for transmission over WiFi.
*/
virtual bool write(Device::MeasurementType &measurement);
static constexpr std::size_t MeasurementSourceCount = static_cast<std::size_t>(MeasurementDeviceId::LAST_NOT_USED);
// Map to store the last measurements for each source
std::array<std::uint32_t, MeasurementSourceCount> lastMeasurement = {0u};
};
}
#endif // CacheMeasurementRecorder_H_