MCPcopy Create free account
hub / github.com/OpenStickCommunity/GP2040-CE / loadConfigInner

Function loadConfigInner

src/config_utils.cpp:1793–1823  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1791#endif
1792
1793static bool loadConfigInner(Config& config)
1794{
1795 config = Config Config_init_zero;
1796
1797 const uint8_t* flashEnd = reinterpret_cast<const uint8_t*>(EEPROM_ADDRESS_START) + EEPROM_SIZE_BYTES;
1798 const ConfigFooter& footer = *reinterpret_cast<const ConfigFooter*>(flashEnd - sizeof(ConfigFooter));
1799
1800 // Check for presence of magic value
1801 if (footer.magic != FOOTER_MAGIC)
1802 {
1803 return false;
1804 }
1805
1806 // Check if dataSize exceeds the reserved space
1807 if (footer.dataSize + sizeof(ConfigFooter) > EEPROM_SIZE_BYTES)
1808 {
1809 return false;
1810 }
1811
1812 const uint8_t* dataPtr = flashEnd - sizeof(ConfigFooter) - footer.dataSize;
1813
1814 // Verify CRC32 hash
1815 if (CRC32::calculate(dataPtr, footer.dataSize) != footer.dataCrc)
1816 {
1817 return false;
1818 }
1819
1820 // We are now sufficiently confident that the data is valid so we run the deserialization
1821 pb_istream_t inputStream = pb_istream_from_buffer(dataPtr, footer.dataSize);
1822 return pb_decode(&inputStream, Config_fields, &config);
1823}
1824
1825void ConfigUtils::load(Config& config)
1826{

Callers 1

loadMethod · 0.85

Calls 2

pb_istream_from_bufferFunction · 0.85
pb_decodeFunction · 0.85

Tested by

no test coverage detected