From 5d5e4521366a3e6972999c2d8e022036745b1dc4 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Fri, 16 Apr 2021 21:46:41 +0200 Subject: [PATCH] Implement HELP command --- firmware/src/commands.c | 23 +++++++++++++++++++++++ firmware/src/commands.h | 3 ++- firmware/src/main.c | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/firmware/src/commands.c b/firmware/src/commands.c index bdd142c..4a71afc 100644 --- a/firmware/src/commands.c +++ b/firmware/src/commands.c @@ -23,6 +23,10 @@ void executeCommand(CommandLine cmdLine) { // INIT command: Initializes connection. commandInit(cmdLine.arg); } + else if (strcmp(cmdLine.command, "HELP") == 0) { + // HELP command: Print a list of supported commands. + commandHelp(cmdLine.arg); + } else if (strcmp(cmdLine.command, "READ") == 0) { // READ command: Takes a hex address range (or single address) as argument, // reads data and returns it in hexadecimal ASCII format. @@ -32,6 +36,10 @@ void executeCommand(CommandLine cmdLine) { // WRITE command: Takes a hex address as argument, reads data from UART and writes it to the EEPROM. commandRead(cmdLine.arg); } + else if (strcmp(cmdLine.command, "ERASE") == 0) { + // ERASE command: Takes a hex address range as argument and writes 0x00 bytes to the specified range. + commandRead(cmdLine.arg); + } else if (strcmp(cmdLine.command, "TESTREAD") == 0) { // TESTREAD command: for testing purposes, reads a few bytes and returns them in a human readable format. commandTestRead(); @@ -68,6 +76,21 @@ void commandInit(char* arg) { } } +void commandHelp() { + uartPutLine("HELP - Supported commands:"); + uartPutLine("HELP - HELP"); + uartPutLine("HELP - INIT [BINARY|ASCII]"); + uartPutLine("HELP - READ 0000:0FFF"); + uartPutLine("HELP - WRITE 0000"); + uartPutLine("HELP - ERASE 0000:0FFF"); + + // TODO remove those + uartPutLine("HELP - TESTREAD (only for testing)"); + uartPutLine("HELP - TESTWRITE (only for testing)"); + + uartPutLine("OK"); +} + void commandRead(char* arg) { if (arg == NULL) { uartPutLine("ERR READ needs an address or address range"); diff --git a/firmware/src/commands.h b/firmware/src/commands.h index b1bf0ac..f31a471 100644 --- a/firmware/src/commands.h +++ b/firmware/src/commands.h @@ -6,7 +6,8 @@ void executeCommand(CommandLine cmdLine); -void commandInit(); +void commandHelp(); +void commandInit(char* arg); void commandRead(char* arg); void commandWrite(char* arg); void commandErase(); diff --git a/firmware/src/main.c b/firmware/src/main.c index 056964f..cfd0404 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -15,7 +15,7 @@ int main(void) { _delay_ms(100); // Write initial message via UART - uartPutLine("INFO -- EEPROM programmer by binaryDiv"); + uartPutLine("INFO - EEPROM programmer by binaryDiv"); while(1) { // Run main loop endlessly