Skip to content

Commit a3ed4b4

Browse files
Merge branch 'master' into gdb
2 parents 06a28bd + 4657666 commit a3ed4b4

23 files changed

+172
-136
lines changed

cores/esp8266/HardwareSerial.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define HardwareSerial_h
2929

3030
#include <inttypes.h>
31+
#include <time.h>
3132
#include "Stream.h"
3233
#include "uart.h"
3334

@@ -167,7 +168,7 @@ class HardwareSerial: public Stream
167168
{
168169
return write((uint8_t) n);
169170
}
170-
size_t write(const uint8_t *buffer, size_t size)
171+
size_t write(const uint8_t *buffer, size_t size) override
171172
{
172173
return uart_write(_uart, (const char*)buffer, size);
173174
}

cores/esp8266/Udp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
class UDP: public Stream {
4242

4343
public:
44+
virtual ~UDP() {};
4445
virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
4546
virtual void stop() =0; // Finish with the UDP socket
4647

doc/installing.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ might be broken.
3535

3636
For more information on the Arduino Board Manager, see:
3737

38-
- https://www.arduino.cc/en/Guide/Libraries
38+
- https://www.arduino.cc/en/guide/cores
3939

4040
Using git version
4141
-----------------
@@ -106,7 +106,7 @@ Instructions - Windows 10
106106
.. code:: bash
107107
108108
cd %USERPROFILE%\Documents\hardware\esp8266com\esp8266
109-
git submodules update --init
109+
git submodule update --init
110110
111111
If error messages about missing files related to ``SoftwareSerial`` are encountered during the build process, it should be because this step was missed and is required.
112112
@@ -180,7 +180,7 @@ Instructions - Other OS
180180
.. code:: bash
181181
182182
cd esp8266
183-
git submodules update --init
183+
git submodule update --init
184184
185185
If error messages about missing files related to ``SoftwareSerial`` are encountered during the build process, it should be because this step was missed and is required.
186186

libraries/ESP8266SSDP/ESP8266SSDP.cpp

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ struct SSDPTimer {
127127

128128
SSDPClass::SSDPClass() :
129129
_server(0),
130-
_timer(new SSDPTimer),
130+
_timer(0),
131131
_port(80),
132132
_ttl(SSDP_MULTICAST_TTL),
133133
_respondToPort(0),
@@ -150,27 +150,26 @@ SSDPClass::SSDPClass() :
150150
}
151151

152152
SSDPClass::~SSDPClass() {
153-
delete _timer;
153+
end();
154154
}
155155

156156
bool SSDPClass::begin() {
157+
end();
158+
157159
_pending = false;
158160
if (strcmp(_uuid,"") == 0) {
159161
uint32_t chipId = ESP.getChipId();
160162
sprintf(_uuid, "38323636-4558-4dda-9188-cda0e6%02x%02x%02x",
161163
(uint16_t) ((chipId >> 16) & 0xff),
162164
(uint16_t) ((chipId >> 8) & 0xff),
163-
(uint16_t) chipId & 0xff );
165+
(uint16_t) chipId & 0xff);
164166
}
165167

166168
#ifdef DEBUG_SSDP
167169
DEBUG_SSDP.printf("SSDP UUID: %s\n", (char *)_uuid);
168170
#endif
169171

170-
if (_server) {
171-
_server->unref();
172-
_server = 0;
173-
}
172+
assert(NULL == _server);
174173

175174
_server = new UdpContext;
176175
_server->ref();
@@ -199,6 +198,34 @@ bool SSDPClass::begin() {
199198
return true;
200199
}
201200

201+
void SSDPClass::end() {
202+
if(!_server)
203+
return; // object is zeroed already, nothing to do
204+
205+
#ifdef DEBUG_SSDP
206+
DEBUG_SSDP.printf_P(PSTR("SSDP end ... "));
207+
#endif
208+
// undo all initializations done in begin(), in reverse order
209+
_stopTimer();
210+
211+
_server->disconnect();
212+
213+
IPAddress local = WiFi.localIP();
214+
IPAddress mcast(SSDP_MULTICAST_ADDR);
215+
216+
if (igmp_leavegroup(local, mcast) != ERR_OK ) {
217+
#ifdef DEBUG_SSDP
218+
DEBUG_SSDP.printf_P(PSTR("SSDP failed to leave igmp group\n"));
219+
#endif
220+
}
221+
222+
_server->unref();
223+
_server = 0;
224+
225+
#ifdef DEBUG_SSDP
226+
DEBUG_SSDP.printf_P(PSTR("ok\n"));
227+
#endif
228+
}
202229
void SSDPClass::_send(ssdp_method_t method) {
203230
char buffer[1460];
204231
IPAddress ip = WiFi.localIP();
@@ -461,13 +488,25 @@ void SSDPClass::_onTimerStatic(SSDPClass* self) {
461488
}
462489

463490
void SSDPClass::_startTimer() {
491+
_stopTimer();
492+
_timer = new SSDPTimer();
464493
ETSTimer* tm = &(_timer->timer);
465494
const int interval = 1000;
466495
os_timer_disarm(tm);
467496
os_timer_setfn(tm, reinterpret_cast<ETSTimerFunc*>(&SSDPClass::_onTimerStatic), reinterpret_cast<void*>(this));
468497
os_timer_arm(tm, interval, 1 /* repeat */);
469498
}
470499

500+
void SSDPClass::_stopTimer() {
501+
if(!_timer)
502+
return;
503+
504+
ETSTimer* tm = &(_timer->timer);
505+
os_timer_disarm(tm);
506+
delete _timer;
507+
_timer = NULL;
508+
}
509+
471510
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SSDP)
472511
SSDPClass SSDP;
473512
#endif

libraries/ESP8266SSDP/ESP8266SSDP.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class SSDPClass{
6161
SSDPClass();
6262
~SSDPClass();
6363
bool begin();
64+
void end();
6465
void schema(WiFiClient client);
6566
void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); }
6667
void setDeviceType(const char *deviceType);
@@ -95,6 +96,7 @@ class SSDPClass{
9596
void _send(ssdp_method_t method);
9697
void _update();
9798
void _startTimer();
99+
void _stopTimer();
98100
static void _onTimerStatic(SSDPClass* self);
99101

100102
UdpContext* _server;

libraries/ESP8266WiFi/src/WiFiClient.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,10 @@ WiFiClient::operator bool()
351351

352352
IPAddress WiFiClient::remoteIP()
353353
{
354-
if (!_client)
354+
if (!_client || !_client->getRemoteAddress())
355355
return IPAddress(0U);
356356

357-
return IPAddress(_client->getRemoteAddress());
357+
return _client->getRemoteAddress();
358358
}
359359

360360
uint16_t WiFiClient::remotePort()

libraries/ESP8266WiFi/src/WiFiUdp.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,26 @@ class WiFiUDP : public UDP, public SList<WiFiUDP> {
3737
WiFiUDP(); // Constructor
3838
WiFiUDP(const WiFiUDP& other);
3939
WiFiUDP& operator=(const WiFiUDP& rhs);
40-
~WiFiUDP();
40+
virtual ~WiFiUDP();
4141

4242
operator bool() const { return _ctx != 0; }
4343

4444
// initialize, start listening on specified port.
4545
// Returns 1 if successful, 0 if there are no sockets available to use
46-
virtual uint8_t begin(uint16_t port);
46+
uint8_t begin(uint16_t port) override;
4747
// Finish with the UDP connetion
48-
virtual void stop();
48+
void stop() override;
4949
// join a multicast group and listen on the given port
5050
uint8_t beginMulticast(IPAddress interfaceAddr, IPAddress multicast, uint16_t port);
5151

5252
// Sending UDP packets
5353

5454
// Start building up a packet to send to the remote host specific in ip and port
5555
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
56-
virtual int beginPacket(IPAddress ip, uint16_t port);
56+
int beginPacket(IPAddress ip, uint16_t port) override;
5757
// Start building up a packet to send to the remote host specific in host and port
5858
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
59-
virtual int beginPacket(const char *host, uint16_t port);
59+
int beginPacket(const char *host, uint16_t port) override;
6060
// Start building up a packet to send to the multicast address
6161
// multicastAddress - muticast address to send to
6262
// interfaceAddress - the local IP address of the interface that should be used
@@ -69,35 +69,35 @@ class WiFiUDP : public UDP, public SList<WiFiUDP> {
6969
int ttl = 1);
7070
// Finish off this packet and send it
7171
// Returns 1 if the packet was sent successfully, 0 if there was an error
72-
virtual int endPacket();
72+
int endPacket() override;
7373
// Write a single byte into the packet
74-
virtual size_t write(uint8_t);
74+
size_t write(uint8_t) override;
7575
// Write size bytes from buffer into the packet
76-
virtual size_t write(const uint8_t *buffer, size_t size);
76+
size_t write(const uint8_t *buffer, size_t size) override;
7777

7878
using Print::write;
7979

8080
// Start processing the next available incoming packet
8181
// Returns the size of the packet in bytes, or 0 if no packets are available
82-
virtual int parsePacket();
82+
int parsePacket() override;
8383
// Number of bytes remaining in the current packet
84-
virtual int available();
84+
int available() override;
8585
// Read a single byte from the current packet
86-
virtual int read();
86+
int read() override;
8787
// Read up to len bytes from the current packet and place them into buffer
8888
// Returns the number of bytes read, or 0 if none are available
89-
virtual int read(unsigned char* buffer, size_t len);
89+
int read(unsigned char* buffer, size_t len) override;
9090
// Read up to len characters from the current packet and place them into buffer
9191
// Returns the number of characters read, or 0 if none are available
92-
virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); };
92+
int read(char* buffer, size_t len) override { return read((unsigned char*)buffer, len); };
9393
// Return the next byte from the current packet without moving on to the next byte
94-
virtual int peek();
95-
virtual void flush(); // Finish reading the current packet
94+
int peek() override;
95+
void flush() override; // Finish reading the current packet
9696

9797
// Return the IP address of the host who sent the current incoming packet
98-
virtual IPAddress remoteIP() const;
98+
IPAddress remoteIP() const override;
9999
// Return the port of the host who sent the current incoming packet
100-
virtual uint16_t remotePort() const;
100+
uint16_t remotePort() const override;
101101
// Return the destination address for incoming packets,
102102
// useful to distinguish multicast and ordinary packets
103103
IPAddress destinationIP() const;

0 commit comments

Comments
 (0)