Implement READ command (for now with ASCII output)

This commit is contained in:
Lexi / Zoe 2021-04-04 17:38:37 +02:00
parent 55b08b7630
commit 1e644b9a5e
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
4 changed files with 80 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>
@ -57,8 +58,33 @@ void commandRead(char* arg) {
return;
}
// TODO read data and output it
uartPutString("ERR not implemented\n");
uartPutString("OK\n");
uint8_t byteBuffer[DATA_BLOCK_SIZE];
DataBuffer buffer = {
.data = byteBuffer,
.maxSize = DATA_BLOCK_SIZE,
.bytes = 0
};
do {
// Read a single block with up to DATA_BLOCK_SIZE bytes
range.from = eepromReadBlock(range, &buffer);
// TODO binary output
// ASCII output
char outBuffer[20];
sprintf(outBuffer, "<%d>", buffer.bytes);
uartPutString(outBuffer);
for (int i = 0; i < buffer.bytes; i++) {
sprintf(outBuffer, " %02X", buffer.data[i]);
uartPutString(outBuffer);
}
uartPutChar('\n');
} while (buffer.bytes > 0);
}
void commandWrite(char* arg) {