Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
#include "lwip/pbuf.h"
#include "lwip/udp.h"
#include "lwip/tcp.h"
#include <string.h>
#include <stdio.h>
Private function prototypes
data
message_count
upcb
udp_echoclient_connect()
udp_echoclient_send()
udp_receive_callback(void *, struct udp_pcb *, struct pbuf *, const ip_addr_t *, u16_t)
Files
loading...
CodeScopeSTM32 Libraries and SamplesLwIP_UDP_Echo_ClientSrc/udp_echoclient.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file LwIP/LwIP_UDP_Echo_Client/Src/udp_echoclient.c * @author MCD Application Team * @brief UDP echo client ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "lwip/pbuf.h" #include "lwip/udp.h" #include "lwip/tcp.h" #include <string.h> #include <stdio.h> 6 includes Includes/* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ void udp_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port); u8_t data[100]; __IO uint32_t message_count = 0; struct udp_pcb *upcb; Private function prototypes /* Private functions ---------------------------------------------------------*/ /** * @brief Connect to UDP echo server * @param None * @retval None *//* ... */ void udp_echoclient_connect(void) { ip_addr_t DestIPaddr; err_t err; /* Create a new UDP control block */ upcb = udp_new(); if (upcb!=NULL) { /*assign destination IP address */ IP4_ADDR( &DestIPaddr, DEST_IP_ADDR0, DEST_IP_ADDR1, DEST_IP_ADDR2, DEST_IP_ADDR3 ); /* configure destination IP address and port */ err= udp_connect(upcb, &DestIPaddr, UDP_SERVER_PORT); if (err == ERR_OK) { /* Set a receive callback for the upcb */ udp_recv(upcb, udp_receive_callback, NULL); }if (err == ERR_OK) { ... } }if (upcb!=NULL) { ... } }{ ... } /** * @brief This function is called when an UDP datagrm has been received on the port UDP_PORT. * @param arg user supplied argument (udp_pcb.recv_arg) * @param pcb the udp_pcb which received data * @param p the packet buffer that was received * @param addr the remote IP address from which the packet was received * @param port the remote port from which the packet was received * @retval None *//* ... */ void udp_echoclient_send(void) { struct pbuf *p; sprintf((char*)data, "sending udp client message %d", (int)message_count); /* allocate pbuf from pool*/ p = pbuf_alloc(PBUF_TRANSPORT,strlen((char*)data), PBUF_POOL); if (p != NULL) { /* copy data to pbuf */ pbuf_take(p, (char*)data, strlen((char*)data)); /* send udp data */ udp_send(upcb, p); /* free pbuf */ pbuf_free(p); }if (p != NULL) { ... } }{ ... } /** * @brief This function is called when an UDP datagrm has been received on the port UDP_PORT. * @param arg user supplied argument (udp_pcb.recv_arg) * @param pcb the udp_pcb which received data * @param p the packet buffer that was received * @param addr the remote IP address from which the packet was received * @param port the remote port from which the packet was received * @retval None *//* ... */ void udp_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) { /*increment message count */ message_count++; /* Free receive pbuf */ pbuf_free(p); }{ ... }