Skip to content

Commit

Permalink
More reliable FS listing
Browse files Browse the repository at this point in the history
  • Loading branch information
geekbozu committed Oct 17, 2021
1 parent 95134c7 commit 4eeb5ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/components/ble/FSService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,26 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
char path[plen+1] = {0};
memcpy(path, header->pathstr, plen);
NRF_LOG_INFO("[FS_S] -> DIR %.10s", path);
lfs_dir_t dir;
struct lfs_info info;
lfs_dir_t dir = {};
struct lfs_info info = {};

ListDirResponse resp;
ListDirResponse resp = {};
resp.command = 0x51; // LISTDIR_ENTRY;
resp.status = 1; // TODO actually use res above!
resp.totalentries = 0;
resp.entry = 0;
int sr;
int res = fs.DirOpen(path, &dir);

NRF_LOG_INFO("[FS_S] ->diropen %d ", res);
while (fs.DirRead(&dir, &info)) {
resp.totalentries++;

}
NRF_LOG_INFO("[FS_S] -> %d ", resp.totalentries);
fs.DirClose(&dir);
fs.DirOpen(path, &dir);

fs.DirRewind(&dir);

while (fs.DirRead(&dir, &info)) {
switch(info.type){
case LFS_TYPE_REG:
Expand All @@ -106,8 +111,10 @@ int FSService::FSCommandHandler(uint16_t connectionHandle, os_mbuf* om) {
NRF_LOG_INFO("[FS_S] ->Path %s ,", info.name);
auto* om = ble_hs_mbuf_from_flat(&resp,sizeof(ListDirResponse));
ble_gattc_notify_custom(connectionHandle,transferCharacteristicHandle,om);
vTaskDelay(1); //Allow stuff to actually go out over the BLE conn
resp.entry++;
}
fs.DirClose(&dir);
resp.entry++;
resp.file_size = 0;
resp.path_length = 0;
Expand Down
4 changes: 3 additions & 1 deletion src/components/fs/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ int FS::DirClose(lfs_dir_t* lfs_dir) {
int FS::DirRead(lfs_dir_t* dir, lfs_info* info) {
return lfs_dir_read(&lfs, dir, info);
}

int FS::DirRewind(lfs_dir_t* dir) {
return lfs_dir_rewind(&lfs, dir);
}
int FS::DirCreate(const char* path) {
return lfs_mkdir(&lfs, path);
}
Expand Down
1 change: 1 addition & 0 deletions src/components/fs/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace Pinetime {
int DirOpen(const char* path, lfs_dir_t* lfs_dir);
int DirClose(lfs_dir_t* lfs_dir);
int DirRead(lfs_dir_t* dir, lfs_info* info);
int DirRewind(lfs_dir_t* dir);
int DirCreate(const char* path);
int DirDelete(const char* path);

Expand Down

0 comments on commit 4eeb5ab

Please sign in to comment.