From fad648f42883f213979f3028cc905c43e0d1abec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=A9=AC=5F666?= <13089258+pony-six-hundred-and-sixty-six@user.noreply.gitee.com> Date: Wed, 11 Jun 2025 10:38:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B7=A5=E4=BD=9C=E6=97=B6?= =?UTF-8?q?=E9=95=BF=E4=B8=BA=E5=B0=8F=E6=97=B6=EF=BC=8C=E5=88=B0=E6=9C=9F?= =?UTF-8?q?=E7=9A=84=E6=A0=87=E5=BF=97=E6=98=BE=E7=A4=BA=EF=BC=8C=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E9=87=8D=E8=BF=9E=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=87=BA?= =?UTF-8?q?=E5=8E=82=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/main.c | 2 +- applications/user_sys.h | 2 +- bsp/src/bsp_flash.c | 2 +- bsp/src/bsp_ml307.c | 91 +++++++++++++++-------------------------- bsp/src/bsp_mq.c | 5 ++- 5 files changed, 39 insertions(+), 63 deletions(-) diff --git a/applications/main.c b/applications/main.c index 2d29b8a..a7baf77 100644 --- a/applications/main.c +++ b/applications/main.c @@ -292,7 +292,7 @@ int main(void) { // 定义超时时间,单位为毫秒 #define TIMEOUT_MS (3 * 60 * 1000) -#define WORK_TIMER_CNT (1000 * 60 * 60 * 24) +#define WORK_TIMER_CNT (1000 * 60 * 60)//按照小时算 if (Get_VIN_VoltageInt1000x() > 10000) { diff --git a/applications/user_sys.h b/applications/user_sys.h index 84927c5..7525a10 100644 --- a/applications/user_sys.h +++ b/applications/user_sys.h @@ -19,7 +19,7 @@ #define SYS_HW_VERSION (0X13U) -#define SYS_SW_VERSION (0X14U) +#define SYS_SW_VERSION (0X16U) #define SYS_IOT_UPLOAD_CYCLE_MIN (0X003CU) // 高位在后,低位在前 #define SYS_IOT_RETRY (0X03U) #define SYS_TEMP_ALARM_THRESHOLD (0X32U) diff --git a/bsp/src/bsp_flash.c b/bsp/src/bsp_flash.c index e28649f..51f93ea 100644 --- a/bsp/src/bsp_flash.c +++ b/bsp/src/bsp_flash.c @@ -902,7 +902,7 @@ int BSP_Flash_Init (void) LOG_D ("Flash_Set_Sever_Data error!"); } - Flash_SetProductTimeLimit (2025, 2, 10, 13, 50, 20, kFactoryTimeId); + Flash_SetProductTimeLimit (2025, 6, 11, 11, 50, 20, kFactoryTimeId); Set_ExpirationTime (MAX_EXPIRATION_DAYS); Flash_Set_Calibration_State(kSysGasCalibStatus); // 标定状态 Flash_Set_Valve_Num(0); diff --git a/bsp/src/bsp_ml307.c b/bsp/src/bsp_ml307.c index b652136..0f589e4 100644 --- a/bsp/src/bsp_ml307.c +++ b/bsp/src/bsp_ml307.c @@ -337,7 +337,8 @@ int _Update_Valve_Data (struct Ml307_Ops *ops) LOG_D ("valve_num: %d", ops->body->valve_num); rt_memcpy (&ops->body->valve_data[0], &valve[0], sizeof (struct valve_t)); // rt_memset(&valve[0].valve_connct_status, 0, (sizeof(struct valve_t) - 7)); // 清空阀门包数据,等待下次更新,如果没更新说明断开了 - ops->body->valve_data[0].valve_voltage = dec_to_bcd (ops->body->valve_data[0].valve_voltage); + // ops->body->valve_data[0].valve_voltage = dec_to_bcd (ops->body->valve_data[0].valve_voltage); + LOG_D ("阀门电压为:%d", ops->body->valve_data[0].valve_voltage); } return RT_EOK; } @@ -345,7 +346,6 @@ int _Update_Valve_Data (struct Ml307_Ops *ops) // 更新函数 int BSP_Ml307_Update (struct Ml307_Ops *ops, rt_uint8_t device_type, rt_uint8_t event_type) { - ops->body->device_type = device_type; ops->body->event_type = event_type; ops->body->hw = (rt_uint8_t)Flash_Get_SysCfg (kHwVerId); @@ -356,9 +356,8 @@ int BSP_Ml307_Update (struct Ml307_Ops *ops, rt_uint8_t device_type, rt_uint8_t ops->body->work_duration = work_duration; ops->body->device_status = device_state_flag; ops->body->valve_num = Flash_Get_Valve_Num(); - _Update_Valve_Data (ops); - return RT_EOK; + return _Update_Valve_Data (ops); } int Ml307_Send_Data (struct Ml307_Ops *ops, rt_uint8_t data_num, rt_uint8_t cmd, rt_uint8_t device_type, rt_uint8_t event_type) @@ -1944,6 +1943,8 @@ static void Ml307_Recv_Thread_Entry (void *parameter) static void Ml307_Life_Thread_Entry (void *parameter) { + rt_uint8_t i = 0; + struct at_device_ml307 *ml307 = &_dev; struct at_device *device = at_device_get_by_name (AT_DEVICE_NAMETYPE_NETDEV, ml307->device_name); RT_ASSERT (device); @@ -2019,38 +2020,6 @@ static void Ml307_Life_Thread_Entry (void *parameter) result = -RT_ERROR; goto __exit; } - if (at_obj_exec_cmd (device->client, resp, "AT+CEREG=1") != RT_EOK) - { - result = -RT_ERROR; - goto __exit; - } - rt_uint8_t i = 0; - /* check the GPRS network is registered */ - for (i = 0; i < 10; i++) - { - if (at_obj_exec_cmd (device->client, resp, "AT+CEREG?") == RT_EOK) - { - int link_stat = 0; - - if (at_resp_parse_line_args_by_kw (resp, "+CEREG:", "+CEREG: %*d,%d", &link_stat) > 0) - { - if ((link_stat == 1) || (link_stat == 5)) - { - LOG_D ("%s device GPRS is registered", device->name); - break; - } - } - } - rt_thread_mdelay (1000); - } - if (i == 10) - { - LOG_E ("%s device GPRS is register failed", device->name); - result = -RT_ERROR; - goto __exit; - } - - /* check SIM card */ for (i = 0; i < 60; i++) { @@ -2080,23 +2049,7 @@ static void Ml307_Life_Thread_Entry (void *parameter) result = -RT_ERROR; goto __exit; } - /* Define PDP Context */ - - for (i = 0; i < 5; i++) - { - if (at_obj_exec_cmd (device->client, resp, "AT+CGDCONT=1,\"IPV4V6\",\"cmnet\"") == RT_EOK) - { - LOG_D ("%s device Define PDP Context Success.", device->name); - break; - } - rt_thread_mdelay (1000); - } - if (i == 5) - { - LOG_E ("%s device Define PDP Context failed.", device->name); - result = -RT_ERROR; - goto __exit; - } + /* Define PDP Context */ for (i = 0; i < 60; i++) { if (at_obj_exec_cmd (device->client, resp, "AT+CGACT=1") == RT_EOK) @@ -2119,6 +2072,28 @@ static void Ml307_Life_Thread_Entry (void *parameter) result = -RT_ERROR; goto __exit; } + + + for (i = 0; i < 5; i++) + { + if (at_obj_exec_cmd (device->client, resp, "AT+CGDCONT=1,\"IPV4V6\",\"cmnet\"") == RT_EOK) + { + LOG_D ("%s device Define PDP Context Success.", device->name); + break; + } + rt_thread_mdelay (1000); + } + if (i == 5) + { + LOG_E ("%s device Define PDP Context failed.", device->name); + result = -RT_ERROR; + goto __exit; + } + if (at_obj_exec_cmd (device->client, resp, "AT+CEREG=1") != RT_EOK) + { + result = -RT_ERROR; + goto __exit; + } /* check the GPRS network is registered */ for (i = 0; i < 60; i++) { @@ -2143,11 +2118,11 @@ static void Ml307_Life_Thread_Entry (void *parameter) result = -RT_ERROR; goto __exit; } - // if (at_obj_exec_cmd (device->client, resp, "AT+MIPCALL=1,1") != RT_EOK) - // { - // result = -RT_ERROR; - // goto __exit; - // } + if (at_obj_exec_cmd (device->client, resp, "AT+MIPCALL=1,1") != RT_EOK) + { + result = -RT_ERROR; + goto __exit; + } #if defined(AT_DEBUG) /* check the GPRS network IP address */ for (i = 0; i < 10; i++) diff --git a/bsp/src/bsp_mq.c b/bsp/src/bsp_mq.c index 7ab7711..8dd7de2 100644 --- a/bsp/src/bsp_mq.c +++ b/bsp/src/bsp_mq.c @@ -47,7 +47,7 @@ uint16_t Get_Gas_VoltageInt1000x(void) uint16_t Get_Gas_VoltageAdcInt1000x(void) { rt_uint16_t voltage_adc = (Get_ADC_Average(kGasAdc) * 3.3 / 4096) * 1000; - LOG_D("Get_Gas_VoltageAdcInt1000x = %04d", voltage_adc); + // LOG_D("Get_Gas_VoltageAdcInt1000x = %04d", voltage_adc); return voltage_adc; } @@ -151,11 +151,12 @@ uint8_t IS_EndOfLife(void) ntp_flag = 0; RTC_GetTime(); - if ((RtcDateTime.year >= 2030) && (work_duration >= 43800)) // 5年后到期 + if ((RtcDateTime.year >= 2031) && (work_duration >= 43800)) // 5年后到期 { if (RTC_GetCounter() >= Sensor_device.expiration_seconds) { Sensor_device.end_of_life = 1; + device_state_flag = 1; } else {