// Load all variables from EEPROM // bool AP_Param::load_all(void) { struct Param_header phdr; uint16_t ofs = sizeof(AP_Param::EEPROM_header); while (ofs < _eeprom_size) { hal.storage->read_block(&phdr, ofs, sizeof(phdr)); // note that this is an || not an && for robustness // against power off while adding a variable if (phdr.type == _sentinal_type || phdr.key == _sentinal_key || phdr.group_element == _sentinal_group) { // we've reached the sentinal return true; } const struct AP_Param::Info *info; void *ptr; info = find_by_header(phdr, &ptr); if (info != NULL) { hal.storage->read_block(ptr, ofs+sizeof(phdr), type_size((enum ap_var_type)phdr.type)); } ofs += type_size((enum ap_var_type)phdr.type) + sizeof(phdr); } // we didn't find the sentinal serialDebug("no sentinal in load_all"); return false; }
// Load all variables from EEPROM // bool AP_Param::load_all(void) { struct Param_header phdr; uint16_t ofs = sizeof(AP_Param::EEPROM_header); /* if the HAL specifies a defaults parameter file then override defaults using that file */ #ifdef HAL_PARAM_DEFAULTS_PATH load_defaults_file(HAL_PARAM_DEFAULTS_PATH); #endif while (ofs < _storage.size()) { _storage.read_block(&phdr, ofs, sizeof(phdr)); // note that this is an || not an && for robustness // against power off while adding a variable if (phdr.type == _sentinal_type || phdr.key == _sentinal_key || phdr.group_element == _sentinal_group) { // we've reached the sentinal return true; } const struct AP_Param::Info *info; void *ptr; info = find_by_header(phdr, &ptr); if (info != NULL) { _storage.read_block(ptr, ofs+sizeof(phdr), type_size((enum ap_var_type)phdr.type)); } ofs += type_size((enum ap_var_type)phdr.type) + sizeof(phdr); } // we didn't find the sentinal Debug("no sentinal in load_all"); return false; }