From 2cf462da0c1226ac5fecc76dd7213f363d245710 Mon Sep 17 00:00:00 2001 From: payton Date: Fri, 28 Jul 2023 17:50:13 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E5=90=AF=E5=8A=A8=E9=80=9F?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/sf_app/code/source/app/sf_app.c | 121 +++++------------- .../source/sf_app/code/source/app/sf_common.c | 2 +- .../source/sf_app/code/source/app/sf_system.c | 113 +++++++++++++++- .../code/source/systemMng/sf_commu_mcu_reg.c | 4 +- .../sifar/code/source/mcu/sf_mcu_client.c | 2 + 5 files changed, 145 insertions(+), 97 deletions(-) diff --git a/code/application/source/sf_app/code/source/app/sf_app.c b/code/application/source/sf_app/code/source/app/sf_app.c index f8209bb8c..18928ea01 100644 --- a/code/application/source/sf_app/code/source/app/sf_app.c +++ b/code/application/source/sf_app/code/source/app/sf_app.c @@ -96,44 +96,7 @@ int test_sd_free(void) return 0; } -UINT8 sf_check_power_on_mode(void) -{ - FILE *fp = NULL; - UINT32 u32ize = 0; - char *pStrSrc = NULL; - char *pStrOtsOk = "Mode="; - char *temp = NULL; - UINT8 startup = 0; - system("cat /proc/cmdline > /tmp/Mode.txt"); - fp = fopen("/tmp/Mode.txt","r"); - if(fp == NULL){ - return FALSE; - } - - fseek(fp, 0, SEEK_END); - u32ize = ftell(fp); // take file size - fseek(fp, 0, SEEK_SET); // move to position zero - pStrSrc = (char *)malloc(u32ize*sizeof(char)); - if (pStrSrc) { - fread(pStrSrc, 1, u32ize, fp); - temp = strstr(pStrSrc, pStrOtsOk); - if ( temp != NULL) { - temp += strlen("Mode="); - sscanf(temp, "%hhd", &startup); - printf("%s: PowerOnModeStr=%d\r\n", __func__,startup); - //printf("%s: temp=%s\r\n", __func__,temp); - } - free(pStrSrc); - } - - fclose(fp); - fp = NULL; - pStrSrc = NULL; - u32ize = 0; - - return startup; -} int main(int argc, char *argv[]) { printf("*********************************************\n"); @@ -143,17 +106,25 @@ int main(int argc, char *argv[]) printf("*********************************************\n"); //gpio_direction_input(C_GPIO(10)); SINT16 startup = 0; - SINT32 UpdateTime = 0; + //SINT32 UpdateTime = 0; + SINT32 isUsb = 0; + SINT32 isCard = 0; + SINT32 isUpdate = 0; //SF_MESSAGE_BUF_S stMessageBuf = {0}; //BOOL autosend = FALSE; SF_MUTEX_INIT_LOCK(Param_mutexLock); SF_MUTEX_INIT_LOCK(GPIO_mutexLock); //test_sd_free(); //return 0; - SINT32 isUsb = sf_usb_IsInsert(); - SINT32 isCard = sf_in_card_exist(); - SINT32 isUpdate = sf_in_update(); - printf("[%s:%d] isUsb = %d isCard = %d isUpdate:%d\n", __FUNCTION__, __LINE__, isUsb,isCard,isUpdate); + + sf_app_mcu_para_start(); + + isUsb = sf_usb_IsInsert(); + isCard = sf_in_card_exist(); + isUpdate = sf_in_update(); + + sf_set_fw_update(isUpdate); + if(!isUsb) { sf_app_load_ko_start(); @@ -166,29 +137,21 @@ int main(int argc, char *argv[]) //app_led_group_register(); app_message_recv_start(); - sf_poweron_type_set(sf_check_power_on_mode()); - - sf_mcu_flag_init(); - sf_mcu_init(); - startup = sf_poweron_type_get(); - if((SF_MCU_STARTUP_NORMAL != startup) && (!isUsb)){ - sf_get_power_on_mode(); - sf_mcu_wdg_set(30); - } - sf_led_init(); sf_customer_param_load(); sf_app_para_check_start(); UIMenuStoreInfo *puiPara = sf_app_ui_para_get(); + startup = sf_poweron_type_get(); + printf("[%s:%d] isUsb = %d isCard = %d isUpdate:%d CamMode:%d startup:%d %s\n", __FUNCTION__, __LINE__, isUsb,isCard,isUpdate,puiPara->CamMode, startup, sf_poweron_type_string(startup)); - printf("[%s:%d] CamMode:%d\n", __FUNCTION__, __LINE__,puiPara->CamMode); - if((!isUsb) && (SF_MCU_STARTUP_NORMAL != startup)) + if((!isUsb) && (SF_MCU_STARTUP_NORMAL != startup) /*&& (0 == isUpdate)*/) { - //sf_usb_mux_s(1); - //sf_load_ko(); - sf_mcu_reg_set(SF_MCU_CTRL_MODULE_PIR, 1); + #if SF_IQ_TEST != ENABLE + sf_4G_usb_init(); + app_RegisterNet_start(); + #endif sf_app_battery_start(); } @@ -196,13 +159,20 @@ int main(int argc, char *argv[]) //sf_app_data_ready_start(); - //sf_set_fw_update(isUpdate); - sf_sys_status_led_set(SF_LED_SYS_STATE_PIR_NOT_DETECT); - sf_sys_status_led_set(SF_LED_SYS_STATE_NORMAL); + if(isUsb){ + sf_sys_status_led_set(SF_LED_SYS_STATE_USB_IN); + } + else{ + sf_sys_status_led_set(SF_LED_SYS_STATE_PIR_NOT_DETECT); + sf_sys_status_led_set(SF_LED_SYS_STATE_NORMAL); + } + if((startup == SF_MCU_STARTUP_NORMAL) && (!isUsb)) + { + app_auto_poweroff_start(); + } - struct sigaction sigAction; sigAction.sa_handler = sf_signalStop; sigemptyset(&sigAction.sa_mask); @@ -214,34 +184,9 @@ int main(int argc, char *argv[]) sigaction(SIGTERM, &sigAction, NULL); //-15 //app_led_pin_init(); //app_upgrade_sd_execute(); - app_preinit(); - startup = sf_poweron_type_get(); - if(SF_MCU_STARTUP_ONKEY == startup) - { - //sf_wifi_app_start(); - } - #if SF_IQ_TEST != ENABLE + //app_preinit(); - if(1 == isUpdate) - { - while (20 > UpdateTime) - { - if(1 == sf_get_fw_update())//check if update - { - printf("[%s:%d] FwUpdate:%d\n", __FUNCTION__, __LINE__,sf_get_fw_update()); - break; - } - UpdateTime++; - sf_sleep_ms(500); - } - } - - if((!isUsb) && (0 == sf_get_fw_update()) && (SF_MCU_STARTUP_NORMAL != startup) && (SF_ON == puiPara->GprsSwitch)) - { - app_RegisterNet_start(); - } - #endif - SLOGD("poweron type beginning :[%d,%s]\n", startup, sf_poweron_type_string(startup)); + //SLOGD("poweron type beginning :[%d,%s]\n", startup, sf_poweron_type_string(startup)); /*if(SF_MCU_STARTUP_ONKEY != startup) { sf_share_mem_file_init(); 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 1dfe50099..d2365854c 100644 --- a/code/application/source/sf_app/code/source/app/sf_common.c +++ b/code/application/source/sf_app/code/source/app/sf_common.c @@ -727,7 +727,7 @@ static SINT32 sf_app_proccess_cmd_mcu(SF_MESSAGE_BUF_S *pMessageBuf) startup = sf_poweron_type_get(); if(SF_MCU_STARTUP_NORMAL != startup){ sf_get_power_on_mode(); - stMessageBuf.arg3 = (SINT32)sf_mcu_get_irshtter(); + stMessageBuf.arg3 = (SINT32)sf_get_light_value(); } stMessageBuf.arg1 = SF_MCU_CMD_POWERON; 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 3e17496a0..0527e0877 100644 --- a/code/application/source/sf_app/code/source/app/sf_system.c +++ b/code/application/source/sf_app/code/source/app/sf_system.c @@ -42,6 +42,7 @@ #include #include "sf_file.h" #include "sf_hal_ttyusb.h" +#include "sf_commu_mcu.h" #ifdef __cplusplus #if __cplusplus extern "C" { @@ -117,6 +118,11 @@ SF_THREAD_S UsbKoTskCfg = .IsRun = 0, .TskId = -1, }; +SF_THREAD_S McuParaTskCfg = +{ + .IsRun = 0, + .TskId = -1, +}; SINT8 debugFlag = 0; @@ -1220,11 +1226,14 @@ void* sf_sys_do_4g_upgrade(void *arg) sf_set_module_update(0); sf_sleep_ms(1000); //Ux_PostEvent(NVTEVT_SYSTEM_SHUTDOWN, 1, 0); - sf_set_power_off_flag(1); - SF_MESSAGE_BUF_S stMessageBuf = {0}; - stMessageBuf.cmdId = CMD_POWEROFF; - stMessageBuf.arg1 = APP_POWER_OFF_NORMAL; - sf_com_message_send_to_cardv(&stMessageBuf); + if(PWR_ON_SETUP == sf_poweron_type_get()){ + sf_set_power_off_flag(1); + SF_MESSAGE_BUF_S stMessageBuf = {0}; + stMessageBuf.cmdId = CMD_POWEROFF; + stMessageBuf.arg1 = APP_POWER_OFF_NORMAL; + sf_com_message_send_to_cardv(&stMessageBuf); + } + } @@ -1259,7 +1268,6 @@ void* sf_app_load_ko_thread(void *arg) UsbKoTskCfg.IsRun = 1; sf_load_ko(); - UsbKoTskCfg.IsRun = 0; SLOGI("thread end\n"); @@ -1300,3 +1308,96 @@ SINT32 sf_app_load_ko_stop(void) } return SF_SUCCESS; } +UINT8 sf_check_power_on_mode(void) +{ + FILE *fp = NULL; + UINT32 u32ize = 0; + char *pStrSrc = NULL; + char *pStrOtsOk = "Mode="; + char *temp = NULL; + UINT8 startup = 0; + + system("cat /proc/cmdline > /tmp/Mode.txt"); + fp = fopen("/tmp/Mode.txt","r"); + if(fp == NULL){ + return FALSE; + } + + fseek(fp, 0, SEEK_END); + u32ize = ftell(fp); // take file size + fseek(fp, 0, SEEK_SET); // move to position zero + pStrSrc = (char *)malloc(u32ize*sizeof(char)); + if (pStrSrc) { + fread(pStrSrc, 1, u32ize, fp); + temp = strstr(pStrSrc, pStrOtsOk); + if ( temp != NULL) { + temp += strlen("Mode="); + sscanf(temp, "%hhd", &startup); + printf("%s: PowerOnModeStr=%d\r\n", __func__,startup); + //printf("%s: temp=%s\r\n", __func__,temp); + } + free(pStrSrc); + } + + fclose(fp); + fp = NULL; + pStrSrc = NULL; + u32ize = 0; + + return startup; +} + +void* sf_app_mcu_para_thread(void *arg) +{ + SLOGI("thread run\n"); + McuParaTskCfg.IsRun = 1; + SINT32 isUsb = sf_usb_IsInsert(); + + sf_poweron_type_set(sf_check_power_on_mode()); + sf_mcu_flag_init(); + sf_mcu_init(); + if((SF_MCU_STARTUP_NORMAL != sf_poweron_type_get()) && (!isUsb)){ + sf_get_power_on_mode(); + sf_mcu_wdg_set(5); + } + + McuParaTskCfg.IsRun = 0; + SLOGI("thread end\n"); + + return NULL; +} +SINT32 sf_app_mcu_para_start(void) +{ + SINT32 ret = SF_FAILURE; + if(McuParaTskCfg.IsRun) + { + SLOGE("thread has already run !!!\n"); + return SF_FAILURE; + } + ret = pthread_create(&McuParaTskCfg.TskId, NULL, sf_app_mcu_para_thread, NULL); + if(ret != SF_SUCCESS) + { + MLOGD("thread creat fail!\n"); + return ret; + } + return SF_SUCCESS; + +} +SINT32 sf_app_mcu_para_stop(void) +{ + UINT16 ret = 0; + MLOGD("s\n"); + + if(0 == McuParaTskCfg.IsRun){ + return SF_SUCCESS; + } + McuParaTskCfg.IsRun = 0; + + ret = pthread_join(McuParaTskCfg.TskId, NULL); + if(ret != SF_SUCCESS) + { + MLOGD("thread stop 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_reg.c b/code/application/source/sf_app/code/source/systemMng/sf_commu_mcu_reg.c index c5f852df0..25adfc72d 100644 --- a/code/application/source/sf_app/code/source/systemMng/sf_commu_mcu_reg.c +++ b/code/application/source/sf_app/code/source/systemMng/sf_commu_mcu_reg.c @@ -1062,8 +1062,8 @@ void sf_mcu_version_get(UINT8 *mcuVer) *************************************************/ UINT8 sf_get_power_on_mode(void) { - static UINT8 ModeFlag = 1; - if(ModeFlag) + static UINT8 ModeFlag = 0; + if(!ModeFlag) { ModeFlag = sf_mcu_power_on_para_get(SF_MCU_POWERON); } diff --git a/code/lib/source/sifar/code/source/mcu/sf_mcu_client.c b/code/lib/source/sifar/code/source/mcu/sf_mcu_client.c index 1b281ad35..d3319ecbc 100644 --- a/code/lib/source/sifar/code/source/mcu/sf_mcu_client.c +++ b/code/lib/source/sifar/code/source/mcu/sf_mcu_client.c @@ -687,6 +687,7 @@ void sf_set_power_off_flag(UINT8 flag) *************************************************/ UINT8 sf_get_power_on_mode(void) { + #if HUNTING_CAMERA_4G != ENABLE static int ModeFlag = 1; if(ModeFlag) { @@ -698,6 +699,7 @@ UINT8 sf_get_power_on_mode(void) ConfigureModeFlag = 1; } } + #endif return PowerOnMode; }