Implement binary mode for READ
This commit is contained in:
parent
e8fbc175ca
commit
d29465b2dd
|
|
@ -10,12 +10,18 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
// Internal function prototypes
|
||||||
|
void _uartPutAsciiBlock(DataBuffer buffer);
|
||||||
|
|
||||||
|
// Mode: ASCII (false) or binary (true)
|
||||||
|
bool binary_mode = false;
|
||||||
|
|
||||||
// Execute a single parsed command
|
// Execute a single parsed command
|
||||||
void executeCommand(CommandLine cmdLine) {
|
void executeCommand(CommandLine cmdLine) {
|
||||||
// Parse command
|
// Parse command
|
||||||
if (strcmp(cmdLine.command, "INIT") == 0) {
|
if (strcmp(cmdLine.command, "INIT") == 0) {
|
||||||
// INIT command: Initializes connection.
|
// INIT command: Initializes connection.
|
||||||
commandInit();
|
commandInit(cmdLine.arg);
|
||||||
}
|
}
|
||||||
else if (strcmp(cmdLine.command, "READ") == 0) {
|
else if (strcmp(cmdLine.command, "READ") == 0) {
|
||||||
// READ command: Takes a hex address range (or single address) as argument,
|
// READ command: Takes a hex address range (or single address) as argument,
|
||||||
|
|
@ -40,9 +46,26 @@ void executeCommand(CommandLine cmdLine) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void commandInit() {
|
void commandInit(char* arg) {
|
||||||
// TODO init... or something?
|
// (Re-)initialize EEPROM functions
|
||||||
uartPutLine("OK");
|
eepromInit();
|
||||||
|
|
||||||
|
// Default mode: ASCII
|
||||||
|
binary_mode = false;
|
||||||
|
|
||||||
|
if (arg != NULL) {
|
||||||
|
if (strcmp(arg, "BINARY") == 0) {
|
||||||
|
binary_mode = true;
|
||||||
|
} else if (strcmp(arg, "ASCII") == 0 || strcmp(arg, "TEXT") == 0) {
|
||||||
|
binary_mode = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (binary_mode) {
|
||||||
|
uartPutLine("OK (binary mode)");
|
||||||
|
} else {
|
||||||
|
uartPutLine("OK (ASCII mode)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void commandRead(char* arg) {
|
void commandRead(char* arg) {
|
||||||
|
|
@ -71,9 +94,23 @@ void commandRead(char* arg) {
|
||||||
// Read a single block with up to DATA_BLOCK_SIZE bytes
|
// Read a single block with up to DATA_BLOCK_SIZE bytes
|
||||||
range.from = eepromReadBlock(range, &buffer);
|
range.from = eepromReadBlock(range, &buffer);
|
||||||
|
|
||||||
// TODO binary output
|
if (binary_mode) {
|
||||||
|
// Send block as binary "package":
|
||||||
|
// First the size of the package (1 byte) followed by the data bytes
|
||||||
|
uartPutChar(buffer.bytes);
|
||||||
|
|
||||||
// ASCII output
|
for (int i = 0; i < buffer.bytes; i++) {
|
||||||
|
uartPutChar(buffer.data[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Fancy ASCII output
|
||||||
|
_uartPutAsciiBlock(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (buffer.bytes > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _uartPutAsciiBlock(DataBuffer buffer) {
|
||||||
char outBuffer[20];
|
char outBuffer[20];
|
||||||
sprintf(outBuffer, "<%d>", buffer.bytes);
|
sprintf(outBuffer, "<%d>", buffer.bytes);
|
||||||
uartPutString(outBuffer);
|
uartPutString(outBuffer);
|
||||||
|
|
@ -84,7 +121,6 @@ void commandRead(char* arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uartPutLine(NULL);
|
uartPutLine(NULL);
|
||||||
} while (buffer.bytes > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void commandWrite(char* arg) {
|
void commandWrite(char* arg) {
|
||||||
|
|
@ -100,6 +136,12 @@ void commandWrite(char* arg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only binary mode
|
||||||
|
if (!binary_mode) {
|
||||||
|
uartPutLine("ERR WRITE in ASCII mode is not implemented");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO read data from input and write to EEPROM
|
// TODO read data from input and write to EEPROM
|
||||||
uartPutLine("ERR not implemented");
|
uartPutLine("ERR not implemented");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue