Skip to content

Commit 820fe1e

Browse files
committed
simulator: implement intFlashCompare()
1 parent 044a646 commit 820fe1e

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

simulator/main.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,33 @@ bool intFlashIsErased(flashaddr_t address, size_t size) {
261261
return true;
262262
}
263263

264+
bool intFlashCompare(flashaddr_t address, const char* buffer, size_t size) {
265+
auto fileName = makeFileName(address);
266+
267+
printf("Simulator: comparing with config from %s\n", fileName.c_str());
268+
269+
std::ifstream flash;
270+
flash.open(fileName, std::ios::binary);
271+
272+
if (!flash.is_open()) {
273+
return false;
274+
}
275+
276+
char ch;
277+
bool same = true;
278+
size_t checked = 0;
279+
while (same && checked < size && flash.get(ch)) {
280+
if (static_cast<unsigned char>(ch) != buffer[checked]) {
281+
same = false;
282+
}
283+
checked++;
284+
}
285+
286+
flash.close();
287+
288+
return same;
289+
}
290+
264291
int intFlashErase(flashaddr_t address, size_t) {
265292
// Try to delete the file, swallow any errors (we can overwrite it anyway)
266293
try {

0 commit comments

Comments
 (0)