1.优化rtos下文件保存

This commit is contained in:
payton 2023-08-18 16:54:12 +08:00
parent d5b15079dd
commit 9ea64c9a1d
3 changed files with 117 additions and 64 deletions

View File

@ -514,7 +514,7 @@ void sf_file_thumb_cfg_fill(char* filepath,char* fileName,UINT32 size, SF_FILE_T
void sf_file_thumb_cfg_set(SF_SRCFILE_ATTR_S *pThumbFileCfgl);
void sf_file_thumb_cfg_clear(void);
void sf_file_thumb_cfg_sava(void);
void sf_add_file_name_to_send_list(char *sendfname);
void sf_add_file_name_to_send_list(char *sendfname, UINT32 fd);
UINT8 sf_mcu_power_on_para_get(MCUParam_t attrId);
void sf_mcu_flag_init(void);
void sf_mcu_flag_set_done(MCU_FLAG_INIT boot_init);

View File

@ -1565,10 +1565,11 @@ void sf_BatteryInfoSave(char *name)
UINT32 batAdc = 0;
//char fileName[64] = {0};
int fd = 0;
struct stat st;
tmpBuf = malloc(512);
FST_FILE fd = 0;
//struct stat st;
UINT32 size = 0;
INT32 ret_fs = 0;
tmpBuf = malloc(100);
if (tmpBuf == NULL) {
printf("%s:%d tmpBuf malloc err\n", __FUNCTION__, __LINE__);
@ -1577,17 +1578,19 @@ void sf_BatteryInfoSave(char *name)
//snprintf(fileName, sizeof(fileName), "%s", SF_BATTERY_TEST_FILE);
if(access(SF_BATTERY_TEST_FILE, F_OK) == 0)
/*if(access(SF_BATTERY_TEST_FILE, F_OK) == 0)
{
printf("fileName:%s\n",SF_BATTERY_TEST_FILE);
fd = open(SF_BATTERY_TEST_FILE, O_APPEND | O_WRONLY);
}
else {
fd = open(SF_BATTERY_TEST_FILE, O_APPEND | O_WRONLY | O_CREAT);
}
}*/
printf("fileName:%s\n",SF_BATTERY_TEST_FILE);
fd = FileSys_OpenFile(SF_BATTERY_TEST_FILE, FST_OPEN_ALWAYS | FST_OPEN_WRITE);
LibatAdc = sf_battery_convert_to_adc(15, 100, LiPolymerVoltageValTest);
batAdc = sf_battery_convert_to_adc(15, 100, BatVoltageValTest);
LibatAdc = sf_battery_convert_to_adc(24, 100, LiPolymerVoltageValTest);
batAdc = sf_battery_convert_to_adc(24, 100, BatVoltageValTest);
sprintf(tmpBuf, "%s BatAdc=%lu BatVal=%lu LiBatAdc=%lu LiBatVal=%lu TemperAdc=%lu\r\n", name, batAdc, BatVoltageValTest, LibatAdc, LiPolymerVoltageValTest, TemperAdc);
@ -1595,11 +1598,22 @@ void sf_BatteryInfoSave(char *name)
if(fd)
{
fstat(fd, &st);
/*fstat(fd, &st);
lseek(fd, 0, SEEK_END);
write(fd, tmpBuf, strlen(tmpBuf));
close(fd);
printf("Add Success st_size:%ld\n", st.st_size);
*/
ret_fs = FileSys_SeekFile((FST_FILE)fd, 0, FST_SEEK_END);
if (ret_fs != FST_STA_OK) {
printf("%s:%d seek file failed\r\n", __FUNCTION__, __LINE__);
}
size = strlen(tmpBuf);
ret_fs = FileSys_WriteFile((FST_FILE)fd, (UINT8*)tmpBuf, &size, 0, NULL);
if (ret_fs != FST_STA_OK) {
printf("%s:%d FileSys_WriteFile failed\r\n", __FUNCTION__, __LINE__);
}
FileSys_CloseFile(fd);
}
free(tmpBuf);
}

View File

@ -2157,13 +2157,60 @@ void sf_file_thumb_cfg_sava(void)
UIMenuStoreInfo *puiPara = sf_ui_para_get();
if (pThumbFileCfg != NULL) {
for(fileIndex = 0; fileIndex < pThumbFileCfg->filecnt; fileIndex++)
{
if((0 == fileIndex) || ((1 == puiPara->SendMulti))){
sf_add_file_name_to_send_list(pThumbFileCfg->stfileattr[fileIndex].thumbfileName);
printf("%s:%d thumbfileSize:%ld thumbfileName:%s thumbfilePath:%s\n", __FUNCTION__, __LINE__,pThumbFileCfg->stfileattr[fileIndex].thumbfileSize,pThumbFileCfg->stfileattr[fileIndex].thumbfileName,pThumbFileCfg->stfileattr[fileIndex].thumbfilePath);
char sendListName[64] = {0};
FST_FILE fs = 0;
//char buff[SF_SEND_LIST_ITEM_LENGTH+1] = {0};
int fd = 0;
static int flag = 0;
//struct stat st;
#if SF_IQ_TEST != ENABLE
INT32 uiStatus = 0;
UINT8 ucAttrib = 0;
uiStatus = FileSys_GetAttrib(PHOTO_THUMB_PATH, &ucAttrib);
if (uiStatus == FST_STA_OK) {
if(!(ucAttrib&FST_ATTRIB_HIDDEN)){
FileSys_SetAttrib(PHOTO_THUMB_PATH, FST_ATTRIB_HIDDEN/* | FST_ATTRIB_SYSTEM*/, TRUE);
}
}
}
#endif
//printf("Add %s to send.List\n", sendfname);
if(0 == puiPara->SendType){
snprintf(sendListName, sizeof(sendListName), "%s", SF_THUMB_SEND_AUTO);
if((access(sendListName, F_OK) == 0) && (0 == flag))
{
if (FileSys_DeleteFile(sendListName) != FST_STA_OK) {
DBG_IND("Ignore deleting file.\r\n");
}
}
flag = 1;
}else {
snprintf(sendListName, sizeof(sendListName), "%s", SF_THUMB_SEND_LIST);
}
/*if(access(sendListName, F_OK) == 0)
{
printf("sendListName:%s\n",sendListName);
fd = open(sendListName, O_APPEND | O_WRONLY);
}
else {
fd = open(sendListName, O_APPEND | O_WRONLY | O_CREAT);
}*/
fs = FileSys_OpenFile(sendListName, FST_OPEN_ALWAYS | FST_OPEN_WRITE);
if(/*fd*/fs)
{
for(fileIndex = 0; fileIndex < pThumbFileCfg->filecnt; fileIndex++)
{
if((0 == fileIndex) || ((1 == puiPara->SendMulti))){
sf_add_file_name_to_send_list(pThumbFileCfg->stfileattr[fileIndex].thumbfileName, fd);
printf("%s:%d thumbfileSize:%ld thumbfileName:%s thumbfilePath:%s\n", __FUNCTION__, __LINE__,pThumbFileCfg->stfileattr[fileIndex].thumbfileSize,pThumbFileCfg->stfileattr[fileIndex].thumbfileName,pThumbFileCfg->stfileattr[fileIndex].thumbfilePath);
}
}
FileSys_CloseFile(fs);
//close(fd);
}
//printf("%s:%d e Size:%ld\n", __FUNCTION__, __LINE__,pThumbFileCfg->stfileattr[fileIndex].thumbfileSize);
free(pThumbFileCfg);
}
@ -2177,61 +2224,39 @@ void sf_file_thumb_cfg_sava(void)
Return: N/A
Others: N/A
*************************************************/
void sf_add_file_name_to_send_list(char *sendfname)
void sf_add_file_name_to_send_list(char *sendfname, UINT32 fd)
{
char sendListName[64] = {0};
//char sendListName[64] = {0};
char buff[SF_SEND_LIST_ITEM_LENGTH+1] = {0};
int fd = 0;
static int flag = 0;
struct stat st;
//struct stat st;
UINT32 size = 0;
INT32 ret_fs = 0;
UIMenuStoreInfo *puiPara = sf_ui_para_get();
#if SF_IQ_TEST != ENABLE
INT32 uiStatus = 0;
UINT8 ucAttrib = 0;
uiStatus = FileSys_GetAttrib(PHOTO_THUMB_PATH, &ucAttrib);
if (uiStatus == FST_STA_OK) {
if(!(ucAttrib&FST_ATTRIB_HIDDEN)){
FileSys_SetAttrib(PHOTO_THUMB_PATH, FST_ATTRIB_HIDDEN/* | FST_ATTRIB_SYSTEM*/, TRUE);
}
}
#endif
if(strlen(sendfname) != SF_SEND_LIST_ITEM_LENGTH-3) //3 ->CamMode \r\n
{
printf("%s:%d AddFileNameToSenddist fail: send file name format error\n", __FUNCTION__, __LINE__);
return;
}
//printf("Add %s to send.List\n", sendfname);
if(0 == puiPara->SendType){
snprintf(sendListName, sizeof(sendListName), "%s", SF_THUMB_SEND_AUTO);
if((access(sendListName, F_OK) == 0) && (0 == flag))
{
if (FileSys_DeleteFile(sendListName) != FST_STA_OK) {
DBG_IND("Ignore deleting file.\r\n");
}
}
flag = 1;
}else {
snprintf(sendListName, sizeof(sendListName), "%s", SF_THUMB_SEND_LIST);
}
if(access(sendListName, F_OK) == 0)
{
printf("sendListName:%s\n",sendListName);
fd = open(sendListName, O_APPEND | O_WRONLY);
}
else {
fd = open(sendListName, O_APPEND | O_WRONLY | O_CREAT);
}
if(fd)
{
fstat(fd, &st);
lseek(fd, 0, SEEK_END);
//fstat(fd, &st);
//lseek(fd, 0, SEEK_END);
ret_fs = FileSys_SeekFile((FST_FILE)fd, 0, FST_SEEK_END);
if (ret_fs != FST_STA_OK) {
printf("%s:%d seek file failed\r\n", __FUNCTION__, __LINE__);
}
snprintf(buff, sizeof(buff), "%d%s\r\n", puiPara->CamMode, sendfname);
size = SF_SEND_LIST_ITEM_LENGTH;
ret_fs = FileSys_WriteFile((FST_FILE)fd, (UINT8*)buff, &size, 0, NULL);
if (ret_fs != FST_STA_OK) {
printf("%s:%d FileSys_WriteFile failed\r\n", __FUNCTION__, __LINE__);
}
//write(fd, buff, SF_SEND_LIST_ITEM_LENGTH);
write(fd, buff, SF_SEND_LIST_ITEM_LENGTH);
close(fd);
//printf("Add Success st_size:%ld\n", st.st_size);
}
#if SF_BATTERY_TEST == ENABLE
@ -2291,8 +2316,10 @@ void sf_hw_info_save(char *name)
//UINT32 batAdc = 0;
//char fileName[64] = {0};
int fd = 0;
FST_FILE fd = 0;
//struct stat st;
UINT32 size = 0;
INT32 ret_fs = 0;
struct tm drRtcTime;
@ -2300,7 +2327,7 @@ void sf_hw_info_save(char *name)
char datestr[30] = { 0 };
tmpBuf = malloc(512);
tmpBuf = malloc(100);
if (tmpBuf == NULL) {
printf("%s:%d tmpBuf malloc err\n", __FUNCTION__, __LINE__);
@ -2326,14 +2353,16 @@ void sf_hw_info_save(char *name)
//snprintf(fileName, sizeof(fileName), "%s", SF_HW_TEST_FILE);
if(access(SF_HW_TEST_FILE, F_OK) == 0)
/*if(access(SF_HW_TEST_FILE, F_OK) == 0)
{
printf("fileName:%s\n",SF_HW_TEST_FILE);
fd = open(SF_HW_TEST_FILE, O_APPEND | O_WRONLY);
}
else {
fd = open(SF_HW_TEST_FILE, O_APPEND | O_WRONLY | O_CREAT);
}
}*/
printf("fileName:%s\n",SF_HW_TEST_FILE);
fd = FileSys_OpenFile(SF_HW_TEST_FILE, FST_OPEN_ALWAYS | FST_OPEN_WRITE);
sprintf(tmpBuf, "%s %s IRSHTTER=%d TemperAdc=%lu ae_adj=%lu iso=%lu exp=%lu lv=%lu\r\n", datestr, name, IRSHTTER, sf_get_temper_adc(), testadj, testiso, testexp, testlv);
@ -2342,10 +2371,20 @@ void sf_hw_info_save(char *name)
if(fd)
{
//fstat(fd, &st);
lseek(fd, 0, SEEK_END);
/*lseek(fd, 0, SEEK_END);
write(fd, tmpBuf, strlen(tmpBuf));
close(fd);
close(fd);*/
//printf("Add Success st_size:%ld\n", st.st_size);
ret_fs = FileSys_SeekFile((FST_FILE)fd, 0, FST_SEEK_END);
if (ret_fs != FST_STA_OK) {
printf("%s:%d seek file failed\r\n", __FUNCTION__, __LINE__);
}
size = strlen(tmpBuf);
ret_fs = FileSys_WriteFile((FST_FILE)fd, (UINT8*)tmpBuf, &size, 0, NULL);
if (ret_fs != FST_STA_OK) {
printf("%s:%d FileSys_WriteFile failed\r\n", __FUNCTION__, __LINE__);
}
FileSys_CloseFile(fd);
}
free(tmpBuf);
}