mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-13 13:01:55 +03:00
Merge pull request #714 from martinayotte/esp8266
add toCharArray() to IPAddress class
This commit is contained in:
@ -64,3 +64,10 @@ size_t IPAddress::printTo(Print& p) const {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String IPAddress::toString()
|
||||||
|
{
|
||||||
|
char szRet[16];
|
||||||
|
sprintf(szRet,"%u.%u.%u.%u", _address.bytes[0], _address.bytes[1], _address.bytes[2], _address.bytes[3]);
|
||||||
|
return String(szRet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#define IPAddress_h
|
#define IPAddress_h
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <WString.h>
|
||||||
#include <Printable.h>
|
#include <Printable.h>
|
||||||
|
|
||||||
// A class to make it easier to handle and pass around IP addresses
|
// A class to make it easier to handle and pass around IP addresses
|
||||||
@ -70,6 +71,7 @@ class IPAddress: public Printable {
|
|||||||
IPAddress& operator=(uint32_t address);
|
IPAddress& operator=(uint32_t address);
|
||||||
|
|
||||||
virtual size_t printTo(Print& p) const;
|
virtual size_t printTo(Print& p) const;
|
||||||
|
String toString();
|
||||||
|
|
||||||
friend class EthernetClass;
|
friend class EthernetClass;
|
||||||
friend class UDP;
|
friend class UDP;
|
||||||
|
@ -177,6 +177,38 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size)
|
|||||||
return _client->write(reinterpret_cast<const char*>(buf), size);
|
return _client->write(reinterpret_cast<const char*>(buf), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t WiFiClient::write_P(PGM_P buf, size_t size)
|
||||||
|
{
|
||||||
|
if (!_client || !size)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char chunkUnit[WIFICLIENT_MAX_PACKET_SIZE + 1];
|
||||||
|
chunkUnit[WIFICLIENT_MAX_PACKET_SIZE] = '\0';
|
||||||
|
while (buf != NULL)
|
||||||
|
{
|
||||||
|
size_t chunkUnitLen;
|
||||||
|
PGM_P chunkNext;
|
||||||
|
chunkNext = (PGM_P)memccpy_P((void*)chunkUnit, (PGM_VOID_P)buf, 0, WIFICLIENT_MAX_PACKET_SIZE);
|
||||||
|
if (chunkNext == NULL)
|
||||||
|
{
|
||||||
|
// no terminator, more data available
|
||||||
|
buf += WIFICLIENT_MAX_PACKET_SIZE;
|
||||||
|
chunkUnitLen = WIFICLIENT_MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// reached terminator
|
||||||
|
chunkUnitLen = chunkNext - buf;
|
||||||
|
buf = NULL;
|
||||||
|
}
|
||||||
|
if (size < WIFICLIENT_MAX_PACKET_SIZE) chunkUnitLen = size;
|
||||||
|
_client->write((const char*)chunkUnit, chunkUnitLen);
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
int WiFiClient::available()
|
int WiFiClient::available()
|
||||||
{
|
{
|
||||||
if (!_client)
|
if (!_client)
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include "include/slist.h"
|
#include "include/slist.h"
|
||||||
|
|
||||||
|
#define WIFICLIENT_MAX_PACKET_SIZE 1460
|
||||||
|
|
||||||
class ClientContext;
|
class ClientContext;
|
||||||
class WiFiServer;
|
class WiFiServer;
|
||||||
|
|
||||||
@ -46,6 +48,7 @@ public:
|
|||||||
virtual int connect(const char *host, uint16_t port);
|
virtual int connect(const char *host, uint16_t port);
|
||||||
virtual size_t write(uint8_t);
|
virtual size_t write(uint8_t);
|
||||||
virtual size_t write(const uint8_t *buf, size_t size);
|
virtual size_t write(const uint8_t *buf, size_t size);
|
||||||
|
size_t write_P(PGM_P buf, size_t size);
|
||||||
template <typename T>
|
template <typename T>
|
||||||
size_t write(T& source, size_t unitSize);
|
size_t write(T& source, size_t unitSize);
|
||||||
|
|
||||||
@ -67,16 +70,16 @@ public:
|
|||||||
static void setLocalPortStart(uint16_t port) { _localPort = port; }
|
static void setLocalPortStart(uint16_t port) { _localPort = port; }
|
||||||
|
|
||||||
template<typename T> size_t write(T &src){
|
template<typename T> size_t write(T &src){
|
||||||
uint8_t obuf[1460];
|
uint8_t obuf[WIFICLIENT_MAX_PACKET_SIZE];
|
||||||
size_t doneLen = 0;
|
size_t doneLen = 0;
|
||||||
size_t sentLen;
|
size_t sentLen;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
while (src.available() > 1460){
|
while (src.available() > WIFICLIENT_MAX_PACKET_SIZE){
|
||||||
src.read(obuf, 1460);
|
src.read(obuf, WIFICLIENT_MAX_PACKET_SIZE);
|
||||||
sentLen = write(obuf, 1460);
|
sentLen = write(obuf, WIFICLIENT_MAX_PACKET_SIZE);
|
||||||
doneLen = doneLen + sentLen;
|
doneLen = doneLen + sentLen;
|
||||||
if(sentLen != 1460){
|
if(sentLen != WIFICLIENT_MAX_PACKET_SIZE){
|
||||||
return doneLen;
|
return doneLen;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user