From 12b8268f833a82003ccdbf1ecf6eab411f1ff1de Mon Sep 17 00:00:00 2001 From: "sober.song" Date: Thu, 4 Jan 2024 14:47:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=86=85=E5=AD=98=E6=B3=84?= =?UTF-8?q?=E9=9C=B2=E9=A3=8E=E9=99=A9=E5=92=8Csd=5Fprocess=E6=AD=BB?= =?UTF-8?q?=E6=9C=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/sf_app/code/source/4gMng/sf_ftp.c | 35 +++++--- .../source/sf_app/code/source/app/sf_common.c | 32 +++---- .../sf_app/code/source/fileMng/sf_file.c | 85 +++++++++---------- .../sf_app/code/source/updataMng/sf_otamng.c | 40 +++++++-- .../sf_app/code/source/wifi/sf_wifi_svr.c | 2 +- 5 files changed, 113 insertions(+), 81 deletions(-) diff --git a/code/application/source/sf_app/code/source/4gMng/sf_ftp.c b/code/application/source/sf_app/code/source/4gMng/sf_ftp.c index 67520d1f2..caa751cc5 100755 --- a/code/application/source/sf_app/code/source/4gMng/sf_ftp.c +++ b/code/application/source/sf_app/code/source/4gMng/sf_ftp.c @@ -1108,11 +1108,10 @@ SINT32 sf_ftp_dailyreport_send(void) MLOGD("start\n"); - char *file_path = NULL; - file_path = sf_root_path_strcat(SF_DAILYREPORT_FILENAME); - if(file_path == NULL) + char *dp_filename = sf_root_path_strcat(SF_DAILYREPORT_FILENAME); + if(dp_filename == NULL) { - free(file_path); + free(dp_filename); return SF_FAILURE; } @@ -1121,8 +1120,8 @@ SINT32 sf_ftp_dailyreport_send(void) printf("%s:%d err create dailyreport file\n", __FUNCTION__, __LINE__); return SF_FAILURE; } - sprintf((char *)filePath, "%s", file_path); - free(file_path); + sprintf((char *)filePath, "%s", dp_filename); + free(dp_filename); //sprintf((char *)filePath, "UFS:/%s-dr.txt", pPara->ModuleImei); printf("%s:%d filePath:%s\n", __FUNCTION__, __LINE__, filePath); @@ -1132,10 +1131,10 @@ SINT32 sf_ftp_dailyreport_send(void) ret = SF_SUCCESS;//sf_quectel_upload_file_to_module((UINT8 *)SF_DAILYREPORT_FILENAME, (UINT8 *)SF_DAILYREPORT_TXT); - file_path = sf_root_path_strcat(SF_ERROR_CODE); - if(file_path == NULL) + char *err_code_path = sf_root_path_strcat(SF_ERROR_CODE); + if(err_code_path == NULL) { - free(file_path); + free(err_code_path); return SF_FAILURE; } if(SF_SUCCESS != ret) @@ -1168,12 +1167,12 @@ SINT32 sf_ftp_dailyreport_send(void) pSifarPara->videoSendFailCount = 0; pSifarPara->videoSendSucessCount = 0; pSifarPara->SendlowPowerWarnCnt = 0; - sf_file_remove(file_path); + sf_file_remove(err_code_path); } sf_dailyReport_set(); } MLOGD(" end ret:[0x%08X]\n", ret); - free(file_path); + free(err_code_path); return ret; } @@ -2211,9 +2210,16 @@ SINT32 sf_log_send_ftp(void) ssl = ((2 == pPara->FtpSwitch) ? 1 : 0); gprsMode = 0;//puiPara->GprsMode; + char *file_path = sf_root_path_strcat(LOG_AT_FILE_PATH); + if(file_path == NULL) + { + free(file_path); + return SF_FAILURE; + } + MLOGD("start\n"); sf_set_send_log(0); - if(sf_file_IsExsit(LOG_AT_FILE_PATH) != SF_TRUE) + if(sf_file_IsExsit(file_path) != SF_TRUE) { printf("%s:%d err file\n", __FUNCTION__, __LINE__); return SF_FAILURE; @@ -2224,8 +2230,8 @@ SINT32 sf_log_send_ftp(void) if(SF_SUCCESS == ret) { //sprintf((char *)filePath, "UFS:/%s", SF_LOG_TXT); - sprintf((char *)filePath, "%s", LOG_AT_FILE_PATH); - + sprintf((char *)filePath, "%s", file_path); + printf("%s:%d filePath:%s\n", __FUNCTION__, __LINE__, filePath); sf_custom_str_get(customStr); @@ -2260,6 +2266,7 @@ SINT32 sf_log_send_ftp(void) //printf("[%s:%d]ret:[0x%08X],ret2:[0x%08X]\n\n", __FUNCTION__, __LINE__, ret, ret2); MLOGD(" end ret:[0x%08X],ret2:[0x%08X]\n", ret, ret2); + free(file_path); if(ret != SF_SUCCESS) { return ret; diff --git a/code/application/source/sf_app/code/source/app/sf_common.c b/code/application/source/sf_app/code/source/app/sf_common.c index 75331bf8b..9c8ef5579 100755 --- a/code/application/source/sf_app/code/source/app/sf_common.c +++ b/code/application/source/sf_app/code/source/app/sf_common.c @@ -602,11 +602,11 @@ static SINT32 sf_app_process_cmd_keyctrl(SF_MESSAGE_BUF_S *pMessageBuf) return SF_SUCCESS; } -static SINT32 sfStrgDevOnActionMount(SF_MESSAGE_BUF_S *pMessageBuf) +static SINT32 sfStrgDevOnActionMount(int dev_id, int result) { SINT16 startup = sf_poweron_type_get(); UINT32 status = 0; - status = pMessageBuf->arg3; + status = result; switch (status) { case FST_STA_OK: @@ -628,7 +628,7 @@ static SINT32 sfStrgDevOnActionMount(SF_MESSAGE_BUF_S *pMessageBuf) } } sf_statistics_param_load(sf_statistics_param_get()); - MLOGI("card-%d mount OK\r\n", pMessageBuf->arg2 + 1); + MLOGI("card-%d mount OK\r\n", dev_id + 1); sf_set_key_fw_update(sf_get_fw_update());//up fw if(sf_get_mcu_update_flag())//up mcu { @@ -637,26 +637,26 @@ static SINT32 sfStrgDevOnActionMount(SF_MESSAGE_BUF_S *pMessageBuf) break; case FST_STA_DISK_UNFORMAT: sf_statistics_param_load(sf_statistics_param_get()); - MLOGI("^Rcard-%d mount FAIL: Unformat\r\n", pMessageBuf->arg2 + 1); + MLOGI("^Rcard-%d mount FAIL: Unformat\r\n", dev_id + 1); break; case FST_STA_DISK_UNKNOWN_FORMAT: sf_sys_status_led_set(SF_LED_SYS_STATE_SD_FULL); - MLOGI("^Rcard-%d mount FAIL: Unknown Format\r\n", pMessageBuf->arg2 + 1); + MLOGI("^Rcard-%d mount FAIL: Unknown Format\r\n", dev_id + 1); break; case FST_STA_CARD_ERR: sf_sys_status_led_set(SF_LED_SYS_STATE_SD_ERROR); - MLOGI("^Rcard-%d mount FAIL: Card Error\r\n", pMessageBuf->arg2 + 1); + MLOGI("^Rcard-%d mount FAIL: Card Error\r\n", dev_id + 1); break; default: - MLOGI("^Rcard-%d mount FAIL: ErrID=%d\r\n", pMessageBuf->arg2 + 1, status); + MLOGI("^Rcard-%d mount FAIL: ErrID=%d\r\n", dev_id + 1, status); break; } return SF_SUCCESS; } -static SINT32 sfStrgDevSdHandler(SF_MESSAGE_BUF_S *pMessageBuf) +static SINT32 sfStrgDevSdHandler(int cb_evt, int dev_id, int result) { - switch(pMessageBuf->arg1) + switch(cb_evt) { case CMD_SD_STRG_CB_UNKNOWN: sf_set_card_full(1); @@ -670,7 +670,7 @@ static SINT32 sfStrgDevSdHandler(SF_MESSAGE_BUF_S *pMessageBuf) sf_sys_status_led_set(SF_LED_SYS_STATE_SD_ERROR); break; case CMD_SD_STRG_CB_MOUNT_FINISH: - sfStrgDevOnActionMount(pMessageBuf->arg3); + sfStrgDevOnActionMount(dev_id, result); break; case CMD_SD_STRG_CB_UNMOUNT_FINISH: sf_set_card(0); @@ -682,16 +682,16 @@ static SINT32 sfStrgDevSdHandler(SF_MESSAGE_BUF_S *pMessageBuf) return SF_SUCCESS; } -static SINT32 sfStrgDevEmmcHandler(SF_MESSAGE_BUF_S *pMessageBuf) +static SINT32 sfStrgDevEmmcHandler(int cb_evt, int dev_id, int result) { - switch(pMessageBuf->arg1) + switch(cb_evt) { case CMD_SD_STRG_CB_UNKNOWN: sf_set_card_full(1); break; case CMD_SD_STRG_CB_MOUNT_FINISH: - sfStrgDevOnActionMount(pMessageBuf->arg3); + sfStrgDevOnActionMount(dev_id, result); break; case CMD_SD_STRG_CB_UNMOUNT_FINISH: sf_set_card(0); @@ -708,13 +708,13 @@ static SINT32 sf_app_process_cmd_SD(SF_MESSAGE_BUF_S *pMessageBuf) { MLOGD("[dev_id:%d,evt:%d]\n",pMessageBuf->arg2,pMessageBuf->arg1); - //if(pMessageBuf->arg2 == MMC_DEV_SD) + if(pMessageBuf->arg2 == MMC_DEV_SD) { - //sfStrgDevSdHandler(pMessageBuf); + sfStrgDevSdHandler(pMessageBuf->arg1, pMessageBuf->arg2, pMessageBuf->arg3); } //else if(pMessageBuf->arg2 == MMC_DEV_EMMC) { - //sfStrgDevEmmcHandler(pMessageBuf); + //sfStrgDevEmmcHandler(pMessageBuf->arg1, pMessageBuf->arg2, pMessageBuf->arg3); } switch(pMessageBuf->arg1) diff --git a/code/application/source/sf_app/code/source/fileMng/sf_file.c b/code/application/source/sf_app/code/source/fileMng/sf_file.c index 33d89b579..4895197b4 100755 --- a/code/application/source/sf_app/code/source/fileMng/sf_file.c +++ b/code/application/source/sf_app/code/source/fileMng/sf_file.c @@ -942,26 +942,25 @@ UINT32 sf_create_dailyreport_file(void) char imageSize = 0; char videoSize = 0; /*Avoid New Card*/ - char *file_path = NULL; - file_path = sf_root_path_strcat(SF_THUMB_DIR); - if(file_path == NULL) + char *thumb_dir = sf_root_path_strcat(SF_THUMB_DIR); + if(thumb_dir == NULL) { - free(file_path); + free(thumb_dir); return SF_FAILURE; } - if (access(file_path, F_OK) == -1) { - printf("%s directory does not exist. Creating...\n", file_path); + if (access(thumb_dir, F_OK) == -1) { + printf("%s directory does not exist. Creating...\n", thumb_dir); - if (mkdir(file_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1) { + if (mkdir(thumb_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1) { perror("mkdir() error"); } else { - printf("%s directory created.\n", file_path); + printf("%s directory created.\n", thumb_dir); } } else { - printf("%s directory exists.\n", file_path); + printf("%s directory exists.\n", thumb_dir); } - free(file_path); + free(thumb_dir); //sf_create_thumb_dir(); if(SF_CAMID_ON == pPara->CamNameSwitch) @@ -1288,20 +1287,20 @@ UINT32 sf_create_dailyreport_file(void) printf("szTmp2=%s\n",szTmp2); printf("cfgTmp:%s\n", cfgTmp); - file_path = sf_root_path_strcat(SF_DAILYREPORT_FILENAME); - if(file_path == NULL) + char *dailyrp_file = sf_root_path_strcat(SF_DAILYREPORT_FILENAME); + if(dailyrp_file == NULL) { - free(file_path); + free(dailyrp_file); return SF_FAILURE; } - if(sf_file_IsExsit(file_path) == SF_TRUE){ - sf_file_remove(file_path); + if(sf_file_IsExsit(dailyrp_file) == SF_TRUE){ + sf_file_remove(dailyrp_file); } - fd = open(file_path, O_APPEND | O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); + fd = open(dailyrp_file, O_APPEND | O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if(fd) { - free(file_path); + free(dailyrp_file); szTmpsize=SF_STRLEN(szTmp); //printf("szTmpsize=%d\n",szTmpsize); write(fd, szTmp, szTmpsize); @@ -1312,17 +1311,18 @@ UINT32 sf_create_dailyreport_file(void) //printf("szTmpsize=%d\n",szTmpsize); write(fd, szTmp2, szTmpsize); - file_path = sf_root_path_strcat(SF_ERROR_CODE); - if(file_path == NULL) + char *err_code_path = sf_root_path_strcat(SF_ERROR_CODE); + if(err_code_path == NULL) { - free(file_path); + free(err_code_path); return SF_FAILURE; } - if(sf_file_IsExsit(file_path) == SF_TRUE){ - size = sf_get_file_size((UINT8 *)file_path); - fd1 = open(file_path, O_RDONLY, S_IRUSR | S_IWUSR); + if(sf_file_IsExsit(err_code_path) == SF_TRUE){ + size = sf_get_file_size((UINT8 *)err_code_path); + fd1 = open(err_code_path, O_RDONLY, S_IRUSR | S_IWUSR); if(fd1) { + free(err_code_path); //size = sp5kFsFileSizeGet(fd1); buf = malloc(size); @@ -1346,7 +1346,7 @@ UINT32 sf_create_dailyreport_file(void) ret = SUCCESS; close(fd); } - free(file_path); + return ret; } @@ -1376,44 +1376,43 @@ UINT32 sf_create_low_power_warn_file(void) return ret; } - char *file_path = NULL; - file_path = sf_root_path_strcat(SF_THUMB_DIR); - if(file_path == NULL) + char *thumb_dir = sf_root_path_strcat(SF_THUMB_DIR); + if(thumb_dir == NULL) { - free(file_path); + free(thumb_dir); return SF_FAILURE; } /*Avoid New Card*/ - if (access(file_path, F_OK) == -1) { - printf("%s directory does not exist. Creating...\n", file_path); + if (access(thumb_dir, F_OK) == -1) { + printf("%s directory does not exist. Creating...\n", thumb_dir); - if (mkdir(file_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1) { + if (mkdir(thumb_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) == -1) { //perror("mkdir() error"); } else { - printf("%s directory created.\n", file_path); + printf("%s directory created.\n", thumb_dir); } } else { - printf("%s directory exists.\n", file_path); + printf("%s directory exists.\n", thumb_dir); } - free(file_path); + free(thumb_dir); - file_path = sf_root_path_strcat(SF_LOW_POWER_WARN_FILENAME); - if(file_path == NULL) + char *lp_path = sf_root_path_strcat(SF_LOW_POWER_WARN_FILENAME); + if(lp_path == NULL) { - free(file_path); + free(lp_path); return SF_FAILURE; } - if(sf_file_IsExsit(file_path) == SF_TRUE){ - sf_file_remove(file_path); + if(sf_file_IsExsit(lp_path) == SF_TRUE){ + sf_file_remove(lp_path); } - fd = open(file_path, O_APPEND | O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); + fd = open(lp_path, O_APPEND | O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if(!fd) { - fd = open(file_path, O_APPEND | O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); + fd = open(lp_path, O_APPEND | O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); } if(fd) @@ -1443,7 +1442,7 @@ UINT32 sf_create_low_power_warn_file(void) if(ret <0) { close(fd); - sf_file_remove(file_path); + sf_file_remove(lp_path); printf("write low power warn file failed!,ret:%d\n",ret); ret = FAIL; } @@ -1454,7 +1453,7 @@ UINT32 sf_create_low_power_warn_file(void) ret = SUCCESS; } } - free(file_path); + free(lp_path); return ret; } diff --git a/code/application/source/sf_app/code/source/updataMng/sf_otamng.c b/code/application/source/sf_app/code/source/updataMng/sf_otamng.c index 156677b7e..75b5e73dd 100644 --- a/code/application/source/sf_app/code/source/updataMng/sf_otamng.c +++ b/code/application/source/sf_app/code/source/updataMng/sf_otamng.c @@ -451,15 +451,41 @@ SINT32 sf_upgrade_ota_init(void) return SF_FAILURE; } MLOGI("filename = [%s]\n",stOtaAttrs.filename); + + char *upgrade_file_path = sf_root_path_strcat(SF_OTA_UPGRADE_FILE_PATH); + if(upgrade_file_path == NULL) + { + free(upgrade_file_path); + return SF_FAILURE; + } + + char *cfg_file_path = sf_root_path_strcat(OTA_CFG_FILE_PATH); + if(cfg_file_path == NULL) + { + free(cfg_file_path); + return SF_FAILURE; + } + + char *ota_file_path = sf_root_path_strcat(OTAFILE_PATH); + if(ota_file_path == NULL) + { + free(ota_file_path); + return SF_FAILURE; + } - if(upgrade_ota_file_IsExsit(SF_OTA_UPGRADE_FILE_PATH) == SF_TRUE) - sf_file_remove(SF_OTA_UPGRADE_FILE_PATH); - if(upgrade_ota_file_IsExsit(OTA_CFG_FILE_PATH) == SF_TRUE) - sf_file_remove(OTA_CFG_FILE_PATH); - if(upgrade_ota_file_IsExsit(OTAFILE_PATH) == SF_TRUE) - sf_file_remove(OTAFILE_PATH); - + if(upgrade_ota_file_IsExsit(upgrade_file_path) == SF_TRUE) { + sf_file_remove(upgrade_file_path); + } + if(upgrade_ota_file_IsExsit(cfg_file_path) == SF_TRUE) { + sf_file_remove(cfg_file_path); + } + if(upgrade_ota_file_IsExsit(ota_file_path) == SF_TRUE) { + sf_file_remove(ota_file_path); + } + free(upgrade_file_path); + free(cfg_file_path); + free(ota_file_path); return SF_SUCCESS; } diff --git a/code/application/source/sf_app/code/source/wifi/sf_wifi_svr.c b/code/application/source/sf_app/code/source/wifi/sf_wifi_svr.c index 6d213e70f..6929ac9b4 100755 --- a/code/application/source/sf_app/code/source/wifi/sf_wifi_svr.c +++ b/code/application/source/sf_app/code/source/wifi/sf_wifi_svr.c @@ -739,7 +739,7 @@ void appCreatThumbList(S8 *fileName)//start file name example: 10010032.JPG if(strg_path == NULL) { free(strg_path); - return SF_FAILURE; + return; } if(fileName != NULL && fileName[0] != '\0' && fileName[0] != '0' && (strstr((char *)fileName, SF_DCF_EXT_MOV) || strstr((char *)fileName, SF_DCF_EXT_PHOTO)))