From e7ec172555bb44d4bfd977e56bcbec99d432f63e 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: Sat, 18 Jan 2025 11:23:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E4=BA=86=E6=8E=89=E7=94=B5=E5=90=8E?= =?UTF-8?q?=E4=B8=8A=E7=94=B5=E7=9A=84=E5=BF=AB=E9=80=9F=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E9=80=BB=E8=BE=91,=E4=BB=A5=E5=8F=8A=E5=8A=A0=E4=BA=86nt26?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=99=A8=E6=BA=A2=E5=87=BA=E9=98=B2=E6=8A=A4?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/main.c | 26 ++++++++++++++++++++------ bsp/inc/bsp_nt26k.h | 3 +++ bsp/src/bsp_nt26k.c | 15 +++++++++++++-- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/applications/main.c b/applications/main.c index c185176..ef37a15 100644 --- a/applications/main.c +++ b/applications/main.c @@ -2,7 +2,7 @@ * @Author: mbw * @Date: 2024-10-23 17:14:16 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2025-01-15 10:36:40 + * @LastEditTime: 2025-01-18 11:21:57 * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\applications\main.c * @Descrt_thread_ * @@ -420,13 +420,27 @@ int main (void) #if (IOT_MODULE_SWITCH == 1) Nt26k_Send_Event (kNt26kPowerDownEvent); #endif - // 等待20s,要是还没断电就重启 - for (uint8_t i = 0; i < 20; i++) + rt_uint8_t cnt = 0; + while ((device_power_down_flag == 0)&&(cnt < 60))//等待接收到掉电事件响应 { - rt_thread_mdelay (1000); - LOG_D (" %d s", i); + rt_thread_mdelay(500); + } + cnt = 0; + while ((nt26k_power_down_flag == 0)&&(cnt < 60))//等待接收到物联网模组关机完成 + { + rt_thread_mdelay(500); + } + while(1) + { + if (Get_VIN_VoltageInt1000x() > 10000) + { + NVIC_SystemReset(); // 直接重启系统 + } + else + { + rt_thread_mdelay(500); + } } - NVIC_SystemReset(); // 直接重启系统 } else if (received_event & Get_Sys_Event_Flag (kSelfCheckEvent)) // 自检 { diff --git a/bsp/inc/bsp_nt26k.h b/bsp/inc/bsp_nt26k.h index f276f9c..997c8a9 100644 --- a/bsp/inc/bsp_nt26k.h +++ b/bsp/inc/bsp_nt26k.h @@ -208,5 +208,8 @@ extern rt_uint8_t nt26k_conncet_tcp_flag; extern rt_uint8_t nt26k_connect_sever_flag; extern rt_uint8_t nt26k_disconnect_pdp_flag; extern rt_uint8_t power_on_send_flag; +extern rt_uint8_t device_power_down_flag; +extern rt_uint8_t nt26k_power_down_flag; + int BSP_Nt26k_Thread_Init(void); void Nt26k_Send_Event(Nt26kEvent event_type); diff --git a/bsp/src/bsp_nt26k.c b/bsp/src/bsp_nt26k.c index 5045d56..fbd760b 100644 --- a/bsp/src/bsp_nt26k.c +++ b/bsp/src/bsp_nt26k.c @@ -2,7 +2,7 @@ * @Author: mbw * @Date: 2024-10-09 08:42:14 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2025-01-17 15:04:55 + * @LastEditTime: 2025-01-18 11:16:47 * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\bsp_nt26k.c * @Description: * @@ -67,6 +67,8 @@ static rt_timer_t nt26k_timer; // 上报心跳 static rt_timer_t nt26k_upload_timer; // 更新本地时间定时器 static rt_timer_t nt26k_power_error_timer; // 上电失败情况下启动定时器 +rt_uint8_t device_power_down_flag; +rt_uint8_t nt26k_power_down_flag; rt_uint8_t nt26k_connect_sever_flag; rt_uint8_t nt26k_conncet_tcp_flag; rt_uint8_t nt26k_disconnect_pdp_flag; // PDP断开连接标志 @@ -830,10 +832,15 @@ int Nt26k_Process_Events(Nt26kEvent nt26k_recv_event, struct at_device *device, } else if (rt_strcmp(event->event_name, "掉电事件") == RT_EOK) { - rt_thread_mdelay(5000); + rt_uint8_t cnt = 0; + while ((device_power_down_flag == 0)&&(cnt < 10)) + { + rt_thread_mdelay(500); + } if (device->class->device_ops->control(device, AT_DEVICE_CTRL_POWER_OFF, RT_NULL) == RT_EOK) { LOG_D("关闭模组"); + nt26k_power_down_flag = 1; } } else @@ -899,6 +906,10 @@ void Handle_Server_Reply(struct Nt26k_Ops *ops) { LOG_D("nt26k send data success\n"); } + else if (ops->recv->recv_data.event_type == EVENT_TYPE_DEVICE_FAILURE)//是掉电事件回应 + { + device_power_down_flag = 1; + } } void Handle_Self_Check(struct Nt26k_Ops *ops)