Skip to content

Commit

Permalink
Merge branch 'master' into gdb
Browse files Browse the repository at this point in the history
  • Loading branch information
earlephilhower authored Jan 23, 2019
2 parents 06a28bd + 4657666 commit a3ed4b4
Show file tree
Hide file tree
Showing 23 changed files with 172 additions and 136 deletions.
3 changes: 2 additions & 1 deletion cores/esp8266/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define HardwareSerial_h

#include <inttypes.h>
#include <time.h>
#include "Stream.h"
#include "uart.h"

Expand Down Expand Up @@ -167,7 +168,7 @@ class HardwareSerial: public Stream
{
return write((uint8_t) n);
}
size_t write(const uint8_t *buffer, size_t size)
size_t write(const uint8_t *buffer, size_t size) override
{
return uart_write(_uart, (const char*)buffer, size);
}
Expand Down
1 change: 1 addition & 0 deletions cores/esp8266/Udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
class UDP: public Stream {

public:
virtual ~UDP() {};
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
virtual void stop() =0; // Finish with the UDP socket

Expand Down
6 changes: 3 additions & 3 deletions doc/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ might be broken.

For more information on the Arduino Board Manager, see:

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

Using git version
-----------------
Expand Down Expand Up @@ -106,7 +106,7 @@ Instructions - Windows 10
.. code:: bash
cd %USERPROFILE%\Documents\hardware\esp8266com\esp8266
git submodules update --init
git submodule update --init
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.
Expand Down Expand Up @@ -180,7 +180,7 @@ Instructions - Other OS
.. code:: bash
cd esp8266
git submodules update --init
git submodule update --init
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.
Expand Down
53 changes: 46 additions & 7 deletions libraries/ESP8266SSDP/ESP8266SSDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ struct SSDPTimer {

SSDPClass::SSDPClass() :
_server(0),
_timer(new SSDPTimer),
_timer(0),
_port(80),
_ttl(SSDP_MULTICAST_TTL),
_respondToPort(0),
Expand All @@ -150,27 +150,26 @@ SSDPClass::SSDPClass() :
}

SSDPClass::~SSDPClass() {
delete _timer;
end();
}

bool SSDPClass::begin() {
end();

_pending = false;
if (strcmp(_uuid,"") == 0) {
uint32_t chipId = ESP.getChipId();
sprintf(_uuid, "38323636-4558-4dda-9188-cda0e6%02x%02x%02x",
(uint16_t) ((chipId >> 16) & 0xff),
(uint16_t) ((chipId >> 8) & 0xff),
(uint16_t) chipId & 0xff );
(uint16_t) chipId & 0xff);
}

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

if (_server) {
_server->unref();
_server = 0;
}
assert(NULL == _server);

_server = new UdpContext;
_server->ref();
Expand Down Expand Up @@ -199,6 +198,34 @@ bool SSDPClass::begin() {
return true;
}

void SSDPClass::end() {
if(!_server)
return; // object is zeroed already, nothing to do

#ifdef DEBUG_SSDP
DEBUG_SSDP.printf_P(PSTR("SSDP end ... "));
#endif
// undo all initializations done in begin(), in reverse order
_stopTimer();

_server->disconnect();

IPAddress local = WiFi.localIP();
IPAddress mcast(SSDP_MULTICAST_ADDR);

if (igmp_leavegroup(local, mcast) != ERR_OK ) {
#ifdef DEBUG_SSDP
DEBUG_SSDP.printf_P(PSTR("SSDP failed to leave igmp group\n"));
#endif
}

_server->unref();
_server = 0;

#ifdef DEBUG_SSDP
DEBUG_SSDP.printf_P(PSTR("ok\n"));
#endif
}
void SSDPClass::_send(ssdp_method_t method) {
char buffer[1460];
IPAddress ip = WiFi.localIP();
Expand Down Expand Up @@ -461,13 +488,25 @@ void SSDPClass::_onTimerStatic(SSDPClass* self) {
}

void SSDPClass::_startTimer() {
_stopTimer();
_timer = new SSDPTimer();
ETSTimer* tm = &(_timer->timer);
const int interval = 1000;
os_timer_disarm(tm);
os_timer_setfn(tm, reinterpret_cast<ETSTimerFunc*>(&SSDPClass::_onTimerStatic), reinterpret_cast<void*>(this));
os_timer_arm(tm, interval, 1 /* repeat */);
}

void SSDPClass::_stopTimer() {
if(!_timer)
return;

ETSTimer* tm = &(_timer->timer);
os_timer_disarm(tm);
delete _timer;
_timer = NULL;
}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SSDP)
SSDPClass SSDP;
#endif
2 changes: 2 additions & 0 deletions libraries/ESP8266SSDP/ESP8266SSDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class SSDPClass{
SSDPClass();
~SSDPClass();
bool begin();
void end();
void schema(WiFiClient client);
void setDeviceType(const String& deviceType) { setDeviceType(deviceType.c_str()); }
void setDeviceType(const char *deviceType);
Expand Down Expand Up @@ -95,6 +96,7 @@ class SSDPClass{
void _send(ssdp_method_t method);
void _update();
void _startTimer();
void _stopTimer();
static void _onTimerStatic(SSDPClass* self);

UdpContext* _server;
Expand Down
4 changes: 2 additions & 2 deletions libraries/ESP8266WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ WiFiClient::operator bool()

IPAddress WiFiClient::remoteIP()
{
if (!_client)
if (!_client || !_client->getRemoteAddress())
return IPAddress(0U);

return IPAddress(_client->getRemoteAddress());
return _client->getRemoteAddress();
}

uint16_t WiFiClient::remotePort()
Expand Down
34 changes: 17 additions & 17 deletions libraries/ESP8266WiFi/src/WiFiUdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,26 @@ class WiFiUDP : public UDP, public SList<WiFiUDP> {
WiFiUDP(); // Constructor
WiFiUDP(const WiFiUDP& other);
WiFiUDP& operator=(const WiFiUDP& rhs);
~WiFiUDP();
virtual ~WiFiUDP();

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

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

// Sending UDP packets

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

using Print::write;

// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket();
int parsePacket() override;
// Number of bytes remaining in the current packet
virtual int available();
int available() override;
// Read a single byte from the current packet
virtual int read();
int read() override;
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len);
int read(unsigned char* buffer, size_t len) override;
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); };
int read(char* buffer, size_t len) override { return read((unsigned char*)buffer, len); };
// Return the next byte from the current packet without moving on to the next byte
virtual int peek();
virtual void flush(); // Finish reading the current packet
int peek() override;
void flush() override; // Finish reading the current packet

// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() const;
IPAddress remoteIP() const override;
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() const;
uint16_t remotePort() const override;
// Return the destination address for incoming packets,
// useful to distinguish multicast and ordinary packets
IPAddress destinationIP() const;
Expand Down
Loading

0 comments on commit a3ed4b4

Please sign in to comment.