备份,通过读取uart的接受标志位来判定通讯断开,恢复通讯

This commit is contained in:
王绪洁 2025-02-11 15:52:55 +08:00
parent 9e44135a34
commit a54ae53b95
6 changed files with 58 additions and 27 deletions

View File

@ -23,7 +23,8 @@
#define __MAIN_H
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
/* Includes ------------------------------------------------------------------*/
@ -40,17 +41,17 @@ extern "C" {
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
extern uint8_t tcp_echo_flags_hart1; // 标志ä½<C3A4>,连接æˆ<C3A6>功ç½?1
extern uint8_t tcp_echo_flags_hart2; // 标志ä½<C3A4>,连接æˆ<C3A6>功ç½?1
extern uint8_t tcp_echo_flags_hart1;
extern uint8_t tcp_echo_flags_hart2;
extern uint8_t tcp_echo_flags_ble1;
extern uint8_t tcp_echo_flags_ble2;
#define ARRAY_LEN(arr) (sizeof(arr)) / (sizeof(arr[0]))
typedef struct
{
uint16_t rx_num; // 接收到数æ<C2B0>®ä¸ªæ•?
uint8_t rx_data[512]; // 接收到数æ<C2B0>®åŒº
uint8_t rx_data_temp[512]; // 接收到数æ<C2B0>®ç¼“冲区
uint8_t tx_data[512]; // å<>é?<3F>æ•°æ<C2B0>®åŒº
uint16_t rx_num;
uint8_t rx_data[512];
uint8_t rx_data_temp[512];
uint8_t tx_data[512];
} uart_t;
extern uart_t lcd_uart4;
@ -70,20 +71,20 @@ extern uart_t hart2_uart2;
#define LOCAL_PORT 5001
/* USER CODE END ET */
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */
/* USER CODE END EC */
/* USER CODE END EC */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */
/* USER CODE END EM */
/* USER CODE END EM */
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);
/* USER CODE BEGIN EFP */
@ -170,7 +171,7 @@ void Error_Handler(void);
/* USER CODE BEGIN Private defines */
#define TRUE 0
#define FAIL -1
/* USER CODE END Private defines */
/* USER CODE END Private defines */
#ifdef __cplusplus
}

View File

@ -27,6 +27,7 @@
/* USER CODE BEGIN Includes */
#include "dac161s997.h"
#include "ad7124.h"
#include "usart.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@ -36,7 +37,7 @@
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
// extern UART_HandleTypeDef huart5;
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
@ -147,8 +148,20 @@ void start_tcp_task(void const *argument)
/* Infinite loop */
for (;;)
{
osThreadTerminate(NULL);
osDelay(1);
// osThreadTerminate(NULL);
// if (tcp_send_flags_hart1 == 1)
// {
// user_send_data_hart1(hart1_uart5.rx_data, hart1_uart5.rx_num);
// tcp_send_flags_hart1 = 0;
// }
// if (tcp_send_flags_hart2 == 1)
// {
// user_send_data_hart2(hart2_uart2.rx_data, hart2_uart2.rx_num);
// tcp_send_flags_hart2 = 0;
// }
vTaskDelay(1);
// osDelay(1);
}
/* USER CODE END start_tcp_task */
}
@ -167,7 +180,7 @@ void start_led_toggle_task(void const *argument)
for (;;)
{
HAL_GPIO_TogglePin(LED2_G_GPIO_Port, LED2_G_Pin);
vTaskDelay(1000);
vTaskDelay(500);
}
/* USER CODE END start_led_toggle_task */
}
@ -188,7 +201,7 @@ void start_dac_task(void const *argument)
{
dac161s997_output(DAC161S997_1, 12.0f);
dac161s997_output(DAC161S997_2, 12.0f);
vTaskDelay(200);
vTaskDelay(100);
}
/* USER CODE END start_dac_task */
}
@ -208,6 +221,14 @@ void start_adc_task(void const *argument)
for (;;)
{
ad7124_get_analog(STOP_NC_ADC);
if (huart5.RxState == HAL_UART_STATE_READY)
{
HAL_UARTEx_ReceiveToIdle_DMA(&huart5, hart1_uart5.rx_data_temp, ARRAY_LEN(hart1_uart5.rx_data_temp));
}
if (huart2.RxState == HAL_UART_STATE_READY)
{
HAL_UARTEx_ReceiveToIdle_DMA(&huart2, hart2_uart2.rx_data_temp, ARRAY_LEN(hart2_uart2.rx_data_temp));
}
vTaskDelay(1000);
}
/* USER CODE END start_adc_task */

View File

@ -71,10 +71,12 @@ uart_t ble2_uart3 = {0};
uart_t hart2_uart2 = {0};
uart_t hart1_uart5 = {0};
float current_buff[2] = {12.0f, 12.0f};
uint8_t tcp_echo_flags_hart1 = 0;
uint8_t tcp_echo_flags_hart2 = 0;
uint8_t tcp_echo_flags_ble1 = 0;
uint8_t tcp_echo_flags_ble2 = 0;
/* USER CODE END 0 */
/**
@ -223,6 +225,7 @@ void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
memcpy(hart1_uart5.rx_data, hart1_uart5.rx_data_temp, Size);
if (tcp_echo_flags_hart1 == 1)
{
// tcp_send_flags_hart1 = 1;
user_send_data_hart1(hart1_uart5.rx_data, Size);
}
HAL_UARTEx_ReceiveToIdle_DMA(&huart5, hart1_uart5.rx_data_temp, ARRAY_LEN(hart1_uart5.rx_data_temp));
@ -235,6 +238,7 @@ void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
memcpy(hart2_uart2.rx_data, hart2_uart2.rx_data_temp, Size);
if (tcp_echo_flags_hart2 == 1)
{
// tcp_send_flags_hart2 = 1;
user_send_data_hart2(hart2_uart2.rx_data, Size);
}
HAL_UARTEx_ReceiveToIdle_DMA(&huart2, hart2_uart2.rx_data_temp, ARRAY_LEN(hart2_uart2.rx_data_temp));
@ -283,10 +287,10 @@ void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
// __disable_irq();
// while (1)
// {
// }
/* USER CODE END Error_Handler_Debug */
}

View File

@ -21,7 +21,6 @@
#include "usart.h"
/* USER CODE BEGIN 0 */
#include "ht1200m.h"
/* USER CODE END 0 */
UART_HandleTypeDef huart4;

View File

@ -225,6 +225,11 @@
<WinNumber>1</WinNumber>
<ItemText>osThread(lwip_task)</ItemText>
</Ww>
<Ww>
<count>15</count>
<WinNumber>1</WinNumber>
<ItemText>hart1_uart5</ItemText>
</Ww>
</WatchWindow1>
<MemoryWindow1>
<Mm>

View File

@ -19,6 +19,7 @@ extern uint8_t tcp_echo_flags_hart1;
extern uint8_t tcp_echo_flags_hart2;
extern uint8_t tcp_echo_flags_ble1;
extern uint8_t tcp_echo_flags_ble2;
/*接收回调函数*/
static err_t tcpecho_recv_hart1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{ // 对应接收数据连接的控制块 接收到的数据