ClearCore Library
Loading...
Searching...
No Matches
EthernetUdp.h
1/*
2 * Copyright (c) 2020 Teknic, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23/*
24 \file EthernetUdp.h
25**/
26
27#ifndef __ETHERNETUDP_H__
28#define __ETHERNETUDP_H__
29
30#include "IpAddress.h"
31#include "lwip/udp.h"
32
33namespace ClearCore {
34
44
45public:
46#ifndef HIDE_FROM_DOXYGEN
50 typedef struct {
51 struct udp_pcb *pcb;
52 struct pbuf *packet;
53 uint16_t available;
54 ip_addr_t remoteIp;
55 u16_t remotePort;
56 } UdpData;
57#endif // !HIDE_FROM_DOXYGEN
58
63
72 bool Begin(uint16_t localPort);
73
77 void End();
78
87 bool Connect(IpAddress remoteIp, uint16_t remotePort);
88
94 bool PacketSend();
95
105 uint32_t PacketWrite(uint8_t c);
106
116 uint32_t PacketWrite(const char *nullTermStr);
117
128 uint32_t PacketWrite(const uint8_t *buffer, uint32_t size);
129
139 uint16_t PacketParse();
140
146 uint16_t BytesAvailable();
147
158 int32_t PacketRead(unsigned char *dataPtr, uint16_t len);
159
171 int16_t Peek();
172
177
184
190 uint16_t RemotePort();
191
192private:
193 UdpData m_udpData;
194 uint16_t m_udpLocalPort;
195
196 struct pbuf *m_outgoingPacket;
197
198 struct pbuf *m_incomingPacket;
199 uint16_t m_udpBytesAvailable;
200 IpAddress m_udpRemoteIpReceived;
201 uint16_t m_udpRemotePortReceived;
202 IpAddress m_udpRemoteIpDestination;
203 uint16_t m_udpRemotePortDestination;
204
205 // Begin() was called.
206 bool m_initialized;
207 // Connect() was called and we can write to a packet.
208 bool m_packetBegun;
209 // PacketWrite() was called and we can send a packet.
210 bool m_packetReadyToSend;
211 // PacketParse() was called and we can read a packet.
212 bool m_packetParsed;
213
214 uint16_t UdpPacketRead(pbuf *packet, uint16_t *available,
215 unsigned char *buffer, uint16_t size);
216}; // EthernetUdp
217
218#ifndef HIDE_FROM_DOXYGEN
219
220void UdpReceive(void *arg, struct udp_pcb *pcb, struct pbuf *p,
221 const ip_addr_t *addr, u16_t port);
222
223#endif // !HIDE_FROM_DOXYGEN
224} // ClearCore namespace
225#endif // !__ETHERNETUDP_H__
ClearCore UDP session class.
Definition EthernetUdp.h:43
IpAddress RemoteIp()
Returns the remote IP address for the current packet.
uint32_t PacketWrite(const char *nullTermStr)
Write data into the outgoing UDP packet.
bool Connect(IpAddress remoteIp, uint16_t remotePort)
Setup to send a UDP packet to a specified remote.
void End()
Disable the UDP session.
void PacketFlush()
Flush the current packet.
uint16_t RemotePort()
Returns the remote port for the current packet.
uint32_t PacketWrite(uint8_t c)
Write data into the outgoing UDP packet.
uint16_t PacketParse()
Check for the newest incoming UDP packet.
int32_t PacketRead(unsigned char *dataPtr, uint16_t len)
Reads the current packet received from the UDP session.
int16_t Peek()
Attempts to get the next available character.
uint32_t PacketWrite(const uint8_t *buffer, uint32_t size)
PacketWrite data into the outgoing UDP packet.
bool PacketSend()
Send the UDP packet set up with Connect().
bool Begin(uint16_t localPort)
Initialize the UDP session and begin listening on the specified local port.
uint16_t BytesAvailable()
Number of bytes available to read from the current packet.
An IP Address class.
Definition IpAddress.h:41
Namespace to encompass the ClearCore board API.
Definition AdcManager.h:36