Exemplo n.º 1
0
/*******************************************************************************
  * @函数名称	scan_files
  * @函数说明   搜索文件目录下所有文件 
  * @输入参数   path: 根目录 
  * @输出参数   无
  * @返回参数   FRESULT
  * @注意事项	无
  *****************************************************************************/
FRESULT scan_files (char* path )    /* Start node to be scanned (also used as work area) */
{
    FRESULT res;
    FILINFO fno;
    DIR dir;
    int i;
    char *fn;   /* This function is assuming non-Unicode cfg. */
#if _USE_LFN
    static char lfn[_MAX_LFN + 1];
    fno.lfname = lfn;
    fno.lfsize = sizeof(lfn);
#endif


    res = f_opendir(&dir, path);                       /* Open the directory */
    if (res == FR_OK) {
        i = strlen(path);
        for (;;) {
            res = f_readdir(&dir, &fno);                   /* Read a directory item */
            if (res != FR_OK || fno.fname[0] == 0) break;  /* Break on error or end of dir */
            if (fno.fname[0] == '.') continue;             /* Ignore dot entry */
#if _USE_LFN
            fn = *fno.lfname ? fno.lfname : fno.fname;
#else
            fn = fno.fname;
#endif
            if (fno.fattrib & AM_DIR) {                    /* It is a directory */
                sprintf(&path[i], "/%s", fn);
				printf("scan file - %s\n\r",path);
                res = scan_files(path);
                if (res != FR_OK) break;
                path[i] = 0;
            } else {                                       /* It is a file. */
                printf("scan file - %s/%s\n\r", path, fn);
            }
        }
    }else{
		printf("scan files error : %d\n\r",res);
	}

    return res;
}
Exemplo n.º 2
0
FRESULT Mp3PlayAllFiles(char* path)
{
  FILINFO fno;
  DIR dir;
  char fpath[50];

  chprintf((BaseChannel*)&SD2, "Mp3PlayAllFiles: Playing all files in \"%s\"\r\n", path);
  FRESULT res = f_opendir(&dir, path);
  if(res == FR_OK)
  {
    res = f_readdir(&dir, &fno);
    while((res == FR_OK) && (fno.fname[0] != 0))
    {
      strcpy(fpath, path);
      strcat(fpath, fno.fname);
      if(fno.fattrib & AM_DIR)
      {
        chprintf((BaseChannel*)&SD2, "Mp3PlayAllFiles: DIR \"%s\"\r\n", fpath);
      }
      else
      {
        chprintf((BaseChannel*)&SD2, "Mp3PlayAllFiles: FILE \"%s\"\r\n", fpath);
        size_t unLen = strlen(fpath);
        if(unLen > 3)
        {
          if(stricmp(fpath + unLen - 4, ".mp3") == 0)
          {
            Mp3Decode(fpath);
          }
        }
      }
      res = f_readdir(&dir, &fno);
    }
  }
  else
  {
    chprintf((BaseChannel*)&SD2, "Mp3PlayAllFiles: f_opendir failed %d\r\n", res);
  }
  chprintf((BaseChannel*)&SD2, "Mp3PlayAllFiles: Finished playing all files\r\n", path);

  return res;
}
Exemplo n.º 3
0
void referenceSystemAudioFiles()
{
  char path[AUDIO_FILENAME_MAXLEN+1];
  FILINFO fno;
  DIR dir;
  char *fn;   /* This function is assuming non-Unicode cfg. */
  TCHAR lfn[_MAX_LFN + 1];
  fno.lfname = lfn;
  fno.lfsize = sizeof(lfn);

  uint64_t availableAudioFiles = 0;

  assert(sizeof(audioFilenames)==AU_FRSKY_FIRST*sizeof(char *));
  assert(sizeof(sdAvailableSystemAudioFiles)*8 >= AU_FRSKY_FIRST);

  char * filename = getSystemAudioPath(path);
  *(filename-1) = '\0';

  FRESULT res = f_opendir(&dir, path);        /* Open the directory */
  if (res == FR_OK) {
    for (;;) {
      res = f_readdir(&dir, &fno);                   /* Read a directory item */
      if (res != FR_OK || fno.fname[0] == 0) break;  /* Break on error or end of dir */
      fn = *fno.lfname ? fno.lfname : fno.fname;
      uint8_t len = strlen(fn);

      // Eliminates directories / non wav files
      if (len < 5 || strcasecmp(fn+len-4, SOUNDS_EXT) || (fno.fattrib & AM_DIR)) continue;

      for (int i=0; i<AU_FRSKY_FIRST; i++) {
        getSystemAudioFile(path, i);
        if (!strcasecmp(filename, fn)) {
          availableAudioFiles |= MASK_SYSTEM_AUDIO_FILE(i);
          break;
        }
      }
    }
    f_closedir(&dir);
  }

  sdAvailableSystemAudioFiles = availableAudioFiles;
}
Exemplo n.º 4
0
FATFS_DIR *opendir(const char* path)
{
	FRESULT res;
	FATFS_DIR* dp;

	/* Malloc memory for dir object */
	dp = (FATFS_DIR *)malloc(sizeof(FATFS_DIR));
	if (!dp) { /* No more memory */
		return NULL;
	}

	res = f_opendir(&dp->dir, path);

	if (res != FR_OK) {
		free(dp);
		return NULL;
	}

	return dp;
}
Exemplo n.º 5
0
FRESULT f_scandir(
    const TCHAR* path , FILINFO*  fileInfo ,unsigned int *nEntrys  /* Start node to be scanned (also used as work area) */
)
{
    FRESULT res;
    DIR dir;
    res = f_opendir(&dir, path);                       /* Open the directory */
    
    if (FR_OK == res) {
        for (unsigned int i = 0;i<*nEntrys;i++) {
            res = f_readdir(&dir, fileInfo+i);             /* Read a directory item */
            if (res != FR_OK || fileInfo[i].fname[0] == 0){
                *nEntrys = i;
                return res;  /* Break on error or end of dir */
            }
        }
    }
    
    return res;
}
Exemplo n.º 6
0
//得到指定目录下的指定类型文件的个数
u16 f_getfilenum(u8* path,u8 ftype)
{
	u8 res;
	u8 type;
	u16 fnum=0;
	FILINFO finfo;
	res=f_opendir(&dir,(const TCHAR*)path);//打开SD卡上的PICTURE文件夹.
    finfo.lfsize=0;//不使用长文件名 
	if(res==FR_OK)
	{
		while(1)
		{	 
			res=f_readdir(&dir,&finfo);	//读取一个文件的信息
	    	if(res!=FR_OK||finfo.fname[0]==0)break;//出错,或者已经读完了
			type=f_typetell((u8*)finfo.fname);//得到文件类型	 
			if(type==ftype)fnum++;//此类型文件个数增加1.
		}
	}
    return fnum;
}			
/**
 * Starts a scan of the folder tree starting from the location passed as parameter
 * \param char* path - path from which to start the scan process
 * \return int - 0 if no error, -1 otherwise
 */
int SDStartScan (char * path)
{
	int retval;
#if _USE_LFN
    static char lfn[_MAX_LFN + 1];   /* Buffer to store the LFN */
    workfno.lfname = lfn;
    workfno.lfsize = sizeof lfn;
#endif

	fRes = f_opendir(&workdir, path);                       /* Open the directory */
	if (fRes != FR_OK)
		retval = _SD_ERR;
	else
	{
		scan_started = TRUE;
		retval = 0;
	}
		
	return retval;		
}
Exemplo n.º 8
0
static FRESULT put_file_directory (const char* path, unsigned char seek) {
    FRESULT res;
    // FILINFO fno; // TODO:: showing directory with UART
    DIR dir;

    res = f_opendir(&dir, path); /* Open the directory */

    if (res == FR_OK) {

        res = f_open(&file, nfile, FA_CREATE_NEW | FA_WRITE);
        /* Open the file with name "Hacking.txt" */
        GPIO_SetBits(GPIOD, GPIO_Pin_13);
        if (res == FR_OK) {
            insert_signatre(&file);
            f_close(&file);
            GPIO_SetBits(GPIOD, GPIO_Pin_15);
        }
    }
    return res;
}
Exemplo n.º 9
0
void OnOpenDir(nwazetMessageContext_t* nmc){
  uint8_t res = (uint8_t) FR_OK;
  uint8_t isTextASCII = 0;
  uint16_t textLength = 0;
  dirObjectMap_t* dirObj = 0;
  const char* dirname = (const char*)GetStringReference(nmc->cmdContext, &textLength, &isTextASCII);
  if(dirname && isTextASCII){
    dirObj = MapDirectoryNameToDirectoryObject(dirname, textLength);
    if(dirObj){
      res = fsCheckSuccess(__func__, "f_opendir", f_opendir(dirObj->dir, dirname), dirname);
      StartResponse(nmc, res, false);
      Put(nmc->respContext, (void*)&dirObj->id, sizeof(dirObj->id), 1);
      EndResponse(nmc);
      return;
    }
  }
  res = FR_INVALID_NAME;
  fsCheckSuccess(__func__, "dirname", res, dirname);
  StartResponse(nmc, res, true);
}
Exemplo n.º 10
0
static void scan_files_recursive(char* path)
{
    FILINFO finfo;
    DIR dirs;
    char out_filename[64] = "c";

    PRINT("========== scan_files_recursive: %s ==========\n", path);

    if (f_opendir(&dirs, path) == FR_OK)
    {
        while ((f_readdir(&dirs, &finfo) == FR_OK) && finfo.fname[0])
        {
            if (finfo.fattrib & AM_DIR)
            {
            	//strcat(path, "\\");
            	//strcat(path, finfo.fname);
            	//PRINT("==== new scan path: %s\n", path);
                //scan_files_recursive(path);
                //path[i] = 0;
            }
            else
            {
                PRINT("%s/%s\n", path, &finfo.fname[0]);
#ifdef COPY_FILES
                /* Create output filenames */
                if(file_counter < MAX_NUM_OF_FILES_TO_COPY)
                {
                    sprintf(out_filename,"c%s", &finfo.fname[0]);
                    strcpy(in_filename_string[file_counter], &finfo.fname[0]);
                    strcpy(out_filename_string[file_counter], out_filename);
                    file_counter++;
                }
#endif
            }
        }
    }
    else
    {
    	PRINT("========== Unable to open the path: %s ==========\n", path);
	}
}
Exemplo n.º 11
0
void game_init()
{
	// XXX  better check those errors !
	int res;

	f_mount(&fso,"",1); //mount now
	
	res = f_opendir(&dir, MOD_PATH);
	if (res != FR_OK) {
		message ("wtf no dir\n");
		die(3,res);
	}
	
	res = f_chdir(MOD_PATH);
	if (res) {
		message ("wtf no dir\n");
		die(2,res);
	}

	loadNextFile();
}
Exemplo n.º 12
0
// Open a directory to read a file list. Returns true if it contains any files, false otherwise.
// If this returns true then the file system mutex is owned. The caller must subsequently release the mutex either
// by calling FindNext until it returns false, or by calling AbandonFindNext.
bool MassStorage::FindFirst(const char *directory, FileInfo &file_info)
{
	// Remove any trailing '/' from the directory name, it sometimes (but not always) confuses f_opendir
	String<MaxFilenameLength> loc;
	loc.copy(directory);
	const size_t len = loc.strlen();
	if (len != 0 && (loc[len - 1] == '/' || loc[len - 1] == '\\'))
	{
		loc.Truncate(len - 1);
	}

	if (!dirMutex.Take(10000))
	{
		return false;
	}

	FRESULT res = f_opendir(&findDir, loc.c_str());
	if (res == FR_OK)
	{
		FILINFO entry;

		for (;;)
		{
			res = f_readdir(&findDir, &entry);
			if (res != FR_OK || entry.fname[0] == 0) break;
			if (!StringEqualsIgnoreCase(entry.fname, ".") && !StringEqualsIgnoreCase(entry.fname, ".."))
			{
				file_info.isDirectory = (entry.fattrib & AM_DIR);
				file_info.fileName.copy(entry.fname);
				file_info.size = entry.fsize;
				file_info.lastModified = ConvertTimeStamp(entry.fdate, entry.ftime);
				return true;
			}
		}
		f_closedir(&findDir);
	}

	dirMutex.Release();
	return false;
}
Exemplo n.º 13
0
/**
  * @brief  List up to 25 file on the root directory with extension .BMP
  * @param  DirName: A pointer to the Directory name
  * @param  Files: Buffer to contain read files
  * @retval The number of the found files
  */
uint32_t Storage_GetDirectoryBitmapFiles(const char* DirName, char* Files[])
{
  uint32_t i = 0, j = 0;
  FRESULT res;

  res = f_opendir(&MyDirectory, DirName);
  
  if(res == FR_OK)
  {
    i = strlen(DirName);
    for (;;)
    {
      res = f_readdir(&MyDirectory, &MyFileInfo);
      if(res != FR_OK || MyFileInfo.fname[0] == 0) break;
      if(MyFileInfo.fname[0] == '.') continue;
      
      if(!(MyFileInfo.fattrib & AM_DIR))
      {
        do
        {
          i++;
        }
        while (MyFileInfo.fname[i] != 0x2E);
        
        
        if(j < MAX_BMP_FILES)
        {
          if((MyFileInfo.fname[i + 1] == 'B') && (MyFileInfo.fname[i + 2] == 'M') && (MyFileInfo.fname[i + 3] == 'P'))
          {
            sprintf(Files[j], "%-11.11s", MyFileInfo.fname);
            j++;
          }
        }
        i = 0;
      }
    }
  }
    
  return j;
}
Exemplo n.º 14
0
/** Пеерчисление файлов */
FRESULT EnumerateFiles ( char* path, action_on_enum_t func)
{
    FRESULT res;
    FILINFO fno;
    DIR dir;
    int i;
    char *fn;   /* This function is assuming non-Unicode cfg. */
#if _USE_LFN
    static char lfn[_MAX_LFN + 1];
    fno.lfname = lfn;
    fno.lfsize = sizeof(lfn);
#endif


    res = f_opendir(&dir, path);                       /* Open the directory */
    if (res == FR_OK) {
        i = strlen(path);
        for (;;) {
            res = f_readdir(&dir, &fno);                   /* Read a directory item */
            if (res != FR_OK || fno.fname[0] == 0) break;  /* Break on error or end of dir */
            if (fno.fname[0] == '.') continue;             /* Ignore dot entry */
#if _USE_LFN
            fn = *fno.lfname ? fno.lfname : fno.fname;
#else
            fn = fno.fname;
#endif
            if (fno.fattrib & AM_DIR) {                    /* It is a directory */
                sprintf(&path[i], "/%s", fn);
                res = EnumerateFiles(path, func);
                if (res != FR_OK) break;
                path[i] = 0;
            } else {                                       /* It is a file. */
                if (func)
                	func(path, fn);
            }
        }
    }

    return res;
}
Exemplo n.º 15
0
static int fatfs_opendir(mount_point_t *point, file_t *file, const char *path)
{
    privinfo_t *priv;
    FRESULT res;

    priv = kmalloc(sizeof(privinfo_t), GFP_KERNEL);
    if (priv != NULL) {
        memset(priv, 0, sizeof(privinfo_t));
        file->ctx = priv;
        res = f_opendir(point->ctx, &priv->dir, path);
        if (res == FR_OK) {
            return 0;
        } else {
            fatfs_result_to_errno(res);
            kfree(priv);
            return -1;
        }
    } else {
        seterrno(ENOMEM);
        return -1;
    }
}
Exemplo n.º 16
0
int load_next()
{

    FRESULT res;

    char *fn=0;   /* This function is assuming non-Unicode cfg. */

    do {
	    do {
		    res = f_readdir(&dir, &fno);                   /* Read a directory item */
		    if (res != FR_OK ) {  
		        message("Error reading directory !");
		        die (2,3);
		    }

		    if (fno.fname[0] == 0) { // end of dir ? rescan
		    	f_closedir(&dir);
			    if (f_opendir(&dir, ROOT_DIR) != FR_OK ) {
			    	message("Error reloading directory !");
			    	die (2,4);
			    }
		    }
		} while ( fno.fname[0] == 0 );
		message("debug: next file, now : %s, %d, %x,%x\n",fno.fname,(endsWith(fno.fname,".bmp") || endsWith(fno.fname,".BMP")),fno.fattrib, AM_DIR);


	    if (!(fno.fattrib & AM_DIR)) { // not a dir
	    	// check extension : only keep .bmp files
	    	if (endsWith(fno.fname,".bmp") || endsWith(fno.fname,".BMP")) { // search ignoring case
			    fn = fno.fname; // ok will load it
	    		message("ok, will load %s\n",fn);
	    	}
	    }
	} while (fn==0); 

	message("now loading : %s\n",fn);
	return load_bmp(fn);

}
Exemplo n.º 17
0
FRESULT SndList_t::CountFilesInDir(const char* DirName, uint32_t *PCnt) {
    FRESULT Rslt = f_opendir(&Dir, DirName);
    if(Rslt != FR_OK) return Rslt;
    *PCnt = 0;
    while(true) {
        Rslt = f_readdir(&Dir, &FileInfo);
        if(Rslt != FR_OK) return Rslt;
        if((FileInfo.fname[0] == 0) and (FileInfo.lfname[0] == 0)) return FR_OK;   // No files left
        else { // Filename ok, check if not dir
            if(!(FileInfo.fattrib & AM_DIR)) {
                // Check if wav or mp3
                char *FName = (FileInfo.lfname[0] == 0)? FileInfo.fname : FileInfo.lfname;
//                Uart.Printf("\r%S", FName);
                uint32_t Len = strlen(FName);
                if(Len > 4) {
                    if((strcasecmp(&FName[Len-3], "mp3") == 0) or (strcasecmp(&FName[Len-3], "wav") == 0)) (*PCnt)++;
                } // if Len>4
            } // if not dir
        } // Filename ok
    }
    return FR_OK;
}
Exemplo n.º 18
0
//------------------------------------------------------------------------------
/// Scan files under a certain path
/// /param path    folder path
/// \return scan result, 1: success.
//------------------------------------------------------------------------------
static FRESULT scan_files(char* path)
{
    FRESULT res;
    FILINFO fno;
    DIR dir;
    int i;
    char *fn;
#if _USE_LFN
    static char lfn[_MAX_LFN * (_DF1S ? 2 : 1) + 1];
    fno.lfname = lfn;
    fno.lfsize = sizeof(lfn);
#endif


    res = f_opendir(&dir, path);
    if (res == FR_OK) {
        i = strlen(path);
        for (;;) {
            res = f_readdir(&dir, &fno);
            if (res != FR_OK || fno.fname[0] == 0) break;
#if _USE_LFN
            fn = *fno.lfname ? fno.lfname : fno.fname;
#else
            fn = fno.fname;
#endif
            if (*fn == '.') continue;
            if (fno.fattrib & AM_DIR) {
                TRACE_MSG(&path[i], "/%s", fn);
                res = scan_files(path);
                if (res != FR_OK) break;
                path[i] = 0;
            } else {
                DEBUG_MSG("%s/%s", path, fn);
            }
        }
    }

    return res;
}
Exemplo n.º 19
0
void fsInit(){
    FRESULT i;
    DIR dir;                /* Directory object */
    f_mount(0, &FatFs);
    
    i = f_opendir(&dir, "0:");
 
    if( i == FR_NO_FILESYSTEM ){
        lcdPrintln("filesystm b0rk");
        lcdPrintln("Formating...");
        lcdRefresh(); 
        format_formatDF();
        lcdPrintln("Done.");
        lcdPrintln("Now copy files");
        lcdPrintln("to drive. See");
        lcdPrintln("");
        lcdPrintln("r0ket.de/init");
        lcdRefresh();
        usbMSCInit();
        while(1);
    }
};
Exemplo n.º 20
0
size_t AdvFileManagerList(const TCHAR *path, TCHAR ***ls) {
	size_t count = 0;

	if (wcscmp(path, L""))
	{
		DIR myDir;
		FILINFO curInfo;
		memset(&myDir, 0, sizeof(DIR));
		memset(&curInfo, 0, sizeof(FILINFO));
		FILINFO *myInfo = &curInfo;

		int res = f_opendir(&myDir, path);
		if (res == FR_NO_FILE) {
			print(strings[STR_ERROR_OPENING], path);
			return 0;
		}
		*ls = NULL;
		*ls = calloc(1000, sizeof(char *));
		count = 0;
		f_readdir(&myDir, myInfo);

		while (!myInfo->fname[0] == 0)
		{
			(*ls)[count++] = wcsdup(myInfo->fname);
			f_readdir(&myDir, myInfo);
		}

		f_closedir(&myDir);
	}
	else
	{
		*ls = calloc(3, sizeof(char *));
		(*ls)[count++] = wcsdup(L"0");
		(*ls)[count++] = wcsdup(L"1");
		(*ls)[count++] = wcsdup(L"2");
	}
	return count;
}
Exemplo n.º 21
0
FRESULT scan_files(void)
{
	FRESULT res;
	FILINFO fno;
	FIL fp;
	DIR dir;
	int j;
	char *fn;
	char path[64];

	strcpy(path, "0:");
	res = f_opendir(&dir, path);
	if (res == FR_OK) {

		for (;;) {
			res = f_readdir(&dir, &fno);
			fn = fno.fname;

			if (res || !fn[0]) { break; }
			if (fn[0] == '.' || fn[0] == '_') { continue; }

			j = strlen(fn);
			if (j < 4) continue;
			if (fn[j-4] != '.' || fn[j-3] != 'W' || fn[j-2] != 'A' || fn[j-1] != 'V') continue;

			strcpy(&path[2], fn);

			res = f_open(&fp, path, FA_OPEN_EXISTING | FA_READ);
			if (res == FR_OK) {
				playfile(&fp);
				break;
			}
		}

	} else {
	}
	return res;
}
Exemplo n.º 22
0
bool TestExtFile::test_rewinddir() {
  Variant d = f_opendir("test");
  Variant entry;
  bool seen = false;
  while (!same(entry = f_readdir(d), false)) {
    if (same(entry, "test_ext_file.txt")) {
      seen = true;
    }
  }
  VERIFY(seen);

  seen = false;
  f_rewinddir(d);
  while (!same(entry = f_readdir(d), false)) {
    if (same(entry, "test_ext_file.txt")) {
      seen = true;
    }
  }
  VERIFY(seen);

  f_closedir(d);
  return Count(true);
}
Exemplo n.º 23
0
//得到指定目录下的文件夹的个数
//包含".."文件夹
u16 f_getfoldernum(u8* path)
{
	u8 res;	    
	u16 fnum=0;
	FILINFO finfo;
	res=f_opendir(&dir,(const TCHAR*)path);//打开SD卡上的PICTURE文件夹.
    finfo.lfsize=0;//不使用长文件名 
	if(res==FR_OK)
	{
		while(1)
		{

			res=f_readdir(&dir,&finfo);	//读取一个文件的信息
	    	if(res!=FR_OK||finfo.fname[0]==0)break;//出错,或者已经读完了
			if(finfo.fattrib&AM_DIR)
			{
				if(finfo.fname[0]=='.'&&finfo.fname[1]=='\0')continue;//不计算"."文件夹
				fnum++;
			}										    
		}
	}
    return fnum;
}									    
Exemplo n.º 24
0
/*-----------------------------------------------------------*/
static FRESULT test_sd_card() {
	FRESULT res = FR_OK;
	DIR dir;
	char buf[1024];
	int variableName = 5;
	res = f_opendir(&dir, "/");
	if (res != FR_OK) {
		return FR_DISK_ERR;
	}
	xputs("SD OK\n");
	FIL testOutput, testInput;

	if (f_open(&testOutput, "/foo.txt",
	FA_WRITE | FA_CREATE_NEW | FA_OPEN_ALWAYS) == FR_OK) {
		f_printf(&testOutput, "\nbar %d\n", variableName);
		f_close(&testOutput);
	}
	if (f_open(&testInput, "/hello", FA_READ) == FR_OK) {
		f_gets(buf, sizeof(buf), &testInput);
		f_close(&testInput);
	}
	return FR_OK;
}
Exemplo n.º 25
0
/**
  * @brief  scan_files,查找路径下所有文件
  * @param  char* path 
  * @retval FRESULT
  */
FRESULT scan_files (
    char* path        /* Start node to be scanned (***also used as work area***) */
)
{
    FRESULT res;
    DIR dir;
    UINT i;
    static FILINFO fno;

    res = f_opendir(&dir, path);                        /* Open the directory */
    if (res == FR_OK) 
	{
        for (;;) 
		{
            res = f_readdir(&dir, &fno);                /* Read a directory item */
            if (res != FR_OK || fno.fname[0] == 0)
			{
				break;  								/* Break on error or end of dir */
			}
            if (fno.fattrib & AM_DIR)  					/* It is a directory */
			{                    
                i = strlen(path);
                sprintf(&path[i], "/%s", fno.fname);
                res = scan_files(path);                 /* Enter the directory */
                if (res != FR_OK) break;
                path[i] = 0;
            } 
			else 
			{                                           /* It is a file. */
                printf("%s/%s\n", path, fno.fname);
            }
        }
        f_closedir(&dir);
    }

    return res;
}
Exemplo n.º 26
0
void fatfs_test(void)
{
    FRESULT rc;//error number

    FIL fil;
    
    rc = f_mkdir("0:/一");
    if(rc)  printf("f_mkdir error\n");
    else    printf("f_mkdir Ok!\n");

/******************************************************************************/
    DIR path;

    FILINFO file_info;
#if _USE_LFN
        file_info.lfsize = 20  + 1;
        file_info.lfname = mymalloc(SRAMEX, file_info.lfsize);
#endif
    rc = f_opendir(&path,"/");
    ERROR_TRACE(rc);
    
    printf("共有%d个文件夹\n",dir_totle(&path,&file_info));
    
/******************************************************************************/    
    uint8_t src[30] = {0};
    get_curr_time(src,NULL);
    printf("时间:%s\n",src);

    log_write(&fil,0);

    f_closedir(&path);
#if _USE_LFN
    myfree(SRAMEX, file_info.lfname);
#endif

    //总电压0.01v 充放电电流 电池温度 单体电压 剩余容量 循环次数 日发电量 总发电量 异常记录(异常类型 发生时间 发生时以上各项目参数)
}
Exemplo n.º 27
0
Arquivo: wavplay.c Projeto: f32c/f32c
void
scan_files(char* path)
{
	FRESULT res;
	FILINFO fno;
	DIR dir;
	int i, t;

	/* Open the directory */
	res = f_opendir(&dir, path);
	if (res != FR_OK)
		return;

	i = strlen(path);
	do {
		/* Read a directory item */
		res = f_readdir(&dir, &fno);
		if (res != FR_OK || fno.fname[0] == 0)
			break;

		/* Ignore dot entry */
		if (fno.fname[0] == '.')
			continue;

		/* Recursively scan subdirectories */
		path[i] = '/';
		strcpy(&path[i+1], fno.fname);
		if (fno.fattrib & AM_DIR)
			scan_files(path);
		else {
			t = strlen(path);
			if (t > 4 && strcmp(&path[t - 4], ".WAV") == 0)
				strcpy(fnames[fcnt++], path);
		}
		path[i] = 0;
	} while (1);
}
Exemplo n.º 28
0
/**
  * @brief  Starts Wave player.
  * @param  None
  * @retval None
  */
void WavePlayerStart(void)
{
  UINT bytesread = 0;
  char path[] = "0:/";
  char* wavefilename = NULL;
  WAVE_FormatTypeDef waveformat;

  /* Get the read out protection status */
  if(f_opendir(&Directory, path) == FR_OK)
  {
    if(WaveRecStatus == 1)
    {
      wavefilename = REC_WAVE_NAME;
    }
    else
    {
      wavefilename = WAVE_NAME;
    }
    /* Open the Wave file to be played */
    if(f_open(&FileRead, wavefilename , FA_READ) != FR_OK)
    {
      BSP_LED_On(LED5);
      CmdIndex = CMD_RECORD;
    }
    else
    {
      /* Read sizeof(WaveFormat) from the selected file */
      f_read (&FileRead, &waveformat, sizeof(waveformat), &bytesread);

      /* Set WaveDataLenght to the Speech Wave length */
      WaveDataLength = waveformat.FileSize;

      /* Play the Wave */
      WavePlayBack(waveformat.SampleRate);
    }
  }
}
Exemplo n.º 29
0
static FRESULT scan_files(BaseSequentialStream *chp, char *path) {
  FRESULT res;
  FILINFO fno;
  DIR dir;
  int i;
  char *fn;

#if _USE_LFN
  fno.lfname = 0;
  fno.lfsize = 0;
#endif
  res = f_opendir(&dir, path);
  if (res == FR_OK) {
    i = strlen(path);
    for (;;) {
      res = f_readdir(&dir, &fno);
      if (res != FR_OK || fno.fname[0] == 0)
        break;
      if (fno.fname[0] == '.')
        continue;
      fn = fno.fname;
      if (fno.fattrib & AM_DIR) {
        path[i++] = '/';
        strcpy(&path[i], fn);
        res = scan_files(chp, path);
        if (res != FR_OK)
          break;
        path[--i] = 0;
      }
      else {
        chprintf(chp, "%s/%s\r\n", path, fn);
      }
    }
  }
  return res;
}
Exemplo n.º 30
0
static void scan_files(char* path)
{
    FILINFO finfo;
    DIR dirs;
    int i;
    char out_filename[64] = "c";

    if (f_opendir(&dirs, path) == FR_OK)
    {
        i = strlen(path);

        while ((f_readdir(&dirs, &finfo) == FR_OK) && finfo.fname[0])
        {
            if (finfo.fattrib & AM_DIR)
            {
                sprintf(&path[i], "/%s", &finfo.fname[0]);
                scan_files(path);
                path[i] = 0;
            }
            else
            {
                PRINT("%s/%s\n", path, &finfo.fname[0]);
#ifdef COPY_FILES
                /* Create output filenames */
                if(file_counter < MAX_NUM_OF_FILES_TO_COPY)
                {
                    sprintf(out_filename,"c%s", &finfo.fname[0]);
                    strcpy(in_filename_string[file_counter], &finfo.fname[0]);
                    strcpy(out_filename_string[file_counter], out_filename);
                    file_counter++;
                }
#endif
            }
        }
    }
}