mirror of
https://gitlab.com/Luci_/arduino-photometrics.git
synced 2026-04-03 11:35:37 +02:00
87 lines
4.6 KiB
C++
87 lines
4.6 KiB
C++
#ifndef STORAGE_INTERFACE_H
|
|
#define STORAGE_INTERFACE_H
|
|
#include <Arduino.h>
|
|
#include <EEPROM.h>
|
|
|
|
// based on https://docs.arduino.cc/learn/programming/eeprom-guide/
|
|
|
|
class Storage_interface
|
|
{
|
|
private:
|
|
|
|
static constexpr uint8_t OFFSET_MEASURES_SCH = 1, OFFSET_NB_PHOTO_SENSOR = 2, OFFSET_NB_TEMP_SENSOR = 3, OFFSET_PHOTO_MEASURES_SIZE = 4, OFFSET_TEMP_MEASURES_SIZE = 5, OFFSET_NB_MEASURES = 6, OFFSET_NEXT_PACKAGE = 8, OFFSET_START_DATA_MEASURES = 10; // unit in byte
|
|
static constexpr uint16_t MEGA_2560_EEPROM_SIZE = 4096;
|
|
|
|
void clear_eeprom_at(uint16_t idx);
|
|
|
|
/* Getter setter EEPROM header functions */
|
|
void inline get_measure_sch(uint16_t header_idx, uint8_t *schedule);
|
|
void inline set_measure_sch(uint16_t header_idx, uint8_t *schedule);
|
|
void inline get_nb_photo_sensor(uint16_t header_idx, uint8_t *nb_photo_sensor);
|
|
void inline set_nb_photo_sensor(uint16_t header_idx, uint8_t *nb_photo_sensor);
|
|
void inline get_nb_temp_sensor(uint16_t header_idx, uint8_t *nb_temp_sensor);
|
|
void inline set_nb_temp_sensor(uint16_t header_idx, uint8_t *nb_temp_sensor);
|
|
void inline get_photo_meas_size(uint16_t header_idx, uint8_t *photo_meas_size);
|
|
void inline set_photo_meas_size(uint16_t header_idx, uint8_t *photo_meas_size);
|
|
void inline get_temp_meas_size(uint16_t header_idx, uint8_t *temp_meas_siz);
|
|
void inline set_temp_meas_size(uint16_t header_idx, uint8_t *temp_meas_size);
|
|
void inline get_nb_measures(uint16_t header_idx, uint16_t *nb_measures);
|
|
void inline set_nb_measures(uint16_t header_idx, uint16_t *nb_measures);
|
|
void inline get_next_package(uint16_t header_idx, uint16_t *next_package);
|
|
void inline set_next_package(uint16_t header_idx, uint16_t *next_package);
|
|
|
|
// Following commented function are uncessary for now
|
|
// void inline get_start_data_measure(uint16_t header_idx, uint16_t *start_data_measure);
|
|
// void inline set_start_data_measure(uint16_t header_idx, uint16_t *start_data_measure);
|
|
|
|
uint16_t get_last_header_nbpackage(uint16_t* last_header_idx);
|
|
uint16_t get_idx_package(uint16_t package_number);
|
|
void get_measure(uint8_t* array_photo_val, uint8_t* array_temp_val, uint32_t* timestamp, uint8_t* nb_photo, uint8_t* nb_temp, uint16_t measure_number);
|
|
|
|
void write_csv_header(bool* timestamp, bool* photo_sensor, bool* temp_sensor, uint8_t* nb_photo_sensor, uint8_t* nb_temp_sensor);
|
|
|
|
|
|
public:
|
|
|
|
Storage_interface();
|
|
~Storage_interface();
|
|
|
|
uint16_t get_nb_package();
|
|
void clear_eeprom();
|
|
void add_last_package(bool timestamp, bool is_final_set, bool photo_sensor, bool temp_sensor, uint8_t timestamp_schedule, uint8_t nb_photo_sensor, uint8_t nb_temp_sensor, uint8_t photo_size, uint8_t temp_size);
|
|
void add_measure(uint8_t* photo_values, uint8_t* temp_values, uint32_t timestamp, uint8_t nb_photo, uint8_t nb_temp);
|
|
void get_measure_at(uint8_t* array_photo_val, uint8_t* array_temp_val, uint32_t* timestamp, uint8_t* nb_photo, uint8_t* nb_temp, uint16_t package_number, uint16_t measure_number);
|
|
|
|
void get_struct(uint16_t offset, bool* timestamp, bool* is_final_set, bool* photo_sensor, bool* temp_sensor, uint8_t* timestamp_schedule, uint8_t* nb_photo_sensor, uint8_t* nb_temp_sensor, uint8_t* photo_size, uint8_t* temp_size, uint16_t* p_next_package, uint16_t* nb_measures);
|
|
void set_struct(uint16_t offset, bool timestamp, bool is_final_set, bool photo_sensor, bool temp_sensor, uint8_t timestamp_schedule, uint8_t nb_photo_sensor, uint8_t nb_temp_sensor, uint8_t photo_size, uint8_t temp_size);
|
|
|
|
void upload_csv();
|
|
|
|
|
|
// The function dont check if the stored measure structure match with the header
|
|
// template< typename T, typename TT>
|
|
// void put_measure(T* photo_values, TT* temp_values, uint32_t timestamp, uint8_t nb_photo, uint8_t nb_temp){
|
|
// uint16_t p_last_header, free_space, idx, nb_measures;
|
|
|
|
// // this->get_last_header_nbpackage(p_last_header);
|
|
|
|
// free_space = EEPROM.read(p_last_header + OFFSET_NEXT_PACKAGE);
|
|
// // this->get_next_package(p_last_header, &free_space);
|
|
|
|
// EEPROM.write(p_last_header + OFFSET_NB_MEASURES, EEPROM.read(p_last_header + OFFSET_NB_MEASURES) + 1);
|
|
// // this->get_nb_measures(p_last_header, &nb_measures);
|
|
// // nb_measures += 1;
|
|
// // this->set_nb_measures(p_last_header, &nb_measures);
|
|
|
|
// EEPROM.put(free_space, timestamp);
|
|
// idx = p_last_header + sizeof(uint32_t);
|
|
// for(int i = 0; i < nb_photo; i++, idx += sizeof(T)){
|
|
// EEPROM.put(idx, photo_values[i]);
|
|
// }
|
|
// for(int i = 0; i < nb_temp; i++, idx += sizeof(TT)){
|
|
// EEPROM.put(idx, temp_values[i]);
|
|
// }
|
|
// }
|
|
};
|
|
|
|
#endif |