From b2a2b1d3bff2d8ba14cbaacd52bc5be6e7ac5798 Mon Sep 17 00:00:00 2001 From: steve Date: Wed, 10 Apr 2024 19:30:59 +0100 Subject: [PATCH 1/4] more nuanced default command args --- TommyPROM/PromDevice.h | 1 + TommyPROM/TommyPROM.ino | 51 ++++++++++++++++++++++++++++------------- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/TommyPROM/PromDevice.h b/TommyPROM/PromDevice.h index a2d1269..358544f 100644 --- a/TommyPROM/PromDevice.h +++ b/TommyPROM/PromDevice.h @@ -29,6 +29,7 @@ class PromDevice byte readData(uint32_t address) { return readByte(address); } void resetDebugStats(); void printDebugStats(); + uint32_t end() const { return mSize-1; } virtual void begin() = 0; virtual const char * getName() = 0; diff --git a/TommyPROM/TommyPROM.ino b/TommyPROM/TommyPROM.ino index dfce3f6..dbedd5c 100644 --- a/TommyPROM/TommyPROM.ino +++ b/TommyPROM/TommyPROM.ino @@ -19,7 +19,7 @@ #include "XModem.h" -static const char * MY_VERSION = "3.4"; +static const char * MY_VERSION = "3.5"; // Global status @@ -95,6 +95,8 @@ XModem xmodem(prom, cmdStatus); * CLI parse functions */ const char hex[] = "0123456789abcdef"; +const uint32_t unspec = ~0;; +inline uint32_t if_unspec(uint32_t val, uint32_t repl) { return val == unspec? repl: val; } enum { // CLI Commands @@ -220,7 +222,7 @@ byte hexDigit(char c) * @param pointer to string with the hex value of the word (modified) * @return unsigned int represented by the digits ************************************************************/ -uint32_t getHex32(char *& pData, uint32_t defaultValue=0) +uint32_t getHex32(char *& pData, uint32_t defaultValue=unspec) { uint32_t u32 = 0; @@ -346,7 +348,7 @@ word checksumBlock(uint32_t start, uint32_t end) /** * Read data from the device and dump it in hex and ascii. **/ -void dumpBlock(uint32_t start, uint32_t end) +uint32_t dumpBlock(uint32_t start, uint32_t end) { char line[81]; // 01234567891 234567892 234567893 234567894 234567895 234567896 234567897 23456789 @@ -404,6 +406,7 @@ void dumpBlock(uint32_t start, uint32_t end) { Serial.println(); } + return end+1; } @@ -476,7 +479,7 @@ void pokeBytes(char * pCursor) //first value returned is the starting address start = getHex32(pCursor, 0); - while (((val = getHex32(pCursor, 0xffff)) != 0xffff) && (byteCtr < BLOCK_SIZE)) + while (((val = getHex32(pCursor)) != unspec) && (byteCtr < BLOCK_SIZE)) { data[byteCtr++] = byte(val); } @@ -682,7 +685,7 @@ void setup() char line[120]; uint32_t start = 0; uint32_t end = 0xff; -byte val = 0xff; +uint32_t val = 0xff; void loop() { @@ -695,9 +698,9 @@ void loop() Serial.println(); byte cmd = parseCommand(line[0]); char * pCursor = line+1; - start = getHex32(pCursor, 0); - end = getHex32(pCursor, 0xff); - val = (byte) getHex32(pCursor, 0); + start = getHex32(pCursor, start); + end = getHex32(pCursor); + val = (byte) getHex32(pCursor); if ((cmd != CMD_LAST_STATUS) && (cmd != CMD_INVALID)) { @@ -707,10 +710,11 @@ void loop() switch (cmd) { case CMD_BLANK: - erasedBlockCheck(start, end); + erasedBlockCheck(start, if_unspec(end, prom.end())); break; case CMD_CHECKSUM: + end = if_unspec(end, prom.end()); w = checksumBlock(start, end); Serial.print(F("Checksum ")); printWord(start); @@ -722,16 +726,30 @@ void loop() break; case CMD_DUMP: - dumpBlock(start, end); + start = dumpBlock(start, start + if_unspec(end, 0xff)); break; case CMD_ERASE: - printRetStatus(prom.erase(start, end)); + if (start == unspec || end == unspec) + { + Serial.println(F("Erase requires explicit start, end")); + } + else + { + printRetStatus(prom.erase(start, end)); + } break; case CMD_FILL: - prom.resetDebugStats(); - fillBlock(start, end, val); + if (start == unspec || end == unspec || val == unspec) + { + Serial.println(F("Fill requires explicit start, end and value")); + } + else + { + prom.resetDebugStats(); + fillBlock(start, end, (byte)val); + } break; case CMD_LOCK: @@ -745,10 +763,11 @@ void loop() break; case CMD_READ: - if (xmodem.SendFile(start, uint32_t(end) - start + 1)) + end = if_unspec(end, prom.end()); + if (xmodem.SendFile(start, end - start + 1)) { cmdStatus.info("Send complete."); - cmdStatus.setValueDec(0, "NumBytes", uint32_t(end) - start + 1); + cmdStatus.setValueDec(0, "NumBytes", end - start + 1); } break; @@ -777,7 +796,7 @@ void loop() break; case CMD_SCAN: - scanBlock(start, end); + scanBlock(start, if_unspec(end, prom.end())); break; case CMD_TEST: From 1ea8f82c6837d196e5e14fb1e33a21f79257b75d Mon Sep 17 00:00:00 2001 From: steve Date: Wed, 10 Apr 2024 19:32:59 +0100 Subject: [PATCH 2/4] cleanups --- TommyPROM/TommyPROM.ino | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TommyPROM/TommyPROM.ino b/TommyPROM/TommyPROM.ino index dbedd5c..d2862bf 100644 --- a/TommyPROM/TommyPROM.ino +++ b/TommyPROM/TommyPROM.ino @@ -95,7 +95,7 @@ XModem xmodem(prom, cmdStatus); * CLI parse functions */ const char hex[] = "0123456789abcdef"; -const uint32_t unspec = ~0;; +const uint32_t unspec = ~0; inline uint32_t if_unspec(uint32_t val, uint32_t repl) { return val == unspec? repl: val; } enum { @@ -406,7 +406,8 @@ uint32_t dumpBlock(uint32_t start, uint32_t end) { Serial.println(); } - return end+1; + + return end+1; } From 6e58a7c2986ecdbbd70fe82bc2255a8243260547 Mon Sep 17 00:00:00 2001 From: steve Date: Wed, 10 Apr 2024 20:02:02 +0100 Subject: [PATCH 3/4] fix gotchas with unspecified start --- TommyPROM/TommyPROM.ino | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/TommyPROM/TommyPROM.ino b/TommyPROM/TommyPROM.ino index d2862bf..5107c99 100644 --- a/TommyPROM/TommyPROM.ino +++ b/TommyPROM/TommyPROM.ino @@ -395,7 +395,7 @@ uint32_t dumpBlock(uint32_t start, uint32_t end) Serial.println(line); if (checkForBreak()) { - return; + return addr; } memset(line, ' ', sizeof(line)); count = 0; @@ -711,10 +711,11 @@ void loop() switch (cmd) { case CMD_BLANK: - erasedBlockCheck(start, if_unspec(end, prom.end())); + erasedBlockCheck(if_unspec(start, 0), if_unspec(end, prom.end())); break; case CMD_CHECKSUM: + start = if_unspec(start, 0); end = if_unspec(end, prom.end()); w = checksumBlock(start, end); Serial.print(F("Checksum ")); @@ -764,6 +765,7 @@ void loop() break; case CMD_READ: + start = if_unspec(start, 0); end = if_unspec(end, prom.end()); if (xmodem.SendFile(start, end - start + 1)) { @@ -779,6 +781,7 @@ void loop() case CMD_WRITE: prom.resetDebugStats(); + start = if_unspec(start, 0); numBytes = xmodem.ReceiveFile(start); if (numBytes) { @@ -797,16 +800,16 @@ void loop() break; case CMD_SCAN: - scanBlock(start, if_unspec(end, prom.end())); + scanBlock(if_unspec(start, 0), if_unspec(end, prom.end())); break; case CMD_TEST: - testAddr(start); + testAddr(if_unspec(start, 0)); break; case CMD_ZAP: prom.resetDebugStats(); - zapTest(start); + zapTest(if_unspec(start, 0)); break; #endif /* ENABLE_DEBUG_COMMANDS */ From 75d611eca6ea88088e36c64179535611ed1a9861 Mon Sep 17 00:00:00 2001 From: steve Date: Wed, 10 Apr 2024 21:20:14 +0100 Subject: [PATCH 4/4] fix from pr comment --- TommyPROM/TommyPROM.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TommyPROM/TommyPROM.ino b/TommyPROM/TommyPROM.ino index 5107c99..33cec12 100644 --- a/TommyPROM/TommyPROM.ino +++ b/TommyPROM/TommyPROM.ino @@ -728,7 +728,7 @@ void loop() break; case CMD_DUMP: - start = dumpBlock(start, start + if_unspec(end, 0xff)); + start = dumpBlock(start, if_unspec(end, start + 0xff)); break; case CMD_ERASE: