From ebd048726756b3cc1e674e22a182110c3ad98962 Mon Sep 17 00:00:00 2001 From: Bjoern Spruck Date: Sat, 25 Nov 2023 15:51:10 +0100 Subject: [PATCH 1/3] fix: HUB_FILE_OPEN return packet should not coupled to file id --- Firmware/Hub-Mega2560/Hub-Mega2560.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Hub-Mega2560/Hub-Mega2560.ino b/Firmware/Hub-Mega2560/Hub-Mega2560.ino index a156778..7054e21 100644 --- a/Firmware/Hub-Mega2560/Hub-Mega2560.ino +++ b/Firmware/Hub-Mega2560/Hub-Mega2560.ino @@ -1418,7 +1418,7 @@ void comProcessCMD() { // Send back file size length = hubFile[comInBuffer[0]].size(); memcpy(serBuffer, (char*)&length, 4); serLen = 4; - pushPacket(HUB_FILE_OPEN, comInBuffer[0]); + pushPacket(HUB_FILE_OPEN, -1); break; case HUB_FILE_SEEK: From 59b0c4e4ab481d96c14949516d9911f375ff0db9 Mon Sep 17 00:00:00 2001 From: Bjoern Spruck Date: Sat, 25 Nov 2023 16:01:51 +0100 Subject: [PATCH 2/3] add HUB_DIR_LS --- Firmware/Hub-Mega2560/Hub-Mega2560.ino | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Firmware/Hub-Mega2560/Hub-Mega2560.ino b/Firmware/Hub-Mega2560/Hub-Mega2560.ino index 7054e21..d042196 100644 --- a/Firmware/Hub-Mega2560/Hub-Mega2560.ino +++ b/Firmware/Hub-Mega2560/Hub-Mega2560.ino @@ -1396,6 +1396,49 @@ void comProcessCMD() { pushPacket(HUB_SYS_IP, -1); break; + case HUB_DIR_LS: // Todo: Implement for root directory /microSD + { + unsigned char skip = comInBuffer[0]; + unsigned char count = 0; + length = 1; + + // TODO: we may want to start a different dir if CD is implemented + File dir = SD.open("/"); + while (true) { + File entry = dir.openNextFile(); + if (!entry) { + // no more files + break; + } + if (!entry.isDirectory()){ + // skip any dir; TODO: change when CD is implemented + if( skip!=0){ + // skip entries as requested + skip--; + }else{ + unsigned int slen=strlen(entry.name()); + if( length+slen+3>255){ + // printf("Buffer length exceeded!"); + break; + } + memcpy(&serBuffer[length], entry.name(), slen); + length += slen; + serBuffer[length++] = 0; + serBuffer[length++] = (unsigned char)(entry.size() & 0xff); + serBuffer[length++] = (unsigned char)((entry.size() >> 8)&0xff); + count++; + } + } + + entry.close(); + } + dir.close(); + serBuffer[0] = count; + } + + pushPacket(HUB_DIR_LS, -1); + break; + case HUB_FILE_OPEN: // Check if file was previously opened if (hubFile[comInBuffer[0]]) From b5bc79fb68a03fae6437cd161a5c6879a0f75241 Mon Sep 17 00:00:00 2001 From: Bjoern Spruck Date: Sun, 26 Nov 2023 15:22:51 +0100 Subject: [PATCH 3/3] fix: set leng of out buffer --- Firmware/Hub-Mega2560/Hub-Mega2560.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/Firmware/Hub-Mega2560/Hub-Mega2560.ino b/Firmware/Hub-Mega2560/Hub-Mega2560.ino index d042196..d98afea 100644 --- a/Firmware/Hub-Mega2560/Hub-Mega2560.ino +++ b/Firmware/Hub-Mega2560/Hub-Mega2560.ino @@ -1434,6 +1434,7 @@ void comProcessCMD() { } dir.close(); serBuffer[0] = count; + serLen = length; } pushPacket(HUB_DIR_LS, -1);