修改了历史数据部分接收

This commit is contained in:
小马_666 2025-01-13 09:12:44 +08:00
parent 5e5ecc7d30
commit 02263c80b6
8 changed files with 132 additions and 224 deletions

16
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "markdownlint",
"problemMatcher": [
"$markdownlint"
],
"label": "markdownlint: Lint all Markdown files in the workspace with markdownlint",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

View File

@ -2,7 +2,7 @@
* @Author: mbw * @Author: mbw
* @Date: 2024-10-23 17:14:16 * @Date: 2024-10-23 17:14:16
* @LastEditors: mbw && 1600520629@qq.com * @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2025-01-09 15:41:13 * @LastEditTime: 2025-01-10 13:37:28
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\applications\main.c * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\applications\main.c
* @Descrt_thread_ * @Descrt_thread_
* *

View File

@ -2,8 +2,8 @@
* @Author: mbw * @Author: mbw
* @Date: 2024-10-10 15:50:39 * @Date: 2024-10-10 15:50:39
* @LastEditors: mbw && 1600520629@qq.com * @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2024-12-31 17:48:21 * @LastEditTime: 2025-01-10 11:43:48
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-4G\applications\user_sys.c * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\applications\user_sys.c
* @Description: * @Description:
* *
* Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
@ -29,6 +29,12 @@
#include "rtdef.h" #include "rtdef.h"
#include "bsp_rng.h" #include "bsp_rng.h"
#include "at_device_nt26k.h" #include "at_device_nt26k.h"
#include <stdlib.h> // 包含stdlib.h以使用rand()和srand()
#define LOG_TAG "user_sys"
#define LOG_LVL LOG_LVL_DBG
#include <ulog.h>
#define K 3 * 1000 #define K 3 * 1000
@ -231,18 +237,17 @@ int Convert_To_Hex(const struct flash_sever_info *sever_info, uint8_t *hex_array
rt_uint32_t IMEI_Delay(void) rt_uint32_t IMEI_Delay(void)
{ {
char imei_str[16]; char imei_str[16];
char randon_char[8] = {0}; char randon_char[6] = {0}; // 调整数组大小为6
rt_uint32_t imei_delay = 0; rt_uint32_t random_number = 0;
unsigned int random_number = 0;
Get_IotImei(imei_str, FLASH_NB_IMEI_LEN); Get_IotImei(imei_str, FLASH_NB_IMEI_LEN);
// 提取 IMEI 的最后 5 位作为种子 // 提取 IMEI 的最后 5 位作为种子
rt_strncpy(randon_char, &imei_str[0] + FLASH_NB_IMEI_LEN - 5, 5); rt_strncpy(randon_char, &imei_str[FLASH_NB_IMEI_LEN - 5], 5);
random_number = atoi(randon_char); random_number = atoi(randon_char);
imei_delay = (random_number + Get_RandomNumber()) % (K); // 生成随机数
// rt_kprintf("IMEI_Delay:%d\r\n", imei_delay); rt_uint32_t imei_delay = (random_number + Get_RandomNumber()) % K;
return (rt_uint32_t)imei_delay; LOG_I("imei_delay: %d", imei_delay);
return imei_delay;
} }

View File

@ -15,14 +15,22 @@
#include "bsp_flash.h" #include "bsp_flash.h"
#define MAX_EXPIRATION_DAYS (uint16_t)(365 * 10 + 30 * 3) #define MAX_EXPIRATION_YEARS (10U)
#define MAX_EXPIRATION_DAYS (365 * MAX_EXPIRATION_YEARS + 30 * 3U)
#define SYS_HW_VERSION (0X10U)
#define SYS_SW_VERSION (0X13U)
#define SYS_IOT_UPLOAD_CYCLE_MIN (0X3C00U) // 高位在前,低位在后
#define SYS_IOT_RETRY (0X03U)
#define SYS_TEMP_ALARM_THRESHOLD (0X30U)
#define SYS_ALARM_VALVE (0X0AU)
#define SYS_EMV_SWITCH (0X04U)
#define SYS_RELAY_SWITCH (0X04U)
#define SYS_ALARM_VALVE_MAX (0X30U)
#define SYS_IOT_URL ("8.130.117.149")
#define SYS_IOT_PORT ("7137")
#define SYS_HW_VERSION 0X10
#define SYS_SW_VERSION 0X13
#define SYS_IOT_UPLOAD_CYCLE_MIN (0X3C00) // 高位在前,低位在后
#define SYS_ALARM_VALVE 0X0A
#define SYS_IOT_URL "8.130.117.149"
#define SYS_IOT_PORT "7137"
typedef enum typedef enum
{ {
kPowerOnEvent, kPowerOnEvent,

View File

@ -2,7 +2,7 @@
* @Author : stark1898y 1658608470@qq.com * @Author : stark1898y 1658608470@qq.com
* @Date : 2024-09-04 13:33:49 * @Date : 2024-09-04 13:33:49
* @LastEditors: mbw && 1600520629@qq.com * @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2025-01-10 09:35:07 * @LastEditTime: 2025-01-10 13:01:45
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\at_device_nt26k.c * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\at_device_nt26k.c
* @Description : * @Description :
* *
@ -405,7 +405,7 @@ int nt26k_check_link_status(struct at_device *device)
} }
} }
} }
if (at_obj_exec_cmd(device->client, resp, "AT+QICFG=\"tcp/keepalive\",1,1800,50,5") != RT_EOK)//保活期为最大30min故30min重设一下 if (at_obj_exec_cmd(device->client, resp, "AT+QICFG=\"tcp/keepalive\",1,600,100,6") != RT_EOK)//保活期为最大30min故30min重设一下
{ {
result = -RT_ERROR; result = -RT_ERROR;
} }
@ -464,7 +464,7 @@ __exit:
*/ */
static void nt26k_check_link_status_entry(void *parameter) static void nt26k_check_link_status_entry(void *parameter)
{ {
#define NT26K_LINK_DELAY_TIME (30 * 60 * RT_TICK_PER_SECOND) #define NT26K_LINK_DELAY_TIME (10 * 60 * RT_TICK_PER_SECOND)
#define NT26K_LINK_STATUS_OK 1 #define NT26K_LINK_STATUS_OK 1

View File

@ -80,22 +80,12 @@ const rt_uint32_t hr_sys_cfg_info_len[kCnt] = {
static rt_base_t interrupt_value; static rt_base_t interrupt_value;
/*默认的系统配置*/ /*默认的系统配置*/
rt_uint8_t sys_hw_ver = SYS_HW_VERSION;
rt_uint8_t sys_sw_ver = SYS_SW_VERSION;
rt_uint8_t sys_iot_retry = 0x03; // 重试次数3次
rt_uint16_t sys_iot_upload_cycle = SYS_IOT_UPLOAD_CYCLE_MIN; // 60分钟一次 ,低位在前,高为在后,为了和服务器下发时保持一致,有利于读取
rt_uint8_t sys_alarm_h_value = 0x32; // 50
rt_uint8_t sys_alarm_l_value = SYS_ALARM_VALVE; // 10
rt_uint8_t sys_temp_alarm_threshold = 0x32;
rt_uint8_t sys_emagnetic_switch = 0x04; // 具备阀门功能
rt_uint8_t sys_relay_switch = 0x04; // 具备继电器功能
struct flash_sever_info sever_info = struct flash_sever_info sever_info =
{ {
.server_url = SYS_IOT_URL, .server_url = SYS_IOT_URL,
.server_port = SYS_IOT_PORT, .server_port = SYS_IOT_PORT,
}; };
static void BSP_Flash_UnLock(void) static void BSP_Flash_UnLock(void)
{ {
#if (SystemCoreClock > SYSCLK_FREQ_96MHz_HSE) #if (SystemCoreClock > SYSCLK_FREQ_96MHz_HSE)
@ -136,8 +126,6 @@ static void BSP_Flash_FastLock(void)
rt_hw_interrupt_enable(interrupt_value); rt_hw_interrupt_enable(interrupt_value);
} }
static rt_size_t Flash_Read(rt_uint32_t addr, rt_uint8_t *buf, rt_size_t len) static rt_size_t Flash_Read(rt_uint32_t addr, rt_uint8_t *buf, rt_size_t len)
{ {
rt_size_t read_len = 0; rt_size_t read_len = 0;
@ -366,7 +354,6 @@ void Flash_Erase_Records(TeRecord record)
LOG_D("Flash_Erase_Records(%d)", record); LOG_D("Flash_Erase_Records(%d)", record);
} }
/* /*
* @description: * @description:
* @param {TeRecord} record * @param {TeRecord} record
@ -394,7 +381,6 @@ static rt_uint16_t Flash_GetMaxIndex_Records(TeRecord record)
return index_max; return index_max;
} }
/** /**
* @description: * @description:
* @param {TeRecord} record * @param {TeRecord} record
@ -419,8 +405,6 @@ rt_uint8_t Flash_GetNum_Records(TeRecord record)
return num; return num;
} }
/** /**
* @description: * @description:
* @param {TuFlashHrRecordFrame*} pHrRecord * @param {TuFlashHrRecordFrame*} pHrRecord
@ -568,7 +552,6 @@ void Flash_Write_Record(TeRecord record)
Flash_Write_RecordIndex(&HrRecord, record, index_new); Flash_Write_RecordIndex(&HrRecord, record, index_new);
} }
void Flash_ErasePage_ConfigInfo(void) void Flash_ErasePage_ConfigInfo(void)
{ {
BSP_Flash_FastUnLock(); BSP_Flash_FastUnLock();
@ -624,8 +607,6 @@ ErrorStatus Flash_GetProductTimeLimit(TuFlashProductTimeLimitFrame *pLimitTime,
return flag; return flag;
} }
void Flash_SetProductTimeLimit(rt_uint16_t year, rt_uint8_t mon, rt_uint8_t day, void Flash_SetProductTimeLimit(rt_uint16_t year, rt_uint8_t mon, rt_uint8_t day,
rt_uint8_t hour, rt_uint8_t min, rt_uint8_t second, rt_uint8_t hour, rt_uint8_t min, rt_uint8_t second,
TeFlashProductTimeLimitId id) TeFlashProductTimeLimitId id)
@ -675,13 +656,8 @@ void Set_ExpirationTime(rt_uint16_t days)
LimitTime.Struct.month, LimitTime.Struct.day, LimitTime.Struct.month, LimitTime.Struct.day,
LimitTime.Struct.hour, LimitTime.Struct.minute, LimitTime.Struct.hour, LimitTime.Struct.minute,
LimitTime.Struct.second); LimitTime.Struct.second);
LOG_D("FactoryTime:%04d-%02d-%02d,%02d:%02d", LimitTime.Struct.year,
LimitTime.Struct.month, LimitTime.Struct.day,
LimitTime.Struct.hour, LimitTime.Struct.minute,
LimitTime.Struct.second);
expiration_seconds = factory_seconds + days * 24 * 3600; expiration_seconds = factory_seconds + days * 24 * 3600;
// LOG_D("factory_seconds = %d, expiration_seconds = %d", factory_seconds, expiration_seconds);
TsRtcDateTime DateTime; TsRtcDateTime DateTime;
Seconds2DateTime(expiration_seconds, &DateTime); Seconds2DateTime(expiration_seconds, &DateTime);
@ -691,7 +667,7 @@ void Set_ExpirationTime(rt_uint16_t days)
if (Flash_GetProductTimeLimit(&LimitTime, kExpirationTimeId) == READY) if (Flash_GetProductTimeLimit(&LimitTime, kExpirationTimeId) == READY)
{ {
LOG_D("Flash_GetProductTimeLimit:%04d-%02d-%02d,%02d:%02d:%02d", LOG_D("到期时间:%04d-%02d-%02d,%02d:%02d:%02d",
LimitTime.Struct.year, LimitTime.Struct.month, LimitTime.Struct.year, LimitTime.Struct.month,
LimitTime.Struct.day, LimitTime.Struct.hour, LimitTime.Struct.day, LimitTime.Struct.hour,
LimitTime.Struct.minute, LimitTime.Struct.second); LimitTime.Struct.minute, LimitTime.Struct.second);
@ -699,7 +675,6 @@ void Set_ExpirationTime(rt_uint16_t days)
} }
} }
rt_uint8_t Flash_Sys_Cfg(TeFlashCfgInfoId id, rt_uint8_t *buf, rt_size_t len) rt_uint8_t Flash_Sys_Cfg(TeFlashCfgInfoId id, rt_uint8_t *buf, rt_size_t len)
{ {
rt_uint8_t page_buf[FLASH_PAGE_SIZE] = {0}; rt_uint8_t page_buf[FLASH_PAGE_SIZE] = {0};
@ -740,8 +715,6 @@ size_t Flash_Get_SysCfg(TeFlashCfgInfoId id)
} }
} }
ErrorStatus Flash_GetTotalRecord(TsTotalRecords *pTotalRecords) ErrorStatus Flash_GetTotalRecord(TsTotalRecords *pTotalRecords)
{ {
ErrorStatus flag = NoREADY; ErrorStatus flag = NoREADY;
@ -822,18 +795,18 @@ int BSP_Flash_Init(void)
Flash_Write(FLASH_INIT_FLAG_ADDR, flash_init_flag, Flash_Write(FLASH_INIT_FLAG_ADDR, flash_init_flag,
sizeof(flash_init_flag)); sizeof(flash_init_flag));
Flash_SetProductTimeLimit(2024, 9, 8, 13, 58, 20, kFactoryTimeId); Flash_SetProductTimeLimit(2025, 1, 10, 13, 50, 20, kFactoryTimeId);
Flash_SetProductTimeLimit(2024 + 8, 9, 8, 13, 58, 20, kExpirationTimeId); Set_ExpirationTime(MAX_EXPIRATION_DAYS);
sci.hw_ver = sys_hw_ver; sci.hw_ver = SYS_HW_VERSION;
sci.sw_ver = sys_sw_ver; sci.sw_ver = SYS_SW_VERSION;
sci.alarm_l_value = sys_alarm_l_value; sci.alarm_l_value = SYS_ALARM_VALVE;
sci.alarm_h_value = sys_alarm_h_value; sci.alarm_h_value = SYS_ALARM_VALVE_MAX;
sci.iot_upload_cycle = sys_iot_upload_cycle; sci.iot_upload_cycle = SYS_IOT_UPLOAD_CYCLE_MIN;
sci.iot_retry = sys_iot_retry; sci.iot_retry = SYS_IOT_RETRY;
sci.temp_alarm_threshold = sys_temp_alarm_threshold; sci.temp_alarm_threshold = SYS_TEMP_ALARM_THRESHOLD;
sci.emagnetic_switch = sys_emagnetic_switch; sci.emagnetic_switch = SYS_EMV_SWITCH;
sci.relay_switch = sys_relay_switch; sci.relay_switch = SYS_RELAY_SWITCH;
Flash_Set_WorkDuration(0); Flash_Set_WorkDuration(0);
LOG_D("work_duration:%d", Flash_Get_WorkDuration()); LOG_D("work_duration:%d", Flash_Get_WorkDuration());
@ -851,7 +824,6 @@ int BSP_Flash_Init(void)
Flash_Write(FLASH_HW_VER_ADDR, (rt_uint8_t *)&sci, Flash_Write(FLASH_HW_VER_ADDR, (rt_uint8_t *)&sci,
(sizeof(sys_config_info) - 50)); (sizeof(sys_config_info) - 50));
} }
return 0; return 0;
} }
@ -859,7 +831,6 @@ int BSP_Flash_Init(void)
// INIT_BOARD_EXPORT(BSP_Flash_Init); // INIT_BOARD_EXPORT(BSP_Flash_Init);
#endif #endif
#ifdef TEST_ENABLE #ifdef TEST_ENABLE
static void TEST_Flash_GetMaxIndex_Records(int argc, char **argv) static void TEST_Flash_GetMaxIndex_Records(int argc, char **argv)
{ {
@ -877,7 +848,6 @@ static void TEST_Flash_GetMaxIndex_Records(int argc, char **argv)
MSH_CMD_EXPORT(TEST_Flash_GetMaxIndex_Records, MSH_CMD_EXPORT(TEST_Flash_GetMaxIndex_Records,
"TEST_Flash_GetMaxIndex_Records"); "TEST_Flash_GetMaxIndex_Records");
static void TEST_Flash_Erase_Records(int argc, char **argv) static void TEST_Flash_Erase_Records(int argc, char **argv)
{ {
if (argc == 2) if (argc == 2)

View File

@ -2,8 +2,8 @@
* @Author : stark1898y 1658608470@qq.com * @Author : stark1898y 1658608470@qq.com
* @Date : 2024-09-04 17:33:57 * @Date : 2024-09-04 17:33:57
* @LastEditors: mbw && 1600520629@qq.com * @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2024-12-26 11:14:51 * @LastEditTime: 2025-01-13 08:42:58
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-4G\bsp\src\bsp_hr.c * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\bsp_hr.c
* @Description : * @Description :
* *
* Copyright (c) 2024 by yzy, All Rights Reserved. * Copyright (c) 2024 by yzy, All Rights Reserved.
@ -40,11 +40,12 @@ static rt_sem_t uart5_rx_ok_sem;
static rt_sem_t uart5_rx_parity_err_sem; static rt_sem_t uart5_rx_parity_err_sem;
static rt_timer_t uart5_timer; static rt_timer_t uart5_timer;
uint8_t hr_rx_count = 0; // 接收缓冲区中,已经收到的数据包数量 uint8_t hr_rx_flag = 0; // 接收缓冲区中,已经收到的数据包数量
void uart5_timeout(void *parameter) void uart5_timeout(void *parameter)
{ {
rt_sem_release(uart5_rx_ok_sem); rt_sem_release(uart5_rx_ok_sem);
rt_timer_stop(uart5_timer); rt_timer_stop(uart5_timer);
hr_rx_flag = 0;
} }
void USARTx_SendByte(USART_TypeDef *pUSARTx, uint8_t data) void USARTx_SendByte(USART_TypeDef *pUSARTx, uint8_t data)
@ -429,94 +430,6 @@ send:
// return n; // return n;
// } // }
// 查找 [] 并判断字符串
// int Process_Factor_Cmd(const char *rx_buff, size_t length)
// {
// TuFlashProductTimeLimitFrame ReadLimitTime;
// char buf[512] = {0};
// char imei[16] = {0};
// char imsi[16] = {0};
// char iccid[21] = {0};
// // 工厂命令
// const char factory_cmd1[] = "[getParameter]"; // 工厂命令1
// const char factory_cmd2[] = "[getCH4]"; // 工厂命令2
// // 查找 []
// const char *start_bracket = memchr(rx_buff, '[', length);
// const char *end_bracket = memchr(start_bracket, ']', length - (start_bracket - rx_buff));
// if (start_bracket && end_bracket)
// {
// // 计算 [] 之间的字符串长度
// size_t cmd_length = end_bracket - start_bracket + 1;
// char cmd[cmd_length + 1];
// rt_strncpy(cmd, start_bracket, cmd_length);
// cmd[cmd_length] = '\0';
// if (rt_strcmp(cmd, factory_cmd1) == 0) // 比较接收到的字符串与 factory_cmd1
// {
// rt_uint8_t time_buf[8] = {0};
// if ((*(rt_uint8_t *)FLASH_FACTOR_TIME_NUM_ADDR != 0xE3)&&(*(rt_uint8_t *)FLASH_FACTOR_TIME_NUM_ADDR != 0x39))
// {
// for (rt_uint8_t i = 0; i < 6; i++)
// {
// time_buf[i] = *(rt_uint8_t *)( FLASH_FACTOR_TIME_NUM_ADDR + i);
// LOG_D("%02x", time_buf[i]);
// }
// rt_uint32_t cnt = (rt_uint32_t)((time_buf[2]<<16)| (time_buf[1] << 8)|time_buf[0]);
// LOG_D("time_buf[2] = %02x time_buf[1] = %02x time_buf[0] = %02x cnt = %04d", time_buf[2], time_buf[1], time_buf[0], cnt);
// Get_IotImei(imei, FLASH_NB_IMEI_LEN);
// Get_IotImsi(imsi, FLASH_NB_IMSI_LEN);
// Get_IotIccid(iccid, FLASH_NB_ICCID_LEN);
// rt_sprintf(buf,
// "\r\n[ID :YD4N02/%02d%02d%02d%04d]\r\n"
// "[IMEI:%s]\r\n"
// "[IMSI:%s]\r\n"
// "[CCID:%s]\r\nOK\r\n",
// time_buf[5], time_buf[4], time_buf[3], cnt, imei, imsi, iccid);
// BSP_Hr_Send_Data(buf, rt_strlen(buf));
// Flash_GetProductTimeLimit(&ReadLimitTime, kFactoryTimeId);
// if ((ReadLimitTime.Struct.year != 2000 + time_buf[5])&&
// (ReadLimitTime.Struct.month != time_buf[4])&&
// (ReadLimitTime.Struct.day != time_buf[3]))//只写入一次
// {
// RTC_GetTime();
// Flash_SetProductTimeLimit(2000 + time_buf[5], time_buf[4], time_buf[3], RtcDateTime.hour, RtcDateTime.minute, RtcDateTime.second, kFactoryTimeId);
// Flash_SetProductTimeLimit(2000 + time_buf[5] + 8, time_buf[4], time_buf[3], RtcDateTime.hour, RtcDateTime.minute, RtcDateTime.second, kExpirationTimeId);
// }
// }
// else
// {
// LOG_E("[%s] is not set\r\n", "factory time");
// BSP_Hr_Send_Data("factory time is not set\r\n", rt_strlen("factory time is not set\r\n"));
// }
// return RT_EOK;
// }
// else if (rt_strcmp(cmd, factory_cmd2) == 0) // 比较接收到的字符串与 factory_cmd2
// {
// rt_sprintf(buf,
// "\r\n[STATUS :0x%X]\r\n"
// "[VALUE :%.2f]\r\n"
// "[LIGHT :%.2f]\r\n"
// "[PD :%.2f]\r\n"
// "[TEMPERTURE :%.2f]\r\n"
// "[TEC-TEMPERTURE:%.2f]\r\n"
// "[WORKTIME :%d]\r\nOK\r\n",
// H308.Data.fault_code, H308.Data.lel, H308.Data.signal_strength, H308.Data.gain, H308.Data.temp, (H308.Data.laser_temp / 10), work_duration);
// LOG_D("buf:%s", buf);
// BSP_Hr_Send_Data(buf, rt_strlen(buf));
// return RT_EOK;
// }
// }
// return RT_ERROR;
// }
int Process_Factor_Cmd(rt_uint8_t cmd) int Process_Factor_Cmd(rt_uint8_t cmd)
{ {
TuFlashProductTimeLimitFrame ReadLimitTime; TuFlashProductTimeLimitFrame ReadLimitTime;
@ -604,24 +517,14 @@ static void hr_thread_entry(void *param)
uint8_t len = lwrb_get_full(&uart5_rx_rb); uint8_t len = lwrb_get_full(&uart5_rx_rb);
lwrb_read(&uart5_rx_rb, rx_buff, len); lwrb_read(&uart5_rx_rb, rx_buff, len);
LOG_HEX("hr_rx_data:", 16, &rx_buff[0], len); LOG_HEX("hr_rx_data:", 16, &rx_buff[0], len);
// if (SysControl.status <= kPreheatingEvent)//等待预热完成和激光器自检
// {
// char buf[128] = "[CH4-Module power-on self-check,please wait]";
// BSP_Hr_Send_Data(buf, rt_strlen(buf));
// }
// else
// {
if (rt_strstr(rx_buff, "[getParameter]" ) != RT_NULL) if (rt_strstr(rx_buff, "[getParameter]" ) != RT_NULL)
{ {
Process_Factor_Cmd(1); Process_Factor_Cmd(1);
lwrb_reset(&uart5_rx_rb);
} }
else if (rt_strstr(rx_buff, "[getCH4]") != RT_NULL) else if (rt_strstr(rx_buff, "[getCH4]") != RT_NULL)
{ {
Process_Factor_Cmd(2); Process_Factor_Cmd(2);
lwrb_reset(&uart5_rx_rb);
EMV_CLOSE_VALVE; EMV_CLOSE_VALVE;
} }
else else
@ -635,12 +538,11 @@ static void hr_thread_entry(void *param)
HR_ProcessData(HostFrameData); HR_ProcessData(HostFrameData);
} }
rt_free(HostFrameData); rt_free(HostFrameData);
HostFrameData = RT_NULL; HostFrameData = RT_NULL;
} }
} }
lwrb_reset(&uart5_rx_rb);
// }
rt_memset(rx_buff, 0, len); rt_memset(rx_buff, 0, len);
} }
} }
@ -667,7 +569,7 @@ void UART5_Init(void)
GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = HR_BAUDRATE; USART_InitStructure.USART_BaudRate = HR_BAUDRATE;
@ -680,11 +582,10 @@ void UART5_Init(void)
USART_Init(UART5, &USART_InitStructure); USART_Init(UART5, &USART_InitStructure);
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE); USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
USART_ITConfig(UART5, USART_IT_PE, ENABLE);
USART_ITConfig(UART5, USART_IT_TXE, DISABLE); USART_ITConfig(UART5, USART_IT_TXE, DISABLE);
NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn; NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure); NVIC_Init(&NVIC_InitStructure);
@ -697,12 +598,12 @@ int BSP_HR_Init(void)
{ {
UART5_Init(); UART5_Init();
uart5_rx_ok_sem = rt_sem_create("uart5_rx", 0, RT_IPC_FLAG_FIFO); uart5_rx_ok_sem = rt_sem_create("uart5_rx", 0, RT_IPC_FLAG_PRIO);
if (uart5_rx_ok_sem == RT_NULL) if (uart5_rx_ok_sem == RT_NULL)
{ {
LOG_E("uart5_rx_ok_sem create failed"); LOG_E("uart5_rx_ok_sem create failed");
} }
uart5_rx_parity_err_sem = rt_sem_create("uart5_rx_pe", 0, RT_IPC_FLAG_FIFO); uart5_rx_parity_err_sem = rt_sem_create("uart5_rx_pe", 0, RT_IPC_FLAG_PRIO);
if (uart5_rx_parity_err_sem == RT_NULL) if (uart5_rx_parity_err_sem == RT_NULL)
{ {
LOG_E("uart5_rx_parity_err_sem create failed"); LOG_E("uart5_rx_parity_err_sem create failed");
@ -748,9 +649,14 @@ void UART5_IRQHandler(void)
} }
if (USART_GetITStatus(UART5, USART_IT_RXNE) != RESET) if (USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)
{ {
data = USART_ReceiveData(UART5); data = USART_ReceiveData(UART5);
lwrb_write(&uart5_rx_rb, &data, 1); lwrb_write(&uart5_rx_rb, &data, 1);
if (hr_rx_flag == 0)
{
rt_timer_start(uart5_timer); rt_timer_start(uart5_timer);
hr_rx_flag = 1;
}
} }
if (USART_GetITStatus(UART5, USART_IT_TXE) != RESET) if (USART_GetITStatus(UART5, USART_IT_TXE) != RESET)
{ {

View File

@ -2,7 +2,7 @@
* @Author: mbw * @Author: mbw
* @Date: 2024-10-09 08:42:14 * @Date: 2024-10-09 08:42:14
* @LastEditors: mbw && 1600520629@qq.com * @LastEditors: mbw && 1600520629@qq.com
* @LastEditTime: 2025-01-10 09:03:13 * @LastEditTime: 2025-01-10 13:09:30
* @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\bsp_nt26k.c * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\bsp_nt26k.c
* @Description: * @Description:
* *
@ -785,11 +785,11 @@ int Nt26k_Process_Events (Nt26kEvent nt26k_recv_event, struct at_device *device,
{ {
if (nt26k_conncet_tcp_flag) if (nt26k_conncet_tcp_flag)
{ {
// 如果事件有关联的发送函数,则调用该发送函数
rt_thread_mdelay (IMEI_Delay());
if (event->send_func) if (event->send_func)
{ {
RTC_ShowTime(); // 每次发送打印下时间,容易定位问题 RTC_ShowTime(); // 每次发送打印下时间,容易定位问题
// 如果事件有关联的发送函数,则调用该发送函数
rt_thread_mdelay (IMEI_Delay());
int result = event->send_func (device, nt26k_ops); int result = event->send_func (device, nt26k_ops);
if (result != RT_EOK) if (result != RT_EOK)
{ {
@ -806,7 +806,10 @@ int Nt26k_Process_Events (Nt26kEvent nt26k_recv_event, struct at_device *device,
} }
else else
{ {
LOG_E ("nt26k send cmd failed\n"); LOG_E ("nt26k send cmd failed\n");//收不到说明断网了重连下10s后再发送
nt26k_conncet_tcp_flag = 0;
rt_sem_release (nt26k_disconnect_sem);
rt_thread_mdelay (5000);
continue; continue;
} }
} }