change storage interface struct, test file in progress and will change

This commit is contained in:
Aurélien Gauthier 2025-12-01 15:09:50 +01:00
parent 9268d1ab11
commit 2447fe2065
4 changed files with 94 additions and 21 deletions

View file

@ -96,14 +96,14 @@ uint16_t Storage_interface::get_nb_package(){
}
void Storage_interface::get_store_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 Storage_interface::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){
uint8_t flags;
flags = EEPROM.read(offset);
// Checking there if a struct is possibly at the index
if ((flags & 0b1) == 0){
DLOGLN("Missing struct index or bad index")
while(true);
//while(true);
}
// timestamps reads
@ -139,22 +139,33 @@ void Storage_interface::get_store_struct(uint16_t offset, bool* timestamp, bool*
*nb_measures = read_eeprom_uint16(offset + OFFSET_NB_TEMP_SENSOR);
}
void Storage_interface::set_store_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){
uint8_t flags = 0;
void Storage_interface::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){
clear_eeprom_at(offset);
uint8_t flags = 0b00000000;
// Existing package flag for function package searcher
flags = flags | 0b10000000;
const uint8_t TIMESTAMP_MASK = 0b01100000;
flags = flags & (~TIMESTAMP_MASK);
// Timestamp init struct
if(timestamp_schedule != 0){
if (timestamp && (timestamp_schedule == 0)) {
flags = flags | 0b01000000;
EEPROM.write(offset + OFFSET_MEASURES_SCH, 0); // Écrire 0 si pas de schedule
}
else if (timestamp_schedule != 0) {
flags = flags | 0b00100000;
EEPROM.write(offset + OFFSET_MEASURES_SCH, timestamp_schedule);
WARN_IF(!timestamp, "Bad timestamp parameter for header writer.")
}else{
EEPROM.write(offset + OFFSET_MEASURES_SCH, 0);
if (timestamp)
flags = flags | 0b01000000;
WARN_IF(!timestamp, "Redundant/conflicting timestamp parameter (expected true for schedule).")
}
else {
EEPROM.write(offset + OFFSET_MEASURES_SCH, 0);
}
// Sensor part
if (photo_sensor){
@ -187,7 +198,7 @@ void Storage_interface::set_store_struct(uint16_t offset, bool timestamp, bool i
// write flags header
EEPROM.write(offset , flags);
clear_eeprom_at(offset + OFFSET_START_DATA_MEASURES);
//clear_eeprom_at(offset + OFFSET_START_DATA_MEASURES);
}
void Storage_interface::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, uint16_t nb_measures){
@ -202,7 +213,7 @@ void Storage_interface::add_last_package(bool timestamp, bool is_final_set, bool
EEPROM.write(p_last_header , flags);
free_space = EEPROM.read(p_last_header + OFFSET_NEXT_PACKAGE);
set_store_struct(free_space, timestamp, is_final_set, photo_sensor, temp_sensor, timestamp_schedule, nb_photo_sensor, nb_temp_sensor, photo_size, temp_size);
set_struct(free_space, timestamp, is_final_set, photo_sensor, temp_sensor, timestamp_schedule, nb_photo_sensor, nb_temp_sensor, photo_size, temp_size);
}
// Dont check if the stored measure structure match with the header

View file

@ -12,12 +12,8 @@ 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();
void clear_eeprom_at(uint16_t idx);
void get_store_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_store_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 get_last_header_nbpackage(uint16_t* last_header_idx);
public:
@ -26,10 +22,14 @@ public:
~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, uint16_t nb_measures);
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(uint8_t* photo_values, uint8_t* temp_values, uint32_t* timestamp, uint8_t* nb_photo, uint8_t* nb_temp, uint16_t idx_measure);
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);
// Dont check if the stored measure structure match with the header
template< typename T, typename TT>

View file

@ -13,6 +13,7 @@ platform = atmelavr
board = megaADK
framework = arduino
test_framework = unity
;upload_port = /dev/ttyACM0
build_flags =
-std=gnu++17
-I lib/
@ -20,5 +21,4 @@ lib_deps =
northernwidget/DS3231@^1.1.2
arduino-libraries/Ethernet
robtillaart/CRC
lib_ldf_mode = deep+

View file

@ -1,12 +1,74 @@
#include <Arduino.h>
#include <unity.h>
#include "storage_interface.h"
#include <EEPROM.h>
void setUp(void)
// uint32_t epoch = 1764249314;
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 test_put_get_struct(){
Storage_interface test;
uint16_t offset = 0, r_next_package, r_nb_measures;
uint8_t schedule = 0, nb_photo_sensor = 2, nb_temp_sensor = 1, sizeofuint8 = sizeof(uint8_t);
bool timestamp = true, is_final = true, photo_sensor = true, temp_sensor = true;
test.set_struct(offset, timestamp, is_final, photo_sensor, temp_sensor, schedule, nb_photo_sensor, nb_temp_sensor, sizeofuint8, sizeofuint8);
uint8_t r_schedule, r_nb_photo_sensor, r_nb_temp_sensor, r_sizeofuint8;
bool r_timestamp, r_is_final, r_photo_sensor, r_temp_sensor;
uint8_t flags;
flags = EEPROM.read(offset);
// if package flag right set
TEST_ASSERT((flags & 0b10000000) != 0);
// test schedule flags
TEST_ASSERT((flags & 0b01000000)!= 0);
TEST_ASSERT(!((flags & 0b00100000) != 0));
// test schedule
TEST_ASSERT(EEPROM.read(offset + OFFSET_MEASURES_SCH) == 0);
TEST_ASSERT((flags & 0b00000100) != 0);
// test.get_struct(offset, &r_timestamp, &r_is_final, &r_photo_sensor, &r_temp_sensor, &r_schedule, &r_nb_photo_sensor, &r_nb_temp_sensor, &r_sizeofuint8, &r_sizeofuint8, &r_next_package, &r_nb_measures);
// Serial.println(r_nb_,DEC);
// if(r_is_final){
// TEST_FAIL_MESSAGE("true");
// }else{
// TEST_FAIL_MESSAGE("false");
// }
// TEST_ASSERT(r_is_final == is_final);
// TEST_ASSERT(r_nb_measures == 0);
// TEST_ASSERT(r_timestamp == timestamp);
// TEST_ASSERT(r_photo_sensor == photo_sensor);
// TEST_ASSERT(r_temp_sensor == temp_sensor);
// TEST_ASSERT(r_schedule == schedule);
// TEST_ASSERT(r_nb_photo_sensor == nb_photo_sensor);
// TEST_ASSERT(r_nb_temp_sensor == nb_temp_sensor);
// TEST_ASSERT(r_sizeofuint8 == sizeofuint8);
}
void test(){
bool yes = true;
TEST_ASSERT(yes);
}
void setup(void)
{
Serial.begin(9600);
}
void test_put_struct(){
}
int main( int argc, char **argv) {
UNITY_BEGIN();
//RUN_TEST(test);
RUN_TEST(test_put_get_struct);
UNITY_END();
}