优化了下时间校准函数
This commit is contained in:
parent
3f3d860222
commit
2e72e72eb5
|
@ -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)
|
||||
|
|
|
@ -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 =
|
||||
{
|
||||
|
|
|
@ -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小时都不行,则重启设备
|
||||
{
|
||||
|
|
|
@ -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 //打开所有的终端测试程序
|
||||
|
|
Loading…
Reference in New Issue