Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DIR_LS #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion Firmware/Hub-Mega2560/Hub-Mega2560.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,50 @@ 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;
serLen = length;
}

pushPacket(HUB_DIR_LS, -1);
break;

case HUB_FILE_OPEN:
// Check if file was previously opened
if (hubFile[comInBuffer[0]])
Expand All @@ -1418,7 +1462,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:
Expand Down