diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..fc65b84 --- /dev/null +++ b/.vscode/tasks.json @@ -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 + } + } + ] +} \ No newline at end of file diff --git a/applications/main.c b/applications/main.c index a9197ce..59d99c6 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-09 15:41:13 + * @LastEditTime: 2025-01-10 13:37:28 * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\applications\main.c * @Descrt_thread_ * @@ -93,7 +93,7 @@ void Send_Laser_Alarm_Event(AlarmEvent event_type) { if (SysControl.status == kPowerDownEvent) { - LOG_D("掉电模式下不处理其他事件"); + LOG_D("掉电模式下不处理其他事件"); } else { @@ -348,8 +348,8 @@ int main(void) else if (received_event & Get_Sys_Event_Flag(kFaultEvent)) // 故障 { LOG_D("故障模式"); - - if (Flash_GetNum_Records(kRecordSensoEndOfLife) != 1)//当设备失效时,只上报设备失效的故障,其他故障不上报 + + if (Flash_GetNum_Records(kRecordSensoEndOfLife) != 1) // 当设备失效时,只上报设备失效的故障,其他故障不上报 { SysControl.last_status = SysControl.status; SysControl.status = kFaultEvent; @@ -417,7 +417,7 @@ int main(void) LOG_D("自检模式"); SysControl.last_status = SysControl.status; - SysControl.status = kSelfCheckEvent; + SysControl.status = kSelfCheckEvent; _Self_Check_Mode(); diff --git a/applications/user_sys.c b/applications/user_sys.c index 3221f10..d94d00e 100644 --- a/applications/user_sys.c +++ b/applications/user_sys.c @@ -2,8 +2,8 @@ * @Author: mbw * @Date: 2024-10-10 15:50:39 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2024-12-31 17:48:21 - * @FilePath: \JT-DT-YD4N02A_RTT_MRS-4G\applications\user_sys.c + * @LastEditTime: 2025-01-10 11:43:48 + * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\applications\user_sys.c * @Description: * * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. @@ -29,6 +29,12 @@ #include "rtdef.h" #include "bsp_rng.h" #include "at_device_nt26k.h" +#include // 包含stdlib.h以使用rand()和srand() + +#define LOG_TAG "user_sys" +#define LOG_LVL LOG_LVL_DBG +#include + #define K 3 * 1000 @@ -227,22 +233,21 @@ int Convert_To_Hex(const struct flash_sever_info *sever_info, uint8_t *hex_array return RT_EOK; } -//利用IMEI号进行错峰延时计算 +// 利用IMEI号进行错峰延时计算 rt_uint32_t IMEI_Delay(void) { char imei_str[16]; - char randon_char[8] = {0}; - rt_uint32_t imei_delay = 0; - unsigned int random_number = 0; + char randon_char[6] = {0}; // 调整数组大小为6 + rt_uint32_t random_number = 0; Get_IotImei(imei_str, FLASH_NB_IMEI_LEN); // 提取 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); - imei_delay = (random_number + Get_RandomNumber()) % (K); - // rt_kprintf("IMEI_Delay:%d\r\n", imei_delay); - return (rt_uint32_t)imei_delay; - + // 生成随机数 + rt_uint32_t imei_delay = (random_number + Get_RandomNumber()) % K; + LOG_I("imei_delay: %d", imei_delay); + return imei_delay; } diff --git a/applications/user_sys.h b/applications/user_sys.h index 5a84b57..3c1b039 100644 --- a/applications/user_sys.h +++ b/applications/user_sys.h @@ -15,15 +15,23 @@ #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 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 +#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") + + typedef enum { kPowerOnEvent, kPreheatingEvent, diff --git a/bsp/src/at_device_nt26k.c b/bsp/src/at_device_nt26k.c index 0e10324..b844352 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-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 * @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; } @@ -464,7 +464,7 @@ __exit: */ 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 diff --git a/bsp/src/bsp_flash.c b/bsp/src/bsp_flash.c index cee68fd..c3f3cc3 100644 --- a/bsp/src/bsp_flash.c +++ b/bsp/src/bsp_flash.c @@ -19,13 +19,13 @@ : (id) == kAlarmLValueId ? (&(info)->alarm_l_value) \ : (id) == kAlarmHValueId ? (&(info)->alarm_h_value) \ : (id) == kTempAlarmThresholdId ? (&(info)->temp_alarm_threshold) \ - : (id) == kIotUploadCycleId ? (&(info)->iot_upload_cycle) \ - : (id) == kIotRetryId ? (&(info)->iot_retry) \ + : (id) == kIotUploadCycleId ? (&(info)->iot_upload_cycle) \ + : (id) == kIotRetryId ? (&(info)->iot_retry) \ : (id) == kEmagneticSwitchId ? (&(info)->emagnetic_switch) \ : (id) == kRelaySwitchId ? (&(info)->relay_switch) \ - : (id) == kIotImeiId ? ((info)->iot_imei) \ - : (id) == kIotImsiId ? ((info)->iot_imsi) \ - : (id) == kIotIccidId ? ((info)->iot_iccid) \ + : (id) == kIotImeiId ? ((info)->iot_imei) \ + : (id) == kIotImsiId ? ((info)->iot_imsi) \ + : (id) == kIotIccidId ? ((info)->iot_iccid) \ : NULL) TsTotalRecords TotalRecords; @@ -80,22 +80,12 @@ const rt_uint32_t hr_sys_cfg_info_len[kCnt] = { 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 = -{ - .server_url = SYS_IOT_URL, - .server_port = SYS_IOT_PORT, +struct flash_sever_info sever_info = + { + .server_url = SYS_IOT_URL, + .server_port = SYS_IOT_PORT, }; - static void BSP_Flash_UnLock(void) { #if (SystemCoreClock > SYSCLK_FREQ_96MHz_HSE) @@ -136,8 +126,6 @@ static void BSP_Flash_FastLock(void) rt_hw_interrupt_enable(interrupt_value); } - - static rt_size_t Flash_Read(rt_uint32_t addr, rt_uint8_t *buf, rt_size_t len) { rt_size_t read_len = 0; @@ -152,7 +140,7 @@ static rt_size_t Flash_Read(rt_uint32_t addr, rt_uint8_t *buf, rt_size_t len) int Get_IotImei(char *buf, rt_size_t len) { - if ((*(rt_uint8_t *)FLASH_NB_IMEI_ADDR != 0xE3)&&(*(rt_uint8_t *)FLASH_NB_IMEI_ADDR != 0x39)) + if ((*(rt_uint8_t *)FLASH_NB_IMEI_ADDR != 0xE3) && (*(rt_uint8_t *)FLASH_NB_IMEI_ADDR != 0x39)) { rt_memcpy(buf, (char *)FLASH_NB_IMEI_ADDR, len); @@ -173,7 +161,7 @@ int Get_IotImei(char *buf, rt_size_t len) int Get_IotImsi(char *buf, rt_size_t len) { - if ((*(rt_uint8_t *)FLASH_NB_IMSI_ADDR != 0xE3)&&(*(rt_uint8_t *)FLASH_NB_IMSI_ADDR != 0x39)) + if ((*(rt_uint8_t *)FLASH_NB_IMSI_ADDR != 0xE3) && (*(rt_uint8_t *)FLASH_NB_IMSI_ADDR != 0x39)) { rt_memcpy(buf, (char *)FLASH_NB_IMSI_ADDR, len); @@ -194,7 +182,7 @@ int Get_IotImsi(char *buf, rt_size_t len) int Get_IotIccid(char *buf, rt_size_t len) { - if ((*(rt_uint8_t *)FLASH_NB_ICCID_ADDR != 0xE3)&&(*(rt_uint8_t *)FLASH_NB_ICCID_ADDR != 0x39)) + if ((*(rt_uint8_t *)FLASH_NB_ICCID_ADDR != 0xE3) && (*(rt_uint8_t *)FLASH_NB_ICCID_ADDR != 0x39)) { rt_memcpy(buf, (char *)FLASH_NB_ICCID_ADDR, len); @@ -287,8 +275,8 @@ int Flash_Get_Sever_Data(struct flash_sever_info *sever_info) rt_memcpy(data, (rt_uint8_t *)FLASH_SERVER_ADDR_ADDR, FLASH_SERVER_LEN); LOG_D("data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x data[%d] = %x", 0, data[0], 1, data[1], 2, data[2], 3, data[3], 4, data[4], 5, data[5]); rt_snprintf(sever_info->server_url, sizeof(sever_info->server_url), "%d.%d.%d.%d", - data[3], data[2], data[1], data[0]); - + data[3], data[2], data[1], data[0]); + rt_uint16_t port_num = ((data[5] << 8) | data[4]); LOG_D("port_num = %d", port_num); rt_snprintf(sever_info->server_port, sizeof(sever_info->server_port), "%d", port_num); @@ -306,14 +294,14 @@ int Flash_Set_Sever_Data(rt_uint8_t *data) { return -RT_ERROR; } - + Flash_ErasePage_ReadConfigInfo(page_buf); - //*将传入的数据写到flash地址中 + //*将传入的数据写到flash地址中 for (size_t i = 0; i < FLASH_SERVER_LEN; i++) { page_buf[in_page_offset++] = data[i]; } - + return Flash_Write_ConfigInfo(page_buf); } @@ -366,7 +354,6 @@ void Flash_Erase_Records(TeRecord record) LOG_D("Flash_Erase_Records(%d)", record); } - /* * @description: * @param {TeRecord} record @@ -394,7 +381,6 @@ static rt_uint16_t Flash_GetMaxIndex_Records(TeRecord record) return index_max; } - /** * @description: * @param {TeRecord} record @@ -419,8 +405,6 @@ rt_uint8_t Flash_GetNum_Records(TeRecord record) return num; } - - /** * @description: * @param {TuFlashHrRecordFrame*} pHrRecord @@ -568,7 +552,6 @@ void Flash_Write_Record(TeRecord record) Flash_Write_RecordIndex(&HrRecord, record, index_new); } - void Flash_ErasePage_ConfigInfo(void) { BSP_Flash_FastUnLock(); @@ -624,8 +607,6 @@ ErrorStatus Flash_GetProductTimeLimit(TuFlashProductTimeLimitFrame *pLimitTime, return flag; } - - 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, TeFlashProductTimeLimitId id) @@ -675,13 +656,8 @@ void Set_ExpirationTime(rt_uint16_t days) LimitTime.Struct.month, LimitTime.Struct.day, LimitTime.Struct.hour, LimitTime.Struct.minute, 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; - // LOG_D("factory_seconds = %d, expiration_seconds = %d", factory_seconds, expiration_seconds); TsRtcDateTime DateTime; Seconds2DateTime(expiration_seconds, &DateTime); @@ -691,7 +667,7 @@ void Set_ExpirationTime(rt_uint16_t days) 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.day, LimitTime.Struct.hour, 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 page_buf[FLASH_PAGE_SIZE] = {0}; @@ -734,14 +709,12 @@ size_t Flash_Get_SysCfg(TeFlashCfgInfoId id) else { rt_memcpy(&iot_upload_cycle[0], (rt_uint8_t *)hr_sys_cfg_info_addr[id], 2); - iot_upload = ((iot_upload_cycle[0]<<8) + iot_upload_cycle[1]); + iot_upload = ((iot_upload_cycle[0] << 8) + iot_upload_cycle[1]); LOG_D("iot_upload: %d", iot_upload); return iot_upload; } } - - ErrorStatus Flash_GetTotalRecord(TsTotalRecords *pTotalRecords) { ErrorStatus flag = NoREADY; @@ -812,7 +785,7 @@ int BSP_Flash_Init(void) LOG_D("BSP_Flash_EraseRecodrs!"); rt_uint8_t flash_init_flag[2]; sys_config_info sci; - rt_uint8_t sever_data[6] = {0}; + rt_uint8_t sever_data[6] = {0}; flash_init_flag[0] = FLASH_FIRST_INIT_VALUE % 256; flash_init_flag[1] = FLASH_FIRST_INIT_VALUE / 256; @@ -822,19 +795,19 @@ int BSP_Flash_Init(void) Flash_Write(FLASH_INIT_FLAG_ADDR, flash_init_flag, sizeof(flash_init_flag)); - Flash_SetProductTimeLimit(2024, 9, 8, 13, 58, 20, kFactoryTimeId); - Flash_SetProductTimeLimit(2024 + 8, 9, 8, 13, 58, 20, kExpirationTimeId); + Flash_SetProductTimeLimit(2025, 1, 10, 13, 50, 20, kFactoryTimeId); + Set_ExpirationTime(MAX_EXPIRATION_DAYS); + + sci.hw_ver = SYS_HW_VERSION; + sci.sw_ver = SYS_SW_VERSION; + sci.alarm_l_value = SYS_ALARM_VALVE; + sci.alarm_h_value = SYS_ALARM_VALVE_MAX; + sci.iot_upload_cycle = SYS_IOT_UPLOAD_CYCLE_MIN; + sci.iot_retry = SYS_IOT_RETRY; + sci.temp_alarm_threshold = SYS_TEMP_ALARM_THRESHOLD; + sci.emagnetic_switch = SYS_EMV_SWITCH; + sci.relay_switch = SYS_RELAY_SWITCH; - sci.hw_ver = sys_hw_ver; - sci.sw_ver = sys_sw_ver; - sci.alarm_l_value = sys_alarm_l_value; - sci.alarm_h_value = sys_alarm_h_value; - sci.iot_upload_cycle = sys_iot_upload_cycle; - sci.iot_retry = sys_iot_retry; - sci.temp_alarm_threshold = sys_temp_alarm_threshold; - sci.emagnetic_switch = sys_emagnetic_switch; - sci.relay_switch = sys_relay_switch; - Flash_Set_WorkDuration(0); LOG_D("work_duration:%d", Flash_Get_WorkDuration()); @@ -843,15 +816,14 @@ int BSP_Flash_Init(void) { LOG_D("%02x", sever_data[i]); } - - if(Flash_Set_Sever_Data(sever_data) <= 0) + + if (Flash_Set_Sever_Data(sever_data) <= 0) { LOG_D("Flash_Set_Sever_Data error!"); } Flash_Write(FLASH_HW_VER_ADDR, (rt_uint8_t *)&sci, (sizeof(sys_config_info) - 50)); - } return 0; } @@ -859,7 +831,6 @@ int BSP_Flash_Init(void) // INIT_BOARD_EXPORT(BSP_Flash_Init); #endif - #ifdef TEST_ENABLE 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, "TEST_Flash_GetMaxIndex_Records"); - static void TEST_Flash_Erase_Records(int argc, char **argv) { if (argc == 2) diff --git a/bsp/src/bsp_hr.c b/bsp/src/bsp_hr.c index 7f1da34..ba5d4fb 100644 --- a/bsp/src/bsp_hr.c +++ b/bsp/src/bsp_hr.c @@ -2,8 +2,8 @@ * @Author : stark1898y 1658608470@qq.com * @Date : 2024-09-04 17:33:57 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2024-12-26 11:14:51 - * @FilePath: \JT-DT-YD4N02A_RTT_MRS-4G\bsp\src\bsp_hr.c + * @LastEditTime: 2025-01-13 08:42:58 + * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\bsp_hr.c * @Description : * * 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_timer_t uart5_timer; -uint8_t hr_rx_count = 0; // 接收缓冲区中,已经收到的数据包数量 +uint8_t hr_rx_flag = 0; // 接收缓冲区中,已经收到的数据包数量 void uart5_timeout(void *parameter) { rt_sem_release(uart5_rx_ok_sem); rt_timer_stop(uart5_timer); + hr_rx_flag = 0; } void USARTx_SendByte(USART_TypeDef *pUSARTx, uint8_t data) @@ -429,94 +430,6 @@ send: // 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) { TuFlashProductTimeLimitFrame ReadLimitTime; @@ -604,43 +517,32 @@ static void hr_thread_entry(void *param) uint8_t len = lwrb_get_full(&uart5_rx_rb); lwrb_read(&uart5_rx_rb, rx_buff, 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); + } + else if (rt_strstr(rx_buff, "[getCH4]") != RT_NULL) + { + Process_Factor_Cmd(2); + EMV_CLOSE_VALVE; + } + else + { + if (len >= HOST_FRAME_MIN_LEN) { - Process_Factor_Cmd(1); - lwrb_reset(&uart5_rx_rb); - } - else if (rt_strstr(rx_buff, "[getCH4]") != RT_NULL) - { - Process_Factor_Cmd(2); - lwrb_reset(&uart5_rx_rb); - EMV_CLOSE_VALVE; - } - else - { - if (len >= HOST_FRAME_MIN_LEN) + TsFrameData *HostFrameData = HR_GetFrameData(rx_buff, len); + if (HostFrameData != RT_NULL) { - TsFrameData *HostFrameData = HR_GetFrameData(rx_buff, len); - if (HostFrameData != RT_NULL) - { - LOG_HEX("HostFrameData", 16, &HostFrameData->data[0], HostFrameData->len); // 数据段 - HR_ProcessData(HostFrameData); - } - rt_free(HostFrameData); - HostFrameData = RT_NULL; + LOG_HEX("HostFrameData", 16, &HostFrameData->data[0], HostFrameData->len); // 数据段 + HR_ProcessData(HostFrameData); } - } + rt_free(HostFrameData); - // } - + HostFrameData = RT_NULL; + } + } + lwrb_reset(&uart5_rx_rb); rt_memset(rx_buff, 0, len); } } @@ -667,7 +569,7 @@ void UART5_Init(void) GPIO_Init(GPIOB, &GPIO_InitStructure); 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); USART_InitStructure.USART_BaudRate = HR_BAUDRATE; @@ -680,11 +582,10 @@ void UART5_Init(void) USART_Init(UART5, &USART_InitStructure); USART_ITConfig(UART5, USART_IT_RXNE, ENABLE); - USART_ITConfig(UART5, USART_IT_PE, ENABLE); USART_ITConfig(UART5, USART_IT_TXE, DISABLE); NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); @@ -697,12 +598,12 @@ int BSP_HR_Init(void) { 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) { 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) { 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) { + data = USART_ReceiveData(UART5); lwrb_write(&uart5_rx_rb, &data, 1); - rt_timer_start(uart5_timer); + if (hr_rx_flag == 0) + { + rt_timer_start(uart5_timer); + hr_rx_flag = 1; + } } if (USART_GetITStatus(UART5, USART_IT_TXE) != RESET) { diff --git a/bsp/src/bsp_nt26k.c b/bsp/src/bsp_nt26k.c index b6b58c3..4a48daf 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-10 09:03:13 + * @LastEditTime: 2025-01-10 13:09:30 * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\bsp_nt26k.c * @Description: * @@ -785,11 +785,11 @@ int Nt26k_Process_Events (Nt26kEvent nt26k_recv_event, struct at_device *device, { if (nt26k_conncet_tcp_flag) { - // 如果事件有关联的发送函数,则调用该发送函数 - rt_thread_mdelay (IMEI_Delay()); if (event->send_func) { RTC_ShowTime(); // 每次发送打印下时间,容易定位问题 + // 如果事件有关联的发送函数,则调用该发送函数 + rt_thread_mdelay (IMEI_Delay()); int result = event->send_func (device, nt26k_ops); if (result != RT_EOK) { @@ -806,7 +806,10 @@ int Nt26k_Process_Events (Nt26kEvent nt26k_recv_event, struct at_device *device, } 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; } }