这一版优化了报警和故障逻辑,以及截止日期的逻辑
This commit is contained in:
parent
e55496541d
commit
da3123744e
|
@ -1,3 +1,13 @@
|
||||||
|
/***
|
||||||
|
* @Author: mbw
|
||||||
|
* @Date: 2024-12-30 11:45:44
|
||||||
|
* @LastEditors: mbw && 1600520629@qq.com
|
||||||
|
* @LastEditTime: 2025-01-25 15:00:21
|
||||||
|
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\inc\at_device_nt26k.h
|
||||||
|
* @Description:
|
||||||
|
* @
|
||||||
|
* @Copyright (c) 2025 by ${git_name_email}, All Rights Reserved.
|
||||||
|
*/
|
||||||
#ifndef __AT_DEVICE_NT26K_H__
|
#ifndef __AT_DEVICE_NT26K_H__
|
||||||
#define __AT_DEVICE_NT26K_H__
|
#define __AT_DEVICE_NT26K_H__
|
||||||
|
|
||||||
|
@ -64,6 +74,7 @@ typedef struct __attribute__((packed))
|
||||||
|
|
||||||
extern nt26k_sys_info nt26k;
|
extern nt26k_sys_info nt26k;
|
||||||
extern rt_uint8_t nt26k_init_complate_flag;
|
extern rt_uint8_t nt26k_init_complate_flag;
|
||||||
|
extern volatile rt_uint8_t ntp_flag;
|
||||||
extern struct rt_completion nt26k_init_complate;
|
extern struct rt_completion nt26k_init_complate;
|
||||||
int at_send_data(struct at_device *device, const char *data, rt_size_t size);
|
int at_send_data(struct at_device *device, const char *data, rt_size_t size);
|
||||||
rt_err_t Nt26k_Reset(struct at_device *device);
|
rt_err_t Nt26k_Reset(struct at_device *device);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: mbw
|
* @Author: mbw
|
||||||
* @Date: 2025-01-24 08:40:39
|
* @Date: 2025-01-24 08:40:39
|
||||||
* @LastEditors: mbw && 1600520629@qq.com
|
* @LastEditors: mbw && 1600520629@qq.com
|
||||||
* @LastEditTime: 2025-01-25 14:14:51
|
* @LastEditTime: 2025-01-25 14:49:06
|
||||||
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\inc\bsp_h308.h
|
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\inc\bsp_h308.h
|
||||||
* @Description:
|
* @Description:
|
||||||
* @
|
* @
|
||||||
|
@ -76,7 +76,7 @@ typedef struct __attribute__((packed))
|
||||||
rt_uint8_t checksum; // 校验
|
rt_uint8_t checksum; // 校验
|
||||||
} TsH308Data;
|
} TsH308Data;
|
||||||
|
|
||||||
typedef struct __attribute__((packed))
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t end_of_life; // 寿命到期
|
uint8_t end_of_life; // 寿命到期
|
||||||
uint8_t last_life; // 上次状态
|
uint8_t last_life; // 上次状态
|
||||||
|
|
|
@ -49,7 +49,7 @@ char data_buf[AT_CLIENT_RECV_BUFF_LEN] = {0};
|
||||||
nt26k_sys_info nt26k = {0};
|
nt26k_sys_info nt26k = {0};
|
||||||
struct rt_completion nt26k_init_complate;
|
struct rt_completion nt26k_init_complate;
|
||||||
volatile rt_uint8_t socket_id = 0;
|
volatile rt_uint8_t socket_id = 0;
|
||||||
|
volatile rt_uint8_t ntp_flag = 0;
|
||||||
// 将本地时间转换为对应时区时间
|
// 将本地时间转换为对应时区时间
|
||||||
void Time_Zone_Conversion(TsRtcDateTime *timeInfo)
|
void Time_Zone_Conversion(TsRtcDateTime *timeInfo)
|
||||||
{
|
{
|
||||||
|
@ -230,12 +230,12 @@ static void urc_tcp_recv(struct at_client *client, const char *data, rt_size_t s
|
||||||
(nt26k_ops.recv->recv_data.event_type == EVENT_TYPE_POWER_ON))
|
(nt26k_ops.recv->recv_data.event_type == EVENT_TYPE_POWER_ON))
|
||||||
// 加这个的原因就是如果有指令下发,会出现两个信号量,指令会执行两次,所以排除心跳包才释放信号量
|
// 加这个的原因就是如果有指令下发,会出现两个信号量,指令会执行两次,所以排除心跳包才释放信号量
|
||||||
{
|
{
|
||||||
rt_sem_release(nt26k_recv_msg_sem);// 接收到的是心跳包
|
rt_sem_release(nt26k_recv_msg_sem); // 接收到的是心跳包
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rt_sem_release(nt26k_recv_sem);
|
rt_sem_release(nt26k_recv_sem);
|
||||||
rt_sem_release(nt26k_recv_msg_sem);// 接收到的是响应包
|
rt_sem_release(nt26k_recv_msg_sem); // 接收到的是响应包
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1059,6 +1059,8 @@ static void nt26k_init_thread_entry(void *parameter)
|
||||||
rtc_dt.hour, rtc_dt.minute, rtc_dt.second); // 设置时间
|
rtc_dt.hour, rtc_dt.minute, rtc_dt.second); // 设置时间
|
||||||
LOG_I("RTC时间: %04d-%02d-%02d %02d:%02d:%02d \n",
|
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);
|
rtc_dt.year, rtc_dt.month, rtc_dt.day, rtc_dt.hour, rtc_dt.minute, rtc_dt.second);
|
||||||
|
// 网络时间同步标志
|
||||||
|
ntp_flag = 1;
|
||||||
result = RT_EOK;
|
result = RT_EOK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1410,8 +1412,17 @@ int Time_Calibration(struct at_device *device)
|
||||||
LOG_I("RTC时间: %04d-%02d-%02d %02d:%02d:%02d \n",
|
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);
|
rtc_dt.year, rtc_dt.month, rtc_dt.day, rtc_dt.hour, rtc_dt.minute, rtc_dt.second);
|
||||||
at_delete_resp(resp);
|
at_delete_resp(resp);
|
||||||
|
ntp_flag = 1;
|
||||||
return RT_EOK;
|
return RT_EOK;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ntp_flag = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ntp_flag = 0;
|
||||||
}
|
}
|
||||||
at_delete_resp(resp);
|
at_delete_resp(resp);
|
||||||
return RT_ERROR;
|
return RT_ERROR;
|
||||||
|
|
|
@ -136,8 +136,9 @@ int Get_IotImei (char *buf, rt_size_t len)
|
||||||
|
|
||||||
if ((*(rt_uint8_t *)FLASH_IOT_IMEI_ADDR != 0xE3) && (*(rt_uint8_t *)FLASH_IOT_IMEI_ADDR != 0x39))
|
if ((*(rt_uint8_t *)FLASH_IOT_IMEI_ADDR != 0xE3) && (*(rt_uint8_t *)FLASH_IOT_IMEI_ADDR != 0x39))
|
||||||
{
|
{
|
||||||
char imei_buf[FLASH_IOT_IMEI_LEN]={0};
|
char imei_buf[FLASH_IOT_IMEI_LEN + 1]={0};
|
||||||
Flash_Read(FLASH_IOT_IMEI_ADDR, (rt_uint8_t *)&imei_buf[0], len);
|
Flash_Read(FLASH_IOT_IMEI_ADDR, (rt_uint8_t *)&imei_buf[0], len);
|
||||||
|
imei_buf[len] = '\0';
|
||||||
LOG_D ("read imei: %s", imei_buf);
|
LOG_D ("read imei: %s", imei_buf);
|
||||||
rt_memcpy(buf, imei_buf, len);
|
rt_memcpy(buf, imei_buf, len);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: mbw
|
* @Author: mbw
|
||||||
* @Date: 2024-11-14 10:21:04
|
* @Date: 2024-11-14 10:21:04
|
||||||
* @LastEditors: mbw && 1600520629@qq.com
|
* @LastEditors: mbw && 1600520629@qq.com
|
||||||
* @LastEditTime: 2025-01-25 14:34:41
|
* @LastEditTime: 2025-01-25 15:07:34
|
||||||
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\bsp_h308.c
|
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\bsp_h308.c
|
||||||
* @Description:
|
* @Description:
|
||||||
*
|
*
|
||||||
|
@ -241,8 +241,12 @@ static uint8_t H308_CheckData(void)
|
||||||
// TODO: 寿命检测
|
// TODO: 寿命检测
|
||||||
uint8_t IS_H308_EndOfLife(void)
|
uint8_t IS_H308_EndOfLife(void)
|
||||||
{
|
{
|
||||||
|
if (ntp_flag) // 是否同步网络时间
|
||||||
|
{
|
||||||
|
ntp_flag = 0;
|
||||||
RTC_GetTime();
|
RTC_GetTime();
|
||||||
if (RtcDateTime.year >= 2035) // 至少大于2035年再检测
|
|
||||||
|
if (RtcDateTime.year >= 2035) &&(work_duration >= 6 * 365) // 至少大于2035年且实际使用时长超过6年
|
||||||
{
|
{
|
||||||
if (RTC_GetCounter() >= H308.expiration_seconds)
|
if (RTC_GetCounter() >= H308.expiration_seconds)
|
||||||
{
|
{
|
||||||
|
@ -259,6 +263,12 @@ uint8_t IS_H308_EndOfLife(void)
|
||||||
H308.end_of_life = 0;
|
H308.end_of_life = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
H308.end_of_life = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return H308.end_of_life;
|
return H308.end_of_life;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,6 @@
|
||||||
#define NT26K_LIFE_THREAD_PRIORITY 26
|
#define NT26K_LIFE_THREAD_PRIORITY 26
|
||||||
#define NT26K_LIFE_THREAD_TICKS 10
|
#define NT26K_LIFE_THREAD_TICKS 10
|
||||||
|
|
||||||
|
|
||||||
// static rt_uint32_t nt26k_status = 0;
|
// static rt_uint32_t nt26k_status = 0;
|
||||||
ALIGN(RT_ALIGN_SIZE)
|
ALIGN(RT_ALIGN_SIZE)
|
||||||
static char nt26k_thread_stack[NT26K_THREAD_STACK_SIZE];
|
static char nt26k_thread_stack[NT26K_THREAD_STACK_SIZE];
|
||||||
|
@ -174,7 +173,7 @@ void Nt26k_Send_Event(Nt26kEvent event_type)
|
||||||
{
|
{
|
||||||
if (nt26k_event_index.current_event != kNt26kPowerOnEvent)
|
if (nt26k_event_index.current_event != kNt26kPowerOnEvent)
|
||||||
{
|
{
|
||||||
if(power_on_send_flag)
|
if (power_on_send_flag)
|
||||||
{
|
{
|
||||||
rt_event_send(&at_device_event, Nt26k_Get_Event_Flag(event_type));
|
rt_event_send(&at_device_event, Nt26k_Get_Event_Flag(event_type));
|
||||||
}
|
}
|
||||||
|
@ -207,7 +206,6 @@ static void Nt26k_Error_Timer_Cb(void *parameter)
|
||||||
{
|
{
|
||||||
Nt26k_Send_Event(kNt26kPowerOnEvent);
|
Nt26k_Send_Event(kNt26kPowerOnEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int _Pack_Send(struct Nt26k_Ops *ops, char *buf)
|
int _Pack_Send(struct Nt26k_Ops *ops, char *buf)
|
||||||
|
@ -850,7 +848,7 @@ int Nt26k_Process_Events(Nt26kEvent nt26k_recv_event, struct at_device *device,
|
||||||
if (rt_strcmp(event->event_name, "掉电事件") == RT_EOK)
|
if (rt_strcmp(event->event_name, "掉电事件") == RT_EOK)
|
||||||
{
|
{
|
||||||
rt_uint8_t cnt = 0;
|
rt_uint8_t cnt = 0;
|
||||||
while ((device_power_down_flag == 0)&&(cnt < 10))
|
while ((device_power_down_flag == 0) && (cnt < 10))
|
||||||
{
|
{
|
||||||
rt_thread_mdelay(500);
|
rt_thread_mdelay(500);
|
||||||
}
|
}
|
||||||
|
@ -903,7 +901,7 @@ void Handle_Server_Reply(struct Nt26k_Ops *ops)
|
||||||
{
|
{
|
||||||
LOG_D("nt26k send data success\n");
|
LOG_D("nt26k send data success\n");
|
||||||
}
|
}
|
||||||
else if (ops->recv->recv_data.event_type == EVENT_TYPE_POWER_OFF)//是掉电事件回应
|
else if (ops->recv->recv_data.event_type == EVENT_TYPE_POWER_OFF) // 是掉电事件回应
|
||||||
{
|
{
|
||||||
device_power_down_flag = 1;
|
device_power_down_flag = 1;
|
||||||
}
|
}
|
||||||
|
@ -1113,7 +1111,7 @@ void Handle_Sever_Addr_Set(struct Nt26k_Ops *ops)
|
||||||
rt_uint8_t data[6] = {0};
|
rt_uint8_t data[6] = {0};
|
||||||
char imei[16] = {0};
|
char imei[16] = {0};
|
||||||
char temp[32] = "0";
|
char temp[32] = "0";
|
||||||
flash_sever_info sever_info= {0};
|
flash_sever_info sever_info = {0};
|
||||||
Get_IotImei(imei, FLASH_IOT_IMEI_LEN);
|
Get_IotImei(imei, FLASH_IOT_IMEI_LEN);
|
||||||
String2Hex(temp, imei); // 将字符串转为十六进制字符串
|
String2Hex(temp, imei); // 将字符串转为十六进制字符串
|
||||||
rt_memcpy(data, (ops->recv->recv_data.res_data + 9), FLASH_SERVER_LEN);
|
rt_memcpy(data, (ops->recv->recv_data.res_data + 9), FLASH_SERVER_LEN);
|
||||||
|
@ -1127,7 +1125,7 @@ void Handle_Sever_Addr_Set(struct Nt26k_Ops *ops)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOG_D("服务器地址修改成功\n");
|
LOG_D("服务器地址修改成功\n");
|
||||||
if(ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_NT26K, INSTRUCTION_DOWN_SEVER_ADDR, temp, RESPONSE_CODE_SUCCESS) == RT_EOK)
|
if (ops->Resp(ops, DATA_SERIAL_NUM, CMD_TYPE_INSTRUCTION_REPLY, DEVICE_TYPE_NT26K, INSTRUCTION_DOWN_SEVER_ADDR, temp, RESPONSE_CODE_SUCCESS) == RT_EOK)
|
||||||
{
|
{
|
||||||
Flash_Set_WorkDuration(work_duration);
|
Flash_Set_WorkDuration(work_duration);
|
||||||
rt_thread_mdelay(100);
|
rt_thread_mdelay(100);
|
||||||
|
@ -1546,18 +1544,17 @@ static void Nt26k_Life_Thread_Entry(void *parameter)
|
||||||
if (result != RT_EOK)
|
if (result != RT_EOK)
|
||||||
{
|
{
|
||||||
nt26k_disconnect_retry_flag = 1;
|
nt26k_disconnect_retry_flag = 1;
|
||||||
LOG_D("重连网络失败,等待%d s后重连\n",delay_n * 5);
|
LOG_D("重连网络失败,等待%d s后重连\n", delay_n * 5);
|
||||||
|
|
||||||
rt_thread_mdelay(delay_n * 5000);
|
rt_thread_mdelay(delay_n * 5000);
|
||||||
delay_n++;
|
delay_n++;
|
||||||
if (delay_n >= 66)//大于3小时的重连都不行,则重启设备
|
if (delay_n >= 66) // 大于3小时的重连都不行,则重启设备
|
||||||
{
|
{
|
||||||
Flash_Set_WorkDuration(work_duration);
|
Flash_Set_WorkDuration(work_duration);
|
||||||
delay_n = 0;
|
delay_n = 0;
|
||||||
reboot();
|
reboot();
|
||||||
}
|
}
|
||||||
rt_sem_release(nt26k_disconnect_sem);
|
rt_sem_release(nt26k_disconnect_sem);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue