Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
|
05eeda22ae | |
|
f5f2abbf8f | |
|
2f81e27eb0 | |
|
fbe63f0ef8 |
|
@ -23,8 +23,7 @@
|
|||
#define __MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
|
@ -37,10 +36,10 @@ extern "C"
|
|||
#include "tcpserverc.h"
|
||||
#include "leds.h"
|
||||
#include <string.h>
|
||||
/* USER CODE END Includes */
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
extern uint8_t tcp_echo_flags_hart1;
|
||||
extern uint8_t tcp_echo_flags_hart2;
|
||||
extern uint8_t tcp_echo_flags_ble1;
|
||||
|
@ -79,20 +78,20 @@ extern "C"
|
|||
|
||||
#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 */
|
||||
#define ENCODE_TIM8 1
|
||||
|
@ -196,7 +195,7 @@ extern "C"
|
|||
/* USER CODE BEGIN Private defines */
|
||||
#define TRUE 0
|
||||
#define FAIL -1
|
||||
/* USER CODE END Private defines */
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -64,7 +64,6 @@ osThreadId dac_taskHandle;
|
|||
osThreadId adc_taskHandle;
|
||||
osThreadId gpio_di_do_taskHandle;
|
||||
osThreadId ec11_taskHandle;
|
||||
osThreadId uart_forwardingHandle;
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN FunctionPrototypes */
|
||||
|
@ -159,10 +158,6 @@ void MX_FREERTOS_Init(void)
|
|||
osThreadDef(ec11_task, start_ec11_task, osPriorityNormal, 0, 512);
|
||||
ec11_taskHandle = osThreadCreate(osThread(ec11_task), NULL);
|
||||
|
||||
/* definition and creation of uart_forwarding */
|
||||
osThreadDef(uart_forwarding, start_uart_forwarding, osPriorityRealtime, 0, 512);
|
||||
uart_forwardingHandle = osThreadCreate(osThread(uart_forwarding), NULL);
|
||||
|
||||
/* USER CODE BEGIN RTOS_THREADS */
|
||||
/* add threads, ... */
|
||||
/* USER CODE END RTOS_THREADS */
|
||||
|
@ -186,54 +181,53 @@ void start_tcp_task(void const *argument)
|
|||
for (;;)
|
||||
{
|
||||
uint32_t phyreg = 0;
|
||||
HAL_ETH_ReadPHYRegister(&heth, 0x00, PHY_BSR, &phyreg);
|
||||
if (((phyreg >> 2) & 0x1) != 0x1)
|
||||
{
|
||||
/* When the netif link is down this function must be called */
|
||||
|
||||
netif_set_link_down(&gnetif);
|
||||
netif_set_down(&gnetif); // 热插拔下线时调用
|
||||
if (tcp_echo_flags_hart1 == 1)
|
||||
if (tcp_echo_flags_hart1 == 1 || tcp_echo_flags_hart2 == 1 || tcp_echo_flags_ble1 == 1 ||
|
||||
tcp_echo_flags_ble2 == 1 || tcp_echo_flags_control == 1)
|
||||
{
|
||||
HAL_ETH_ReadPHYRegister(&heth, 0x00, PHY_BSR, &phyreg);
|
||||
if (((phyreg >> 2) & 0x1) != 0x1)
|
||||
{
|
||||
tcp_abort(server_pcb_hart1); // 热插拔下线时调用
|
||||
tcp_echo_flags_hart1 = 0;
|
||||
}
|
||||
if (tcp_echo_flags_hart2 == 1)
|
||||
{
|
||||
tcp_abort(server_pcb_hart2); // 热插拔下线时调用
|
||||
tcp_echo_flags_hart2 = 0;
|
||||
}
|
||||
/* When the netif link is down this function must be called */
|
||||
|
||||
netif_set_link_down(&gnetif);
|
||||
netif_set_down(&gnetif); // 热插拔下线时调用
|
||||
if (tcp_echo_flags_hart1 == 1)
|
||||
{
|
||||
tcp_abort(server_pcb_hart1); // 热插拔下线时调用
|
||||
tcp_echo_flags_hart1 = 0;
|
||||
}
|
||||
if (tcp_echo_flags_hart2 == 1)
|
||||
{
|
||||
tcp_abort(server_pcb_hart2); // 热插拔下线时调用
|
||||
tcp_echo_flags_hart2 = 0;
|
||||
}
|
||||
#if (BLE2_USART6 == 1)
|
||||
|
||||
if (tcp_echo_flags_ble1 == 1)
|
||||
{
|
||||
tcp_abort(server_pcb_ble1); // 热插拔下线时调用
|
||||
tcp_echo_flags_ble1 = 0;
|
||||
}
|
||||
if (tcp_echo_flags_ble1 == 1)
|
||||
{
|
||||
tcp_abort(server_pcb_ble1); // 热插拔下线时调用
|
||||
tcp_echo_flags_ble1 = 0;
|
||||
}
|
||||
#endif
|
||||
if (tcp_echo_flags_ble2 == 1)
|
||||
{
|
||||
tcp_abort(server_pcb_ble2); // 热插拔下线时调用
|
||||
tcp_echo_flags_ble2 = 0;
|
||||
if (tcp_echo_flags_ble2 == 1)
|
||||
{
|
||||
tcp_abort(server_pcb_ble2); // 热插拔下线时调用
|
||||
tcp_echo_flags_ble2 = 0;
|
||||
}
|
||||
if (tcp_echo_flags_control == 1)
|
||||
{
|
||||
tcp_abort(server_pcb_control); // 热插拔下线时调用
|
||||
tcp_echo_flags_control = 0;
|
||||
}
|
||||
}
|
||||
if (tcp_echo_flags_control == 1)
|
||||
else
|
||||
{
|
||||
tcp_abort(server_pcb_control); // 热插拔下线时调用
|
||||
tcp_echo_flags_control = 0;
|
||||
/* When the netif is fully configured this function must be called */
|
||||
netif_set_link_up(&gnetif);
|
||||
netif_set_up(&gnetif); // 热插拔上线时调用
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* When the netif is fully configured this function must be called */
|
||||
netif_set_link_up(&gnetif);
|
||||
netif_set_up(&gnetif); // 热插拔上线时调用
|
||||
// if (tcp_echo_flags_ble1 == 2)
|
||||
// {
|
||||
// tcp_echo_init(); // 热插拔上线时调用
|
||||
// // uart_lcd_draw_ipaddr(); // 初始化显示IP地址信息
|
||||
// tcp_echo_flags_ble1 = 0;
|
||||
// }
|
||||
}
|
||||
|
||||
vTaskDelay(1000);
|
||||
// osThreadTerminate(NULL);
|
||||
|
@ -276,7 +270,7 @@ void start_dac_task(void const *argument)
|
|||
/* Infinite loop */
|
||||
for (;;)
|
||||
{
|
||||
osThreadSuspend(adc_taskHandle); // 暂停ADC任务,防止DAC采集时产生干<E7949F>????????,因为ADC和DAC采用的是同一路SPI,但是时序不<E5BA8F>????????
|
||||
osThreadSuspend(adc_taskHandle); // 暂停ADC任务,防止DAC采集时产生干<E7949F>?????????,因为ADC和DAC采用的是同一路SPI,但是时序不<E5BA8F>?????????
|
||||
dac161s997_output(DAC161S997_1, current_buff[0]);
|
||||
dac161s997_output(DAC161S997_2, current_buff[1]);
|
||||
osThreadResume(adc_taskHandle);
|
||||
|
@ -299,7 +293,7 @@ void start_adc_task(void const *argument)
|
|||
/* Infinite loop */
|
||||
for (;;)
|
||||
{
|
||||
osThreadSuspend(dac_taskHandle); // 暂停DAC任务,防止ADC采集时产生干<E7949F>????????,因为ADC和DAC采用的是同一路SPI,但是时序不<E5BA8F>????????
|
||||
osThreadSuspend(dac_taskHandle); // 暂停DAC任务,防止ADC采集时产生干<E7949F>?????????,因为ADC和DAC采用的是同一路SPI,但是时序不<E5BA8F>?????????
|
||||
uint8_t ch = 0;
|
||||
for (ch = STOP_NC_ADC; ch < AD7124_CHANNEL_EN_MAX; ch++)
|
||||
{
|
||||
|
|
|
@ -97,9 +97,9 @@ extern ip4_addr_t ipaddr;
|
|||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
@ -175,22 +175,22 @@ int main(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
|
||||
/** Configure the main internal regulator output voltage
|
||||
*/
|
||||
*/
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
|
@ -205,8 +205,9 @@ void SystemClock_Config(void)
|
|||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
|
||||
|
@ -363,20 +364,19 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
|||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief Period elapsed callback in non blocking mode
|
||||
* @note This function is called when TIM4 interrupt took place, inside
|
||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||
* a global variable "uwTick" used as application time base.
|
||||
* @param htim : TIM handle
|
||||
* @retval None
|
||||
*/
|
||||
* @brief Period elapsed callback in non blocking mode
|
||||
* @note This function is called when TIM4 interrupt took place, inside
|
||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||
* a global variable "uwTick" used as application time base.
|
||||
* @param htim : TIM handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
/* USER CODE BEGIN Callback 0 */
|
||||
|
||||
/* USER CODE END Callback 0 */
|
||||
if (htim->Instance == TIM4)
|
||||
{
|
||||
if (htim->Instance == TIM4) {
|
||||
HAL_IncTick();
|
||||
}
|
||||
/* USER CODE BEGIN Callback 1 */
|
||||
|
@ -385,9 +385,9 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
|
@ -399,14 +399,14 @@ void Error_Handler(void)
|
|||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
|
|
|
@ -148,24 +148,7 @@
|
|||
<Name>-U420014000D0000504A51544E -O2254 -SF1800 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8004 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC800 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407VGTx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name>
|
||||
</SetRegEntry>
|
||||
</TargetDriverDllRegistry>
|
||||
<Breakpoint>
|
||||
<Bp>
|
||||
<Number>0</Number>
|
||||
<Type>0</Type>
|
||||
<LineNumber>2413</LineNumber>
|
||||
<EnabledFlag>1</EnabledFlag>
|
||||
<Address>134234468</Address>
|
||||
<ByteObject>0</ByteObject>
|
||||
<HtxType>0</HtxType>
|
||||
<ManyObjects>0</ManyObjects>
|
||||
<SizeOfObject>0</SizeOfObject>
|
||||
<BreakByAccess>0</BreakByAccess>
|
||||
<BreakIfRCount>1</BreakIfRCount>
|
||||
<Filename>../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c</Filename>
|
||||
<ExecCommand></ExecCommand>
|
||||
<Expression>\\semi_finished_product_testing\../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c\2413</Expression>
|
||||
</Bp>
|
||||
</Breakpoint>
|
||||
<Breakpoint/>
|
||||
<WatchWindow1>
|
||||
<Ww>
|
||||
<count>0</count>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -45,9 +45,8 @@ static err_t tcpecho_recv_hart1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
|
|||
if (p != NULL)
|
||||
{
|
||||
/* 更新窗口*/
|
||||
tcp_echo_flags_hart1 = 1;
|
||||
|
||||
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
|
||||
server_pcb_hart1 = tpcb; // 直接赋值
|
||||
memcpy(hart1_uart5.tx_data, (int *)p->payload, p->tot_len);
|
||||
if (huart5.gState == HAL_UART_STATE_READY)
|
||||
{
|
||||
|
@ -58,7 +57,6 @@ static err_t tcpecho_recv_hart1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
|
|||
}
|
||||
else if (err == ERR_OK) // 检测到对方主动关闭连接时,也会调用recv函数,此时p为空
|
||||
{
|
||||
// HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
|
||||
tcp_echo_flags_hart1 = 0;
|
||||
return tcp_close(tpcb);
|
||||
}
|
||||
|
@ -70,9 +68,8 @@ static err_t tcpecho_recv_hart2(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
|
|||
if (p != NULL)
|
||||
{
|
||||
/* 更新窗口*/
|
||||
tcp_echo_flags_hart2 = 1;
|
||||
|
||||
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
|
||||
server_pcb_hart2 = tpcb; // 直接赋值
|
||||
memcpy(hart2_uart2.tx_data, (int *)p->payload, p->tot_len);
|
||||
if (huart2.gState == HAL_UART_STATE_READY)
|
||||
{
|
||||
|
@ -96,9 +93,8 @@ static err_t tcpecho_recv_ble1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
|
|||
if (p != NULL)
|
||||
{
|
||||
/* 更新窗口*/
|
||||
tcp_echo_flags_ble1 = 1;
|
||||
|
||||
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
|
||||
server_pcb_ble1 = tpcb; // 直接赋值
|
||||
|
||||
memcpy(ble1_uart6.tx_data, (int *)p->payload, p->tot_len);
|
||||
if (huart6.gState == HAL_UART_STATE_READY)
|
||||
|
@ -110,6 +106,7 @@ static err_t tcpecho_recv_ble1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
|
|||
}
|
||||
else if (err == ERR_OK) // 检测到对方主动关闭连接时,也会调用recv函数,此时p为空
|
||||
{
|
||||
tcp_echo_flags_ble1 = 0;
|
||||
return tcp_close(tpcb);
|
||||
}
|
||||
return ERR_OK;
|
||||
|
@ -121,9 +118,9 @@ static err_t tcpecho_recv_ble2(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
|
|||
if (p != NULL)
|
||||
{
|
||||
/* 更新窗口*/
|
||||
tcp_echo_flags_ble2 = 1;
|
||||
|
||||
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
|
||||
server_pcb_ble2 = tpcb; // 直接赋值
|
||||
|
||||
memcpy(ble2_uart3.tx_data, (int *)p->payload, p->tot_len);
|
||||
if (huart3.gState == HAL_UART_STATE_READY)
|
||||
{
|
||||
|
@ -133,7 +130,6 @@ static err_t tcpecho_recv_ble2(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
|
|||
}
|
||||
else if (err == ERR_OK) // 检测到对方主动关闭连接时,也会调用recv函数,此时p为空
|
||||
{
|
||||
// HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
|
||||
tcp_echo_flags_ble2 = 0;
|
||||
return tcp_close(tpcb);
|
||||
}
|
||||
|
@ -149,10 +145,10 @@ static err_t tcpecho_recv_control(void *arg, struct tcp_pcb *tpcb, struct pbuf *
|
|||
communication_data_u communication_data;
|
||||
if (p != NULL)
|
||||
{
|
||||
tcp_echo_flags_control = 1;
|
||||
|
||||
/* 更新窗口*/
|
||||
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
|
||||
server_pcb_control = tpcb; // 直接赋值
|
||||
|
||||
memcpy(tcp_rx_data, (int *)p->payload, p->tot_len);
|
||||
rx_data_len = p->tot_len;
|
||||
/*1. 对接收的数据做异或校验、帧头帧尾判断,校验失败返回信息,校验通过继续下一步、校验数据从帧头后面到校验位结束*/
|
||||
|
@ -234,7 +230,6 @@ static err_t tcpecho_recv_control(void *arg, struct tcp_pcb *tpcb, struct pbuf *
|
|||
}
|
||||
else if (err == ERR_OK) // 检测到对方主动关闭连接时,也会调用recv函数,此时p为空
|
||||
{
|
||||
// HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
|
||||
tcp_echo_flags_control = 0;
|
||||
return tcp_close(tpcb);
|
||||
}
|
||||
|
@ -243,35 +238,45 @@ static err_t tcpecho_recv_control(void *arg, struct tcp_pcb *tpcb, struct pbuf *
|
|||
}
|
||||
static err_t tcpecho_accept_hart1(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的,形参的数量和类型必须一致
|
||||
{
|
||||
tcp_recv(newpcb, tcpecho_recv_hart1); // 当收到数据时,回调用户自己写的tcpecho_recv
|
||||
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出,用于关闭蜂鸣器发声
|
||||
tcp_recv(newpcb, tcpecho_recv_hart1); // 当收到数据时,回调用户自己写的tcpecho_recv
|
||||
server_pcb_hart1 = newpcb; // 直接赋值
|
||||
tcp_echo_flags_hart1 = 1;
|
||||
// HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出,用于关闭蜂鸣器发声
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static err_t tcpecho_accept_hart2(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
|
||||
{
|
||||
tcp_recv(newpcb, tcpecho_recv_hart2); // 当收到数据时,回调用户自己写的tcpecho_recv
|
||||
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出,用于关闭蜂鸣器发声
|
||||
tcp_recv(newpcb, tcpecho_recv_hart2); // 当收到数据时,回调用户自己写的tcpecho_recv
|
||||
server_pcb_hart2 = newpcb; // 直接赋值
|
||||
tcp_echo_flags_hart2 = 1;
|
||||
// HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出,用于关闭蜂鸣器发声
|
||||
return ERR_OK;
|
||||
}
|
||||
#if (BLE2_USART6 == 1)
|
||||
static err_t tcpecho_accept_ble1(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
|
||||
{
|
||||
tcp_recv(newpcb, tcpecho_recv_ble1); // 当收到数据时,回调用户自己写的tcpecho_recv
|
||||
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出,用于关闭蜂鸣器发声
|
||||
tcp_recv(newpcb, tcpecho_recv_ble1); // 当收到数据时,回调用户自己写的tcpecho_recv
|
||||
server_pcb_ble1 = newpcb; // 直接赋值
|
||||
tcp_echo_flags_ble1 = 1;
|
||||
// HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出,用于关闭蜂鸣器发声
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif
|
||||
static err_t tcpecho_accept_ble2(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
|
||||
{
|
||||
tcp_recv(newpcb, tcpecho_recv_ble2); // 当收到数据时,回调用户自己写的tcpecho_recv
|
||||
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出,用于关闭蜂鸣器发声
|
||||
tcp_recv(newpcb, tcpecho_recv_ble2); // 当收到数据时,回调用户自己写的tcpecho_recv
|
||||
server_pcb_ble2 = newpcb; // 直接赋值
|
||||
tcp_echo_flags_ble2 = 1;
|
||||
// HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出,用于关闭蜂鸣器发声
|
||||
return ERR_OK;
|
||||
}
|
||||
static err_t tcpecho_accept_control(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的
|
||||
{
|
||||
tcp_recv(newpcb, tcpecho_recv_control); // 当收到数据时,回调用户自己写的tcpecho_recv
|
||||
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出,用于关闭蜂鸣器发声
|
||||
tcp_recv(newpcb, tcpecho_recv_control); // 当收到数据时,回调用户自己写的tcpecho_recv
|
||||
server_pcb_control = newpcb; // 直接赋值
|
||||
tcp_echo_flags_control = 1;
|
||||
// HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出,用于关闭蜂鸣器发声
|
||||
return ERR_OK;
|
||||
}
|
||||
void tcp_echo_init(void)
|
||||
|
@ -347,12 +352,10 @@ void tcp_echo_init(void)
|
|||
|
||||
void user_send_data_hart1(uint8_t *data, uint16_t len)
|
||||
{
|
||||
|
||||
tcp_write(server_pcb_hart1, data, len, 1);
|
||||
}
|
||||
void user_send_data_hart2(uint8_t *data, uint16_t len)
|
||||
{
|
||||
|
||||
tcp_write(server_pcb_hart2, data, len, 1);
|
||||
}
|
||||
#if (BLE2_USART6 == 1)
|
||||
|
@ -364,7 +367,6 @@ void user_send_data_ble1(uint8_t *data, uint16_t len)
|
|||
#endif
|
||||
void user_send_data_ble2(uint8_t *data, uint16_t len)
|
||||
{
|
||||
|
||||
tcp_write(server_pcb_ble2, data, len, 1);
|
||||
}
|
||||
|
||||
|
@ -373,6 +375,16 @@ void user_send_data_control(uint8_t *data, uint16_t len)
|
|||
tcp_write(server_pcb_control, data, len, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief UART 数据转发到 TCP 服务
|
||||
*
|
||||
* 该函数用于将从 UART 接口接收到的数据转发到 TCP 服务。
|
||||
*
|
||||
* 如果 uart_echo_flags_hart1 标志位为 1,则将该标志位清零,并通过 user_send_data_hart1 函数将 hart1_uart5 接收到的数据发送到 TCP 服务。
|
||||
* 如果 uart_echo_flags_hart2 标志位为 1,则将该标志位清零,并通过 user_send_data_hart2 函数将 hart2_uart2 接收到的数据发送到 TCP 服务。
|
||||
* 如果定义了 BLE2_USART6 并且 uart_echo_flags_ble1 标志位为 1,则将该标志位清零,并通过 user_send_data_ble1 函数将 ble1_uart6 接收到的数据发送到 TCP 服务。
|
||||
* 如果 uart_echo_flags_ble2 标志位为 1,则将该标志位清零,并通过 user_send_data_ble2 函数将 ble2_uart3 接收到的数据发送到 TCP 服务。
|
||||
*/
|
||||
void uart_forwarding_tcp(void)
|
||||
{
|
||||
if (uart_echo_flags_hart1 == 1)
|
||||
|
|
|
@ -7,8 +7,8 @@ uint8_t di_state_now[DI_MAX] = {0};
|
|||
void user_write_gpio(communication_do_t *do_data)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint8_t start_addr = do_data->start_addr; // 写输出的起始地址
|
||||
uint8_t length = do_data->num; // 写输出的数量
|
||||
uint8_t start_addr = do_data->start_addr; // 写输出的起始地址
|
||||
uint8_t length = do_data->num; // 写输出的数量
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
if (do_data->data[i] == 0x01)
|
||||
|
@ -24,20 +24,20 @@ void user_write_gpio(communication_do_t *do_data)
|
|||
void user_read_gpio(communication_di_t *di_data, uint8_t *tx_data, const uint8_t *const rx_data)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint8_t start_addr = di_data->start_addr; // 读输入的起始地址
|
||||
uint8_t length = di_data->num; // 读输入的数量
|
||||
uint8_t tx_data_len = 7 + length; // 数据长度
|
||||
tx_data[0] = FRAME_HEAD; // 帧头
|
||||
tx_data[1] = COM_OK; // 状态
|
||||
tx_data[2] = rx_data[2]; // 设备号
|
||||
tx_data[3] = rx_data[3]; // 命令号
|
||||
tx_data[4] = length; // 数据长度
|
||||
uint8_t start_addr = di_data->start_addr; // 读输入的起始地址
|
||||
uint8_t length = di_data->num; // 读输入的数量
|
||||
uint8_t tx_data_len = 7 + length; // 数据长度
|
||||
tx_data[0] = FRAME_HEAD; // 帧头
|
||||
tx_data[1] = COM_OK; // 状态
|
||||
tx_data[2] = rx_data[2]; // 设备号
|
||||
tx_data[3] = rx_data[3]; // 命令号
|
||||
tx_data[4] = length; // 数据长度
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
tx_data[5 + i] = gpio_di_test(DI_1 + i + start_addr);
|
||||
}
|
||||
tx_data[5 + length] = xor_compute(tx_data + 1, tx_data_len - 3); // 异或校验
|
||||
tx_data[6 + length] = FRAME_TAIL; // 帧尾
|
||||
tx_data[5 + length] = xor_compute(tx_data + 1, tx_data_len - 3); // 异或校验
|
||||
tx_data[6 + length] = FRAME_TAIL; // 帧尾
|
||||
}
|
||||
|
||||
void user_gpio_trigger(void)
|
||||
|
@ -62,11 +62,11 @@ void user_gpio_trigger(void)
|
|||
}
|
||||
if ((send_data_flag_cmd != 0) && (1 == tcp_echo_flags_control))
|
||||
{
|
||||
tx_data[5 + DI_MAX] = xor_compute(tx_data + 1, tx_data_len - 3); // 寮傛垨鏍¢獙
|
||||
tx_data[6 + DI_MAX] = FRAME_TAIL; // 甯у熬
|
||||
tx_data[5 + DI_MAX] = xor_compute(tx_data + 1, tx_data_len - 3); // 寮傛垨鏍¢獙
|
||||
tx_data[6 + DI_MAX] = FRAME_TAIL; // 甯у熬
|
||||
user_send_data_control(tx_data, tx_data_len);
|
||||
send_data_flag_cmd++;
|
||||
if (send_data_flag_cmd > 3) // 杩炵画涓夋涓婁綅鏈烘病鏈夊洖搴旓紝鍒欏仠姝㈠彂閫佹暟鎹寘
|
||||
if (send_data_flag_cmd > 3) // 杩炵画涓夋?涓婁綅鏈烘病鏈夊洖搴旓紝鍒欏仠姝㈠彂閫佹暟鎹?寘
|
||||
{
|
||||
send_data_flag_cmd = 0;
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ ETH.IPParameters=MediaInterface
|
|||
ETH.MediaInterface=HAL_ETH_RMII_MODE
|
||||
FREERTOS.FootprintOK=true
|
||||
FREERTOS.IPParameters=Tasks01,configMAX_TASK_NAME_LEN,configENABLE_FPU,configMAX_PRIORITIES,FootprintOK
|
||||
FREERTOS.Tasks01=lwip_task,2,512,start_tcp_task,Default,NULL,Dynamic,NULL,NULL;led_task,-2,128,start_led_toggle_task,Default,NULL,Dynamic,NULL,NULL;dac_task,0,512,start_dac_task,Default,NULL,Dynamic,NULL,NULL;adc_task,-1,128,start_adc_task,Default,NULL,Dynamic,NULL,NULL;gpio_di_do_task,0,128,start_gpio_di_do_task,Default,NULL,Dynamic,NULL,NULL;ec11_task,0,512,start_ec11_task,Default,NULL,Dynamic,NULL,NULL;uart_forwarding,3,512,start_uart_forwarding,Default,NULL,Dynamic,NULL,NULL
|
||||
FREERTOS.Tasks01=lwip_task,2,512,start_tcp_task,Default,NULL,Dynamic,NULL,NULL;led_task,-2,128,start_led_toggle_task,Default,NULL,Dynamic,NULL,NULL;dac_task,0,512,start_dac_task,Default,NULL,Dynamic,NULL,NULL;adc_task,-1,128,start_adc_task,Default,NULL,Dynamic,NULL,NULL;gpio_di_do_task,0,128,start_gpio_di_do_task,Default,NULL,Dynamic,NULL,NULL;ec11_task,0,512,start_ec11_task,Default,NULL,Dynamic,NULL,NULL
|
||||
FREERTOS.configENABLE_FPU=1
|
||||
FREERTOS.configMAX_PRIORITIES=32
|
||||
FREERTOS.configMAX_TASK_NAME_LEN=24
|
||||
|
|
Loading…
Reference in New Issue