Example #1
0
void ZP_CreateLogFile(void)
{
	char file[50];
	uint32_t ul_hour, ul_minute, ul_second;
	uint32_t ul_year, ul_month, ul_day, ul_week;
	rtc_get_time(RTC, &ul_hour, &ul_minute, &ul_second);
	rtc_get_date(RTC, &ul_year, &ul_month, &ul_day, &ul_week);
	
	f_mkdir("0:Logs");
	sprintf(file, "0:logs/%04u", ul_year);
	f_mkdir((char const *)file);
	sprintf(file, "0:logs/%04u/%02u", ul_year, ul_month);
	f_mkdir((char const *)file);
	sprintf(file, "0:logs/%04u/%02u/%02u", ul_year, ul_month, ul_day);
	f_mkdir((char const *)file);
	
	sprintf(file, "0:Logs/%04u/%02u/%02u/Flight_Log_%02u.%02u.%02u.log", ul_year, ul_month, ul_day, ul_hour, ul_minute, ul_second);
	f_open(&f_log, (char const *)file, FA_CREATE_ALWAYS | FA_WRITE);
	f_puts("Goblin-Tech", &f_log);
	f_puts("GT101-0001", &f_log);
	f_puts("00.00.00", &f_log);
	uint16_t size = f_size(&f_script);
	uint8_t dummy;
	f_write(&f_log, &size, 2, &dummy);
	f_write(&f_log, &Script, size, &dummy);
	f_sync(&f_log);
}
Example #2
0
void writeHeader()
{
#if defined(RTCLOCK)
  f_puts("Date,Time,", &g_oLogFile);
#else
  f_puts("Time,", &g_oLogFile);
#endif

#if defined(FRSKY)
#if !defined(CPUARM)
  f_puts("Buffer,RX,TX,A1,A2,", &g_oLogFile);
#if defined(FRSKY_HUB)
  if (IS_USR_PROTO_FRSKY_HUB()) {
    f_puts("GPS Date,GPS Time,Long,Lat,Course,GPS Speed(kts),GPS Alt,Baro Alt(", &g_oLogFile);
    f_puts(TELEMETRY_BARO_ALT_UNIT, &g_oLogFile);
    f_puts("),Vertical Speed,Air Speed(kts),Temp1,Temp2,RPM,Fuel," TELEMETRY_CELLS_LABEL "Current,Consumption,Vfas,AccelX,AccelY,AccelZ,", &g_oLogFile);
  }
#endif
#if defined(WS_HOW_HIGH)
  if (IS_USR_PROTO_WS_HOW_HIGH()) {
    f_puts("WSHH Alt,", &g_oLogFile);
  }
#endif
#endif

#if defined(CPUARM)
  char label[TELEM_LABEL_LEN+7];
  for (int i=0; i<MAX_SENSORS; i++) {
    TelemetrySensor & sensor = g_model.telemetrySensors[i];
    if (sensor.logs) {
      memset(label, 0, sizeof(label));
      zchar2str(label, sensor.label, TELEM_LABEL_LEN);
      if (sensor.unit != UNIT_RAW && sensor.unit != UNIT_GPS && sensor.unit != UNIT_DATETIME) {
        strcat(label, "(");
        strncat(label, STR_VTELEMUNIT+1+3*sensor.unit, 3);
        strcat(label, ")");
      }
      strcat(label, ",");
      f_puts(label, &g_oLogFile);
    }
  }
#endif
#endif

#if defined(PCBTARANIS)
  for (uint8_t i=1; i<NUM_STICKS+NUM_POTS+1; i++) {
    const char * p = STR_VSRCRAW + i * STR_VSRCRAW[0] + 2;
    for (uint8_t j=0; j<STR_VSRCRAW[0]-1; ++j) {
      if (!*p) break;
      f_putc(*p, &g_oLogFile);
      ++p;
    }
    f_putc(',', &g_oLogFile);
  }
  f_puts("SA,SB,SC,SD,SE,SF,SG,SH\n", &g_oLogFile);
#else
  f_puts("Rud,Ele,Thr,Ail,P1,P2,P3,THR,RUD,ELE,3POS,AIL,GEA,TRN\n", &g_oLogFile);
#endif
}
Example #3
0
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;
}
Example #4
0
static void json_write_string(uint8_t level, const char* st, FIL* fff) { //use to write brackets into json
	char sss[20] = { 0 };
	memset(sss, '\t', level * JSON_TAB);
	strcat(sss, st);
	strcat(sss, "\r\n");
	f_puts(sss, fff);
}
Example #5
0
FRESULT ff_test(void)
{
    printf("test fatfs begin\n\r");
    SD_NVIC_Configuration();

    res = f_mount(&fatfs, "", 0);
    if(res != FR_OK) printf("mount failed: %d\n\r", res);
    
    res = f_open(&file, "test.txt", FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
    res = f_open(&file2, "var.txt", FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
    if(res != FR_OK) printf("open failed: %d\n\r", res);
    
    res = f_write(&file, buff, 12 * sizeof(char), &bw);
    res = f_printf(&file, "test-");
    res = f_printf(&file, "speed:%d,%d\n\r",speed[0],speed[1]--);
    res = f_puts("end of file\n\r", &file);

    speed[0] = 65;
    speed[1] = 1;
    res = f_write(&file2, speed, sizeof(speed), &bw);
    if(res != FR_OK) printf("fwrite failed: %d\n\r", res);
    
    res = f_close(&file);
    res = f_close(&file2);
    if(res != FR_OK) printf("fclose failled: %d\n\r", res);

    res = f_mount(NULL,"", 0);
    if(res != FR_OK) printf("umonut failed: %d\n\r", res);
    
    if(res == FR_OK) printf("test fatfs success\n\r");
}
Example #6
0
static void json_write_object(uint8_t level, const char* name, FIL* fff) {
	char sss[64] = { 0 };
	memset(sss, '\t', level * JSON_TAB);
	strcat(sss, "\"");
	strcat(sss, name);
	strcat(sss, "\":{\r\n");
	f_puts(sss, fff);
}
Example #7
0
//------------------------------------------------------------------------------------------------------------------------------------------------------
void WriteToFile(FIL *file, char *string)
{
    //    uint bytesWritten;
    f_open(file, "list.txt", FA_OPEN_EXISTING);
    //f_write(file, string, strlen(string), (void*)&bytesWritten);
    f_puts(string, file);
    f_close(file);
}
Example #8
0
void config_printf(char *fmt, ...) {
	char buf[LINE_SIZE+1];
    va_list va;
    va_start (va, fmt);
    vsprintf (buf, fmt, va);
    va_end (va);
    f_puts(buf, &config);
}
Example #9
0
unsigned int ini_renentry(const char *filename, const char *entry, const char *newentry) //entry and newentry in upper case
{
  FRESULT res;
  unsigned int i, len, entry_start, found, rd;
  char c;

  res = f_open(&fileobj, filename, FA_OPEN_EXISTING | FA_READ | FA_WRITE);
  if(res != FR_OK)
  {
    return 1;
  }

  found = ini_searchentry(&fileobj, entry, &entry_start);
  if(found == 0)
  {
    f_close(&fileobj);
    return 2;
  }

  res = f_lseek(&fileobj, entry_start);
  if(res != FR_OK)
  {
    f_close(&fileobj);
    return 3;
  }

  //calc current entry size
  for(i=0; ; i++) //line len
  {
    res = f_read(&fileobj, &c, 1, &rd);
    if((res != FR_OK) || (rd != 1))
    {
      break;
    }
    if((c == '=') || (c == 0) || (c == '\n') || (c == '\r'))
    {
      break;
    }
  }

  len = strlen(newentry); //new entry len
  if(i > len) //new entry size is smaller
  {
    ini_stripfile(&fileobj, entry_start, (i-len)); //strip file: old-new
  }
  else if(i < len) //new entry size is bigger
  {
    ini_extendfile(&fileobj, entry_start, (len-i)); //extend file: new-old
  }

  //write new entry name
  f_lseek(&fileobj, entry_start);
  f_puts(newentry, &fileobj);

  f_close(&fileobj);

  return 0;
}
Example #10
0
int main(void) {
	/* Init system clock for maximum system speed */
	TM_RCC_InitSystem();
	
	/* Init HAL layer */
	HAL_Init();
	
	/* Init leds */
	TM_DISCO_LedInit();
	
	/* Try to mount card */
	if (f_mount(&FS, "SD:", 1) == FR_OK) {
		/* Try to open file */
		if ((fres = f_open(&fil, "SD:first_file.txt", FA_OPEN_ALWAYS | FA_READ | FA_WRITE)) == FR_OK) {
			/* Read SDCARD size */
			TM_FATFS_GetDriveSize("SD:", &CardSize);
			
			/* Format string */
			sprintf(buffer, "Total card size: %u kBytes\n", CardSize.Total);
			
			/* Write total card size to file */
			f_puts(buffer, &fil);
			
			/* Format string for free card size */
			sprintf(buffer, "Free card size:  %u kBytes\n", CardSize.Free);
			
			/* Write free card size to file */
			f_puts(buffer, &fil);
			
			/* Close file */
			f_close(&fil);
			
			/* Turn led ON */
			TM_DISCO_LedOn(LED_ALL);
		}
		
		/* Unmount SDCARD */
		f_mount(NULL, "SD:", 1);
	}
	
	/* Do nothing */
	while (1) {
		
	}
}
static int32_t data_logging_put_float(FIL* fp, float c, int32_t after_digits)
{
	int32_t i;
	int32_t res = 0;
	float num = c;
	
	if (c<0)
	{
		res = f_puts("-",fp);
		if (res == EOF)
		{
			return res;
		}
		num=-c;
	}

	int32_t whole=abs((int32_t)num);
	float after=(num-(float)whole);

	res = f_printf(fp,"%d", whole);
	if (res == EOF)
	{
		return res;
	}
	
	res = f_puts(".",fp);
	if (res == EOF)
	{
		return res;
	}
	
	for (i=0; i<after_digits; i++)
	{
		after*=10;
		res = f_printf(fp, "%d",(int32_t)after);
		if (res == EOF)
		{
			return res;
		}
		after=after-(int32_t)after;
	}
	
	return res;
}
Example #12
0
int cfg_save() {
  int err = 0;
  uint64_t bcdtime = srtctime2bcdtime(CFG.bsx_time);
  file_open((uint8_t*)CFG_FILE, FA_CREATE_ALWAYS | FA_WRITE);
  f_puts("---\n", &file_handle);
  f_puts("##############################\n", &file_handle);
  f_puts("# sd2snes configuration file #\n", &file_handle);
  f_puts("##############################\n\n", &file_handle);
  f_puts("# Allow SuperCIC Pair Mode (required for video mode setting)\n", &file_handle);
  f_printf(&file_handle, "%s: %s\n", CFG_PAIR_MODE_ALLOWED, CFG.pair_mode_allowed ? "true" : "false");
  f_printf(&file_handle, "\n# Video mode (%d = 60Hz, %d = 50Hz, %d = Auto (game only))\n", VIDMODE_60, VIDMODE_50, VIDMODE_AUTO);
  f_printf(&file_handle, "%s: %d\n", CFG_VIDMODE_MENU, CFG.vidmode_menu);
  f_printf(&file_handle, "%s: %d\n", CFG_VIDMODE_GAME, CFG.vidmode_game);
  f_printf(&file_handle, "\n# Satellaview Settings\n#  %s: use user defined time instead of real time\n", CFG_BSX_USE_USERTIME);
  f_printf(&file_handle, "#  %s: user defined Satellaview broadcast time (format: YYYYMMDDhhmmss)\n", CFG_BSX_TIME);
  f_printf(&file_handle, "%s: %s\n", CFG_BSX_USE_USERTIME, CFG.bsx_use_usertime ? "true" : "false");
  f_printf(&file_handle, "%s: %06lX%08lX\n", CFG_BSX_TIME, (uint32_t)(bcdtime>>32), (uint32_t)(bcdtime & 0xffffffffLL));
  f_puts("\n# Enable PPU region flag patching\n", &file_handle);
  f_printf(&file_handle, "%s: %s\n", CFG_R213F_OVERRIDE, CFG.r213f_override ? "true" : "false");
  f_puts("\n# IRQ hook related settings\n", &file_handle);
  f_printf(&file_handle, "#  %s: Overall enable IRQ hooks (required for in-game buttons & WRAM cheats)\n", CFG_ENABLE_IRQ_HOOK);
  f_printf(&file_handle, "#  %s: Enable in-game buttons (en/disable cheats, reset sd2snes...)\n", CFG_ENABLE_IRQ_BUTTONS);
  f_printf(&file_handle, "#  %s: Enable 10s grace period after reset before enabling in-game hooks\n", CFG_ENABLE_IRQ_HOLDOFF);
  f_printf(&file_handle, "%s: %s\n", CFG_ENABLE_IRQ_HOOK, CFG.enable_irq_hook ? "true" : "false");
  f_printf(&file_handle, "%s: %s\n", CFG_ENABLE_IRQ_BUTTONS, CFG.enable_irq_buttons ? "true" : "false");
  f_printf(&file_handle, "%s: %s\n", CFG_ENABLE_IRQ_HOLDOFF, CFG.enable_irq_holdoff ? "true" : "false");
  f_puts("\n# Screensaver settings\n", &file_handle);
  f_printf(&file_handle, "#  %s: Enable screensaver\n", CFG_ENABLE_SCREENSAVER);
//  f_printf(&file_handle, "#  %s: Dim screen after n seconds\n", CFG_SCREENSAVER_TIMEOUT);
  f_printf(&file_handle, "%s: %s\n", CFG_ENABLE_SCREENSAVER, CFG.enable_screensaver ? "true" : "false");
//  f_printf(&file_handle, "%s: %d\n", CFG_SCREENSAVER_TIMEOUT, CFG.screensaver_timeout);
  f_puts("\n# UI related settings\n", &file_handle);
  f_printf(&file_handle, "#  %s: Sort directories (slower but files are guaranteed to be in order)\n", CFG_SORT_DIRECTORIES);
  f_printf(&file_handle, "#  %s: Hide file extensions\n", CFG_HIDE_EXTENSIONS);
  f_printf(&file_handle, "%s: %s\n", CFG_SORT_DIRECTORIES, CFG.sort_directories ? "true" : "false");
  f_printf(&file_handle, "%s: %s\n", CFG_HIDE_EXTENSIONS, CFG.hide_extensions ? "true" : "false");
  f_puts("\n# Enhancement chip settings\n", &file_handle);
  f_printf(&file_handle, "#  %s: Cx4 core speed (0: original, 1: fast, all instructions are single cycle)\n", CFG_CX4_SPEED);
  f_printf(&file_handle, "%s: %d\n", CFG_CX4_SPEED, CFG.cx4_speed);
  f_printf(&file_handle, "#  %s: MSU audio volume boost\n#    (0: none; 1: +3.5dBFS; 2: +6dBFS; 3: +9.5dBFS; 4: +12dBFS)\n", CFG_MSU_VOLUME_BOOST);
  f_printf(&file_handle, "%s: %d\n", CFG_MSU_VOLUME_BOOST, CFG.msu_volume_boost);
  file_close();
  return err;
}
Example #13
0
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;
}
static int32_t data_logging_put_double(FIL* fp, double c, int32_t after_digits)
{
	int32_t i;
	int32_t res = 0;
	double num = c;
	
	if (c<0)
	{
		res = f_puts("-",fp);
		if (res == EOF)
		{
			return res;
		}
		num=-c;
	}

	int64_t whole=(int64_t)floor(num);
	double after=(num-(double)whole);

	data_logging_put_uint64_t(fp,(uint64_t)whole);
	
	res = f_puts(".",fp);
	if (res == EOF)
	{
		return res;
	}
	
	for (i=0; i<after_digits; i++)
	{
		after*=10;
		res = f_printf(fp, "%ld",(int32_t)after);
		if (res == EOF)
		{
			return res;
		}
		after=after-(int64_t)after;
	}
	
	return res;
}
Example #15
0
void record_init()
{
	
	uint16_t num=0;
	int8_t i;
	NVIC_InitTypeDef NVIC_InitStructure;

  /* Configure the NVIC Preemption Priority Bits */
 // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

  NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  NVIC_InitStructure.NVIC_IRQChannel = SD_SDIO_DMA_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_Init(&NVIC_InitStructure);  
	
	
	disk_initialize(0);
	res=f_mount(0, &fs[0]);

	res=f_open(&fsrc, "0:/num.txt",FA_OPEN_EXISTING | FA_READ | FA_WRITE);  //  以读方式打开,如果文件不存在则打开失败
	
	if ( res == FR_OK )
  { 

		res=f_read(&fsrc, read_Buff, sizeof(read_Buff), &br);
		for (i=0;i<br;i++)
		{
			num=num*10+(read_Buff[i]-0x30);
		}
		if (num>=99)
			num=0;


		sprintf(record_num,"%d",num+1);
		f_lseek(&fsrc,0);
		f_puts (record_num,&fsrc);
		f_truncate(&fsrc);		
    f_close(&fsrc);  
		
		sprintf(record_file_name,"0:/N%d.txt",num+1);
		f_open(&file, record_file_name,FA_CREATE_NEW| FA_WRITE);  //  以读方式打开,如果文件不存在则打开失败
		f_close(&file);  
  }
	else
		f_close(&fsrc);	                                      /* 关闭打开的文件 */	
	
}
static void data_logging_put_r_or_n(data_logging_t* data_logging, uint16_t param_num)
{
	int32_t res = 0;
	
	if (param_num == (data_logging->data_logging_set->data_logging_count-1))
	{
		res = f_puts("\n",&data_logging->fil);
	}
	else
	{
		res = f_puts("\t",&data_logging->fil);
	}
	if (res == EOF)
	{
		if (data_logging->debug)
		{
			data_logging->fr = f_stat(data_logging->name_n_extension,NULL);
			print_util_dbg_print("Error putting tab or new line character!\r\n");
			data_logging_print_error_signification(data_logging);
			print_util_dbg_print("\r\n");
		}
	}
}
Example #17
0
void SD_Init(void){	
	FRESULT res;                                          /* FatFs function common result code */
  uint32_t byteswritten;                     /* File write/read counts */
  uint8_t wtext[] = "This is STM32 working with FatFs"; /* File write buffer */
                                 
if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0) 
  {
    if(f_mount(&SDFatFs,(TCHAR const*)SDPath, 0) != FR_OK)
    {
      Error_Handler();
    }
    else
    {
        if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS  | FA_WRITE) != FR_OK) 
        {
          Error_Handler();
        }
        else
        {
					f_puts("First string in my file\n", &MyFile);
					/*
          res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);
          if((byteswritten == 0) || (res != FR_OK))
          {
            Error_Handler();
          }
          else
          {
						*/
            f_close(&MyFile);
           BSP_LED_On(LED0);
				BSP_LED_Toggle(LED0);
        HAL_Delay(100);
						BSP_LED_Toggle(LED0);
        HAL_Delay(100);
						BSP_LED_Toggle(LED0);
        HAL_Delay(100);
						BSP_LED_Toggle(LED0);
        HAL_Delay(100);
						BSP_LED_Toggle(LED0);
        HAL_Delay(100);
						BSP_LED_Toggle(LED0);
        HAL_Delay(100);
						BSP_LED_Toggle(LED0);
       //   }
        }
		}
	}
		 FATFS_UnLinkDriver(SDPath);
}
Example #18
0
void OnWriteString(nwazetMessageContext_t* nmc){
  fileObjectMap_t* fileObj = GetFileObjectById(nmc);
  if(fileObj){
    uint8_t isTextASCII = 0;
    uint16_t textLength = 0;
    void* text = GetStringReference(nmc->cmdContext, &textLength, &isTextASCII);
    if(text && textLength){
      int32_t charactersWritten = f_puts((const TCHAR*) text, fileObj->file);
      StartResponse(nmc, FR_OK, false);
      Put(nmc->respContext, (void*)&charactersWritten, sizeof(charactersWritten), 1);
      EndResponse(nmc);
    }
  }
}
Example #19
0
static void json_write_value(uint8_t level, const char* name,
	                  const char* value, uint8_t colon, FIL* fff) {
	char sss[64] = { 0 };
	memset(sss, '\t', level * JSON_TAB);
	strcat(sss, "\"");
	strcat(sss, name);
	strcat(sss, "\":\"");
	strcat(sss, value);
	if (colon != 0) {
		strcat(sss, "\",\r\n");
	} else {
		strcat(sss, "\"\r\n");
	}
	f_puts(sss, fff);
}
SDFS_status_type SDFS_writeString(FIL* fp, char* text) {
	SDFS_status_type ret_wert = SDFS_WRITE_ERR;
	int check = 0;

	check = f_puts(text, fp);

	if (check >= 0) {
		ret_wert = SDFS_OK;
		f_putc('\n', fp);
	} else {
		ret_wert = SDFS_WRITE_ERR;
	}

	return (ret_wert);
}
Example #21
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;
}
Example #22
0
void Filewrite(void)
{


	if (FR_OK == f_open(&fileW, "0:Segg.txt", FA_CREATE_ALWAYS | FA_WRITE))
	{
		//strcpy((char*)buffer,"PROBASZOVEG.");
		//res = f_write(&fileW, buffer, 512, &bw);
		if (f_puts((char*)"Probaszoveg.",&fileW)>0)
		{
			GPIO_SetBits(GPIOD, GPIO_Pin_15);
		}
	}
	f_close(&fileW);
	//f_mount( 0, NULL );
}
Example #23
0
void main(void)
{
    FIL fdst;  //文件
    FATFS fs;  //文件系统

    uint32 size, sizetmp;
    int res;
    char *str = "感谢您选用 野火Kinetis开发板 !^_^ ";
    u8 buff[BUFF_SIZE];

    for(size = 0; size < BUFF_SIZE; size++)buff[size] = 0;

    f_mount(0, &fs);		                                                       //SD卡系统初始化

    res = f_open(&fdst, "0:/FireDemo.txt", FA_OPEN_ALWAYS | FA_WRITE | FA_READ);  //打开文件,如果没有就创建,带读写打开

    if( res == FR_DISK_ERR)
    {
        printf( "\n没插入SD卡??\n" );
        return;
    }
    else if ( res == FR_OK )
    {
        printf( "\n文件打开成功 \n" );
    }
    else
    {
        printf("\n返回值异常");
    }


    f_puts(str, &fdst);                     //往文件里写入字符串

    size = f_size(&fdst);                   //获取文件的大小

    printf( "\n文件大小为:%d \n" , size);  //串口打印文件的大小

    if(size > BUFF_SIZE)size = BUFF_SIZE;   //防止溢出

    f_lseek(&fdst, 0);                      //把指针指向文件顶部
    f_read (&fdst, buff, size, (UINT *)&sizetmp);   //读取


    printf("文件内容为:%s", (char const *)buff);

    f_close(&fdst);                         //关闭文件
}
Example #24
0
static void json_write_number(uint8_t level, const char* name,
	int number, uint8_t colon, FIL* fff) { //write some json parameter with numeric int value
	char sss[64]={0};
	char lll[16];
	memset(sss, '\t', level * JSON_TAB);
	strcat(sss, "\"");
	strcat(sss, name);
	strcat(sss,"\":");
	itoa(number,lll);
	strcat(sss,lll);
	if (colon) {
		strcat(sss,",\r\n");
	}else{
		strcat(sss,"\r\n");
	}
	f_puts(sss, fff);
}
Example #25
0
void DebugCanFrame(u8 tx, u8 extFrame, CanMessage_t *msg)
{
  u8 i;
  u8 debugString[60];
  u8 *p = debugString;

  if (canDebug)
  {
    p += sprintf(p, "%s %s id=%03x len=%d payload=", tx?"TX":"RX", extFrame?"EXT":"STD", msg->id, msg->len);
    for (i=0; i<msg->len; i++)
    {
      p += sprintf(p, "%02x ", msg->payload[i]);
    }
    p += sprintf(p, "\n");
  
    f_puts(debugString, log_file);
  }
}
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;
}
static int32_t data_logging_put_int64_t(FIL* fp, int64_t c)
{
	int32_t res = 0;
	int64_t num = c;
	
	if (c<0)
	{
		res = f_puts("-",fp);
		if (res == EOF)
		{
			return res;
		}
		num=-c;
	}
	
	res = data_logging_put_uint64_t(fp,(uint64_t)num);
	
	return res;
}
Example #28
0
static void vBaro(void* pvParameters) {
	static FIL f_baro_log;
	static char baro_str_buf[0x20];
	int result;
	int counter = 0;
	LPS_init(I2C0);
	LPS_enable();
	strcpy(baro_str_buf, "0:BARO.TAB");
	{
		int rename_number = 1;
		while(true) {
			if (f_stat(baro_str_buf, NULL) == FR_OK) {
				sprintf(baro_str_buf, "0:BARO%d.TAB", rename_number);
				rename_number ++;
				continue;
			}
			break;
		}
	}
	LOG_INFO("Baro output is %s", baro_str_buf);
	result = f_open(&f_baro_log, baro_str_buf, FA_WRITE | FA_CREATE_ALWAYS);

	// DEBUG
	xTaskCreate(vIMU, (signed char*) "IMU", 512, NULL, (tskIDLE_PRIORITY + 1UL), NULL);
	// ENDBEBUG
	while (true) {
		float temp, alt;
		xSemaphoreTake(mutex_i2c, portMAX_DELAY);
		temp = LPS_read_data(LPS_TEMPERATURE);
		alt = LPS_read_data(LPS_ALTITUDE);
		xSemaphoreGive(mutex_i2c);
		if (result == FR_OK) {
			sprintf(baro_str_buf, "%d\t%f\t%f\n", xTaskGetTickCount(), temp, alt);
			f_puts(baro_str_buf, &f_baro_log);
			if ((counter % 50) == 0) {
				f_sync(&f_baro_log);
			}
		}
		vTaskDelay(50);
		counter ++;
	}
}
Example #29
0
File: hooks.c Project: x893/OpenBLT
/************************************************************************************//**
** \brief     Callback that gets called each time new log information becomes 
**            available during a firmware update.
** \param     info_string Pointer to a character array with the log entry info.
** \return    none.
**
****************************************************************************************/
void FileFirmwareUpdateLogHook(blt_char *info_string)
{
  /* write the string to the log file */
  if (logfile.canUse == BLT_TRUE)
  {
    if (f_puts(info_string, &logfile.handle) < 0)
    {
      logfile.canUse = BLT_FALSE;
      f_close(&logfile.handle);
    }
  }
  /* echo all characters in the string on UART */
  while(*info_string != '\0')
  {
    /* write character to transmit holding register */
    USART_SendData(USART6, *info_string);
    /* wait for tx holding register to be empty */
    while(USART_GetFlagStatus(USART6, USART_FLAG_TXE) == RESET);
    /* point to the next character in the string */
    info_string++;
  }
} /*** end of FileFirmwareUpdateLogHook ***/
Example #30
0
File: hooks.c Project: x893/OpenBLT
/************************************************************************************//**
** \brief     Callback that gets called each time new log information becomes 
**            available during a firmware update.
** \param     info_string Pointer to a character array with the log entry info.
** \return    none.
**
****************************************************************************************/
void FileFirmwareUpdateLogHook(blt_char *info_string)
{
  /* write the string to the log file */
  if (logfile.canUse == BLT_TRUE)
  {
    if (f_puts(info_string, &logfile.handle) < 0)
    {
      logfile.canUse = BLT_FALSE;
      f_close(&logfile.handle);
    }
  }
  /* echo all characters in the string on UART */
  while(*info_string != '\0')
  {
    /* write character to transmit holding register */
    UARTCharPutNonBlocking(UART0_BASE, *info_string);
    /* wait for tx holding register to be empty */
    while(UARTSpaceAvail(UART0_BASE) == false);
    /* point to the next character in the string */
    info_string++;
  }
} /*** end of FileFirmwareUpdateLogHook ***/