示例#1
0
文件: kl_sd.cpp 项目: Kreyl/nute
// ======================== Implementation =====================================
bool iniReadString(const char *ASection, const char *AKey, const char *AFileName, char *AOutput, uint32_t AMaxLen) {
    FRESULT rslt;
    // Open file
    rslt = f_open(&SD.File, AFileName, FA_READ+FA_OPEN_EXISTING);
    if (rslt != FR_OK) {
        Uart.Printf(AFileName);
        if (rslt == FR_NO_FILE) Uart.Printf(": file not found\r");
        else Uart.Printf(": openFile error: %u", rslt);
        return false;
    }
    // Check if zero file
    if (SD.File.fsize == 0) {
        f_close(&SD.File);
        Uart.Printf("Empty file\r");
        return false;
    }

    // Move through file one line at a time until a section is matched or EOF.
    char *StartP, *EndP;
    uint32_t len = strlen(ASection);
    do {
        if (!f_gets(IBuf, INI_BUF_SIZE, &SD.File)) {
            f_close(&SD.File);
            return false;
        }
        StartP = skipleading(IBuf);
        EndP = strchr(StartP, ']');
    } while ((*StartP != '[') or (EndP == NULL) or ((uint32_t)(EndP-StartP-1) != len or strnicmp(StartP+1, ASection, len) != 0));

    // Section found, find the key
    len = strlen(AKey);
    do {
        if (!f_gets(IBuf, INI_BUF_SIZE, &SD.File) or *(StartP = skipleading(IBuf)) == '[') {
            f_close(&SD.File);
            return false;
        }
        StartP = skipleading(IBuf);
        EndP = strchr(StartP, '='); /* Parse out the equal sign */
    } while ((*StartP == ';') or (*StartP == '#') or (EndP == NULL) or ((uint32_t)(skiptrailing(EndP, StartP)-StartP) != len or strnicmp(StartP, AKey, len) != 0));

    // Copy up to ALength chars to AOutput
    StartP = skipleading(EndP + 1);
    // Remove a trailing comment
    uint8_t isstring = 0;
    for (EndP = StartP; (*EndP != '\0') and (((*EndP != ';') and (*EndP != '#')) or isstring) and ((uint32_t)(EndP - StartP) < AMaxLen); EndP++) {
        if (*EndP == '"') {
            if (*(EndP + 1) == '"') EndP++;     // skip "" (both quotes)
            else isstring = !isstring; // single quote, toggle isstring
        }
        else if (*EndP == '\\' && *(EndP + 1) == '"') EndP++; // skip \" (both quotes)
    } // for
    *EndP = '\0';   // Terminate at a comment
    striptrailing(StartP);
    strcpy(AOutput, StartP);
    f_close(&SD.File);
    return &AOutput[EndP-StartP-2]; // Pointer to last '\0'
}
示例#2
0
文件: sd.c 项目: smitra/TicTocTrac
unsigned int loadSettings(void){
	char bl_ct[5];
	char time[25];
	char MinInterval[10];
	char MaxInterval[10];


	f_mount(0, &FileSystemObject);
	FRESULT res = f_open(&settingsFile, "/settings.dat", FA_WRITE | FA_READ | FA_OPEN_EXISTING);
	if(res)	return res; // File opening failed!
	//loop through file 
	f_gets(bl_ct, 5, &settingsFile);	
	f_gets(time, 25, &settingsFile);
	f_gets(MinInterval, 10, &settingsFile);
	f_gets(MaxInterval, 10, &settingsFile);
	
	
	if (bl_ct[0] == 'B'){ 			// Bootload if proper flag is set
		f_lseek(&settingsFile, 0); 	// Jump to beginning of file
		f_putc('*', &settingsFile); // Disable bootload flag
		f_sync(&settingsFile);		// Make sure the file is saved
		f_close(&settingsFile);
		f_mount(0,0);
		// Bootload by forcing reset using the watchdog timer
		cli();
		wdt_enable(WDTO_4S);
		while(1);
	}
	 
	if (bl_ct[1] == 'T'){			// Set the current time if proper flag is set
		f_lseek(&settingsFile, 1); 	// Jump proper position in file
		f_putc('*', &settingsFile);	// Disable set time flag
 		//set time on RTC		
		unsigned int sec;
		unsigned int min;
		unsigned int hr;
		unsigned int day;
		unsigned int month;
		unsigned int year;
		//YYYY-MM-DD hh:mm:ss
		sscanf(time, "CT %4u-%2u-%2u %2u:%2u:%2u", &year, &month, &day, &hr, &min, &sec);
		setTime((unsigned char)sec, (unsigned char)min, (unsigned char)hr, 0, (unsigned char)day, (unsigned char)month, year);
		f_sync(&settingsFile); // Make sure file is synched
	}
	// Load in the max and min duration creation test settings
	unsigned int min;
	unsigned int max;
	sscanf(MinInterval, "min %2u", &min);
	sscanf(MaxInterval, "max %2u", &max);

	// Close out and return the max and min duration creation test settings
	f_close(&settingsFile);
	f_mount(0,0);
	return (max<<8)|min;
}
示例#3
0
文件: config.c 项目: scintilist/MSD
void getNonBlankLine(char* line, int32_t skipCount){
	int32_t i;
	for(i=0;i<=skipCount;i++){
		f_gets(line, LINE_SIZE, &config);
		while (isBlank(line)) {
			if(f_gets(line, LINE_SIZE, &config) == NULL){ // Break if f_gets fails
				break;
			}
		}
	}
}
示例#4
0
文件: util_CSV.c 项目: jdaheron/GHB
/***************************************************************************************************
 * @brief	Placement du curseur dans le fichier CSV
 * @return 	Taille de la colonne devant laquelle le curseur est placee
 */
uint32_t
CSV_Ecriture_PlaceCursor(
		FIL* 		pFile,			/**<[in] Pointeur Fichier.*/
		uint32_t	Indice_Ligne,	/**<[in] Numero de ligne.*/
		uint32_t	Indice_Colonne	/**<[in] Numero de colonne.*/
) {

	// Declaration des variables
	Etape_Placement_e	Etape = 0;
	char	 	car[2];
	uint32_t	cpt_line;
	uint32_t 	CurrentLine;
	uint32_t	cpt_column;

	if(Indice_Ligne < INDICE_PREMIERE_LIGNE || Indice_Colonne < INDICE_PREMIERE_COLONNE)
		return 0;

	cpt_line 	= INDICE_PREMIERE_LIGNE;
	cpt_column = INDICE_PREMIERE_COLONNE;

	// Placement du curseur
	for(CurrentLine=INDICE_PREMIERE_LIGNE; CurrentLine<NB_CHAR_CSV_MAX; CurrentLine++) {

		switch(Etape) {

			//--------------------------------------------------------------------------------------
			case Etape_Placement_Ligne:
				if(cpt_line == Indice_Ligne)
					Etape = Etape_Placement_Colonne;
				else
				{
					f_gets(car, 2, pFile);
					if(car[0] == '\n')
						cpt_line++;
				}
				break;

			//-----------------------------------------------------------------------------------
			case Etape_Placement_Colonne:
				if(cpt_column == Indice_Colonne)
					return f_tell(pFile);
				else
				{
					f_gets(car, 2, pFile);
					if(car[0] == CSV_SEPARATOR)
						cpt_column++;
				}
				break;
		}
	}

	return f_tell(pFile);
}
示例#5
0
文件: main.c 项目: li1794/CNC-STM32
/***************************************************
 *	Initialize _smParam and load from config file
 */
void initSmParam(void)
{
	_smParam.smoothStartF_from0[0] = SM_SMOOTH_START_X*K_FRQ;
	_smParam.smoothStartF_from0[1] = SM_SMOOTH_START_Y*K_FRQ;
	_smParam.smoothStartF_from0[2] = SM_SMOOTH_START_Z*K_FRQ;
	_smParam.smoothStopF_to0[0] = SM_SMOOTH_STOP_X*K_FRQ;
	_smParam.smoothStopF_to0[1] = SM_SMOOTH_STOP_Y*K_FRQ;
	_smParam.smoothStopF_to0[2] = SM_SMOOTH_STOP_Z*K_FRQ;
	_smParam.smoothAF[0] = SM_SMOOTH_DFEED_X*SM_X_STEPS_PER_MM*SM_SMOOTH_TFEED*K_FRQ / 1000;
	_smParam.smoothAF[1] = SM_SMOOTH_DFEED_Y*SM_Y_STEPS_PER_MM*SM_SMOOTH_TFEED*K_FRQ / 1000;
	_smParam.smoothAF[2] = SM_SMOOTH_DFEED_Z*SM_Z_STEPS_PER_MM*SM_SMOOTH_TFEED / 1000 * K_FRQ;
	_smParam.maxFeedRate[0] = SM_X_MAX_STEPS_PER_SEC*K_FRQ;
	_smParam.maxFeedRate[1] = SM_Y_MAX_STEPS_PER_SEC*K_FRQ;
	_smParam.maxFeedRate[2] = SM_Z_MAX_STEPS_PER_SEC*K_FRQ;
	_smParam.maxSpindleTemperature = MAX_SPINDEL_TEMPERATURE;

#if (USE_SDCARD == 1)
	FIL fid;
	char str[256], *p;
	int i;
	FRESULT fres = f_open(&fid, CONF_FILE_NAME, FA_READ);
	if (fres == FR_OK)
	{
		scr_printf("\nloading %s", CONF_FILE_NAME);
		for (i = 0; i < 3; i++)
		{
			scr_puts(".");
			if (f_gets(str, sizeof(str), &fid) == NULL)
				break;
			DBG("\nc:%d:'%s'", i, str);
			if (f_gets(str, sizeof(str), &fid) == NULL)
				break;
			DBG("\nd:%d:'%s'", i, str);
			p = str;
			_smParam.smoothStartF_from0[i] = strtod_M(p, &p);
			_smParam.smoothStopF_to0[i] = strtod_M(p, &p);
			_smParam.smoothAF[i] = strtod_M(p, &p);
			_smParam.maxFeedRate[i] = strtod_M(p, &p);
		}
		if (f_gets(str, sizeof(str), &fid) != NULL)
		{
			DBG("t:'%s'", str);
			if (f_gets(str, sizeof(str), &fid) != NULL)
				_smParam.maxSpindleTemperature = strtod_M(str, &p);
		}
		scr_puts("*");
		f_close(&fid);
		scr_puts(" OK");
	}
#endif
}
示例#6
0
文件: record.c 项目: jssmile/TestEPW2
FRESULT ff_read(void)
{
    char line[20];

    printf("ff_read begin\n\r");
    res = f_mount(&fatfs, "", 0);
    if(res != FR_OK) printf("mount failed: %d\n\r", res);

    res = f_open(&file, "test.txt", FA_READ);
    res = f_open(&file2, "var.txt", FA_READ);
    if(res != FR_OK) printf("open failed: %d\n\r", res);

    speed[0] = 1;
    speed[1] = 0;

    while(1)
    {
	f_gets(line, sizeof(line), &file);
	if(line[0] == 0) break;
	USART_puts(USART3, line);

	int i;
	for(i = 0; i < 20; i++) line[i] = 0;
    }

    res = f_read(&file2, speed, sizeof(speed), &br);
    printf("speed:%d, %d\n\r",speed[0], speed[1]);

    res = f_close(&file);
    res = f_close(&file2);
    if(res != FR_OK) printf("close failed: %d\n\r", res);

    res = f_mount(NULL, "", 0);
    if(res != FR_OK) printf("umnout failed: %d\n\r", res);
}
示例#7
0
文件: cfg.c 项目: Skarsnik/sd2snes
int cfg_validity_check_recent_games() {
  int err = 0, index, index_max, write_indices[10], rewrite_lastfile = 0;
  TCHAR fntmp[10][256];
  file_open(LAST_FILE, FA_READ);
  if(file_status == FILE_ERR) {
    return 0;
  }
  for(index = 0; index < 10 && !f_eof(&file_handle); index++) {
    f_gets(fntmp[index], 255, &file_handle);
  }
  if(!f_eof(&file_handle))
    index_max = 10;
  else
    index_max = index;
  file_close();
  for(index = 0; index < index_max; index++) {
    file_open((uint8_t*)fntmp[index], FA_READ);
    write_indices[index] = file_status;
    if(file_status != FILE_OK)
      rewrite_lastfile = 1;
    file_close();
  }
  if(rewrite_lastfile) {
    f_rename ((TCHAR*)LAST_FILE, (TCHAR*)LAST_FILE_BAK);
    file_open(LAST_FILE, FA_CREATE_ALWAYS | FA_WRITE);
    for(index = 0; index < index_max; index++) {
      if(write_indices[index] == FILE_OK) {
        err = f_puts(fntmp[index], &file_handle);
        err = f_putc(0, &file_handle);
      }
    }
    file_close();
  }
  return err;
}
示例#8
0
static void HighLevelTest() {
    FATFS FatFs;
    FIL FHandle;

    if (f_mount(&FatFs, "", 0) != FR_OK) {
        xil_printf("Failed to mount filesystem.\n\r");
        return;
    }

    if (f_open(&FHandle, "foo.txt", FA_READ) != FR_OK) {
        xil_printf("Failed to open foo.txt.\n\r");
        return;
    }

    while (!f_eof(&FHandle)) {
        if (f_gets(Buff, 100, &FHandle) == NULL) {
            xil_printf("Failed to read a line from foo.txt.\r\n");
            return;
        }

        xil_printf("%s", Buff);
    }

    f_close(&FHandle);

    xil_printf("Test Successful!\n\r");
}
示例#9
0
/*---------------------------------------------------------------------------*/
void initialize_userland(void)
{
	FIL paramFile;
	
	//J パラメータファイルからパラメータを読み込む
	char fileName[16] = "uparam.txt";
	int8_t ret = f_open(&paramFile, fileName, FA_READ);	
	if (ret == FR_OK) {
		char line[100];
		while (f_gets(line, 100, &paramFile) != NULL) {
			setupParams(line, sCheckAndStoreParam);
		}

		f_close(&paramFile);
	} else {
	}
	
	//J ユーザログファイルを開く
	char logFileName[16] = "ulog.txt";
	ret = f_open(&sLogFile, logFileName,  FA_WRITE | FA_OPEN_ALWAYS);
	//J 基本追記でやります
	if (ret == FR_OK) {
		UINT len = 0;
		f_lseek(&sLogFile, f_size(&sLogFile));
		f_write(&sLogFile, "-- Start Userland\n", 18, &len);
		f_sync(&sLogFile);
	} else {
	}

	return;	
}
示例#10
0
void OnReadString(nwazetMessageContext_t* nmc){
  SerializerContext snapshot;
  uint16_t characterCount = 0;
  uint16_t bufferSizeInCharacters = MAX_FGETS_BUFFER_LENGTH_IN_BYTES / sizeof(TCHAR);
  uint8_t isTextASCII = 1;
  uint8_t res = (uint8_t) FR_OK;
  uint8_t terminator = 0;
  fileObjectMap_t* fileObj = GetFileObjectById(nmc);
  if(fileObj){
    InitializeSendBuffer(nmc->respContext, nmc->responseBuffer, nmc->responseBufferSize);
    Put(nmc->respContext, (void*)&res, sizeof(res), 1);
    Put(nmc->respContext, (void*)&isTextASCII, sizeof(isTextASCII), 1);
    TakeContextSnapshot(&snapshot, nmc->respContext);
    Put(nmc->respContext, (void*)&characterCount, sizeof(characterCount), 1);
    TCHAR* strBuffer = (TCHAR*)(nmc->respContext->Buffer + nmc->respContext->CurrentIndex);
    Put(nmc->respContext, (void*)&terminator, sizeof(terminator), 1); // will get overwritten by the string or will stay if f_gets fails

    TCHAR* str = f_gets(strBuffer, bufferSizeInCharacters, fileObj->file);
    if(str){
      characterCount = strnlen(str, bufferSizeInCharacters);
      nmc->respContext->CurrentIndex += characterCount;
    }

    RestoreContextFromSnapshot(&snapshot, nmc->respContext);
    Put(nmc->respContext, (void*)&characterCount, sizeof(characterCount), 1);
    FinalizeSendBuffer(nmc->respContext);
  }
}
示例#11
0
void MX_FATFS_Init(void) 
{
  /*## FatFS: Link the SD driver ###########################*/
  retSD = FATFS_LinkDriver(&SD_Driver, SD_Path);

  /* USER CODE BEGIN Init */
  /* additional user code for init */     
  if(!retSD)
  {
	  if(f_mount(&SDFatFS, (TCHAR const*)SD_Path, 0) != FR_OK)
		  strToUART("mount failure\n");
	  else
	  {
		  strToUART("mount success\n");
		  if(f_open(&hello, "hello.txt", FA_READ) == FR_OK)
		  {
			  strToUART("opened hello.txt\n");
			  volatile char * str;
			  //int readcount;
			  TCHAR * buffer[10];
			  str = f_gets((char*)buffer, hello.fsize, &hello);
			  strToUART(str);
			  f_close(&hello);
		  }
		  else	strToUART("could not open hello.txt\n");

	  }
  }
  /* USER CODE END Init */
}
示例#12
0
文件: cfg.c 项目: Skarsnik/sd2snes
int cfg_get_last_game(uint8_t *fn, uint8_t index) {
  int err = 0;
  file_open(LAST_FILE, FA_READ);
  do {
    f_gets((TCHAR*)fn, 255, &file_handle);
  } while (index--);
  file_close();
  return err;
}
示例#13
0
//从文件里面读取一段字符串
//size:要读取的长度
void mf_gets(u16 size)
{
 	TCHAR* rbuf;
	rbuf=f_gets((TCHAR*)fatbuf,size,file);
	if(*rbuf==0)return  ;//没有数据读到
	else
	{
		printf("\r\nThe String Readed Is:%s\r\n",rbuf);  	  
	}			    	
}
示例#14
0
uint16_t read_u16 (FIL *file, char *line)
{
  f_gets(line, 80, file); /* read one line */
  char *p_pos = strchr(line, '='); /* find the '=' position */

  if (p_pos != NULL)
    return (atoi(p_pos+1));
  else
    return 0;
}
示例#15
0
/**
  * @brief Read a line of text from the file.
  * @brief buf Output buffer.
  */
int CFile::readline(CARIBOU::CByteArray& buf,int max)
{
    int rc=-1;
    buf.resize(max+1);
    if ( f_gets(buf.data(),max,&mFileDescriptor) != NULL )
    {
        rc = strlen(buf.data());
        buf.resize(rc);
    }
    return rc;
}
示例#16
0
文件: cfg.c 项目: Skarsnik/sd2snes
void cfg_dump_recent_games_for_snes(uint32_t address) {
  TCHAR fntmp[256];
  int index;
  file_open(LAST_FILE, FA_READ);
  for(index = 0; index < 10 && !f_eof(&file_handle); index++) {
    f_gets(fntmp, 255, &file_handle);
    sram_writestrn(strrchr((const char*)fntmp, '/')+1, address+256*index, 256);
  }
  ST.num_recent_games = index;
  file_close();
}
void read_all(char * filename){
  FIL file;
  
  char buff[64];       //Буффер для чтения в него
  if (f_mount(&Fatfs, "0:", 1) == FR_OK){;                         //Монтируемся
     char r=f_open(&file, filename, FA_READ);                  //Открываем
      while (f_gets(buff, sizeof(buff), &file)) 1+1;
            // DEBUG("LOG: %s\r\n", buff);
      f_close(&file);                                        //Закрываем
      f_mount(NULL, "0:", 1); //Unmount
   }
}  
SDFS_status_type SDFS_readString(FIL* fp, char* text, uint32_t len) {
	SDFS_status_type ret_wert = SDFS_RD_STRING_ERR;
	int check;

	f_gets(text, len, fp);
	check = f_eof(fp);
	if (check != 0)
		return (SDFS_EOF);
	check = f_error(fp);
	if (check != 0)
		return (SDFS_RD_STRING_ERR);
	ret_wert = SDFS_OK;

	return (ret_wert);
}
示例#19
0
int main(void)
{
    int i;

    if(sdcard_mount(&sddisk, 0) == FR_OK)
    {
        // open a new file for writing
        if(f_open(&appdata.file, TEST_FILENAME, FA_WRITE|FA_OPEN_ALWAYS) == FR_OK)
        {

            // flash twice
            appdata.flash = 2;
            // write a number to the file (no newline needed in this case)
            f_puts((const TCHAR *)TEST_FLASHES, &appdata.file);
            f_close(&appdata.file);
        }

        // open the new file for reading
        if(f_open(&appdata.file, TEST_FILENAME, FA_READ) == FR_OK)
        {
            // flash three times
            appdata.flash = 3;

            if(f_gets((TCHAR *)appdata.buffer, sizeof(appdata.buffer)-1, &appdata.file))
            {
                // flash the number of times set in the file
                // decode the number in the file
                appdata.flash = atoi(appdata.buffer);
            }
            f_close(&appdata.file);
        }
    }

    while(1)
    {
        for(i = 0; i < appdata.flash; i++)
        {
            set_led(LED1);
            usleep(100000);
            clear_led(LED1);
            usleep(200000);
        }

        sleep(1);
    }

    return 0;
}
示例#20
0
int main()
{
	print("About to init_platform\n\r");
    init_platform();
    print("Hello World\n\r");

    print("Attempting to mount file system...\n\r");
    FATFS fs; // File system object
    FRESULT status; // FatFs return code

    status = f_mount(&fs, "", 0);
    switch (status) {
		case FR_OK:
			print("Mounting successful!\n\r");
			break;
		case FR_INVALID_DRIVE:
			print("Return code FR_INVALID_DRIVE\n\r");
		case FR_DISK_ERR:
			print("Return code FR_DISK_ERR\n\r");
			break;
		case FR_NOT_READY:
			print("Return code FR_NOT_READY\n\r");
			break;
		case FR_NO_FILESYSTEM:
			print("Return code FR_NO_FILESYSTEM\n\r");
			break;
		default:
			print("Return code was not a possible return value from f_mount\n\r");
    }

    FIL file; // File object
    char line[82]; // Line buffer
    print("Opening hello.txt...\n\r");
    status = f_open(&file, "hello.txt", FA_READ);
    if (status == FR_OK) {
    	print("Successfully opened file!\n\r");
    	while (f_gets(line, sizeof line, &file)) {
    		print(line);
    		print("\r");
    	}
    	f_close(&file);
    }

    print("All done, cleaning up now...\n\r");
    cleanup_platform();
    print("Exiting...\n\r");
    return 0;
}
示例#21
0
int
mon_log(int argc, char **argv){
  FIL fil;
  int line_buf_size = MD_BUF_SIZE;
  char *line_buf;
  FRESULT fr; 

  if(argc!=2){
    printf("specify [read] or [erase]\n");
    return -1;
  }
  if(strcmp(argv[1],"read")==0){
    //allocate the line buffer
    line_buf = core_malloc(line_buf_size);
    //print the log out to STDOUT
    fr = f_open(&fil, LOG_FILE, FA_READ);
    if(fr){
      printf("error reading log: %d\n",(int)fr);
      core_free(line_buf);
      return -1;
    }
    while(f_gets(line_buf, line_buf_size, &fil)){
      printf("%s",line_buf);
    }
    f_close(&fil);
    core_free(line_buf);
    return 0;
  }
  else if(strcmp(argv[1],"erase")==0){
    fr = f_open(&fil, LOG_FILE, FA_WRITE);
    if(fr){
      printf("error erasing log: %d\n", (int)fr);
      return -1;
    }
    f_lseek(&fil,0);
    f_truncate(&fil);
    f_close(&fil);
    if(wemo_config.echo)
      printf("erased log\n");
    return 0;
  }
  else{
    printf("specify [read] or [erase]\n");
    return -1;
  }
  //shouldn't get here
  return 0;
}
示例#22
0
文件: util_CSV.c 项目: jdaheron/GHB
/***************************************************************************************************
* @brief	Placement du curseur colonne
* @return 	Taille de la colonne devant laquelle le curseur est placee
*/
uint32_t
CSV_PlaceColumn(
		FIL* 		pFile,				/**<[in] Pointeur Fichier.*/
		uint32_t	Line_Length,		/**<[in] longueur de la ligne.*/
		uint32_t	Indice_Colonne		/**<[in] Numero de colonne.*/
) {

	Bool_e		LastColumn 	= FALSE;
	Bool_e		FirstLine	= FALSE;
	uint8_t 	Ligne[TAILLE_LIGNE_MAX];
	uint8_t* 	pLigne = Ligne;
	uint32_t 	b_Column;
	uint32_t	cmpt_column;
	uint32_t	Column_Length;

	Column_Length 	= 0;
	cmpt_column 	= 0;
	memset(pLigne, 0, TAILLE_LIGNE_MAX);

	if(f_tell(pFile) == 0)
		FirstLine = TRUE;

	for(b_Column= INDICE_PREMIERE_COLONNE; b_Column<=Line_Length+1; b_Column++) {
		if(cmpt_column == Indice_Colonne) {
			b_Column = Line_Length+1;
			f_lseek(pFile, f_tell(pFile)-Column_Length);
		} else {
			f_gets((char*)pLigne, 2, pFile);
			if( (*pLigne == CSV_SEPARATOR) || (*pLigne == '\n') ) {
				 cmpt_column++;
				if(b_Column >= Line_Length && FirstLine == FALSE) {
					Column_Length++;
					LastColumn = TRUE;
				}
				Column_Length++;
				if(cmpt_column != Indice_Colonne)
					Column_Length = 0;
			} else {
				Column_Length++; pLigne++;
			}
		}
	}

	if(LastColumn == TRUE)
		Column_Length--;

	return Column_Length;
}
示例#23
0
文件: util_CSV.c 项目: jdaheron/GHB
/***************************************************************************************************
* @brief	Placement du curseur ligne
* @return 	Taille de la ligne devant laquelle le curseur est placee
*/
uint32_t
CSV_PlaceLine(
		FIL*			pFile,			/**<[in] Pointeur Fichier.*/
		uint32_t		Indice_Ligne	/**<[in] Numero de ligne.*/
) {

	//------------------------------- Declaration des variables
	uint8_t 	Ligne[TAILLE_LIGNE_MAX];
	uint8_t* 	pLigne = Ligne;
	uint32_t	Line_Length[NOMBRE_LIGNE_MAX];
	uint32_t	cmpt_lgn;
	uint32_t 	b_Ligne;
	uint32_t	b_Calcul_Offset;
	uint32_t	offset;

	offset = 0;
	memset(pLigne, 		0, TAILLE_LIGNE_MAX);
	memset(Line_Length, 0, NOMBRE_LIGNE_MAX);


		//------------------------------- Placement sur la ligne Version B
		cmpt_lgn = 0;
		for(b_Ligne=INDICE_PREMIERE_LIGNE; b_Ligne<NB_CHAR_CSV_MAX; b_Ligne++) {
			if(cmpt_lgn == Indice_Ligne) {
				b_Ligne = NB_CHAR_CSV_MAX;
				for(b_Calcul_Offset=0; b_Calcul_Offset<cmpt_lgn-1; b_Calcul_Offset++)
					offset += Line_Length[b_Calcul_Offset];
				if(Indice_Ligne == 1)
					f_lseek(pFile, 0);
				else
					f_lseek(pFile, offset+cmpt_lgn);
			} else {
				f_gets((char*)pLigne, 2, pFile);

				if(*pLigne == '\n') {
					cmpt_lgn++; Line_Length[cmpt_lgn]++;
					if(cmpt_lgn != Indice_Ligne) {
						pLigne = Ligne;
						memset(pLigne, 0, TAILLE_LIGNE_MAX);
					}
				} else {
					pLigne++; Line_Length[cmpt_lgn]++;
				}
			}
		}

	return Line_Length[cmpt_lgn-1];
}
示例#24
0
文件: app.c 项目: FanHongchuang/Tina
/*
*********************************************************************************************************
*                                            App_DanceTask()
*
* Description : 机器人舞蹈管理任务
*
* Argument(s) : pdata.
*
* Return(s)   : none.
*
*********************************************************************************************************
*/
static void App_DanceTask(void *pdata)
{
	FRESULT result;
 	char ContentOfTheLine[6] = {0};
	
	uint32_t action = 0;
	uint32_t action_delay  = 0;
	
	INT8U err;

	while(1)
	{	
		OSSemPend(DanceSem,0,&err);
		
		/*##-1- 打开表情配置文件 */
		result = f_open(&CfgFile, "0:/dance/apple.txt", FA_OPEN_EXISTING | FA_READ);

		/*##-2- 逐行读取表情配置文件内容 */	
			do
			{
				
				f_gets(ContentOfTheLine,6,&CfgFile);
//				f_lseek(&CfgFile, f_tell(&CfgFile) + 2);
				sscanf((const char *)ContentOfTheLine, "%u %u" ,&action, &action_delay);
				
				ExecuteAction(action);
				OSTimeDlyHMSM(0,0,action_delay,10);
				ExecuteAction(127);
				
				
				if(f_eof(&CfgFile) != 0) //若文件读完,则将移动指针到文件头
				{
					//文件读完的时候,也就是舞蹈跳完的时候,跳出循环
					break;
					
				}

				
			}while(1);
			
		/*##-3- 关闭表情配置文件 */
			f_close(&CfgFile);
			
			OSTimeDlyHMSM(0,0,0,10);
		
	}
}
示例#25
0
static void read_config_file(void) {
	FRESULT rc = FR_DISK_ERR;
	FIL file_object;

	rc = f_open(&file_object, FILE_NAME_PARAMS, (BYTE) FA_READ);

	if (rc == FR_OK) {
		TCHAR buffer[128];
		for (;;) {
			if (f_gets(buffer, (int) sizeof(buffer), &file_object) == NULL)
				break; // Error or end of file
			(void) process_line_read((const char *) buffer);
		}
		(void) f_close(&file_object);
	} else {
		// nothing to do here
	}
}
static void modify_dev_list_file(uint8_t ep_id, uint8_t dev_type)
{
    FIL fil;
    FRESULT f_res;
    uint32_t dev_list[ha_host_ns::max_end_point];

    memset(dev_list, 0, sizeof(dev_list));

    f_res = f_open(&fil, ha_host_ns::ha_dev_list_file_name,
    FA_READ | FA_OPEN_ALWAYS);
    if (f_res != FR_OK) {
        print_ferr(f_res);
        return;
    }

    char line[64];
    for (uint8_t i = 0; i < ha_host_ns::max_end_point; i++) {
        if (f_gets(line, sizeof(line), &fil)) {
            sscanf(line, ha_host_ns::dev_list_pattern, &dev_list[i]);
        } else {
            break;
        }
    }
    f_close(&fil);

    dev_list[ep_id] = ((uint32_t) ha_ns::sixlowpan_node_id << 16)
            | ((uint32_t) ep_id << 8) | (uint32_t) dev_type;

    f_res = f_open(&fil, ha_host_ns::ha_dev_list_file_name,
    FA_WRITE | FA_CREATE_ALWAYS);
    if (f_res != FR_OK) {
        print_ferr(f_res);
        return;
    }
    f_sync(&fil);

    for (uint8_t i = 0; i < ha_host_ns::max_end_point; i++) {
        snprintf(line, sizeof(line), ha_host_ns::dev_list_pattern, dev_list[i]);
        f_puts(line, &fil);
    }
    f_close(&fil);

    return;
}
char * getALineCode(FIL *m_file)
{
	mymemset(str,'\0',96);

	if ((f_gets(str,96,m_file)!=NULL))//?????
	{

		tempNum++;
		return str;

	}
	else{
		printf("\r\nFile read over!\n");

		return NULL;
	}

	
}
示例#28
0
std::string SDCard::get_file_cont(const char* filename){
	std::string result;
	FIL fil;
	char line[82];
	FRESULT fr;

	fr = f_open(&fil, filename, FA_READ);
	if ( fr == FR_OK ) {
		while (f_gets(line, sizeof line, &fil))
			result.append(line);
	}else{
		//char msg[50] = {};
		//sprintf(msg, "File %s not found.", filename);
		//error(msg);
		return "";
	}

	f_close(&fil);
	return result;
}
示例#29
0
文件: cfg.c 项目: Skarsnik/sd2snes
int cfg_add_last_game(uint8_t *fn) {
  int err = 0, index, index2, found = 0, foundindex = 0, written = 0;
  TCHAR fqfn[256];
  TCHAR fntmp[10][256];
  file_open(LAST_FILE, FA_READ);
  fqfn[0] = 0;
  if(fn[0] !=  '/') {
    strncpy(fqfn, (const char*)file_path, 256);
  }
  strncat(fqfn, (const char*)fn, 256);
  for(index = 0; index < 10; index++) {
    f_gets(fntmp[index], 255, &file_handle);
    if((*fntmp[index] == 0) || (*fntmp[index] == '\n')) {
      break; /* last entry found */
    }
    if(!strncasecmp((TCHAR*)fqfn, fntmp[index], 255)) {
      found = 1; /* file already in list */
      foundindex = index;
    }
  }
  file_close();
  file_open(LAST_FILE, FA_CREATE_ALWAYS | FA_WRITE);
  /* always put new entry on top of list */
  err = f_puts((const TCHAR*)fqfn, &file_handle);
  err = f_putc(0, &file_handle);
  written++;
  if(index > 9 + found) index = 9 + found; /* truncate oldest entry */
  /* allow number of destination entries to be the same as source in case
   * we're only moving a previous entry to top */
  for(index2 = 0; index2 < index; index2++) {
    if(found && (index2 == foundindex)){
      continue; /* omit found entry here to prevent dupe */
    }
    err = f_puts(fntmp[index2], &file_handle);
    err = f_putc(0, &file_handle);
    written++;
  }
  file_close();
  return err;
}
示例#30
0
文件: iap.c 项目: yallawalla/stm32
/*******************************************************************************
* Function Name  : CanHexProg request, server
* Description    : dekodira in razbije vrstice hex fila na 	pakete 8 bytov in jih
*								 : pošlje na CAN bootloader
* Input          : pointer na string, zaporedne vrstice hex fila, <cr> <lf> ali <null> niso nujni
* Output         : 
* Return         : 0 ce je checksum error sicer eof(-1). bootloader asinhrono odgovarja z ACK message
*				 				 : za vsakih 8 bytov !!!
*******************************************************************************/							
int					HexrecOk(char *filename, FIL *f) {
int	 				xa=0,a,amax=0,amin=INT_MAX;
char				*p,s[64];
						if(f_open(f,filename,FA_READ)==FR_OK) {
							while(!f_eof(f)) {
								p=s;
								f_gets(p,64,f);
								if(*p != ':') {
									f_close(f);
									return 0;
								}
								if(HexChecksumError(++p)) {
									f_close(f);
									return 0;
								}
								a=(xa<<16)+str2hex(&p,4)+str2hex(&p,2);														// set address
								switch(str2hex(&p,2)) {
									case 00: 																												// data record
										if(a<amin)
											amin=a;
										if(a>amax)
											amax=a;
										break;
									case 04:
										xa=str2hex(&p,4);	
										break;
									default:
										break;
								}
							}
							if(amin == (int)__Vectors) {
								f_close(f);
								return 0;
							}
							f_lseek(f,0);
							return amin;
						}
						return NULL;
}