Implement ERASE command

This commit is contained in:
Lexi / Zoe 2021-04-17 17:38:32 +02:00
parent 1f668b6032
commit d898f6e518
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
3 changed files with 59 additions and 2 deletions

View file

@ -6,6 +6,7 @@
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <util/delay.h>
@ -219,8 +220,30 @@ void commandWrite(char* arg) {
uartPutLine("OK END");
}
void commandErase() {
uartPutLine("ERROR not implemented");
void commandErase(char* arg) {
if (arg == NULL) {
uartPutLine("ERROR ERASE needs a start address");
return;
}
// Parse address(es)
AddressRange range = parseAddressRange(arg);
if (!range.isValid || range.to < range.from) {
uartPutLine("ERROR invalid address format");
return;
}
uint32_t bytesErased = eepromEraseBlock(range);
if (bytesErased == 0) {
uartPutLine("ERROR 0 bytes erased");
} else {
char outBuffer[16];
snprintf(outBuffer, 16, "%lu", bytesErased);
uartPutString("OK erased ");
uartPutString(outBuffer);
uartPutLine(" bytes");
}
}
// TESTREAD command: for testing purposes, reads a few bytes and returns them in a human readable format.