| 1182 | } |
| 1183 | |
| 1184 | bool write_config(const uint8_t *buffer, uint16_t bufsize, uint32_t start) |
| 1185 | { |
| 1186 | const ConfigFooter &footer = *reinterpret_cast<const ConfigFooter *>(EEPROM.writeCache + EEPROM_SIZE_BYTES - sizeof(ConfigFooter)); |
| 1187 | if (bufsize + start > footer.dataSize) |
| 1188 | { |
| 1189 | bufsize = footer.dataSize - start; |
| 1190 | } |
| 1191 | memcpy(EEPROM.writeCache + start, buffer, bufsize); |
| 1192 | if (start + bufsize < footer.dataSize) |
| 1193 | { |
| 1194 | // printf("writing up to: %d < %d\r\n", start + bufsize, footer.dataSize); |
| 1195 | working = true; |
| 1196 | return true; |
| 1197 | } |
| 1198 | uint32_t crc = CRC32::calculate(EEPROM.writeCache, footer.dataSize); |
| 1199 | if (crc != footer.dataCrc) |
| 1200 | { |
| 1201 | printf("Crc didnt match after writing? %d\r\n", footer.dataCrc); |
| 1202 | return false; |
| 1203 | } |
| 1204 | printf("Everything matched, saving!\r\n"); |
| 1205 | // Move the encoded data in memory down to the footer |
| 1206 | memmove(EEPROM.writeCache + EEPROM_SIZE_BYTES - sizeof(ConfigFooter) - footer.dataSize, EEPROM.writeCache, footer.dataSize); |
| 1207 | memset(EEPROM.writeCache, 0, EEPROM_SIZE_BYTES - sizeof(ConfigFooter) - footer.dataSize); |
| 1208 | EEPROM.commit(); |
| 1209 | inner_load(footer.currentProfile, EEPROM.writeCache + EEPROM_SIZE_BYTES - sizeof(ConfigFooter) - footer.dataSize, footer.dataSize, footer.mainSize, footer.auxSize); |
| 1210 | working = false; |
| 1211 | return true; |
| 1212 | } |
| 1213 | |
| 1214 | uint32_t copy_config(uint8_t *buffer, uint32_t start) |
| 1215 | { |
no test coverage detected