From e17cb4df26df7692027234f288b8246a567985d1 Mon Sep 17 00:00:00 2001 From: Jeff Hoefs Date: Sat, 5 Mar 2016 16:15:08 -0800 Subject: [PATCH 1/3] modifications to allow BLE Nano to work with StandardFirmataBLE --- .../RBL_nRF51822/cores/RBL_nRF51822/Client.h | 42 +++++++++++ .../cores/RBL_nRF51822/HardwareSerial.h | 4 +- .../cores/RBL_nRF51822/IPAddress.h | 75 +++++++++++++++++++ .../RBL_nRF51822/{WStream.cpp => Stream.cpp} | 34 ++++----- .../RBL_nRF51822/{WStream.h => Stream.h} | 8 +- .../mbed/api/{Stream.h => MStream.h} | 10 +-- .../cores/RBL_nRF51822/mbed/api/Serial.h | 4 +- .../cores/RBL_nRF51822/mbed/api/SerialBase.h | 2 +- .../mbed/common/{Stream.cpp => MStream.cpp} | 32 ++++---- .../cores/RBL_nRF51822/mbed/common/Serial.cpp | 2 +- .../RBL/RBL_nRF51822/libraries/Wire/Wire.h | 4 +- 11 files changed, 167 insertions(+), 50 deletions(-) create mode 100644 arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/Client.h create mode 100644 arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/IPAddress.h rename arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/{WStream.cpp => Stream.cpp} (89%) rename arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/{WStream.h => Stream.h} (97%) rename arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/{Stream.h => MStream.h} (91%) rename arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/{Stream.cpp => MStream.cpp} (78%) diff --git a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/Client.h b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/Client.h new file mode 100644 index 0000000..f98bdda --- /dev/null +++ b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/Client.h @@ -0,0 +1,42 @@ +/* + Client.h - Base class that provides Client + Copyright (c) 2011 Adrian McEwen. All right reserved. + 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, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef client_h +#define client_h +#include "Print.h" +#include "Stream.h" +#include "IPAddress.h" + +class Client : public Stream { + +public: + virtual int connect(IPAddress ip, uint16_t port) =0; + virtual int connect(const char *host, uint16_t port) =0; + virtual size_t write(uint8_t) =0; + virtual size_t write(const uint8_t *buf, size_t size) =0; + virtual int available() = 0; + virtual int read() = 0; + virtual int read(uint8_t *buf, size_t size) = 0; + virtual int peek() = 0; + virtual void flush() = 0; + virtual void stop() = 0; + virtual uint8_t connected() = 0; + virtual operator bool() = 0; +protected: + uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; +}; + +#endif diff --git a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/HardwareSerial.h b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/HardwareSerial.h index 0556be8..ecba701 100644 --- a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/HardwareSerial.h +++ b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/HardwareSerial.h @@ -21,9 +21,9 @@ #include -#include "WStream.h" +#include "Stream.h" -class HardwareSerial : public WStream +class HardwareSerial : public Stream { public: void begin( const uint32_t dwBaudRate ); diff --git a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/IPAddress.h b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/IPAddress.h new file mode 100644 index 0000000..7c8cdd1 --- /dev/null +++ b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/IPAddress.h @@ -0,0 +1,75 @@ +/* + IPAddress.h - Base class that provides IPAddress + Copyright (c) 2011 Adrian McEwen. All right reserved. + 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, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef IPAddress_h +#define IPAddress_h + +#include +#include "Printable.h" +#include "WString.h" + +// A class to make it easier to handle and pass around IP addresses + +class IPAddress : public Printable { +private: + union { + uint8_t bytes[4]; // IPv4 address + uint32_t dword; + } _address; + + // Access the raw byte array containing the address. Because this returns a pointer + // to the internal structure rather than a copy of the address this function should only + // be used when you know that the usage of the returned uint8_t* will be transient and not + // stored. + uint8_t* raw_address() { return _address.bytes; }; + +public: + // Constructors + IPAddress(); + IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); + IPAddress(uint32_t address); + IPAddress(const uint8_t *address); + + bool fromString(const char *address); + bool fromString(const String &address) { return fromString(address.c_str()); } + + // Overloaded cast operator to allow IPAddress objects to be used where a pointer + // to a four-byte uint8_t array is expected + operator uint32_t() const { return _address.dword; }; + bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; }; + bool operator==(const uint8_t* addr) const; + + // Overloaded index operator to allow getting and setting individual octets of the address + uint8_t operator[](int index) const { return _address.bytes[index]; }; + uint8_t& operator[](int index) { return _address.bytes[index]; }; + + // Overloaded copy operators to allow initialisation of IPAddress objects from other types + IPAddress& operator=(const uint8_t *address); + IPAddress& operator=(uint32_t address); + + virtual size_t printTo(Print& p) const; + + friend class EthernetClass; + friend class UDP; + friend class Client; + friend class Server; + friend class DhcpClass; + friend class DNSClient; +}; + +//const IPAddress INADDR_NONE(0,0,0,0); + +#endif \ No newline at end of file diff --git a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/WStream.cpp b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/Stream.cpp similarity index 89% rename from arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/WStream.cpp rename to arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/Stream.cpp index 815b75f..6c58c56 100644 --- a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/WStream.cpp +++ b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/Stream.cpp @@ -22,13 +22,13 @@ */ #include "Arduino.h" -#include "WStream.h" +#include "Stream.h" #define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait #define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field // private method to read stream with timeout -int WStream::timedRead() +int Stream::timedRead() { int c; _startMillis = millis(); @@ -40,7 +40,7 @@ int WStream::timedRead() } // private method to peek stream with timeout -int WStream::timedPeek() +int Stream::timedPeek() { int c; _startMillis = millis(); @@ -53,7 +53,7 @@ int WStream::timedPeek() // returns peek of the next digit in the stream or -1 if timeout // discards non-numeric characters -int WStream::peekNextDigit() +int Stream::peekNextDigit() { int c; while (1) { @@ -68,26 +68,26 @@ int WStream::peekNextDigit() // Public Methods ////////////////////////////////////////////////////////////// -void WStream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait +void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait { _timeout = timeout; } // find returns true if the target string is found -bool WStream::find(char *target) +bool Stream::find(char *target) { return findUntil(target, NULL); } // reads data from the stream until the target string of given length is found // returns true if target string is found, false if timed out -bool WStream::find(char *target, size_t length) +bool Stream::find(char *target, size_t length) { return findUntil(target, length, NULL, 0); } // as find but search ends if the terminator string is found -bool WStream::findUntil(char *target, char *terminator) +bool Stream::findUntil(char *target, char *terminator) { return findUntil(target, strlen(target), terminator, strlen(terminator)); } @@ -95,7 +95,7 @@ bool WStream::findUntil(char *target, char *terminator) // reads data from the stream until the target string of the given length is found // search terminated if the terminator string is found // returns true if target string is found, false if terminated or timed out -bool WStream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen) +bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen) { size_t index = 0; // maximum target string length is 64k bytes! size_t termIndex = 0; @@ -129,14 +129,14 @@ bool WStream::findUntil(char *target, size_t targetLen, char *terminator, size_t // returns the first valid (long) integer value from the current position. // initial characters that are not digits (or the minus sign) are skipped // function is terminated by the first character that is not a digit. -long WStream::parseInt() +long Stream::parseInt() { return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout) } // as above but a given skipChar is ignored // this allows format characters (typically commas) in values to be ignored -long WStream::parseInt(char skipChar) +long Stream::parseInt(char skipChar) { boolean isNegative = false; long value = 0; @@ -166,14 +166,14 @@ long WStream::parseInt(char skipChar) // as parseInt but returns a floating point value -float WStream::parseFloat() +float Stream::parseFloat() { return parseFloat(NO_SKIP_CHAR); } // as above but the given skipChar is ignored // this allows format characters (typically commas) in values to be ignored -float WStream::parseFloat(char skipChar){ +float Stream::parseFloat(char skipChar){ boolean isNegative = false; boolean isFraction = false; long value = 0; @@ -215,7 +215,7 @@ float WStream::parseFloat(char skipChar){ // returns the number of characters placed in the buffer // the buffer is NOT null terminated. // -size_t WStream::readBytes(char *buffer, size_t length) +size_t Stream::readBytes(char *buffer, size_t length) { size_t count = 0; while (count < length) { @@ -232,7 +232,7 @@ size_t WStream::readBytes(char *buffer, size_t length) // terminates if length characters have been read, timeout, or if the terminator character detected // returns the number of characters placed in the buffer (0 means no valid data found) -size_t WStream::readBytesUntil(char terminator, char *buffer, size_t length) +size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length) { if (length < 1) return 0; size_t index = 0; @@ -245,7 +245,7 @@ size_t WStream::readBytesUntil(char terminator, char *buffer, size_t length) return index; // return number of characters, not including null terminator } -String WStream::readString() +String Stream::readString() { String ret; int c = timedRead(); @@ -257,7 +257,7 @@ String WStream::readString() return ret; } -String WStream::readStringUntil(char terminator) +String Stream::readStringUntil(char terminator) { String ret; int c = timedRead(); diff --git a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/WStream.h b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/Stream.h similarity index 97% rename from arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/WStream.h rename to arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/Stream.h index 81ce6e6..163ae03 100644 --- a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/WStream.h +++ b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/Stream.h @@ -20,8 +20,8 @@ parsing functions based on TextFinder library by Michael Margolis */ -#ifndef WStream_h -#define WStream_h +#ifndef Stream_h +#define Stream_h #include #include "Print.h" @@ -36,7 +36,7 @@ readBytesBetween( pre_string, terminator, buffer, length) */ -class WStream : public Print +class Stream : public Print { private: unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read @@ -51,7 +51,7 @@ class WStream : public Print virtual int peek() = 0; virtual void flush() = 0; - WStream() {_timeout=1000;} + Stream() {_timeout=1000;} // parsing methods diff --git a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/Stream.h b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/MStream.h similarity index 91% rename from arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/Stream.h rename to arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/MStream.h index ca5dfe6..4697b46 100644 --- a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/Stream.h +++ b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/MStream.h @@ -26,11 +26,11 @@ extern void mbed_set_unbuffered_stream(FILE *_file); extern int mbed_getc(FILE *_file); extern char* mbed_gets(char *s, int size, FILE *_file); -class Stream : public FileLike { +class MStream : public FileLike { public: - Stream(const char *name=NULL); - virtual ~Stream(); + MStream(const char *name=NULL); + virtual ~MStream(); int putc(int c); int puts(const char *s); @@ -59,8 +59,8 @@ class Stream : public FileLike { /* disallow copy constructor and assignment operators */ private: - Stream(const Stream&); - Stream & operator = (const Stream&); + MStream(const MStream&); + MStream & operator = (const MStream&); }; } // namespace mbed diff --git a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/Serial.h b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/Serial.h index aa06540..a3278b6 100644 --- a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/Serial.h +++ b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/Serial.h @@ -20,7 +20,7 @@ #if DEVICE_SERIAL -#include "Stream.h" +#include "MStream.h" #include "SerialBase.h" #include "serial_api.h" @@ -44,7 +44,7 @@ namespace mbed { * } * @endcode */ -class Serial : public SerialBase, public Stream { +class Serial : public SerialBase, public MStream { public: #if DEVICE_SERIAL_ASYNCH diff --git a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/SerialBase.h b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/SerialBase.h index 51aeb33..e7daa7b 100644 --- a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/SerialBase.h +++ b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/api/SerialBase.h @@ -20,7 +20,7 @@ #if DEVICE_SERIAL -#include "Stream.h" +#include "MStream.h" #include "FunctionPointer.h" #include "serial_api.h" diff --git a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/Stream.cpp b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/MStream.cpp similarity index 78% rename from arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/Stream.cpp rename to arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/MStream.cpp index 2b3105f..e5f02ad 100644 --- a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/Stream.cpp +++ b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/MStream.cpp @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "Stream.h" +#include "MStream.h" namespace mbed { -Stream::Stream(const char *name) : FileLike(name), _file(NULL) { +MStream::MStream(const char *name) : FileLike(name), _file(NULL) { /* open ourselves */ char buf[12]; /* :0x12345678 + null byte */ std::sprintf(buf, ":%p", this); @@ -25,32 +25,32 @@ Stream::Stream(const char *name) : FileLike(name), _file(NULL) { mbed_set_unbuffered_stream(_file); } -Stream::~Stream() { +MStream::~MStream() { fclose(_file); } -int Stream::putc(int c) { +int MStream::putc(int c) { fflush(_file); return std::fputc(c, _file); } -int Stream::puts(const char *s) { +int MStream::puts(const char *s) { fflush(_file); return std::fputs(s, _file); } -int Stream::getc() { +int MStream::getc() { fflush(_file); return mbed_getc(_file); } -char* Stream::gets(char *s, int size) { +char* MStream::gets(char *s, int size) { fflush(_file); return mbed_gets(s,size,_file); } -int Stream::close() { +int MStream::close() { return 0; } -ssize_t Stream::write(const void* buffer, size_t length) { +ssize_t MStream::write(const void* buffer, size_t length) { const char* ptr = (const char*)buffer; const char* end = ptr + length; while (ptr != end) { @@ -61,7 +61,7 @@ ssize_t Stream::write(const void* buffer, size_t length) { return ptr - (const char*)buffer; } -ssize_t Stream::read(void* buffer, size_t length) { +ssize_t MStream::read(void* buffer, size_t length) { char* ptr = (char*)buffer; char* end = ptr + length; while (ptr != end) { @@ -72,23 +72,23 @@ ssize_t Stream::read(void* buffer, size_t length) { return ptr - (const char*)buffer; } -off_t Stream::lseek(off_t offset, int whence) { +off_t MStream::lseek(off_t offset, int whence) { return 0; } -int Stream::isatty() { +int MStream::isatty() { return 0; } -int Stream::fsync() { +int MStream::fsync() { return 0; } -off_t Stream::flen() { +off_t MStream::flen() { return 0; } -int Stream::printf(const char* format, ...) { +int MStream::printf(const char* format, ...) { std::va_list arg; va_start(arg, format); fflush(_file); @@ -97,7 +97,7 @@ int Stream::printf(const char* format, ...) { return r; } -int Stream::scanf(const char* format, ...) { +int MStream::scanf(const char* format, ...) { std::va_list arg; va_start(arg, format); fflush(_file); diff --git a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/Serial.cpp b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/Serial.cpp index 602c87a..66d15bf 100644 --- a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/Serial.cpp +++ b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/Serial.cpp @@ -20,7 +20,7 @@ namespace mbed { -Serial::Serial(PinName tx, PinName rx, const char *name) : SerialBase(tx, rx), Stream(name) { +Serial::Serial(PinName tx, PinName rx, const char *name) : SerialBase(tx, rx), MStream(name) { } int Serial::_getc() { diff --git a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/libraries/Wire/Wire.h b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/libraries/Wire/Wire.h index a65072f..176801e 100644 --- a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/libraries/Wire/Wire.h +++ b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/libraries/Wire/Wire.h @@ -30,7 +30,7 @@ #ifndef _WIRE_H_ #define _WIRE_H_ -#include "WStream.h" +#include "Stream.h" #include "Arduino.h" @@ -41,7 +41,7 @@ #define TWI_FREQUENCY_400K 400000 -class TwoWire : public WStream +class TwoWire : public Stream { public : enum TwoWireStatus { From a14a46ebd985dd05d54350e50005d9dac8a10f98 Mon Sep 17 00:00:00 2001 From: Jeff Hoefs Date: Fri, 23 Dec 2016 11:50:59 -0800 Subject: [PATCH 2/3] remove files that were not needed --- .../RBL_nRF51822/cores/RBL_nRF51822/Client.h | 42 ----------- .../cores/RBL_nRF51822/IPAddress.h | 75 ------------------- 2 files changed, 117 deletions(-) delete mode 100644 arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/Client.h delete mode 100644 arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/IPAddress.h diff --git a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/Client.h b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/Client.h deleted file mode 100644 index f98bdda..0000000 --- a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/Client.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - Client.h - Base class that provides Client - Copyright (c) 2011 Adrian McEwen. All right reserved. - 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, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef client_h -#define client_h -#include "Print.h" -#include "Stream.h" -#include "IPAddress.h" - -class Client : public Stream { - -public: - virtual int connect(IPAddress ip, uint16_t port) =0; - virtual int connect(const char *host, uint16_t port) =0; - virtual size_t write(uint8_t) =0; - virtual size_t write(const uint8_t *buf, size_t size) =0; - virtual int available() = 0; - virtual int read() = 0; - virtual int read(uint8_t *buf, size_t size) = 0; - virtual int peek() = 0; - virtual void flush() = 0; - virtual void stop() = 0; - virtual uint8_t connected() = 0; - virtual operator bool() = 0; -protected: - uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; -}; - -#endif diff --git a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/IPAddress.h b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/IPAddress.h deleted file mode 100644 index 7c8cdd1..0000000 --- a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/IPAddress.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - IPAddress.h - Base class that provides IPAddress - Copyright (c) 2011 Adrian McEwen. All right reserved. - 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, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef IPAddress_h -#define IPAddress_h - -#include -#include "Printable.h" -#include "WString.h" - -// A class to make it easier to handle and pass around IP addresses - -class IPAddress : public Printable { -private: - union { - uint8_t bytes[4]; // IPv4 address - uint32_t dword; - } _address; - - // Access the raw byte array containing the address. Because this returns a pointer - // to the internal structure rather than a copy of the address this function should only - // be used when you know that the usage of the returned uint8_t* will be transient and not - // stored. - uint8_t* raw_address() { return _address.bytes; }; - -public: - // Constructors - IPAddress(); - IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); - IPAddress(uint32_t address); - IPAddress(const uint8_t *address); - - bool fromString(const char *address); - bool fromString(const String &address) { return fromString(address.c_str()); } - - // Overloaded cast operator to allow IPAddress objects to be used where a pointer - // to a four-byte uint8_t array is expected - operator uint32_t() const { return _address.dword; }; - bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; }; - bool operator==(const uint8_t* addr) const; - - // Overloaded index operator to allow getting and setting individual octets of the address - uint8_t operator[](int index) const { return _address.bytes[index]; }; - uint8_t& operator[](int index) { return _address.bytes[index]; }; - - // Overloaded copy operators to allow initialisation of IPAddress objects from other types - IPAddress& operator=(const uint8_t *address); - IPAddress& operator=(uint32_t address); - - virtual size_t printTo(Print& p) const; - - friend class EthernetClass; - friend class UDP; - friend class Client; - friend class Server; - friend class DhcpClass; - friend class DNSClient; -}; - -//const IPAddress INADDR_NONE(0,0,0,0); - -#endif \ No newline at end of file From 300b49c3ca9fe29ef2ac0ebb7f8219d180bd6f83 Mon Sep 17 00:00:00 2001 From: Jeff Hoefs Date: Fri, 23 Dec 2016 12:33:28 -0800 Subject: [PATCH 3/3] change Stream to MStream for new methods --- .../RBL_nRF51822/cores/RBL_nRF51822/mbed/common/MStream.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/MStream.cpp b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/MStream.cpp index e5f02ad..3a2afbf 100644 --- a/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/MStream.cpp +++ b/arduino-1.6.x/hardware/RBL/RBL_nRF51822/cores/RBL_nRF51822/mbed/common/MStream.cpp @@ -106,13 +106,13 @@ int MStream::scanf(const char* format, ...) { return r; } -int Stream::vprintf(const char* format, std::va_list args) { +int MStream::vprintf(const char* format, std::va_list args) { fflush(_file); int r = vfprintf(_file, format, args); return r; } -int Stream::vscanf(const char* format, std::va_list args) { +int MStream::vscanf(const char* format, std::va_list args) { fflush(_file); int r = vfscanf(_file, format, args); return r;