From 9ea64c9a1dc94004db7404717ec844f941b380a5 Mon Sep 17 00:00:00 2001 From: payton Date: Fri, 18 Aug 2023 16:54:12 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96rtos=E4=B8=8B=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rtos/code/driver/na51089/include/sf_mcu.h | 2 +- .../driver/na51089/source/mcu/sf_battery.c | 32 ++-- rtos/code/driver/na51089/source/mcu/sf_mcu.c | 147 +++++++++++------- 3 files changed, 117 insertions(+), 64 deletions(-) diff --git a/rtos/code/driver/na51089/include/sf_mcu.h b/rtos/code/driver/na51089/include/sf_mcu.h index 3e67556e2..6bd5db036 100755 --- a/rtos/code/driver/na51089/include/sf_mcu.h +++ b/rtos/code/driver/na51089/include/sf_mcu.h @@ -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); diff --git a/rtos/code/driver/na51089/source/mcu/sf_battery.c b/rtos/code/driver/na51089/source/mcu/sf_battery.c index 9243c385c..356d0a5d5 100755 --- a/rtos/code/driver/na51089/source/mcu/sf_battery.c +++ b/rtos/code/driver/na51089/source/mcu/sf_battery.c @@ -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); } diff --git a/rtos/code/driver/na51089/source/mcu/sf_mcu.c b/rtos/code/driver/na51089/source/mcu/sf_mcu.c index 27e68741d..a589cf61b 100755 --- a/rtos/code/driver/na51089/source/mcu/sf_mcu.c +++ b/rtos/code/driver/na51089/source/mcu/sf_mcu.c @@ -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); }