-
Notifications
You must be signed in to change notification settings - Fork 44
/
WiFiUdp.h
98 lines (74 loc) · 2.68 KB
/
WiFiUdp.h
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
/*
This file is part of the WiFiEspAT library for Arduino
https://github.com/jandrassy/WiFiEspAT
Copyright 2019, 2024 Juraj Andrassy
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _WIFIUDP_H_
#define _WIFIUDP_H_
#include <Udp.h>
#include "WiFiEspAtConfig.h"
#include "WiFiEspAtSharedBuffStreamPtr.h"
#include "utility/EspAtDrvTypes.h"
class WiFiUDP : public UDP
#ifdef WIFIESPAT1
, protected EspAtDrvUdpDataCallback
#endif
{
public:
// Sending UDP packets
virtual int beginPacket(IPAddress ip, uint16_t port);
virtual int beginPacket(const char *host, uint16_t port);
virtual int endPacket();
virtual size_t write(uint8_t);
virtual size_t write(const uint8_t *buffer, size_t size);
virtual void flush();
virtual int availableForWrite();
size_t write(SendCallbackFnc callback);
using Print::write;
virtual uint8_t begin(uint16_t port);
#ifndef WIFIESPAT1 // AT2
virtual uint8_t beginMulticast(IPAddress ip, uint16_t port);
// WiFiEspAT AT2 special functions for receive
size_t availableForParse();
size_t parsePacket(uint8_t* buffer, size_t bufferSize, IPAddress& remoteIP, uint16_t& remotePort);
#endif
virtual void stop();
// Listening for UDP packets
virtual int parsePacket();
virtual int available();
virtual int read();
virtual int read(uint8_t* buffer, size_t len);
virtual int read(char* buffer, size_t len) {return read((uint8_t*) buffer, len);}
virtual int peek();
#ifdef WIFIESPAT1
virtual IPAddress remoteIP();
virtual uint16_t remotePort();
protected:
virtual uint8_t readRxData(Stream* serial, size_t len); // EspAtDrvUdpDataCallback implementation
#else
virtual IPAddress remoteIP() {return senderIP;}
virtual uint16_t remotePort() {return senderPort;}
#endif
private:
uint8_t linkId = WIFIESPAT_NO_LINK;
bool listening = false;
WiFiEspAtSharedBuffStreamPtr txStream;
WiFiEspAtSharedBuffStreamPtr rxStream;
char strIP[16]; // to hold the string version of IP for beginPacket(ip, port);
#ifndef WIFIESPAT1 //AT2
IPAddress senderIP;
uint16_t senderPort;
uint8_t begin(const char* ip, uint16_t port);
#endif
};
#endif