void backupEeprom() { char filename[60]; uint8_t buffer[1024]; FIL file; lcd_clear(); displayProgressBar(STR_WRITING); // reset unexpectedShutdown to prevent warning when user restores EEPROM backup g_eeGeneral.unexpectedShutdown = 0; eeDirty(EE_GENERAL); eeCheck(true); // create the directory if needed... DIR folder; FRESULT result = f_opendir(&folder, EEPROMS_PATH); if (result != FR_OK) { if (result == FR_NO_PATH) result = f_mkdir(EEPROMS_PATH); if (result != FR_OK) { POPUP_WARNING(SDCARD_ERROR(result)); return; } } // prepare the filename... char * tmp = strAppend(filename, EEPROMS_PATH "/eeprom"); tmp = strAppendDate(tmp, true); strAppend(tmp, EEPROM_EXT); // open the file for writing... f_open(&file, filename, FA_WRITE | FA_CREATE_ALWAYS); for (int i=0; i<EESIZE; i+=1024) { UINT count; eepromReadBlock(buffer, i, 1024); f_write(&file, buffer, 1024, &count); updateProgressBar(i, EESIZE); SIMU_SLEEP(100/*ms*/); } f_close(&file); //set back unexpectedShutdown g_eeGeneral.unexpectedShutdown = 1; eeDirty(EE_GENERAL); eeCheck(true); }
const pm_char *openLogs() { // Determine and set log file filename FRESULT result; DIR folder; char filename[34]; // /LOGS/modelnamexxx-2013-01-01.log if (!sdMounted()) return STR_NO_SDCARD; if (sdGetFreeSectors() == 0) return STR_SDCARD_FULL; // check and create folder here strcpy_P(filename, STR_LOGS_PATH); result = f_opendir(&folder, filename); if (result != FR_OK) { if (result == FR_NO_PATH) result = f_mkdir(filename); if (result != FR_OK) return SDCARD_ERROR(result); } filename[sizeof(LOGS_PATH)-1] = '/'; memcpy(&filename[sizeof(LOGS_PATH)], g_model.header.name, sizeof(g_model.header.name)); filename[sizeof(LOGS_PATH)+sizeof(g_model.header.name)] = '\0'; uint8_t i = sizeof(LOGS_PATH)+sizeof(g_model.header.name)-1; uint8_t len = 0; while (i>sizeof(LOGS_PATH)-1) { if (!len && filename[i]) len = i+1; if (len) { if (filename[i]) filename[i] = idx2char(filename[i]); else filename[i] = '_'; } i--; } if (len == 0) { uint8_t num = g_eeGeneral.currModel + 1; strcpy_P(&filename[sizeof(LOGS_PATH)], STR_MODEL); filename[sizeof(LOGS_PATH) + PSIZE(TR_MODEL)] = (char)((num / 10) + '0'); filename[sizeof(LOGS_PATH) + PSIZE(TR_MODEL) + 1] = (char)((num % 10) + '0'); len = sizeof(LOGS_PATH) + PSIZE(TR_MODEL) + 2; } char * tmp = &filename[len]; #if defined(RTCLOCK) tmp = strAppendDate(&filename[len]); #endif strcpy_P(tmp, STR_LOGS_EXT); result = f_open(&g_oLogFile, filename, FA_OPEN_ALWAYS | FA_WRITE); if (result != FR_OK) { return SDCARD_ERROR(result); } if (f_size(&g_oLogFile) == 0) { writeHeader(); } else { result = f_lseek(&g_oLogFile, f_size(&g_oLogFile)); // append if (result != FR_OK) { return SDCARD_ERROR(result); } } return NULL; }
const pm_char * openLogs() { // Determine and set log file filename FRESULT result; DIR folder; char filename[34]; // /LOGS/modelnamexxx-2013-01-01.log if (!sdMounted()) return STR_NO_SDCARD; strcpy_P(filename, STR_LOGS_PATH); result = f_opendir(&folder, filename); if (result != FR_OK) { if (result == FR_NO_PATH) result = f_mkdir(filename); if (result != FR_OK) return SDCARD_ERROR(result); } filename[sizeof(LOGS_PATH)-1] = '/'; memcpy(&filename[sizeof(LOGS_PATH)], g_model.header.name, sizeof(g_model.header.name)); filename[sizeof(LOGS_PATH)+sizeof(g_model.header.name)] = '\0'; uint8_t i = sizeof(LOGS_PATH)+sizeof(g_model.header.name)-1; uint8_t len = 0; while (i>sizeof(LOGS_PATH)-1) { if (!len && filename[i]) len = i+1; if (len) { if (filename[i]) filename[i] = idx2char(filename[i]); else filename[i] = '_'; } i--; } if (len == 0) { uint8_t num = g_eeGeneral.currModel + 1; strcpy_P(&filename[sizeof(LOGS_PATH)], STR_MODEL); filename[sizeof(LOGS_PATH) + PSIZE(TR_MODEL)] = (char)((num / 10) + '0'); filename[sizeof(LOGS_PATH) + PSIZE(TR_MODEL) + 1] = (char)((num % 10) + '0'); len = sizeof(LOGS_PATH) + PSIZE(TR_MODEL) + 2; } char * tmp = &filename[len]; #if defined(RTCLOCK) tmp = strAppendDate(&filename[len]); #endif strcpy_P(tmp, STR_LOGS_EXT); result = f_open(&g_oLogFile, filename, FA_OPEN_ALWAYS | FA_WRITE); if (result != FR_OK) { return SDCARD_ERROR(result); } if (f_size(&g_oLogFile) == 0) { #if defined(RTCLOCK) f_puts("Date,Time,", &g_oLogFile); #else f_puts("Time,", &g_oLogFile); #endif #if defined(PCBTARANIS) && defined(REVPLUS) f_puts("RSSI,A1,A2,A3,A4,", &g_oLogFile); #elif defined(CPUARM) && defined(FRSKY) f_puts("SWR,RSSI,A1,A2,A3,A4,", &g_oLogFile); #elif defined(FRSKY) f_puts("Buffer,RX,TX,A1,A2,", &g_oLogFile); #endif #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 #if defined(PCBTARANIS) f_puts("Rud,Ele,Thr,Ail,S1,S2,S3,LS,RS,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 } else { result = f_lseek(&g_oLogFile, f_size(&g_oLogFile)); // append if (result != FR_OK) { return SDCARD_ERROR(result); } } return NULL; }