diff --git a/code/application/source/sf_app/code/include/sf_commu_mcu.h b/code/application/source/sf_app/code/include/sf_commu_mcu.h index a2e868de7..a304c41cf 100644 --- a/code/application/source/sf_app/code/include/sf_commu_mcu.h +++ b/code/application/source/sf_app/code/include/sf_commu_mcu.h @@ -49,6 +49,14 @@ typedef enum MCU_FLAG_INIT { MCU_FLAG_INIT_MAX_CNT = 32, //flag max bit cnt is 32 } MCU_FLAG_INIT; +typedef enum NET_FLAG_INIT { + NET_FLAG_INITT = 0x00, + NET_FLAG_INITT_OK, + NET_FLAG_NET_OK, + NET_FLAG_SEND_END, + +} NET_FLAG_INIT; + void mcubuf_reset(void); int sf_commu_mcu_interface_init(int speed, char flow_ctrl, int databits, int stopbits, char parity); int sf_commu_mcu_open(void); @@ -79,7 +87,9 @@ void sf_mcu_flag_set_done(MCU_FLAG_INIT boot_init); void sf_mcu_flag_wait_done(MCU_FLAG_INIT boot_init); int sf_mcu_flag_wait_done_timeout(MCU_FLAG_INIT boot_init, int timeout_ms); void sf_mcu_flag_clear_done(MCU_FLAG_INIT boot_init); - +void sf_net_flag_init(void); +void sf_net_flag_set_done(NET_FLAG_INIT boot_init); +int sf_net_flag_wait_done_timeout(NET_FLAG_INIT boot_init, int timeout_ms); #ifdef __cplusplus } #endif //__cplusplus diff --git a/code/application/source/sf_app/code/include/sf_service.h b/code/application/source/sf_app/code/include/sf_service.h index c31d67f4c..bc1af36f1 100755 --- a/code/application/source/sf_app/code/include/sf_service.h +++ b/code/application/source/sf_app/code/include/sf_service.h @@ -106,6 +106,9 @@ void sf_save_camera_gps_info(void); void set_at_parament(void); int sf_net_dns_ck(void); void sf_register_net_para_ck(void); +SINT32 sf_app_auto_send_start(void); +SINT32 sf_file_send_auto(void); +SINT32 sf_app_auto_net_start(void); #ifdef __cplusplus #if __cplusplus } diff --git a/code/application/source/sf_app/code/source/4gMng/sf_eg91_sim.c b/code/application/source/sf_app/code/source/4gMng/sf_eg91_sim.c index 5ad28708c..3074ac9e9 100755 --- a/code/application/source/sf_app/code/source/4gMng/sf_eg91_sim.c +++ b/code/application/source/sf_app/code/source/4gMng/sf_eg91_sim.c @@ -25,7 +25,7 @@ extern "C" { #include "sf_ftp.h" #include "sf_module.h" #include "at_manager.h" - +#include "sf_commu_mcu.h" #define APNGPRS_WUYUAN1 "America.bics" #define APNGPRS_WUYUAN2 "bicsapn" #define MEGA_TEST 0 @@ -4281,12 +4281,13 @@ SINT32 sf_auto_net_reg(void) ret = SF_SIM_ERROR_APN; sprintf((char *)logStr, "Error Code:0x%08X\n", ret); SLOGE(logStr); - + sf_net_flag_set_done(NET_FLAG_NET_OK); //sf_guide_operator_match_status_set(); goto SF_MODULE_END; } else { + sf_net_flag_set_done(NET_FLAG_NET_OK); sprintf((char *)logStr, "Auto Operation Success,MCCMNC:%s\n", puiPara->OperatorCode); SLOGI(logStr); } 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 e814ffe32..798e9c204 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 @@ -53,6 +53,8 @@ extern "C" { #include "sf_system.h" #include "curl/curl.h" #include "sf_4G_sms_lpa_cmd.h" +#include "sf_commu_mcu.h" + /************************************************************************** * C O N S T A N T S * **************************************************************************/ @@ -888,7 +890,7 @@ SINT32 sf_pic_send_ftp(void) UINT8 piccount = 0; UINT8 pic = 0; UINT8 csqlevel = 0; - int timeout = 120000; + int timeout = 60000; //SINT64 sendStartTime = 0; UINT8 sendAlreadyFlag = 0; UINT8 timeoutCnt = 0; @@ -918,7 +920,7 @@ SINT32 sf_pic_send_ftp(void) if(tempPicSize == 0) { - timeout = 120000; + timeout = 60000; } else { @@ -950,6 +952,11 @@ SINT32 sf_pic_send_ftp(void) printf("%s:%d pic:%d ftpFileName:%s filePath:%s fileStr:%s\n", __FUNCTION__, __LINE__, pic, ftpFileName[pic], filePath[pic], fileStr[pic]); } */ + SF_STARTUP_TYPE_E StartMode = sf_poweron_type_get(); + if((SF_MCU_STARTUP_TIMELAPSE == StartMode) || (SF_MCU_STARTUP_PIR == StartMode)) + { + sf_net_flag_wait_done_timeout(NET_FLAG_INITT_OK, 120000); + } for(pic = 0; pic < piccount; pic++) { if(SF_FILE_TYPE_PIC_VIDEO == pThumbFileCfg->stfileattr[pic].enFileTye){ diff --git a/code/application/source/sf_app/code/source/4gMng/sf_sms.c b/code/application/source/sf_app/code/source/4gMng/sf_sms.c index c29c47a4e..341111645 100755 --- a/code/application/source/sf_app/code/source/4gMng/sf_sms.c +++ b/code/application/source/sf_app/code/source/4gMng/sf_sms.c @@ -2704,8 +2704,8 @@ SINT32 sf_power_off_check_sd(void) //sf_FlowLogCopyToCard(); //if(sf_in_card_exist()) { - if(sf_get_mode_flag() || ((0 == puiPara->SendType)) || (startup == SF_MCU_STARTUP_RESET)) - sf_delete_send_flie_list(); + // if(sf_get_mode_flag() || ((0 == puiPara->SendType)) || (startup == SF_MCU_STARTUP_RESET)) + // sf_delete_send_flie_list(); } /*check disk free size*/ diff --git a/code/application/source/sf_app/code/source/app/sf_service.c b/code/application/source/sf_app/code/source/app/sf_service.c index 594d88264..46284d271 100755 --- a/code/application/source/sf_app/code/source/app/sf_service.c +++ b/code/application/source/sf_app/code/source/app/sf_service.c @@ -60,6 +60,7 @@ #include "Log.h" #include "sf_4g_lpa.h" #include "sf_eg91_gps.h" +#include "sf_commu_mcu.h" #ifdef __cplusplus #if __cplusplus extern "C" { @@ -84,6 +85,14 @@ SF_THREAD_S QlogTsk = { .TskId = -1, }; +void sf_set_flag_wait(signed int ret) +{ + if(ret != SF_SUCCESS) + { + sf_net_flag_set_done(NET_FLAG_SEND_END); + } +} + SINT32 app_ttyusb_IsOpen(void) { int retryTime = 0; int retryFlag = 0; @@ -272,10 +281,10 @@ SINT32 sf_USB_net_init(void) UIMenuStoreInfo *puiPara = sf_app_ui_para_get(); if (!sf_app_while_flag()) - { - printf("[%s:%d]is update ... \n", __FUNCTION__, __LINE__); - return; - } + { + printf("[%s:%d]is update ... \n", __FUNCTION__, __LINE__); + return ret; + } if (flag == 0) { flag = 1; @@ -292,25 +301,25 @@ SINT32 sf_USB_net_init(void) } - for (i = 0; i < 20; i++) + for (i = 0; i < 100; i++) { if(strncmp(puiPara->ModuleVer, GPRS_MODULE_TYPE_EG915Q, 6) == 0) { ret = sf_check_usb0(); - if(ret != SUCCESS) - { - ret = sf_check_eth0(); - } + // if(ret != SUCCESS) + // { + // ret = sf_check_eth0(); + // } } else { ret = sf_check_eth0(); - if(ret != SUCCESS) - { - ret = sf_check_usb0(); - } + // if(ret != SUCCESS) + // { + // ret = sf_check_usb0(); + // } } if (SUCCESS == ret) { @@ -320,7 +329,7 @@ SINT32 sf_USB_net_init(void) } else { - sf_sleep_ms(500); + sf_sleep_ms(100); } } //sf_net_dns_ck(); @@ -1262,6 +1271,9 @@ static SINT32 app_file_transfer(SF_FN_PARAM_S *pfnParam) { //pCustomerParam->GpsSendFlag = 0; } + //to do : send lpa direct + sf_ftp_lpa_log_send(); + if (sf_get_pic()) { s32ret = sf_send_file_to_ftp(1); sf_sms_set_pic(0); @@ -1692,7 +1704,43 @@ static SINT32 app_Register_Net_startup_mode(SF_FN_PARAM_S *pfnParam) if (pCustomerParam->SendType != 0) { break; } + #ifdef SF_HARDWARE_TEST + app_system_poweroff(SF_POWEROFF_NOT); + break; + #endif + s32ret = sf_4G_sim_IsInsert(); + if (!s32ret) { + SF_APPCOMM_CHECK_RETURN(SF_FAILURE, SF_APP_ERROR_REQUEST); + } + + s32ret = app_ttyusb_IsOpen(); + SF_APPCOMM_CHECK_RETURN(s32ret, SF_APP_ERROR_REQUEST); + + #if SF_QLOG_ENABLE + if (pCustomerParam->QLogSwitch == 1) + { + sf_app_qlog_start(); + } + #endif + if (pCustomerParam->GprsMode != 1) + { + s32ret = sf_4G_sim_init(pfnParam); + SF_APPCOMM_CHECK_RETURN(s32ret, SF_APP_ERROR_REQUEST); + } + sf_app_auto_net_start(); + s32ret = sf_4G_register_net_auto(pfnParam); + if (s32ret != SF_SUCCESS) { + sf_set_flag_wait(s32ret); + sf_set_signal_ready_flag(TRUE); + } + sf_app_auto_send_start(); + // sf_share_mem_customer_down(1); + // SF_APPCOMM_CHECK_RETURN(s32ret, SF_APP_ERROR_REQUEST); + + + + break; case SF_MCU_STARTUP_BATCH_SEND: #ifdef SF_HARDWARE_TEST @@ -1949,8 +1997,6 @@ static SINT32 app_Register_Net_startup_mode(SF_FN_PARAM_S *pfnParam) set_at_parament(); sf_USB_net_init(); - //to do : send lpa direct - sf_ftp_lpa_log_send(); if ((SF_ON == pCustomerParam->GpsSwitch) || (pCustomerParam->FristSendDailyAndGps)) { diff --git a/code/application/source/sf_app/code/source/app/sf_system.c b/code/application/source/sf_app/code/source/app/sf_system.c index a8c663037..7e5161f38 100755 --- a/code/application/source/sf_app/code/source/app/sf_system.c +++ b/code/application/source/sf_app/code/source/app/sf_system.c @@ -156,6 +156,16 @@ SF_THREAD_S LpaTskCfg = .TskId = -1, }; +SF_THREAD_S AtuoSendTskCfg = +{ + .IsRun = 0, + .TskId = -1, +}; +SF_THREAD_S AtuoNetTskCfg = +{ + .IsRun = 0, + .TskId = -1, +}; SINT8 debugFlag = 0; UINT8 McuInitFlag = 0; @@ -913,6 +923,28 @@ UINT8 *sf_versionGet(UINT8 ver[],UINT8 fea[]) return ver; } +/************************************************* + Function: sf_power_off_net_flag_wait + Description: sf power off . + Input: N/A + Output: N/A + Return: 0:SUCCESS, errcode:FAIL + Others: N/A +*************************************************/ +SINT32 sf_power_off_net_flag_wait(void) +{ + UIMenuStoreInfo *puiPara = sf_app_ui_para_get(); + SF_STARTUP_TYPE_E StartMode = sf_poweron_type_get(); + if((SF_MCU_STARTUP_TIMELAPSE == StartMode) || (SF_MCU_STARTUP_PIR == StartMode)) + { + sf_net_flag_wait_done_timeout(NET_FLAG_SEND_END, 120000); + } + if(sf_get_mode_flag() || ((0 == puiPara->SendType)) || (StartMode == SF_MCU_STARTUP_RESET)) + { + sf_delete_send_flie_list(); + } + return 0; +} /************************************************* Function: sf_power_off @@ -936,11 +968,13 @@ void sf_power_off(void) sf_power_off_check_sd(); sf_power_off_check_sd_fail(); + sf_power_off_net_flag_wait(); + + sf_power_off_check_sms(); + sf_poweroff_check_lpa_excute_cmd(); sf_poweroff_check_lpa_enable_profile(); - - sf_power_off_check_sms(); sf_power_off_module_ota(); @@ -1763,3 +1797,61 @@ SINT32 sf_app_lpa_start(void) } return SF_SUCCESS; } + +void* sf_auto_send_thread(void *arg) +{ + SLOGI("thread run\n"); + sf_file_send_auto(); + sf_net_flag_set_done(NET_FLAG_SEND_END); + AtuoSendTskCfg.IsRun = 0; + SLOGI("thread end\n"); + return NULL; +} +SINT32 sf_app_auto_send_start(void) +{ + SINT32 ret = SF_FAILURE; + if(AtuoSendTskCfg.IsRun) + { + SLOGE("thread has already run !!!\n"); + return SF_FAILURE; + } + AtuoSendTskCfg.IsRun = 1; + SLOGI("thread run\n"); + ret = pthread_create(&AtuoSendTskCfg.TskId, NULL, sf_auto_send_thread, NULL); + if(ret != SF_SUCCESS) + { + MLOGD("thread creat fail!\n"); + return ret; + } + return SF_SUCCESS; +} + +void* sf_auto_net_thread(void *arg) +{ + SLOGI("thread run\n"); + sf_net_flag_wait_done_timeout(NET_FLAG_NET_OK, 120000); + set_at_parament(); + sf_USB_net_init(); + sf_net_flag_set_done(NET_FLAG_INITT_OK); + AtuoNetTskCfg.IsRun = 0; + SLOGI("thread end\n"); + return NULL; +} +SINT32 sf_app_auto_net_start(void) +{ + SINT32 ret = SF_FAILURE; + if(AtuoNetTskCfg.IsRun) + { + SLOGE("thread has already run !!!\n"); + return SF_FAILURE; + } + AtuoNetTskCfg.IsRun = 1; + SLOGI("thread run\n"); + ret = pthread_create(&AtuoNetTskCfg.TskId, NULL, sf_auto_net_thread, NULL); + if(ret != SF_SUCCESS) + { + MLOGD("thread creat fail!\n"); + return ret; + } + return SF_SUCCESS; +} \ No newline at end of file diff --git a/code/application/source/sf_app/code/source/systemMng/sf_commu_mcu.c b/code/application/source/sf_app/code/source/systemMng/sf_commu_mcu.c index 2e4e8c88b..6469ec140 100755 --- a/code/application/source/sf_app/code/source/systemMng/sf_commu_mcu.c +++ b/code/application/source/sf_app/code/source/systemMng/sf_commu_mcu.c @@ -133,6 +133,50 @@ static pthread_t sfCommuMcuThread = 0; int gsfd = -1; + +#if 1 +static ID sf_net_flag_id = 0; + +void sf_net_flag_init(void) +{ + ER ret = E_OK; + T_CFLG cflg; + if ((ret |= vos_flag_create(&sf_net_flag_id, &cflg, "sf_mcu_flag_id")) != E_OK) + { + SYS_SLOGE("sf_net_flag_id fail\r\n"); + } + vos_flag_clr(sf_net_flag_id, (FLGPTN)-1); +} + +void sf_net_flag_set_done(NET_FLAG_INIT boot_init) +{ + static int initflag = 0; + if(!initflag) + { + sf_net_flag_init(); + initflag = 1; + } + + vos_flag_set(sf_net_flag_id, (FLGPTN)(1 << boot_init)); +} + +int sf_net_flag_wait_done_timeout(NET_FLAG_INIT boot_init, int timeout_ms) +{ + ER ret = E_OK; + FLGPTN flgptn; + if(sf_net_flag_id) + { + ret = vos_flag_wait_timeout(&flgptn, sf_net_flag_id, (FLGPTN)(1 << boot_init), TWF_ANDW, vos_util_msec_to_tick(timeout_ms)); + if(unlikely(ret != E_OK)){ + printf("[%s:%d]wait(%lu) init timeout(%ld ms)!\n", __FUNCTION__, __LINE__, boot_init, timeout_ms); + } + } + + + return ret; +} + +#endif static ID sf_mcu_flag_id = 0; void sf_mcu_flag_init(void) @@ -164,7 +208,7 @@ int sf_mcu_flag_wait_done_timeout(MCU_FLAG_INIT boot_init, int timeout_ms) ret = vos_flag_wait_timeout(&flgptn, sf_mcu_flag_id, (FLGPTN)(1 << boot_init), TWF_ANDW, vos_util_msec_to_tick(timeout_ms)); if(unlikely(ret != E_OK)){ - printf("wait(%lu) init timeout(%ld ms)!\n", boot_init, timeout_ms); + printf("[%s:%d]wait(%lu) init timeout(%ld ms)!\n", __FUNCTION__, __LINE__, boot_init, timeout_ms); } return ret;