From 2e72e72eb5be2ab669a7932f643460f4c54cc12f 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: Thu, 13 Feb 2025 08:56:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86=E4=B8=8B=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=A0=A1=E5=87=86=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/user_sys.h | 2 +- bsp/src/at_device_nt26k.c | 151 ++++++++++++++++++++------------------ bsp/src/bsp_nt26k.c | 3 +- rt-thread/rtconfig.h | 4 +- 4 files changed, 84 insertions(+), 76 deletions(-) diff --git a/applications/user_sys.h b/applications/user_sys.h index d823194..44057e6 100644 --- a/applications/user_sys.h +++ b/applications/user_sys.h @@ -21,7 +21,7 @@ #define SYS_HW_VERSION (0X22U) #define SYS_SW_VERSION (0X10U) -#define SYS_IOT_UPLOAD_CYCLE_MIN (0X3C00U) // 高位在前,低位在后 +#define SYS_IOT_UPLOAD_CYCLE_MIN (0X3C00U) // 高位在后,低位在前 #define SYS_IOT_RETRY (0X03U) #define SYS_TEMP_ALARM_THRESHOLD (0X30U) #define SYS_ALARM_VALVE (0X0AU) diff --git a/bsp/src/at_device_nt26k.c b/bsp/src/at_device_nt26k.c index 45ea806..91c2341 100644 --- a/bsp/src/at_device_nt26k.c +++ b/bsp/src/at_device_nt26k.c @@ -2,7 +2,7 @@ * @Author : stark1898y 1658608470@qq.com * @Date : 2024-09-04 13:33:49 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2025-02-06 09:10:34 + * @LastEditTime: 2025-02-13 08:55:43 * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\at_device_nt26k.c * @Description : * @@ -769,6 +769,55 @@ static struct netdev *nt26k_netdev_add(const char *netdev_name) } /* ============================= nt26k device operations ============================= */ +int Time_Calibration(struct at_device *device) +{ + at_response_t resp = RT_NULL; + RT_ASSERT(device); + resp = at_create_resp(64, 2, rt_tick_from_millisecond(2000)); + if (resp == RT_NULL) + { + LOG_E("no memory for resp create."); + at_delete_resp(resp); + return RT_ERROR; + } + if (at_obj_exec_cmd(device->client, resp, "AT+CCLK?") == RT_EOK) + { + TsRtcDateTime rtc_dt; + int year, mounth, days, hous, min, sec; + /*+CCLK:24/11/12,06:08:19+32*/ + if (at_resp_parse_line_args_by_kw(resp, "+CCLK:", "+CCLK: \"%d/%d/%d,%d:%d:%d+32\"", &year, &mounth, &days, &hous, &min, &sec) > 0) + { + if ((year != 0) && (year < 70))//如果获取失败,则不配置 例: +CCLK:00/01/01,00:00:12+08 + { + rtc_dt.year = (2000 + year); + rtc_dt.month = mounth; + rtc_dt.day = days; + rtc_dt.hour = hous; // 此时为零区时间,需要转化为东八区 + rtc_dt.minute = min; + rtc_dt.second = sec; + Time_Zone_Conversion(&rtc_dt); // 时区设置 + rtc_dt.week = RTC_GetWeek(rtc_dt.year, rtc_dt.month, rtc_dt.day); + RTC_SetTime(rtc_dt.year, rtc_dt.month, rtc_dt.day, + rtc_dt.hour, rtc_dt.minute, rtc_dt.second); // 设置时间 + LOG_I("RTC时间: %04d-%02d-%02d %02d:%02d:%02d \n", + rtc_dt.year, rtc_dt.month, rtc_dt.day, rtc_dt.hour, rtc_dt.minute, rtc_dt.second); + ntp_flag = 1; + at_delete_resp(resp); + } + return RT_EOK; + } + else + { + ntp_flag = 0; + } + } + else + { + ntp_flag = 0; + } + at_delete_resp(resp); + return RT_ERROR; +} /* initialize for nt26k */ static void nt26k_init_thread_entry(void *parameter) @@ -1043,30 +1092,35 @@ static void nt26k_init_thread_entry(void *parameter) result = -RT_ERROR; goto __exit; } - if (at_obj_exec_cmd(device->client, resp, "AT+CCLK?") == RT_EOK) - { - TsRtcDateTime rtc_dt; - int year, mounth, days, hous, min, sec; - /*+CCLK:24/11/12,06:08:19+32*/ - if (at_resp_parse_line_args_by_kw(resp, "+CCLK:", "+CCLK: \"%d/%d/%d,%d:%d:%d+32\"", &year, &mounth, &days, &hous, &min, &sec) > 0) - { - rtc_dt.year = (2000 + year); - rtc_dt.month = mounth; - rtc_dt.day = days; - rtc_dt.hour = hous; // 此时为零区时间,需要转化为东八区 - rtc_dt.minute = min; - rtc_dt.second = sec; - Time_Zone_Conversion(&rtc_dt); // 时区设置 - rtc_dt.week = RTC_GetWeek(rtc_dt.year, rtc_dt.month, rtc_dt.day); - RTC_SetTime(rtc_dt.year, rtc_dt.month, rtc_dt.day, - rtc_dt.hour, rtc_dt.minute, rtc_dt.second); // 设置时间 - LOG_I("RTC时间: %04d-%02d-%02d %02d:%02d:%02d \n", - rtc_dt.year, rtc_dt.month, rtc_dt.day, rtc_dt.hour, rtc_dt.minute, rtc_dt.second); - // 网络时间同步标志 - ntp_flag = 1; - result = RT_EOK; - } - } + // if (at_obj_exec_cmd(device->client, resp, "AT+CCLK?") == RT_EOK) + // { + // TsRtcDateTime rtc_dt; + // int year, mounth, days, hous, min, sec; + // /*+CCLK:24/11/12,06:08:19+32*/ + // if (at_resp_parse_line_args_by_kw(resp, "+CCLK:", "+CCLK: \"%d/%d/%d,%d:%d:%d+32\"", &year, &mounth, &days, &hous, &min, &sec) > 0) + // { + // if ((year != 0) && (year < 70))//如果获取失败,则不配置 例: +CCLK:00/01/01,00:00:12+08 + // { + // rtc_dt.year = (2000 + year); + // rtc_dt.month = mounth; + // rtc_dt.day = days; + // rtc_dt.hour = hous; // 此时为零区时间,需要转化为东八区 + // rtc_dt.minute = min; + // rtc_dt.second = sec; + // Time_Zone_Conversion(&rtc_dt); // 时区设置 + // rtc_dt.week = RTC_GetWeek(rtc_dt.year, rtc_dt.month, rtc_dt.day); + // RTC_SetTime(rtc_dt.year, rtc_dt.month, rtc_dt.day, + // rtc_dt.hour, rtc_dt.minute, rtc_dt.second); // 设置时间 + // LOG_I("RTC时间: %04d-%02d-%02d %02d:%02d:%02d \n", + // rtc_dt.year, rtc_dt.month, rtc_dt.day, rtc_dt.hour, rtc_dt.minute, rtc_dt.second); + // // 网络时间同步标志 + // ntp_flag = 1; + // } + + // result = RT_EOK; + // } + // } + Time_Calibration(device); /* initialize successfully */ result = RT_EOK; break; @@ -1385,53 +1439,6 @@ static int nt26k_control(struct at_device *device, int cmd, void *arg) return result; } -int Time_Calibration(struct at_device *device) -{ - at_response_t resp = RT_NULL; - RT_ASSERT(device); - resp = at_create_resp(64, 2, rt_tick_from_millisecond(2000)); - if (resp == RT_NULL) - { - LOG_E("no memory for resp create."); - at_delete_resp(resp); - return RT_ERROR; - } - if (at_obj_exec_cmd(device->client, resp, "AT+CCLK?") == RT_EOK) - { - TsRtcDateTime rtc_dt; - int year, mounth, days, hous, min, sec; - /*+CCLK:24/11/12,06:08:19+32*/ - if (at_resp_parse_line_args_by_kw(resp, "+CCLK:", "+CCLK: \"%d/%d/%d,%d:%d:%d+32\"", &year, &mounth, &days, &hous, &min, &sec) > 0) - { - rtc_dt.year = (2000 + year); - rtc_dt.month = mounth; - rtc_dt.day = days; - rtc_dt.hour = hous; // 此时为零区时间,需要转化为东八区 - rtc_dt.minute = min; - rtc_dt.second = sec; - Time_Zone_Conversion(&rtc_dt); // 时区设置 - rtc_dt.week = RTC_GetWeek(rtc_dt.year, rtc_dt.month, rtc_dt.day); - RTC_SetTime(rtc_dt.year, rtc_dt.month, rtc_dt.day, - rtc_dt.hour, rtc_dt.minute, rtc_dt.second); // 设置时间 - LOG_I("RTC时间: %04d-%02d-%02d %02d:%02d:%02d \n", - rtc_dt.year, rtc_dt.month, rtc_dt.day, rtc_dt.hour, rtc_dt.minute, rtc_dt.second); - ntp_flag = 1; - at_delete_resp(resp); - - return RT_EOK; - } - else - { - ntp_flag = 0; - } - } - else - { - ntp_flag = 0; - } - at_delete_resp(resp); - return RT_ERROR; -} const struct at_device_ops nt26k_device_ops = { diff --git a/bsp/src/bsp_nt26k.c b/bsp/src/bsp_nt26k.c index 22662e9..f45000e 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-02-08 21:11:31 + * @LastEditTime: 2025-02-12 11:01:27 * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\bsp_nt26k.c * @Description: * @@ -1594,6 +1594,7 @@ static void Nt26k_Life_Thread_Entry(void *parameter) } nt26k_disconnect_retry_flag = 1; LOG_D("联网错误,等待10s后重连"); + rt_thread_mdelay(10000);//上一版本未加延时 delay_n++; if (delay_n >= 360) // 连续重连大于1小时都不行,则重启设备 { diff --git a/rt-thread/rtconfig.h b/rt-thread/rtconfig.h index 50a3a0f..f7da23a 100644 --- a/rt-thread/rtconfig.h +++ b/rt-thread/rtconfig.h @@ -15,8 +15,8 @@ /*使用动态日志及密码功能时,需开启宏 FINSH_USING_AUTH ULOG_USING_FILTER ENABLE_LOG_ALL ULOG_OUTPUT_LVL = 7 以及设置ulog.c 1522行 输出等级为0*/ /**/ -#define FINSH_USING_AUTH //开启终端密码登录功能 -#define ULOG_USING_FILTER //开启动态修改日志等级 默认修改在ulog.c 1522行 +// #define FINSH_USING_AUTH //开启终端密码登录功能 +// #define ULOG_USING_FILTER //开启动态修改日志等级 默认修改在ulog.c 1522行 #define ENABLE_LOG_ALL #define TEST_ENABLE //打开所有的终端测试程序