This commit is contained in:
王绪洁 2025-03-28 17:52:26 +08:00
parent 4c3843e20e
commit d1de706ea5
6 changed files with 3601 additions and 3567 deletions

View File

@ -165,12 +165,13 @@ void start_tcp_task(void const *argument)
MX_LWIP_Init(); MX_LWIP_Init();
/* USER CODE BEGIN start_tcp_task */ /* USER CODE BEGIN start_tcp_task */
tcp_echo_init(); tcp_echo_init();
uart_lcd_draw_ipaddr(); // 初始化显示IP地址信息
/* Infinite loop */ /* Infinite loop */
for (;;) for (;;)
{ {
uart_lcd_draw_ipaddr(); // 初始化显示IP地址信息
osThreadTerminate(NULL); vTaskDelay(1000);
// osThreadTerminate(NULL);
} }
/* USER CODE END start_tcp_task */ /* USER CODE END start_tcp_task */
} }

View File

@ -22,7 +22,7 @@
#include "lwip.h" #include "lwip.h"
#include "lwip/init.h" #include "lwip/init.h"
#include "lwip/netif.h" #include "lwip/netif.h"
#if defined ( __CC_ARM ) /* MDK ARM Compiler */ #if defined(__CC_ARM) /* MDK ARM Compiler */
#include "lwip/sio.h" #include "lwip/sio.h"
#endif /* MDK ARM Compiler */ #endif /* MDK ARM Compiler */
#include "ethernetif.h" #include "ethernetif.h"
@ -71,15 +71,15 @@ void MX_LWIP_Init(void)
GATEWAY_ADDRESS[2] = 1; GATEWAY_ADDRESS[2] = 1;
GATEWAY_ADDRESS[3] = 29; GATEWAY_ADDRESS[3] = 29;
/* USER CODE BEGIN IP_ADDRESSES */ /* USER CODE BEGIN IP_ADDRESSES */
/* USER CODE END IP_ADDRESSES */ /* USER CODE END IP_ADDRESSES */
/* Initilialize the LwIP stack with RTOS */ /* Initilialize the LwIP stack with RTOS */
tcpip_init( NULL, NULL ); tcpip_init(NULL, NULL);
/* IP addresses initialization without DHCP (IPv4) */ /* IP addresses initialization without DHCP (IPv4) */
IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]); IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]);
IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1] , NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]); IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1], NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]);
IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]); IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]);
/* add the network interface (IPv4/IPv6) with RTOS */ /* add the network interface (IPv4/IPv6) with RTOS */
@ -103,19 +103,19 @@ void MX_LWIP_Init(void)
netif_set_link_callback(&gnetif, ethernet_link_status_updated); netif_set_link_callback(&gnetif, ethernet_link_status_updated);
/* Create the Ethernet link handler thread */ /* Create the Ethernet link handler thread */
/* USER CODE BEGIN H7_OS_THREAD_DEF_CREATE_CMSIS_RTOS_V1 */ /* USER CODE BEGIN H7_OS_THREAD_DEF_CREATE_CMSIS_RTOS_V1 */
osThreadDef(EthLink, ethernet_link_thread, osPriorityBelowNormal, 0, configMINIMAL_STACK_SIZE * 2); osThreadDef(EthLink, ethernet_link_thread, osPriorityBelowNormal, 0, configMINIMAL_STACK_SIZE * 2);
osThreadCreate(osThread(EthLink), &gnetif); osThreadCreate(osThread(EthLink), &gnetif);
/* USER CODE END H7_OS_THREAD_DEF_CREATE_CMSIS_RTOS_V1 */ /* USER CODE END H7_OS_THREAD_DEF_CREATE_CMSIS_RTOS_V1 */
/* USER CODE BEGIN 3 */ /* USER CODE BEGIN 3 */
flash_read_data(FLASH_USER_START_ADDR, IP_ADDRESS, 4); flash_read_data(FLASH_USER_START_ADDR, IP_ADDRESS, 4);
if (IP_ADDRESS[0] == 192) if (IP_ADDRESS[0] == 192)
{ {
IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]); IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]);
gnetif.ip_addr = ipaddr; gnetif.ip_addr = ipaddr;
} }
/* USER CODE END 3 */ /* USER CODE END 3 */
} }
#ifdef USE_OBSOLETE_USER_CODE_SECTION_4 #ifdef USE_OBSOLETE_USER_CODE_SECTION_4
@ -134,17 +134,17 @@ static void ethernet_link_status_updated(struct netif *netif)
{ {
if (netif_is_up(netif)) if (netif_is_up(netif))
{ {
/* USER CODE BEGIN 5 */ /* USER CODE BEGIN 5 */
/* USER CODE END 5 */ /* USER CODE END 5 */
} }
else /* netif is down */ else /* netif is down */
{ {
/* USER CODE BEGIN 6 */ /* USER CODE BEGIN 6 */
/* USER CODE END 6 */ /* USER CODE END 6 */
} }
} }
#if defined ( __CC_ARM ) /* MDK ARM Compiler */ #if defined(__CC_ARM) /* MDK ARM Compiler */
/** /**
* Opens a serial device for communication. * Opens a serial device for communication.
* *
@ -155,9 +155,9 @@ sio_fd_t sio_open(u8_t devnum)
{ {
sio_fd_t sd; sio_fd_t sd;
/* USER CODE BEGIN 7 */ /* USER CODE BEGIN 7 */
sd = 0; // dummy code sd = 0; // dummy code
/* USER CODE END 7 */ /* USER CODE END 7 */
return sd; return sd;
} }
@ -172,8 +172,8 @@ sio_fd_t sio_open(u8_t devnum)
*/ */
void sio_send(u8_t c, sio_fd_t fd) void sio_send(u8_t c, sio_fd_t fd)
{ {
/* USER CODE BEGIN 8 */ /* USER CODE BEGIN 8 */
/* USER CODE END 8 */ /* USER CODE END 8 */
} }
/** /**
@ -191,9 +191,9 @@ u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len)
{ {
u32_t recved_bytes; u32_t recved_bytes;
/* USER CODE BEGIN 9 */ /* USER CODE BEGIN 9 */
recved_bytes = 0; // dummy code recved_bytes = 0; // dummy code
/* USER CODE END 9 */ /* USER CODE END 9 */
return recved_bytes; return recved_bytes;
} }
@ -210,10 +210,9 @@ u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len)
{ {
u32_t recved_bytes; u32_t recved_bytes;
/* USER CODE BEGIN 10 */ /* USER CODE BEGIN 10 */
recved_bytes = 0; // dummy code recved_bytes = 0; // dummy code
/* USER CODE END 10 */ /* USER CODE END 10 */
return recved_bytes; return recved_bytes;
} }
#endif /* MDK ARM Compiler */ #endif /* MDK ARM Compiler */

View File

@ -148,7 +148,24 @@
<Name>-U090F00028316303030303032 -O2254 -SF1000 -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> <Name>-U090F00028316303030303032 -O2254 -SF1000 -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> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint/> <Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>52</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134250286</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\User\application\src\tcpserverc.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\semi_finished_product_testing\../User/application/src/tcpserverc.c\52</Expression>
</Bp>
</Breakpoint>
<WatchWindow1> <WatchWindow1>
<Ww> <Ww>
<count>0</count> <count>0</count>
@ -330,6 +347,31 @@
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>tcp_rx_data</ItemText> <ItemText>tcp_rx_data</ItemText>
</Ww> </Ww>
<Ww>
<count>36</count>
<WinNumber>1</WinNumber>
<ItemText>server_pcb_hart1</ItemText>
</Ww>
<Ww>
<count>37</count>
<WinNumber>1</WinNumber>
<ItemText>LAN8742</ItemText>
</Ww>
<Ww>
<count>38</count>
<WinNumber>1</WinNumber>
<ItemText>server_pcb_ble1</ItemText>
</Ww>
<Ww>
<count>39</count>
<WinNumber>1</WinNumber>
<ItemText>server_pcb_ble2</ItemText>
</Ww>
<Ww>
<count>40</count>
<WinNumber>1</WinNumber>
<ItemText>tcp_echo_flags_hart1</ItemText>
</Ww>
</WatchWindow1> </WatchWindow1>
<MemoryWindow1> <MemoryWindow1>
<Mm> <Mm>
@ -421,7 +463,7 @@
<GroupNumber>2</GroupNumber> <GroupNumber>2</GroupNumber>
<FileNumber>2</FileNumber> <FileNumber>2</FileNumber>
<FileType>1</FileType> <FileType>1</FileType>
<tvExp>1</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2> <bDave2>0</bDave2>
<PathWithFileName>../Core/Src/main.c</PathWithFileName> <PathWithFileName>../Core/Src/main.c</PathWithFileName>
@ -973,7 +1015,7 @@
<Group> <Group>
<GroupName>Middlewares/LwIP</GroupName> <GroupName>Middlewares/LwIP</GroupName>
<tvExp>1</tvExp> <tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>

View File

@ -68,7 +68,7 @@
* @ingroup lwip_opts * @ingroup lwip_opts
*/ */
/* /*
------------------------------------ ------------------------------------
-------------- NO SYS -------------- -------------- NO SYS --------------
------------------------------------ ------------------------------------
@ -134,7 +134,7 @@
* one included in your C library * one included in your C library
*/ */
#if !defined MEMCPY || defined __DOXYGEN__ #if !defined MEMCPY || defined __DOXYGEN__
#define MEMCPY(dst,src,len) memcpy(dst,src,len) #define MEMCPY(dst, src, len) memcpy(dst, src, len)
#endif #endif
/** /**
@ -142,7 +142,7 @@
* call to memcpy() if the length is known at compile time and is small. * call to memcpy() if the length is known at compile time and is small.
*/ */
#if !defined SMEMCPY || defined __DOXYGEN__ #if !defined SMEMCPY || defined __DOXYGEN__
#define SMEMCPY(dst,src,len) memcpy(dst,src,len) #define SMEMCPY(dst, src, len) memcpy(dst, src, len)
#endif #endif
/** /**
@ -151,7 +151,7 @@
* fragmentation support is enabled. * fragmentation support is enabled.
*/ */
#if !defined MEMMOVE || defined __DOXYGEN__ #if !defined MEMMOVE || defined __DOXYGEN__
#define MEMMOVE(dst,src,len) memmove(dst,src,len) #define MEMMOVE(dst, src, len) memmove(dst, src, len)
#endif #endif
/** /**
* @} * @}
@ -505,7 +505,7 @@
* The number of sys timeouts used by the core stack (not apps) * The number of sys timeouts used by the core stack (not apps)
* The default number of timeouts is calculated here for all enabled modules. * The default number of timeouts is calculated here for all enabled modules.
*/ */
#define LWIP_NUM_SYS_TIMEOUT_INTERNAL (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_NUM_TIMEOUTS + (LWIP_IPV6 * (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD))) #define LWIP_NUM_SYS_TIMEOUT_INTERNAL (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2 * LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_NUM_TIMEOUTS + (LWIP_IPV6 * (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD)))
/** /**
* MEMP_NUM_SYS_TIMEOUT: the number of simultaneously active timeouts. * MEMP_NUM_SYS_TIMEOUT: the number of simultaneously active timeouts.
@ -941,7 +941,7 @@
* LWIP_DHCP_GETS_NTP==1: Request NTP servers with discover/select. For each * LWIP_DHCP_GETS_NTP==1: Request NTP servers with discover/select. For each
* response packet, an callback is called, which has to be provided by the port: * response packet, an callback is called, which has to be provided by the port:
* void dhcp_set_ntp_servers(u8_t num_ntp_servers, ip_addr_t* ntp_server_addrs); * void dhcp_set_ntp_servers(u8_t num_ntp_servers, ip_addr_t* ntp_server_addrs);
*/ */
#if !defined LWIP_DHCP_GET_NTP_SRV || defined __DOXYGEN__ #if !defined LWIP_DHCP_GET_NTP_SRV || defined __DOXYGEN__
#define LWIP_DHCP_GET_NTP_SRV 0 #define LWIP_DHCP_GET_NTP_SRV 0
#endif #endif
@ -1305,7 +1305,6 @@
#define TCP_CALCULATE_EFF_SEND_MSS 1 #define TCP_CALCULATE_EFF_SEND_MSS 1
#endif #endif
/** /**
* TCP_SND_BUF: TCP sender buffer space (bytes). * TCP_SND_BUF: TCP sender buffer space (bytes).
* To achieve good performance, this should be at least 2 * TCP_MSS. * To achieve good performance, this should be at least 2 * TCP_MSS.
@ -1319,7 +1318,7 @@
* as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. * as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work.
*/ */
#if !defined TCP_SND_QUEUELEN || defined __DOXYGEN__ #if !defined TCP_SND_QUEUELEN || defined __DOXYGEN__
#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1))/(TCP_MSS)) #define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1)) / (TCP_MSS))
#endif #endif
/** /**
@ -1328,7 +1327,7 @@
* TCP snd_buf for select to return writable (combined with TCP_SNDQUEUELOWAT). * TCP snd_buf for select to return writable (combined with TCP_SNDQUEUELOWAT).
*/ */
#if !defined TCP_SNDLOWAT || defined __DOXYGEN__ #if !defined TCP_SNDLOWAT || defined __DOXYGEN__
#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF)/2), (2 * TCP_MSS) + 1), (TCP_SND_BUF) - 1) #define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF) / 2), (2 * TCP_MSS) + 1), (TCP_SND_BUF) - 1)
#endif #endif
/** /**
@ -1337,7 +1336,7 @@
* this number, select returns writable (combined with TCP_SNDLOWAT). * this number, select returns writable (combined with TCP_SNDLOWAT).
*/ */
#if !defined TCP_SNDQUEUELOWAT || defined __DOXYGEN__ #if !defined TCP_SNDQUEUELOWAT || defined __DOXYGEN__
#define TCP_SNDQUEUELOWAT LWIP_MAX(((TCP_SND_QUEUELEN)/2), 5) #define TCP_SNDQUEUELOWAT LWIP_MAX(((TCP_SND_QUEUELEN) / 2), 5)
#endif #endif
/** /**
@ -1545,7 +1544,7 @@
* TCP_MSS, IP header, and link header. * TCP_MSS, IP header, and link header.
*/ */
#if !defined PBUF_POOL_BUFSIZE || defined __DOXYGEN__ #if !defined PBUF_POOL_BUFSIZE || defined __DOXYGEN__
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN) #define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN)
#endif #endif
/** /**
@ -2695,7 +2694,7 @@
* LWIP_DHCP6_GETS_NTP==1: Request NTP servers via DHCPv6. For each * LWIP_DHCP6_GETS_NTP==1: Request NTP servers via DHCPv6. For each
* response packet, a callback is called, which has to be provided by the port: * response packet, a callback is called, which has to be provided by the port:
* void dhcp6_set_ntp_servers(u8_t num_ntp_servers, ip_addr_t* ntp_server_addrs); * void dhcp6_set_ntp_servers(u8_t num_ntp_servers, ip_addr_t* ntp_server_addrs);
*/ */
#if !defined LWIP_DHCP6_GET_NTP_SRV || defined __DOXYGEN__ #if !defined LWIP_DHCP6_GET_NTP_SRV || defined __DOXYGEN__
#define LWIP_DHCP6_GET_NTP_SRV 0 #define LWIP_DHCP6_GET_NTP_SRV 0
#endif #endif
@ -2932,7 +2931,7 @@
* This function is meant to implement advanced IPv4 routing together with * This function is meant to implement advanced IPv4 routing together with
* LWIP_HOOK_IP4_ROUTE(). The actual routing/gateway table implementation is * LWIP_HOOK_IP4_ROUTE(). The actual routing/gateway table implementation is
* not part of lwIP but can e.g. be hidden in the netif's state argument. * not part of lwIP but can e.g. be hidden in the netif's state argument.
*/ */
#ifdef __DOXYGEN__ #ifdef __DOXYGEN__
#define LWIP_HOOK_ETHARP_GET_GW(netif, dest) #define LWIP_HOOK_ETHARP_GET_GW(netif, dest)
#endif #endif
@ -2990,7 +2989,7 @@
* This function is meant to implement advanced IPv6 routing together with * This function is meant to implement advanced IPv6 routing together with
* LWIP_HOOK_IP6_ROUTE(). The actual routing/gateway table implementation is * LWIP_HOOK_IP6_ROUTE(). The actual routing/gateway table implementation is
* not part of lwIP but can e.g. be hidden in the netif's state argument. * not part of lwIP but can e.g. be hidden in the netif's state argument.
*/ */
#ifdef __DOXYGEN__ #ifdef __DOXYGEN__
#define LWIP_HOOK_ND6_GET_GW(netif, dest) #define LWIP_HOOK_ND6_GET_GW(netif, dest)
#endif #endif

View File

@ -40,7 +40,7 @@ static err_t tcpecho_recv_hart1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
if (p != NULL) if (p != NULL)
{ {
/* 更新窗口*/ /* 更新窗口*/
tcp_echo_flags_hart1 = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度 tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart1 = tpcb; // 直接赋值 server_pcb_hart1 = tpcb; // 直接赋值
memcpy(hart1_uart5.tx_data, (int *)p->payload, p->tot_len); memcpy(hart1_uart5.tx_data, (int *)p->payload, p->tot_len);
@ -54,6 +54,7 @@ static err_t tcpecho_recv_hart1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空 else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{ {
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
tcp_echo_flags_hart1 = 0;
return tcp_close(tpcb); return tcp_close(tpcb);
} }
return ERR_OK; return ERR_OK;
@ -64,7 +65,6 @@ static err_t tcpecho_recv_hart2(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
if (p != NULL) if (p != NULL)
{ {
/* 更新窗口*/ /* 更新窗口*/
tcp_echo_flags_hart2 = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度 tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_hart2 = tpcb; // 直接赋值 server_pcb_hart2 = tpcb; // 直接赋值
memcpy(hart2_uart2.tx_data, (int *)p->payload, p->tot_len); memcpy(hart2_uart2.tx_data, (int *)p->payload, p->tot_len);
@ -79,6 +79,7 @@ static err_t tcpecho_recv_hart2(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空 else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{ {
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
tcp_echo_flags_hart2 = 0;
return tcp_close(tpcb); return tcp_close(tpcb);
} }
return ERR_OK; return ERR_OK;
@ -114,7 +115,6 @@ static err_t tcpecho_recv_ble2(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
if (p != NULL) if (p != NULL)
{ {
/* 更新窗口*/ /* 更新窗口*/
tcp_echo_flags_ble2 = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度 tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_ble2 = tpcb; // 直接赋值 server_pcb_ble2 = tpcb; // 直接赋值
memcpy(ble2_uart3.tx_data, (int *)p->payload, p->tot_len); memcpy(ble2_uart3.tx_data, (int *)p->payload, p->tot_len);
@ -127,6 +127,7 @@ static err_t tcpecho_recv_ble2(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空 else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{ {
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
tcp_echo_flags_ble2 = 0;
return tcp_close(tpcb); return tcp_close(tpcb);
} }
return ERR_OK; return ERR_OK;
@ -143,7 +144,6 @@ static err_t tcpecho_recv_control(void *arg, struct tcp_pcb *tpcb, struct pbuf *
{ {
HAL_GPIO_TogglePin(LED3_G_GPIO_Port, LED3_G_Pin); HAL_GPIO_TogglePin(LED3_G_GPIO_Port, LED3_G_Pin);
/* 更新窗口*/ /* 更新窗口*/
tcp_echo_flags_control = 1;
tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度 tcp_recved(tpcb, p->tot_len); // 读取数据的控制块 得到所有数据的长度
server_pcb_control = tpcb; // 直接赋值 server_pcb_control = tpcb; // 直接赋值
memcpy(tcp_rx_data, (int *)p->payload, p->tot_len); memcpy(tcp_rx_data, (int *)p->payload, p->tot_len);
@ -228,6 +228,7 @@ static err_t tcpecho_recv_control(void *arg, struct tcp_pcb *tpcb, struct pbuf *
else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空 else if (err == ERR_OK) // 检测到对方主动关闭连接时也会调用recv函数此时p为空
{ {
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3); HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3);
tcp_echo_flags_control = 2;
return tcp_close(tpcb); return tcp_close(tpcb);
} }
@ -237,6 +238,7 @@ static err_t tcpecho_accept_hart1(void *arg, struct tcp_pcb *newpcb, err_t err)
// 形参的数量和类型必须一致 // 形参的数量和类型必须一致
{ {
tcp_recv(newpcb, tcpecho_recv_hart1); // 当收到数据时回调用户自己写的tcpecho_recv tcp_recv(newpcb, tcpecho_recv_hart1); // 当收到数据时回调用户自己写的tcpecho_recv
tcp_echo_flags_hart1 = 1;
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出用于关闭蜂鸣器发声 HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出用于关闭蜂鸣器发声
return ERR_OK; return ERR_OK;
} }
@ -244,6 +246,7 @@ static err_t tcpecho_accept_hart1(void *arg, struct tcp_pcb *newpcb, err_t err)
static err_t tcpecho_accept_hart2(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的 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 tcp_recv(newpcb, tcpecho_recv_hart2); // 当收到数据时回调用户自己写的tcpecho_recv
tcp_echo_flags_hart2 = 1;
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出用于关闭蜂鸣器发声 HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出用于关闭蜂鸣器发声
return ERR_OK; return ERR_OK;
} }
@ -258,12 +261,14 @@ static err_t tcpecho_accept_ble1(void *arg, struct tcp_pcb *newpcb, err_t err) /
static err_t tcpecho_accept_ble2(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的 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 tcp_recv(newpcb, tcpecho_recv_ble2); // 当收到数据时回调用户自己写的tcpecho_recv
tcp_echo_flags_ble2 = 1;
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出用于关闭蜂鸣器发声 HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出用于关闭蜂鸣器发声
return ERR_OK; return ERR_OK;
} }
static err_t tcpecho_accept_control(void *arg, struct tcp_pcb *newpcb, err_t err) // 由于这个函数是*tcp_accept_fn类型的 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 tcp_recv(newpcb, tcpecho_recv_control); // 当收到数据时回调用户自己写的tcpecho_recv
tcp_echo_flags_control = 1;
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出用于关闭蜂鸣器发声 HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_3); // 停止蜂鸣器PWM输出用于关闭蜂鸣器发声
return ERR_OK; return ERR_OK;
} }