More reliable FS listing
This commit is contained in:
		
							parent
							
								
									91c644b43c
								
							
						
					
					
						commit
						1dd7174480
					
				@ -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:
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user