diff --git a/README.md b/README.md index 31e6f38..47bd12f 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,6 @@ To facilitate the understanding of the storage in the EEPROM see the following i ## Executable files All executables files are in `exec/` folder. -### Time update -Once the arduino is connected to your desktop. - - ## Tutorial In first, you need to mount the arduino (image shown higher in the Readme). diff --git a/lib/storage/storage_interface.cpp b/lib/storage/storage_interface.cpp index 7c56257..8e0c966 100644 --- a/lib/storage/storage_interface.cpp +++ b/lib/storage/storage_interface.cpp @@ -305,7 +305,7 @@ void Storage_interface::set_struct(uint16_t offset, bool timestamp, bool is_fina 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; uint8_t flags; diff --git a/lib/storage/storage_interface.h b/lib/storage/storage_interface.h index a4f6f3c..0a8310d 100644 --- a/lib/storage/storage_interface.h +++ b/lib/storage/storage_interface.h @@ -14,7 +14,7 @@ private: 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 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); @@ -38,7 +38,7 @@ private: 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 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: @@ -48,9 +48,9 @@ public: 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_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 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 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(); // 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; + // 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; - 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); - EEPROM.write(p_last_header + OFFSET_NB_MEASURES, EEPROM.read(p_last_header + OFFSET_NB_MEASURES) + 1); + // 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]); - } - } + // 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 \ No newline at end of file diff --git a/test/EEPROM_test_struct.cpp b/test/EEPROM_test_struct.cpp index 95c775b..b12a83d 100644 --- a/test/EEPROM_test_struct.cpp +++ b/test/EEPROM_test_struct.cpp @@ -179,20 +179,174 @@ void test_add_measure(){ } } -void test_put_measure(){ - // test if the template type work right - // test if values -} +// void test_put_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; +// } + +// 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(){ - // + 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 test_gather_package(){ +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) { Serial.begin(9600); @@ -201,8 +355,12 @@ void setup(void) //WARNING: Tests are not exhaustive and do not cover all possibilities. int main( int argc, char **argv) { UNITY_BEGIN(); + RUN_TEST(test_get_measure); + RUN_TEST(test_get_measure_at); RUN_TEST(test_add_measure); RUN_TEST(test_get_struct); RUN_TEST(test_set_struct); + // RUN_TEST(test_put_measure); + UNITY_END(); } \ No newline at end of file