historique and minors changes, get_measure_at, get_measure and put_measure

This commit is contained in:
Aurélien Gauthier 2025-12-09 11:25:40 +01:00
parent 573019aa8b
commit 7cda108dea
4 changed files with 189 additions and 30 deletions

View file

@ -15,10 +15,6 @@ To facilitate the understanding of the storage in the EEPROM see the following i
## Executable files ## Executable files
All executables files are in `exec/` folder. All executables files are in `exec/` folder.
### Time update
Once the arduino is connected to your desktop.
## Tutorial ## Tutorial
In first, you need to mount the arduino (image shown higher in the Readme). In first, you need to mount the arduino (image shown higher in the Readme).

View file

@ -305,7 +305,7 @@ void Storage_interface::set_struct(uint16_t offset, bool timestamp, bool is_fina
set_temp_meas_size(offset, &temp_size); set_temp_meas_size(offset, &temp_size);
} }
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){ 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 p_last_header, free_space; uint16_t p_last_header, free_space;
uint8_t flags; uint8_t flags;

View file

@ -14,7 +14,7 @@ private:
void clear_eeprom_at(uint16_t idx); void clear_eeprom_at(uint16_t idx);
// Getter setter EEPROM header functions /* Getter setter EEPROM header functions */
void inline get_measure_sch(uint16_t header_idx, uint8_t *schedule); 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 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 get_nb_photo_sensor(uint16_t header_idx, uint8_t *nb_photo_sensor);
@ -38,7 +38,7 @@ private:
uint16_t get_idx_package(uint16_t package_number); uint16_t get_idx_package(uint16_t package_number);
void write_csv_header(bool* timestamp, bool* photo_sensor, bool* temp_sensor, uint8_t* nb_photo_sensor, uint8_t* nb_temp_sensor); void write_csv_header(bool* timestamp, bool* photo_sensor, bool* temp_sensor, uint8_t* nb_photo_sensor, uint8_t* nb_temp_sensor);
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 idx_measure); 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);
public: public:
@ -48,9 +48,9 @@ public:
uint16_t get_nb_package(); uint16_t get_nb_package();
void clear_eeprom(); 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_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 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 idx_package, uint16_t idx_measure); 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 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 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);
@ -58,24 +58,29 @@ public:
void upload_csv(); void upload_csv();
// The function dont check if the stored measure structure match with the header // The function dont check if the stored measure structure match with the header
template< typename T, typename TT> // 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){ // 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; // uint16_t p_last_header, free_space, idx, nb_measures;
get_last_header_nbpackage(&p_last_header); // // this->get_last_header_nbpackage(p_last_header);
free_space = EEPROM.read(p_last_header + OFFSET_NEXT_PACKAGE); // free_space = EEPROM.read(p_last_header + OFFSET_NEXT_PACKAGE);
EEPROM.write(p_last_header + OFFSET_NB_MEASURES, EEPROM.read(p_last_header + OFFSET_NB_MEASURES) + 1); // // this->get_next_package(p_last_header, &free_space);
EEPROM.put(free_space, timestamp); // EEPROM.write(p_last_header + OFFSET_NB_MEASURES, EEPROM.read(p_last_header + OFFSET_NB_MEASURES) + 1);
idx = p_last_header + sizeof(uint32_t); // // this->get_nb_measures(p_last_header, &nb_measures);
for(int i = 0; i < nb_photo; i++, idx += sizeof(T)){ // // nb_measures += 1;
EEPROM.put(idx, photo_values[i]); // // this->set_nb_measures(p_last_header, &nb_measures);
}
for(int i = 0; i < nb_temp; i++, idx += sizeof(TT)){ // EEPROM.put(free_space, timestamp);
EEPROM.put(idx, temp_values[i]); // 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 #endif

View file

@ -179,18 +179,172 @@ void test_add_measure(){
} }
} }
void test_put_measure(){ // void test_put_measure(){
// test if the template type work right // Storage_interface test;
// test if values // uint16_t offset = 0, reading_head;
} // uint8_t schedule = 0, nb_photo_sensor = 2, nb_temp_sensor = 1, sizeofuint8 = sizeof(uint8_t);
// // Useless folowing EEPROM.GET, here only for avoid wrong flags of unused variable of reading_head
// EEPROM.get(offset, reading_head);
// 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 photo_val_array[nb_photo_sensor], temp_val_array[nb_temp_sensor];
// for (int i = 0; i < nb_photo_sensor; i++){
// photo_val_array[i] = i;
// }
// for (int i = 0; i < nb_temp_sensor; i++){
// temp_val_array[i] = i;
// }
// test.put_measure(photo_val_array, temp_val_array, epoch, nb_photo_sensor, nb_temp_sensor);
// uint32_t horo;
// EEPROM.get(offset + OFFSET_START_DATA_MEASURES, horo);
// TEST_ASSERT(horo == epoch);
// for (int i = 0, reading_head = offset + OFFSET_START_DATA_MEASURES + sizeof(uint32_t); i < nb_photo_sensor; i++, reading_head += sizeofuint8){
// TEST_ASSERT(EEPROM.read(reading_head) == photo_val_array[i]);
// }
// for (int i = 0, reading_head = offset + OFFSET_START_DATA_MEASURES + sizeof(uint32_t) + sizeofuint8 * nb_photo_sensor; i < nb_temp_sensor; i++, reading_head += sizeofuint8){
// TEST_ASSERT(EEPROM.read(reading_head) == temp_val_array[i]);
// }
// }
void test_get_measure(){ void test_get_measure(){
// Storage_interface test;
uint16_t offset = 0, reading_head;
uint8_t schedule = 0, nb_photo_sensor = 2, nb_temp_sensor = 1, sizeofuint8 = sizeof(uint8_t);
// Useless folowing EEPROM.GET, here only for avoid wrong flags of unused variable of reading_head
EEPROM.get(offset, reading_head);
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 photo_val_array[nb_photo_sensor], temp_val_array[nb_temp_sensor];
for (int i = 0; i < nb_photo_sensor; i++){
photo_val_array[i] = i;
}
for (int i = 0; i < nb_temp_sensor; i++){
temp_val_array[i] = i;
} }
void test_gather_package(){ // test on first measure of the first package
test.add_measure(photo_val_array, temp_val_array, epoch, nb_photo_sensor, nb_temp_sensor);
uint32_t v_epoch;
uint8_t v_photo_val_array[nb_photo_sensor], v_temp_val_array[nb_temp_sensor];
test.get_measure_at(v_photo_val_array, v_temp_val_array, &epoch, &nb_photo_sensor, &nb_temp_sensor, 0, 0);
TEST_ASSERT(v_epoch == epoch);
for (int i = 0, reading_head = offset + OFFSET_START_DATA_MEASURES + sizeof(uint32_t); i < nb_photo_sensor; i++, reading_head += sizeofuint8){
TEST_ASSERT(v_photo_val_array[i] == photo_val_array[i]);
} }
for (int i = 0, reading_head = offset + OFFSET_START_DATA_MEASURES + sizeof(uint32_t) + sizeofuint8 * nb_photo_sensor; i < nb_temp_sensor; i++, reading_head += sizeofuint8){
TEST_ASSERT(v_temp_val_array[i] == temp_val_array[i]);
}
// test on the second measure of the first package
test.add_measure(photo_val_array, temp_val_array, epoch, nb_photo_sensor, nb_temp_sensor);
test.get_measure_at(v_photo_val_array, v_temp_val_array, &epoch, &nb_photo_sensor, &nb_temp_sensor, 1, 2);
TEST_ASSERT(v_epoch == epoch);
for (int i = 0, reading_head = offset + OFFSET_START_DATA_MEASURES + sizeof(uint32_t); i < nb_photo_sensor; i++, reading_head += sizeofuint8){
TEST_ASSERT(v_photo_val_array[i] == photo_val_array[i]);
}
for (int i = 0, reading_head = offset + OFFSET_START_DATA_MEASURES + sizeof(uint32_t) + sizeofuint8 * nb_photo_sensor; i < nb_temp_sensor; i++, reading_head += sizeofuint8){
TEST_ASSERT(v_temp_val_array[i] == temp_val_array[i]);
}
// test on the first measure of the seconde package
test.add_last_package(timestamp, is_final, photo_sensor, temp_sensor, schedule, nb_photo_sensor, nb_temp_sensor, sizeofuint8, sizeofuint8);
test.add_measure(photo_val_array, temp_val_array, epoch, nb_photo_sensor, nb_temp_sensor);
test.get_measure_at(v_photo_val_array, v_temp_val_array, &epoch, &nb_photo_sensor, &nb_temp_sensor, 2, 1);
TEST_ASSERT(v_epoch == epoch);
for (int i = 0, reading_head = offset + OFFSET_START_DATA_MEASURES + sizeof(uint32_t); i < nb_photo_sensor; i++, reading_head += sizeofuint8){
TEST_ASSERT(v_photo_val_array[i] == photo_val_array[i]);
}
for (int i = 0, reading_head = offset + OFFSET_START_DATA_MEASURES + sizeof(uint32_t) + sizeofuint8 * nb_photo_sensor; i < nb_temp_sensor; i++, reading_head += sizeofuint8){
TEST_ASSERT(v_temp_val_array[i] == temp_val_array[i]);
}
}
void test_get_measure_at(){
Storage_interface test;
uint16_t offset = 0, reading_head;
uint8_t schedule = 0, nb_photo_sensor = 2, nb_temp_sensor = 1, sizeofuint8 = sizeof(uint8_t);
// Useless folowing EEPROM.GET, here only for avoid wrong flags of unused variable of reading_head
EEPROM.get(offset, reading_head);
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 photo_val_array[nb_photo_sensor], temp_val_array[nb_temp_sensor];
for (int i = 0; i < nb_photo_sensor; i++){
photo_val_array[i] = i;
}
for (int i = 0; i < nb_temp_sensor; i++){
temp_val_array[i] = i;
}
// test on first measure of the first package
test.add_measure(photo_val_array, temp_val_array, epoch, nb_photo_sensor, nb_temp_sensor);
uint32_t v_epoch;
uint8_t v_photo_val_array[nb_photo_sensor], v_temp_val_array[nb_temp_sensor];
test.get_measure_at(v_photo_val_array, v_temp_val_array, &epoch, &nb_photo_sensor, &nb_temp_sensor, 0, 0);
TEST_ASSERT(v_epoch == epoch);
for (int i = 0, reading_head = offset + OFFSET_START_DATA_MEASURES + sizeof(uint32_t); i < nb_photo_sensor; i++, reading_head += sizeofuint8){
TEST_ASSERT(v_photo_val_array[i] == photo_val_array[i]);
}
for (int i = 0, reading_head = offset + OFFSET_START_DATA_MEASURES + sizeof(uint32_t) + sizeofuint8 * nb_photo_sensor; i < nb_temp_sensor; i++, reading_head += sizeofuint8){
TEST_ASSERT(v_temp_val_array[i] == temp_val_array[i]);
}
// test on the second measure of the first package
test.add_measure(photo_val_array, temp_val_array, epoch, nb_photo_sensor, nb_temp_sensor);
test.get_measure_at(v_photo_val_array, v_temp_val_array, &epoch, &nb_photo_sensor, &nb_temp_sensor, 1, 2);
TEST_ASSERT(v_epoch == epoch);
for (int i = 0, reading_head = offset + OFFSET_START_DATA_MEASURES + sizeof(uint32_t); i < nb_photo_sensor; i++, reading_head += sizeofuint8){
TEST_ASSERT(v_photo_val_array[i] == photo_val_array[i]);
}
for (int i = 0, reading_head = offset + OFFSET_START_DATA_MEASURES + sizeof(uint32_t) + sizeofuint8 * nb_photo_sensor; i < nb_temp_sensor; i++, reading_head += sizeofuint8){
TEST_ASSERT(v_temp_val_array[i] == temp_val_array[i]);
}
// test on the first measure of the seconde package
test.add_last_package(timestamp, is_final, photo_sensor, temp_sensor, schedule, nb_photo_sensor, nb_temp_sensor, sizeofuint8, sizeofuint8);
test.add_measure(photo_val_array, temp_val_array, epoch, nb_photo_sensor, nb_temp_sensor);
test.get_measure_at(v_photo_val_array, v_temp_val_array, &epoch, &nb_photo_sensor, &nb_temp_sensor, 2, 1);
TEST_ASSERT(v_epoch == epoch);
for (int i = 0, reading_head = offset + OFFSET_START_DATA_MEASURES + sizeof(uint32_t); i < nb_photo_sensor; i++, reading_head += sizeofuint8){
TEST_ASSERT(v_photo_val_array[i] == photo_val_array[i]);
}
for (int i = 0, reading_head = offset + OFFSET_START_DATA_MEASURES + sizeof(uint32_t) + sizeofuint8 * nb_photo_sensor; i < nb_temp_sensor; i++, reading_head += sizeofuint8){
TEST_ASSERT(v_temp_val_array[i] == temp_val_array[i]);
}
}
void setup(void) void setup(void)
@ -201,8 +355,12 @@ void setup(void)
//WARNING: Tests are not exhaustive and do not cover all possibilities. //WARNING: Tests are not exhaustive and do not cover all possibilities.
int main( int argc, char **argv) { int main( int argc, char **argv) {
UNITY_BEGIN(); UNITY_BEGIN();
RUN_TEST(test_get_measure);
RUN_TEST(test_get_measure_at);
RUN_TEST(test_add_measure); RUN_TEST(test_add_measure);
RUN_TEST(test_get_struct); RUN_TEST(test_get_struct);
RUN_TEST(test_set_struct); RUN_TEST(test_set_struct);
// RUN_TEST(test_put_measure);
UNITY_END(); UNITY_END();
} }