2024-05-30 11:07:10 +02:00

73 lines
1.8 KiB
C++

#ifndef STA_UTILS_LOGGER_HPP
#define STA_UTILS_LOGGER_HPP
#include <sta/drivers/w25qxx.hpp>
#include <sta/debug/assert.hpp>
#include <cstring>
namespace sta
{
template <typename T>
class Logger
{
public:
/**
* @brief Construct a new Logger object
*
* @param flash
* @param startAddr
* @param endAddr
*/
Logger(W25Qxx * flash, uint32_t startSector, uint32_t endSector);
/**
* @brief Write a new data point to the flash chip.
* @note If the total capacity of this logger was exceeded, it restarts at the first sector, overwriting its data.
*
* @param data The data to write to the flash chip.
*/
void write(T data);
/**
* @brief Clear the flash memory used by the logger.
*
*/
void clear();
/**
* @brief Get the number of data points currently written to the memory segment.
*
* @return size_t The number of data points.
*/
size_t occupied();
/**
* @brief Get the number of data points that can be written to the logger before an overflow occurs.
*
* @return size_t The number of data points.
*/
size_t remaining();
/**
* @brief Get the total number of data points that fit into the logger.
*
* @return size_t The number of data points.
*/
size_t length();
const T& operator[](std::size_t idx);
private:
W25Qxx * flash_;
uint32_t start_;
uint32_t end_;
uint32_t address_;
uint8_t buffer_[W25QXX_PAGE_SIZE];
uint8_t ptr_;
};
} // namespace sta
#include <sta/utils/logger.tpp>
#endif // STA_UTILS_LOGGER_HPP