forked from khoih-prog/AsyncHTTPRequest_Generic
Update Packages' Patches
This commit is contained in:
@@ -27,18 +27,19 @@
|
||||
|
||||
// compatability macros for testing
|
||||
/*
|
||||
#define getInt() parseInt()
|
||||
#define getInt(ignore) parseInt(ignore)
|
||||
#define getFloat() parseFloat()
|
||||
#define getFloat(ignore) parseFloat(ignore)
|
||||
#define getString( pre_string, post_string, buffer, length)
|
||||
readBytesBetween( pre_string, terminator, buffer, length)
|
||||
#define getInt() parseInt()
|
||||
#define getInt(ignore) parseInt(ignore)
|
||||
#define getFloat() parseFloat()
|
||||
#define getFloat(ignore) parseFloat(ignore)
|
||||
#define getString( pre_string, post_string, buffer, length)
|
||||
readBytesBetween( pre_string, terminator, buffer, length)
|
||||
*/
|
||||
|
||||
// This enumeration provides the lookahead options for parseInt(), parseFloat()
|
||||
// The rules set out here are used until either the first valid character is found
|
||||
// or a time out occurs due to lack of input.
|
||||
enum LookaheadMode{
|
||||
enum LookaheadMode
|
||||
{
|
||||
SKIP_ALL, // All invalid characters are ignored.
|
||||
SKIP_NONE, // Nothing is skipped, and the stream is not touched unless the first waiting character is valid.
|
||||
SKIP_WHITESPACE // Only tabs, spaces, line feeds & carriage returns are skipped.
|
||||
@@ -60,28 +61,49 @@ class Stream : public Print
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
Stream() {_timeout=1000;}
|
||||
Stream()
|
||||
{
|
||||
_timeout = 1000;
|
||||
}
|
||||
|
||||
// parsing methods
|
||||
// parsing methods
|
||||
|
||||
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
||||
unsigned long getTimeout(void) { return _timeout; }
|
||||
unsigned long getTimeout(void)
|
||||
{
|
||||
return _timeout;
|
||||
}
|
||||
|
||||
bool find(char *target); // reads data from the stream until the target string is found
|
||||
bool find(uint8_t *target) { return find ((char *)target); }
|
||||
bool find(uint8_t *target)
|
||||
{
|
||||
return find ((char *)target);
|
||||
}
|
||||
// returns true if target string is found, false if timed out (see setTimeout)
|
||||
|
||||
bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
|
||||
bool find(uint8_t *target, size_t length) { return find ((char *)target, length); }
|
||||
bool find(uint8_t *target, size_t length)
|
||||
{
|
||||
return find ((char *)target, length);
|
||||
}
|
||||
// returns true if target string is found, false if timed out
|
||||
|
||||
bool find(char target) { return find (&target, 1); }
|
||||
bool find(char target)
|
||||
{
|
||||
return find (&target, 1);
|
||||
}
|
||||
|
||||
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
|
||||
bool findUntil(uint8_t *target, char *terminator) { return findUntil((char *)target, terminator); }
|
||||
bool findUntil(uint8_t *target, char *terminator)
|
||||
{
|
||||
return findUntil((char *)target, terminator);
|
||||
}
|
||||
|
||||
bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
|
||||
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); }
|
||||
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen)
|
||||
{
|
||||
return findUntil((char *)target, targetLen, terminate, termLen);
|
||||
}
|
||||
|
||||
long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||
// returns the first valid (long) integer value from the current position.
|
||||
@@ -94,12 +116,18 @@ class Stream : public Print
|
||||
// float version of parseInt
|
||||
|
||||
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
|
||||
size_t readBytes( uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
|
||||
size_t readBytes( uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
// terminates if length characters have been read or timeout (see setTimeout)
|
||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||
|
||||
size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
|
||||
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); }
|
||||
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytesUntil(terminator, (char *)buffer, 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)
|
||||
|
||||
@@ -108,13 +136,20 @@ class Stream : public Print
|
||||
String readStringUntil(char terminator);
|
||||
|
||||
protected:
|
||||
long parseInt(char ignore) { return parseInt(SKIP_ALL, ignore); }
|
||||
float parseFloat(char ignore) { return parseFloat(SKIP_ALL, ignore); }
|
||||
long parseInt(char ignore)
|
||||
{
|
||||
return parseInt(SKIP_ALL, ignore);
|
||||
}
|
||||
float parseFloat(char ignore)
|
||||
{
|
||||
return parseFloat(SKIP_ALL, ignore);
|
||||
}
|
||||
// These overload exists for compatibility with any class that has derived
|
||||
// Stream and used parseFloat/Int with a custom ignore character. To keep
|
||||
// the public API simple, these overload remains protected.
|
||||
|
||||
struct MultiTarget {
|
||||
struct MultiTarget
|
||||
{
|
||||
const char *str; // string you're searching for
|
||||
size_t len; // length of string you're searching for
|
||||
size_t index; // index used by the search routine.
|
||||
|
@@ -27,18 +27,19 @@
|
||||
|
||||
// compatability macros for testing
|
||||
/*
|
||||
#define getInt() parseInt()
|
||||
#define getInt(ignore) parseInt(ignore)
|
||||
#define getFloat() parseFloat()
|
||||
#define getFloat(ignore) parseFloat(ignore)
|
||||
#define getString( pre_string, post_string, buffer, length)
|
||||
readBytesBetween( pre_string, terminator, buffer, length)
|
||||
#define getInt() parseInt()
|
||||
#define getInt(ignore) parseInt(ignore)
|
||||
#define getFloat() parseFloat()
|
||||
#define getFloat(ignore) parseFloat(ignore)
|
||||
#define getString( pre_string, post_string, buffer, length)
|
||||
readBytesBetween( pre_string, terminator, buffer, length)
|
||||
*/
|
||||
|
||||
// This enumeration provides the lookahead options for parseInt(), parseFloat()
|
||||
// The rules set out here are used until either the first valid character is found
|
||||
// or a time out occurs due to lack of input.
|
||||
enum LookaheadMode{
|
||||
enum LookaheadMode
|
||||
{
|
||||
SKIP_ALL, // All invalid characters are ignored.
|
||||
SKIP_NONE, // Nothing is skipped, and the stream is not touched unless the first waiting character is valid.
|
||||
SKIP_WHITESPACE // Only tabs, spaces, line feeds & carriage returns are skipped.
|
||||
@@ -60,28 +61,49 @@ class Stream : public Print
|
||||
virtual int read() = 0;
|
||||
virtual int peek() = 0;
|
||||
|
||||
Stream() {_timeout=1000;}
|
||||
Stream()
|
||||
{
|
||||
_timeout = 1000;
|
||||
}
|
||||
|
||||
// parsing methods
|
||||
// parsing methods
|
||||
|
||||
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
|
||||
unsigned long getTimeout(void) { return _timeout; }
|
||||
unsigned long getTimeout(void)
|
||||
{
|
||||
return _timeout;
|
||||
}
|
||||
|
||||
bool find(char *target); // reads data from the stream until the target string is found
|
||||
bool find(uint8_t *target) { return find ((char *)target); }
|
||||
bool find(uint8_t *target)
|
||||
{
|
||||
return find ((char *)target);
|
||||
}
|
||||
// returns true if target string is found, false if timed out (see setTimeout)
|
||||
|
||||
bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
|
||||
bool find(uint8_t *target, size_t length) { return find ((char *)target, length); }
|
||||
bool find(uint8_t *target, size_t length)
|
||||
{
|
||||
return find ((char *)target, length);
|
||||
}
|
||||
// returns true if target string is found, false if timed out
|
||||
|
||||
bool find(char target) { return find (&target, 1); }
|
||||
bool find(char target)
|
||||
{
|
||||
return find (&target, 1);
|
||||
}
|
||||
|
||||
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
|
||||
bool findUntil(uint8_t *target, char *terminator) { return findUntil((char *)target, terminator); }
|
||||
bool findUntil(uint8_t *target, char *terminator)
|
||||
{
|
||||
return findUntil((char *)target, terminator);
|
||||
}
|
||||
|
||||
bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
|
||||
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); }
|
||||
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen)
|
||||
{
|
||||
return findUntil((char *)target, targetLen, terminate, termLen);
|
||||
}
|
||||
|
||||
long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
|
||||
// returns the first valid (long) integer value from the current position.
|
||||
@@ -94,12 +116,18 @@ class Stream : public Print
|
||||
// float version of parseInt
|
||||
|
||||
size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
|
||||
size_t readBytes( uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
|
||||
size_t readBytes( uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytes((char *)buffer, length);
|
||||
}
|
||||
// terminates if length characters have been read or timeout (see setTimeout)
|
||||
// returns the number of characters placed in the buffer (0 means no valid data found)
|
||||
|
||||
size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
|
||||
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); }
|
||||
size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length)
|
||||
{
|
||||
return readBytesUntil(terminator, (char *)buffer, 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)
|
||||
|
||||
@@ -108,13 +136,20 @@ class Stream : public Print
|
||||
String readStringUntil(char terminator);
|
||||
|
||||
protected:
|
||||
long parseInt(char ignore) { return parseInt(SKIP_ALL, ignore); }
|
||||
float parseFloat(char ignore) { return parseFloat(SKIP_ALL, ignore); }
|
||||
long parseInt(char ignore)
|
||||
{
|
||||
return parseInt(SKIP_ALL, ignore);
|
||||
}
|
||||
float parseFloat(char ignore)
|
||||
{
|
||||
return parseFloat(SKIP_ALL, ignore);
|
||||
}
|
||||
// These overload exists for compatibility with any class that has derived
|
||||
// Stream and used parseFloat/Int with a custom ignore character. To keep
|
||||
// the public API simple, these overload remains protected.
|
||||
|
||||
struct MultiTarget {
|
||||
struct MultiTarget
|
||||
{
|
||||
const char *str; // string you're searching for
|
||||
size_t len; // length of string you're searching for
|
||||
size_t index; // index used by the search routine.
|
||||
|
@@ -0,0 +1,466 @@
|
||||
/*
|
||||
Copyright (c) 2014 Arduino. 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
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
//using namespace arduino;
|
||||
|
||||
// Public Methods //////////////////////////////////////////////////////////////
|
||||
|
||||
/* default implementation: may be overridden */
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
return print(reinterpret_cast<const char *>(ifsh));
|
||||
}
|
||||
|
||||
size_t Print::print(const String &s)
|
||||
{
|
||||
return write(s.c_str(), s.length());
|
||||
}
|
||||
|
||||
size_t Print::print(const char str[])
|
||||
{
|
||||
return write(str);
|
||||
}
|
||||
|
||||
size_t Print::print(char c)
|
||||
{
|
||||
return write(c);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned char b, int base)
|
||||
{
|
||||
return print((unsigned long) b, base);
|
||||
}
|
||||
|
||||
size_t Print::print(int n, int base)
|
||||
{
|
||||
return print((long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned int n, int base)
|
||||
{
|
||||
return print((unsigned long) n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
{
|
||||
return printFloat(n, digits);
|
||||
}
|
||||
|
||||
size_t Print::println(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
size_t n = print(ifsh);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::print(const Printable& x)
|
||||
{
|
||||
return x.printTo(*this);
|
||||
}
|
||||
|
||||
size_t Print::println(void)
|
||||
{
|
||||
return write("\r\n");
|
||||
}
|
||||
|
||||
size_t Print::println(const String &s)
|
||||
{
|
||||
size_t n = print(s);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const char c[])
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(char c)
|
||||
{
|
||||
size_t n = print(c);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned char b, int base)
|
||||
{
|
||||
size_t n = print(b, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned int num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(unsigned long long num, int base)
|
||||
{
|
||||
size_t n = print(num, base);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(double num, int digits)
|
||||
{
|
||||
size_t n = print(num, digits);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::println(const Printable& x)
|
||||
{
|
||||
size_t n = print(x);
|
||||
n += println();
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printf(const char * format, ...)
|
||||
{
|
||||
char buf[256];
|
||||
int len;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
len = vsnprintf(buf, 256, format, ap);
|
||||
this->write(buf, len);
|
||||
|
||||
va_end(ap);
|
||||
return len;
|
||||
}
|
||||
|
||||
// Private Methods /////////////////////////////////////////////////////////////
|
||||
|
||||
size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
{
|
||||
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
|
||||
char *str = &buf[sizeof(buf) - 1];
|
||||
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
}
|
||||
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
// size_t Print::printULLNumber(unsigned long long n, uint8_t base)
|
||||
// {
|
||||
// // if limited to base 10 and 16 the bufsize can be smaller
|
||||
// char buf[65];
|
||||
// char *str = &buf[64];
|
||||
|
||||
// *str = '\0';
|
||||
|
||||
// // prevent crash if called with base == 1
|
||||
// if (base < 2) base = 10;
|
||||
|
||||
// do {
|
||||
// unsigned long long t = n / base;
|
||||
// char c = n - t * base; // faster than c = n%base;
|
||||
// n = t;
|
||||
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
// } while(n);
|
||||
|
||||
// return write(str);
|
||||
// }
|
||||
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// if limited to base 10 and 16 the bufsize can be 20
|
||||
char buf[64];
|
||||
uint8_t i = 0;
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
innerLoops++;
|
||||
}
|
||||
|
||||
while (n64 > th16)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
'A' + buf[i - 1] - 10));
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
size_t Print::printFloat(double number, int digits)
|
||||
{
|
||||
if (digits < 0)
|
||||
digits = 2;
|
||||
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
{
|
||||
n += print('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
while (digits-- > 0)
|
||||
{
|
||||
remainder *= 10.0;
|
||||
unsigned int toPrint = (unsigned int)remainder;
|
||||
n += print(toPrint);
|
||||
remainder -= toPrint;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
Copyright (c) 2016 Arduino LLC. 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h> // for size_t
|
||||
|
||||
#include "WString.h"
|
||||
#include "Printable.h"
|
||||
|
||||
#define DEC 10
|
||||
#define HEX 16
|
||||
#define OCT 8
|
||||
#define BIN 2
|
||||
|
||||
class Print
|
||||
{
|
||||
private:
|
||||
int write_error;
|
||||
size_t printNumber(unsigned long, uint8_t);
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
size_t print(const char[]);
|
||||
size_t print(char);
|
||||
size_t print(unsigned char, int = DEC);
|
||||
size_t print(int, int = DEC);
|
||||
size_t print(unsigned int, int = DEC);
|
||||
size_t print(long, int = DEC);
|
||||
size_t print(unsigned long, int = DEC);
|
||||
size_t print(long long, int = DEC);
|
||||
size_t print(unsigned long long, int = DEC);
|
||||
size_t print(double, int = 2);
|
||||
size_t print(const Printable&);
|
||||
|
||||
size_t println(const __FlashStringHelper *);
|
||||
size_t println(const String &s);
|
||||
size_t println(const char[]);
|
||||
size_t println(char);
|
||||
size_t println(unsigned char, int = DEC);
|
||||
size_t println(int, int = DEC);
|
||||
size_t println(unsigned int, int = DEC);
|
||||
size_t println(long, int = DEC);
|
||||
size_t println(unsigned long, int = DEC);
|
||||
size_t println(long long, int = DEC);
|
||||
size_t println(unsigned long long, int = DEC);
|
||||
size_t println(double, int = 2);
|
||||
size_t println(const Printable&);
|
||||
size_t println(void);
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
virtual void flush() { /* Empty implementation for backward compatibility */ }
|
||||
};
|
||||
|
||||
|
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
Udp.cpp: Library to send/receive UDP packets.
|
||||
|
||||
NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
|
||||
1) UDP does not guarantee the order in which assembled UDP packets are received. This
|
||||
might not happen often in practice, but in larger network topologies, a UDP
|
||||
packet can be received out of sequence.
|
||||
2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
|
||||
aware of it. Again, this may not be a concern in practice on small local networks.
|
||||
For more information, see http://www.cafeaulait.org/course/week12/35.html
|
||||
|
||||
MIT License:
|
||||
Copyright (c) 2008 Bjoern Hartmann
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
bjoern@cs.stanford.edu 12/30/2008
|
||||
*/
|
||||
|
||||
#ifndef udp_h
|
||||
#define udp_h
|
||||
|
||||
#include <Stream.h>
|
||||
#include <IPAddress.h>
|
||||
|
||||
class UDP : public Stream
|
||||
{
|
||||
|
||||
public:
|
||||
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
|
||||
|
||||
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
|
||||
virtual uint8_t beginMulticast(IPAddress, uint16_t)
|
||||
{
|
||||
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
|
||||
}
|
||||
|
||||
virtual void stop() = 0; // Finish with the UDP socket
|
||||
|
||||
// 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) = 0;
|
||||
// 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) = 0;
|
||||
// Finish off this packet and send it
|
||||
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||
virtual int endPacket() = 0;
|
||||
// Write a single byte into the packet
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
// Write size bytes from buffer into the packet
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
|
||||
// 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() = 0;
|
||||
// Number of bytes remaining in the current packet
|
||||
virtual int available() = 0;
|
||||
// Read a single byte from the current packet
|
||||
virtual int read() = 0;
|
||||
// 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) = 0;
|
||||
// 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) = 0;
|
||||
// Return the next byte from the current packet without moving on to the next byte
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0; // Finish reading the current packet
|
||||
|
||||
// Return the IP address of the host who sent the current incoming packet
|
||||
virtual IPAddress remoteIP() = 0;
|
||||
// Return the port of the host who sent the current incoming packet
|
||||
virtual uint16_t remotePort() = 0;
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
163
Packages_Patches/Seeeduino/hardware/nrf52/1.0.0/platform.txt
Normal file
163
Packages_Patches/Seeeduino/hardware/nrf52/1.0.0/platform.txt
Normal file
@@ -0,0 +1,163 @@
|
||||
# Copyright (c) 2014-2015 Arduino LLC. All right reserved.
|
||||
# Copyright (c) 2016 Sandeep Mistry All right reserved.
|
||||
# Copyright (c) 2017 Adafruit Industries. All rights 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
|
||||
|
||||
name=Seeed nRF52 Boards
|
||||
version=1.0.0
|
||||
|
||||
# Compile variables
|
||||
# -----------------
|
||||
|
||||
compiler.warning_flags=-Werror=return-type
|
||||
compiler.warning_flags.none=-Werror=return-type
|
||||
compiler.warning_flags.default=-Werror=return-type
|
||||
compiler.warning_flags.more=-Wall -Werror=return-type
|
||||
compiler.warning_flags.all=-Wall -Wextra -Werror=return-type -Wno-unused-parameter -Wno-missing-field-initializers -Wno-pointer-arith
|
||||
|
||||
# Allow changing optimization settings via platform.local.txt / boards.local.txt
|
||||
compiler.optimization_flag=-Ofast
|
||||
|
||||
compiler.path={runtime.tools.arm-none-eabi-gcc.path}/bin/
|
||||
compiler.c.cmd=arm-none-eabi-gcc
|
||||
compiler.c.flags=-mcpu={build.mcu} -mthumb -c -g {compiler.warning_flags} {build.float_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD
|
||||
|
||||
# KH, Error here to use gcc, must use g++
|
||||
#compiler.c.elf.cmd=arm-none-eabi-gcc
|
||||
compiler.c.elf.cmd=arm-none-eabi-g++
|
||||
|
||||
compiler.c.elf.flags={compiler.optimization_flag} -Wl,--gc-sections -save-temps
|
||||
compiler.S.cmd=arm-none-eabi-gcc
|
||||
compiler.S.flags=-mcpu={build.mcu} -mthumb -mabi=aapcs {compiler.optimization_flag} -g -c {build.float_flags} -x assembler-with-cpp
|
||||
|
||||
compiler.cpp.cmd=arm-none-eabi-g++
|
||||
compiler.cpp.flags=-mcpu={build.mcu} -mthumb -c -g {compiler.warning_flags} {build.float_flags} -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD
|
||||
compiler.ar.cmd=arm-none-eabi-ar
|
||||
compiler.ar.flags=rcs
|
||||
compiler.objcopy.cmd=arm-none-eabi-objcopy
|
||||
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
|
||||
compiler.elf2bin.flags=-O binary
|
||||
compiler.elf2bin.cmd=arm-none-eabi-objcopy
|
||||
compiler.elf2hex.flags=-O ihex
|
||||
compiler.elf2hex.cmd=arm-none-eabi-objcopy
|
||||
compiler.ldflags=-mcpu={build.mcu} -mthumb {build.float_flags} -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--wrap=malloc -Wl,--wrap=free --specs=nano.specs --specs=nosys.specs
|
||||
compiler.size.cmd=arm-none-eabi-size
|
||||
|
||||
# this can be overriden in boards.txt
|
||||
# Logger 0: Serial (CDC), 1 Serial1 (UART), 2 Segger RTT
|
||||
build.float_flags=-mfloat-abi=hard -mfpu=fpv4-sp-d16 -u _printf_float
|
||||
build.debug_flags=-DCFG_DEBUG=0
|
||||
build.logger_flags=-DCFG_LOGGER=0
|
||||
build.sysview_flags=-DCFG_SYSVIEW=0
|
||||
|
||||
# USB flags
|
||||
build.flags.usb= -DUSBCON -DUSE_TINYUSB -DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'
|
||||
|
||||
# These can be overridden in platform.local.txt
|
||||
compiler.c.extra_flags=
|
||||
compiler.c.elf.extra_flags=
|
||||
compiler.cpp.extra_flags=
|
||||
compiler.S.extra_flags=
|
||||
compiler.ar.extra_flags=
|
||||
compiler.libraries.ldflags=
|
||||
compiler.elf2bin.extra_flags=
|
||||
compiler.elf2hex.extra_flags=
|
||||
|
||||
compiler.arm.cmsis.c.flags="-I{runtime.tools.CMSIS-5.7.0.path}/CMSIS/Core/Include/" "-I{runtime.tools.CMSIS-5.7.0.path}/CMSIS/DSP/Include/"
|
||||
compiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-5.7.0.path}/CMSIS/DSP/Lib/GCC/" -larm_cortexM4lf_math
|
||||
|
||||
# common compiler for nrf
|
||||
rtos.path={build.core.path}/freertos
|
||||
nordic.path={build.core.path}/nordic
|
||||
|
||||
build.flags.nrf= -DSOFTDEVICE_PRESENT -DARDUINO_NRF52_ADAFRUIT -DNRF52_SERIES -DDX_CC_TEE -DLFS_NAME_MAX=64 {compiler.optimization_flag} {build.debug_flags} {build.logger_flags} {build.sysview_flags} {compiler.arm.cmsis.c.flags} "-I{nordic.path}" "-I{nordic.path}/nrfx" "-I{nordic.path}/nrfx/hal" "-I{nordic.path}/nrfx/mdk" "-I{nordic.path}/nrfx/soc" "-I{nordic.path}/nrfx/drivers/include" "-I{nordic.path}/nrfx/drivers/src" "-I{nordic.path}/softdevice/{build.sd_name}_nrf52_{build.sd_version}_API/include" "-I{nordic.path}/softdevice/{build.sd_name}_nrf52_{build.sd_version}_API/include/nrf52" "-I{rtos.path}/Source/include" "-I{rtos.path}/config" "-I{rtos.path}/portable/GCC/nrf52" "-I{rtos.path}/portable/CMSIS/nrf52" "-I{build.core.path}/sysview/SEGGER" "-I{build.core.path}/sysview/Config" "-I{runtime.platform.path}/libraries/Adafruit_TinyUSB_Arduino/src/arduino"
|
||||
|
||||
# Compile patterns
|
||||
# ----------------
|
||||
|
||||
## Compile c files
|
||||
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} '-DARDUINO_BSP_VERSION="{version}"' {compiler.c.extra_flags} {build.extra_flags} {build.flags.nrf} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile c++ files
|
||||
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} '-DARDUINO_BSP_VERSION="{version}"' {compiler.cpp.extra_flags} {build.extra_flags} {build.flags.nrf} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Compile S files
|
||||
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.flags.nrf} {includes} "{source_file}" -o "{object_file}"
|
||||
|
||||
## Create archives
|
||||
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
|
||||
|
||||
## Combine gc-sections, archives, and objects
|
||||
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-L{build.core.path}/linker" "-T{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} -Wl,--start-group {compiler.arm.cmsis.ldflags} -lm "{build.path}/{archive_file}" {compiler.libraries.ldflags} -Wl,--end-group
|
||||
|
||||
## Create output (bin file)
|
||||
#recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2bin.cmd}" {compiler.elf2bin.flags} {compiler.elf2bin.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
|
||||
|
||||
## Create output (hex file)
|
||||
recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
|
||||
|
||||
## Create dfu package zip file
|
||||
recipe.objcopy.zip.pattern="{tools.nrfutil.cmd}" dfu genpkg --dev-type 0x0052 --sd-req {build.sd_fwid} --application "{build.path}/{build.project_name}.hex" "{build.path}/{build.project_name}.zip"
|
||||
|
||||
## Create uf2 file
|
||||
#recipe.objcopy.uf2.pattern=python "{runtime.platform.path}/tools/uf2conv/uf2conv.py" -f 0xADA52840 -c -o "{build.path}/{build.project_name}.uf2" "{build.path}/{build.project_name}.hex"
|
||||
|
||||
## Save bin
|
||||
recipe.output.tmp_file_bin={build.project_name}.bin
|
||||
recipe.output.save_file_bin={build.project_name}.save.bin
|
||||
|
||||
## Save hex
|
||||
recipe.output.tmp_file_hex={build.project_name}.hex
|
||||
recipe.output.save_file_hexu={build.project_name}.save.hex
|
||||
|
||||
## Compute size
|
||||
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
|
||||
recipe.size.regex=^(?:\.text|\.data|)\s+([0-9]+).*
|
||||
recipe.size.regex.data=^(?:\.data|\.bss)\s+([0-9]+).*
|
||||
|
||||
## Export Compiled Binary
|
||||
recipe.output.tmp_file={build.project_name}.hex
|
||||
recipe.output.save_file={build.project_name}.{build.variant}.hex
|
||||
|
||||
#***************************************************
|
||||
# adafruit-nrfutil for uploading
|
||||
# https://github.com/adafruit/Adafruit_nRF52_nrfutil
|
||||
# pre-built binaries are provided for macos and windows
|
||||
#***************************************************
|
||||
tools.nrfutil.cmd=adafruit-nrfutil
|
||||
tools.nrfutil.cmd.windows={runtime.platform.path}/tools/adafruit-nrfutil/win32/adafruit-nrfutil.exe
|
||||
tools.nrfutil.cmd.macosx={runtime.platform.path}/tools/adafruit-nrfutil/macos/adafruit-nrfutil
|
||||
|
||||
tools.nrfutil.upload.params.verbose=--verbose
|
||||
tools.nrfutil.upload.params.quiet=
|
||||
tools.nrfutil.upload.pattern="{cmd}" {upload.verbose} dfu serial -pkg "{build.path}/{build.project_name}.zip" -p {serial.port} -b 115200 --singlebank
|
||||
|
||||
#***************************************************
|
||||
# Burning bootloader with either jlink or nrfutil
|
||||
#***************************************************
|
||||
|
||||
# Bootloader version
|
||||
tools.bootburn.bootloader.file={runtime.platform.path}/bootloader/{build.variant}/{build.variant}_bootloader-0.6.2_{build.sd_name}_{build.sd_version}
|
||||
|
||||
tools.bootburn.bootloader.params.verbose=
|
||||
tools.bootburn.bootloader.params.quiet=
|
||||
tools.bootburn.bootloader.pattern={program.burn_pattern}
|
||||
|
||||
# erase flash page while programming
|
||||
tools.bootburn.erase.params.verbose=
|
||||
tools.bootburn.erase.params.quiet=
|
||||
tools.bootburn.erase.pattern=
|
||||
|
@@ -6,7 +6,7 @@
|
||||
#define __PINS_ARDUINO__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" unsigned int PINCOUNT_fn();
|
||||
extern "C" unsigned int PINCOUNT_fn();
|
||||
#endif
|
||||
|
||||
// Pin count
|
||||
|
@@ -44,7 +44,7 @@ typedef uint16_t word;
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
@@ -100,25 +100,25 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
#define min(a,b) \
|
||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
|
@@ -36,10 +36,15 @@
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
while (size--) {
|
||||
if (write(*buffer++)) n++;
|
||||
else break;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -80,46 +85,64 @@ size_t Print::print(unsigned int n, int base)
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0) {
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
} else if (base == 10) {
|
||||
if (n < 0) {
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0) return write(n);
|
||||
else return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0) {
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
} else if (base == 10) {
|
||||
if (n < 0) {
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0) return write(n);
|
||||
else return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
@@ -253,14 +276,16 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2) base = 10;
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while(n);
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
}
|
||||
@@ -268,23 +293,23 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
// size_t Print::printULLNumber(unsigned long long n, uint8_t base)
|
||||
// {
|
||||
// // if limited to base 10 and 16 the bufsize can be smaller
|
||||
// char buf[65];
|
||||
// char *str = &buf[64];
|
||||
// // if limited to base 10 and 16 the bufsize can be smaller
|
||||
// char buf[65];
|
||||
// char *str = &buf[64];
|
||||
|
||||
// *str = '\0';
|
||||
// *str = '\0';
|
||||
|
||||
// // prevent crash if called with base == 1
|
||||
// if (base < 2) base = 10;
|
||||
// // prevent crash if called with base == 1
|
||||
// if (base < 2) base = 10;
|
||||
|
||||
// do {
|
||||
// unsigned long long t = n / base;
|
||||
// char c = n - t * base; // faster than c = n%base;
|
||||
// n = t;
|
||||
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
// } while(n);
|
||||
// do {
|
||||
// unsigned long long t = n / base;
|
||||
// char c = n - t * base; // faster than c = n%base;
|
||||
// n = t;
|
||||
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
// } while(n);
|
||||
|
||||
// return write(str);
|
||||
// return write(str);
|
||||
// }
|
||||
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
@@ -296,11 +321,13 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2) base = 10;
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
@@ -311,27 +338,29 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q*th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j=0; j < innerLoops; j++)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r/base;
|
||||
buf[i++] = r - qq*base;
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16/base;
|
||||
buf[i++] = n16 - qq*base;
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
@@ -347,10 +376,17 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number)) return print("nan");
|
||||
if (isinf(number)) return print("inf");
|
||||
if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
@@ -361,7 +397,8 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for (uint8_t i=0; i<digits; ++i)
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
@@ -372,7 +409,8 @@ size_t Print::printFloat(double number, int digits)
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0) {
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
@@ -390,31 +428,39 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0) return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for(int i=0; i<len; i++)
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 ) print(delim);
|
||||
if ( byteline && (i%byteline == 0) ) println();
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len*3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0) return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for(int i=0; i<len; i++)
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0) print(delim);
|
||||
if ( byteline && (i%byteline == 0) ) println();
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
this->printf("%02X", buffer[len-1-i]);
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len*3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
@@ -38,26 +38,42 @@ class Print
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1) { write_error = err; }
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError() { return write_error; }
|
||||
void clearWriteError() { setWriteError(0); }
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str) {
|
||||
if (str == NULL) return 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite() { return 0; }
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
@@ -90,14 +106,14 @@ class Print
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim=' ', int byteline = 0)
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim=' ', int byteline = 0)
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ typedef uint16_t word;
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
@@ -100,25 +100,25 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
#define min(a,b) \
|
||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
|
@@ -36,10 +36,15 @@
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
while (size--) {
|
||||
if (write(*buffer++)) n++;
|
||||
else break;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -80,46 +85,64 @@ size_t Print::print(unsigned int n, int base)
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0) {
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
} else if (base == 10) {
|
||||
if (n < 0) {
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0) return write(n);
|
||||
else return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0) {
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
} else if (base == 10) {
|
||||
if (n < 0) {
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0) return write(n);
|
||||
else return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
@@ -253,14 +276,16 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2) base = 10;
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while(n);
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
}
|
||||
@@ -268,23 +293,23 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
// size_t Print::printULLNumber(unsigned long long n, uint8_t base)
|
||||
// {
|
||||
// // if limited to base 10 and 16 the bufsize can be smaller
|
||||
// char buf[65];
|
||||
// char *str = &buf[64];
|
||||
// // if limited to base 10 and 16 the bufsize can be smaller
|
||||
// char buf[65];
|
||||
// char *str = &buf[64];
|
||||
|
||||
// *str = '\0';
|
||||
// *str = '\0';
|
||||
|
||||
// // prevent crash if called with base == 1
|
||||
// if (base < 2) base = 10;
|
||||
// // prevent crash if called with base == 1
|
||||
// if (base < 2) base = 10;
|
||||
|
||||
// do {
|
||||
// unsigned long long t = n / base;
|
||||
// char c = n - t * base; // faster than c = n%base;
|
||||
// n = t;
|
||||
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
// } while(n);
|
||||
// do {
|
||||
// unsigned long long t = n / base;
|
||||
// char c = n - t * base; // faster than c = n%base;
|
||||
// n = t;
|
||||
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
// } while(n);
|
||||
|
||||
// return write(str);
|
||||
// return write(str);
|
||||
// }
|
||||
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
@@ -296,11 +321,13 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2) base = 10;
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
@@ -311,27 +338,29 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q*th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j=0; j < innerLoops; j++)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r/base;
|
||||
buf[i++] = r - qq*base;
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16/base;
|
||||
buf[i++] = n16 - qq*base;
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
@@ -347,10 +376,17 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number)) return print("nan");
|
||||
if (isinf(number)) return print("inf");
|
||||
if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
@@ -361,7 +397,8 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for (uint8_t i=0; i<digits; ++i)
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
@@ -372,7 +409,8 @@ size_t Print::printFloat(double number, int digits)
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0) {
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
@@ -390,31 +428,39 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0) return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for(int i=0; i<len; i++)
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 ) print(delim);
|
||||
if ( byteline && (i%byteline == 0) ) println();
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len*3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0) return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for(int i=0; i<len; i++)
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0) print(delim);
|
||||
if ( byteline && (i%byteline == 0) ) println();
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
this->printf("%02X", buffer[len-1-i]);
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len*3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
@@ -38,26 +38,42 @@ class Print
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1) { write_error = err; }
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError() { return write_error; }
|
||||
void clearWriteError() { setWriteError(0); }
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str) {
|
||||
if (str == NULL) return 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite() { return 0; }
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
@@ -90,14 +106,14 @@ class Print
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim=' ', int byteline = 0)
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim=' ', int byteline = 0)
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ typedef uint16_t word;
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
@@ -100,25 +100,25 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
#define min(a,b) \
|
||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
|
@@ -36,10 +36,15 @@
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
while (size--) {
|
||||
if (write(*buffer++)) n++;
|
||||
else break;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -80,46 +85,64 @@ size_t Print::print(unsigned int n, int base)
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0) {
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
} else if (base == 10) {
|
||||
if (n < 0) {
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0) return write(n);
|
||||
else return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0) {
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
} else if (base == 10) {
|
||||
if (n < 0) {
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0) return write(n);
|
||||
else return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
@@ -253,14 +276,16 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2) base = 10;
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while(n);
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
}
|
||||
@@ -268,23 +293,23 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
// size_t Print::printULLNumber(unsigned long long n, uint8_t base)
|
||||
// {
|
||||
// // if limited to base 10 and 16 the bufsize can be smaller
|
||||
// char buf[65];
|
||||
// char *str = &buf[64];
|
||||
// // if limited to base 10 and 16 the bufsize can be smaller
|
||||
// char buf[65];
|
||||
// char *str = &buf[64];
|
||||
|
||||
// *str = '\0';
|
||||
// *str = '\0';
|
||||
|
||||
// // prevent crash if called with base == 1
|
||||
// if (base < 2) base = 10;
|
||||
// // prevent crash if called with base == 1
|
||||
// if (base < 2) base = 10;
|
||||
|
||||
// do {
|
||||
// unsigned long long t = n / base;
|
||||
// char c = n - t * base; // faster than c = n%base;
|
||||
// n = t;
|
||||
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
// } while(n);
|
||||
// do {
|
||||
// unsigned long long t = n / base;
|
||||
// char c = n - t * base; // faster than c = n%base;
|
||||
// n = t;
|
||||
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
// } while(n);
|
||||
|
||||
// return write(str);
|
||||
// return write(str);
|
||||
// }
|
||||
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
@@ -296,11 +321,13 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2) base = 10;
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
@@ -311,27 +338,29 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q*th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j=0; j < innerLoops; j++)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r/base;
|
||||
buf[i++] = r - qq*base;
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16/base;
|
||||
buf[i++] = n16 - qq*base;
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
@@ -347,10 +376,17 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number)) return print("nan");
|
||||
if (isinf(number)) return print("inf");
|
||||
if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
@@ -361,7 +397,8 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for (uint8_t i=0; i<digits; ++i)
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
@@ -372,7 +409,8 @@ size_t Print::printFloat(double number, int digits)
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0) {
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
@@ -390,31 +428,39 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0) return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for(int i=0; i<len; i++)
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 ) print(delim);
|
||||
if ( byteline && (i%byteline == 0) ) println();
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len*3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0) return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for(int i=0; i<len; i++)
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0) print(delim);
|
||||
if ( byteline && (i%byteline == 0) ) println();
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
this->printf("%02X", buffer[len-1-i]);
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len*3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
@@ -38,26 +38,42 @@ class Print
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1) { write_error = err; }
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError() { return write_error; }
|
||||
void clearWriteError() { setWriteError(0); }
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str) {
|
||||
if (str == NULL) return 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite() { return 0; }
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
@@ -90,14 +106,14 @@ class Print
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim=' ', int byteline = 0)
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim=' ', int byteline = 0)
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ typedef uint16_t word;
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
@@ -100,25 +100,25 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
#define min(a,b) \
|
||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
|
@@ -36,10 +36,15 @@
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
while (size--) {
|
||||
if (write(*buffer++)) n++;
|
||||
else break;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -80,46 +85,64 @@ size_t Print::print(unsigned int n, int base)
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0) {
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
} else if (base == 10) {
|
||||
if (n < 0) {
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0) return write(n);
|
||||
else return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0) {
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
} else if (base == 10) {
|
||||
if (n < 0) {
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0) return write(n);
|
||||
else return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
@@ -253,14 +276,16 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2) base = 10;
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while(n);
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
}
|
||||
@@ -268,23 +293,23 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
// size_t Print::printULLNumber(unsigned long long n, uint8_t base)
|
||||
// {
|
||||
// // if limited to base 10 and 16 the bufsize can be smaller
|
||||
// char buf[65];
|
||||
// char *str = &buf[64];
|
||||
// // if limited to base 10 and 16 the bufsize can be smaller
|
||||
// char buf[65];
|
||||
// char *str = &buf[64];
|
||||
|
||||
// *str = '\0';
|
||||
// *str = '\0';
|
||||
|
||||
// // prevent crash if called with base == 1
|
||||
// if (base < 2) base = 10;
|
||||
// // prevent crash if called with base == 1
|
||||
// if (base < 2) base = 10;
|
||||
|
||||
// do {
|
||||
// unsigned long long t = n / base;
|
||||
// char c = n - t * base; // faster than c = n%base;
|
||||
// n = t;
|
||||
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
// } while(n);
|
||||
// do {
|
||||
// unsigned long long t = n / base;
|
||||
// char c = n - t * base; // faster than c = n%base;
|
||||
// n = t;
|
||||
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
// } while(n);
|
||||
|
||||
// return write(str);
|
||||
// return write(str);
|
||||
// }
|
||||
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
@@ -296,11 +321,13 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2) base = 10;
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
@@ -311,27 +338,29 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q*th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j=0; j < innerLoops; j++)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r/base;
|
||||
buf[i++] = r - qq*base;
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16/base;
|
||||
buf[i++] = n16 - qq*base;
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
@@ -347,10 +376,17 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number)) return print("nan");
|
||||
if (isinf(number)) return print("inf");
|
||||
if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
@@ -361,7 +397,8 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for (uint8_t i=0; i<digits; ++i)
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
@@ -372,7 +409,8 @@ size_t Print::printFloat(double number, int digits)
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0) {
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
@@ -390,31 +428,39 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0) return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for(int i=0; i<len; i++)
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 ) print(delim);
|
||||
if ( byteline && (i%byteline == 0) ) println();
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len*3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0) return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for(int i=0; i<len; i++)
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0) print(delim);
|
||||
if ( byteline && (i%byteline == 0) ) println();
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
this->printf("%02X", buffer[len-1-i]);
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len*3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
@@ -38,26 +38,42 @@ class Print
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1) { write_error = err; }
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError() { return write_error; }
|
||||
void clearWriteError() { setWriteError(0); }
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str) {
|
||||
if (str == NULL) return 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite() { return 0; }
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
@@ -90,14 +106,14 @@ class Print
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim=' ', int byteline = 0)
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim=' ', int byteline = 0)
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ typedef uint16_t word;
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
@@ -100,25 +100,25 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
#define min(a,b) \
|
||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
|
@@ -36,10 +36,15 @@
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
while (size--) {
|
||||
if (write(*buffer++)) n++;
|
||||
else break;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -80,46 +85,64 @@ size_t Print::print(unsigned int n, int base)
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0) {
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
} else if (base == 10) {
|
||||
if (n < 0) {
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0) return write(n);
|
||||
else return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0) {
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
} else if (base == 10) {
|
||||
if (n < 0) {
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0) return write(n);
|
||||
else return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
@@ -253,14 +276,16 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2) base = 10;
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while(n);
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
}
|
||||
@@ -268,23 +293,23 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
// size_t Print::printULLNumber(unsigned long long n, uint8_t base)
|
||||
// {
|
||||
// // if limited to base 10 and 16 the bufsize can be smaller
|
||||
// char buf[65];
|
||||
// char *str = &buf[64];
|
||||
// // if limited to base 10 and 16 the bufsize can be smaller
|
||||
// char buf[65];
|
||||
// char *str = &buf[64];
|
||||
|
||||
// *str = '\0';
|
||||
// *str = '\0';
|
||||
|
||||
// // prevent crash if called with base == 1
|
||||
// if (base < 2) base = 10;
|
||||
// // prevent crash if called with base == 1
|
||||
// if (base < 2) base = 10;
|
||||
|
||||
// do {
|
||||
// unsigned long long t = n / base;
|
||||
// char c = n - t * base; // faster than c = n%base;
|
||||
// n = t;
|
||||
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
// } while(n);
|
||||
// do {
|
||||
// unsigned long long t = n / base;
|
||||
// char c = n - t * base; // faster than c = n%base;
|
||||
// n = t;
|
||||
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
// } while(n);
|
||||
|
||||
// return write(str);
|
||||
// return write(str);
|
||||
// }
|
||||
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
@@ -296,11 +321,13 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2) base = 10;
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
@@ -311,27 +338,29 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q*th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j=0; j < innerLoops; j++)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r/base;
|
||||
buf[i++] = r - qq*base;
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16/base;
|
||||
buf[i++] = n16 - qq*base;
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
@@ -347,10 +376,17 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number)) return print("nan");
|
||||
if (isinf(number)) return print("inf");
|
||||
if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
@@ -361,7 +397,8 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for (uint8_t i=0; i<digits; ++i)
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
@@ -372,7 +409,8 @@ size_t Print::printFloat(double number, int digits)
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0) {
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
@@ -390,31 +428,39 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0) return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for(int i=0; i<len; i++)
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 ) print(delim);
|
||||
if ( byteline && (i%byteline == 0) ) println();
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len*3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0) return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for(int i=0; i<len; i++)
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0) print(delim);
|
||||
if ( byteline && (i%byteline == 0) ) println();
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
this->printf("%02X", buffer[len-1-i]);
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len*3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
@@ -38,26 +38,42 @@ class Print
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1) { write_error = err; }
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError() { return write_error; }
|
||||
void clearWriteError() { setWriteError(0); }
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str) {
|
||||
if (str == NULL) return 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite() { return 0; }
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
@@ -90,14 +106,14 @@ class Print
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim=' ', int byteline = 0)
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim=' ', int byteline = 0)
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ typedef uint16_t word;
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
@@ -100,25 +100,25 @@ int __debug_buf(const char* head, char* buf, int len);
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
|
||||
#ifdef __cplusplus
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#ifndef min
|
||||
#define min(a,b) \
|
||||
@@ -164,18 +164,18 @@ static inline unsigned char __interruptsStatus(void)
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
// Interrupts
|
||||
#define digitalPinToInterrupt(P) ( P )
|
||||
#endif
|
||||
|
||||
// USB
|
||||
#ifdef USE_TINYUSB
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#include "Adafruit_TinyUSB_Core.h"
|
||||
#else
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#include "USB/USBDesc.h"
|
||||
#include "USB/USBCore.h"
|
||||
#include "USB/USBAPI.h"
|
||||
#include "USB/USB_host.h"
|
||||
#endif
|
||||
|
||||
#endif // Arduino_h
|
||||
|
@@ -36,10 +36,15 @@
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
while (size--) {
|
||||
if (write(*buffer++)) n++;
|
||||
else break;
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (write(*buffer++))
|
||||
n++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -80,46 +85,64 @@ size_t Print::print(unsigned int n, int base)
|
||||
|
||||
size_t Print::print(long n, int base)
|
||||
{
|
||||
if (base == 0) {
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
} else if (base == 10) {
|
||||
if (n < 0) {
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printNumber(n, 10);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return printNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long n, int base)
|
||||
{
|
||||
if (base == 0) return write(n);
|
||||
else return printNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(long long n, int base)
|
||||
{
|
||||
if (base == 0) {
|
||||
if (base == 0)
|
||||
{
|
||||
return write(n);
|
||||
} else if (base == 10) {
|
||||
if (n < 0) {
|
||||
}
|
||||
else if (base == 10)
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
int t = print('-');
|
||||
n = -n;
|
||||
return printULLNumber(n, 10) + t;
|
||||
}
|
||||
|
||||
return printULLNumber(n, 10);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
}
|
||||
|
||||
size_t Print::print(unsigned long long n, int base)
|
||||
{
|
||||
if (base == 0) return write(n);
|
||||
else return printULLNumber(n, base);
|
||||
if (base == 0)
|
||||
return write(n);
|
||||
else
|
||||
return printULLNumber(n, base);
|
||||
}
|
||||
|
||||
size_t Print::print(double n, int digits)
|
||||
@@ -253,14 +276,16 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
*str = '\0';
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2) base = 10;
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
|
||||
*--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
} while(n);
|
||||
} while (n);
|
||||
|
||||
return write(str);
|
||||
}
|
||||
@@ -268,23 +293,23 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
|
||||
// REFERENCE IMPLEMENTATION FOR ULL
|
||||
// size_t Print::printULLNumber(unsigned long long n, uint8_t base)
|
||||
// {
|
||||
// // if limited to base 10 and 16 the bufsize can be smaller
|
||||
// char buf[65];
|
||||
// char *str = &buf[64];
|
||||
// // if limited to base 10 and 16 the bufsize can be smaller
|
||||
// char buf[65];
|
||||
// char *str = &buf[64];
|
||||
|
||||
// *str = '\0';
|
||||
// *str = '\0';
|
||||
|
||||
// // prevent crash if called with base == 1
|
||||
// if (base < 2) base = 10;
|
||||
// // prevent crash if called with base == 1
|
||||
// if (base < 2) base = 10;
|
||||
|
||||
// do {
|
||||
// unsigned long long t = n / base;
|
||||
// char c = n - t * base; // faster than c = n%base;
|
||||
// n = t;
|
||||
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
// } while(n);
|
||||
// do {
|
||||
// unsigned long long t = n / base;
|
||||
// char c = n - t * base; // faster than c = n%base;
|
||||
// n = t;
|
||||
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
|
||||
// } while(n);
|
||||
|
||||
// return write(str);
|
||||
// return write(str);
|
||||
// }
|
||||
|
||||
// FAST IMPLEMENTATION FOR ULL
|
||||
@@ -296,11 +321,13 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
uint8_t innerLoops = 0;
|
||||
|
||||
// prevent crash if called with base == 1
|
||||
if (base < 2) base = 10;
|
||||
if (base < 2)
|
||||
base = 10;
|
||||
|
||||
// process chunks that fit in "16 bit math".
|
||||
uint16_t top = 0xFFFF / base;
|
||||
uint16_t th16 = 1;
|
||||
|
||||
while (th16 < top)
|
||||
{
|
||||
th16 *= base;
|
||||
@@ -311,27 +338,29 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
{
|
||||
// 64 bit math part
|
||||
uint64_t q = n64 / th16;
|
||||
uint16_t r = n64 - q*th16;
|
||||
uint16_t r = n64 - q * th16;
|
||||
n64 = q;
|
||||
|
||||
// 16 bit math loop to do remainder. (note buffer is filled reverse)
|
||||
for (uint8_t j=0; j < innerLoops; j++)
|
||||
for (uint8_t j = 0; j < innerLoops; j++)
|
||||
{
|
||||
uint16_t qq = r/base;
|
||||
buf[i++] = r - qq*base;
|
||||
uint16_t qq = r / base;
|
||||
buf[i++] = r - qq * base;
|
||||
r = qq;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16/base;
|
||||
buf[i++] = n16 - qq*base;
|
||||
uint16_t qq = n16 / base;
|
||||
buf[i++] = n16 - qq * base;
|
||||
n16 = qq;
|
||||
}
|
||||
|
||||
size_t bytes = i;
|
||||
|
||||
for (; i > 0; i--)
|
||||
write((char) (buf[i - 1] < 10 ?
|
||||
'0' + buf[i - 1] :
|
||||
@@ -347,10 +376,17 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
size_t n = 0;
|
||||
|
||||
if (isnan(number)) return print("nan");
|
||||
if (isinf(number)) return print("inf");
|
||||
if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
|
||||
if (isnan(number))
|
||||
return print("nan");
|
||||
|
||||
if (isinf(number))
|
||||
return print("inf");
|
||||
|
||||
if (number > 4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
if (number < -4294967040.0)
|
||||
return print ("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0)
|
||||
@@ -361,7 +397,8 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for (uint8_t i=0; i<digits; ++i)
|
||||
|
||||
for (uint8_t i = 0; i < digits; ++i)
|
||||
rounding /= 10.0;
|
||||
|
||||
number += rounding;
|
||||
@@ -372,7 +409,8 @@ size_t Print::printFloat(double number, int digits)
|
||||
n += print(int_part);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0) {
|
||||
if (digits > 0)
|
||||
{
|
||||
n += print(".");
|
||||
}
|
||||
|
||||
@@ -390,31 +428,39 @@ size_t Print::printFloat(double number, int digits)
|
||||
|
||||
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0) return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for(int i=0; i<len; i++)
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if ( i != 0 ) print(delim);
|
||||
if ( byteline && (i%byteline == 0) ) println();
|
||||
if ( i != 0 )
|
||||
print(delim);
|
||||
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[i]);
|
||||
}
|
||||
|
||||
return (len*3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
|
||||
{
|
||||
if (buffer == NULL || len == 0) return 0;
|
||||
if (buffer == NULL || len == 0)
|
||||
return 0;
|
||||
|
||||
for(int i=0; i<len; i++)
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (i != 0) print(delim);
|
||||
if ( byteline && (i%byteline == 0) ) println();
|
||||
if (i != 0)
|
||||
print(delim);
|
||||
|
||||
this->printf("%02X", buffer[len-1-i]);
|
||||
if ( byteline && (i % byteline == 0) )
|
||||
println();
|
||||
|
||||
this->printf("%02X", buffer[len - 1 - i]);
|
||||
}
|
||||
|
||||
return (len*3 - 1);
|
||||
return (len * 3 - 1);
|
||||
}
|
||||
|
||||
|
@@ -38,26 +38,42 @@ class Print
|
||||
size_t printULLNumber(unsigned long long, uint8_t);
|
||||
size_t printFloat(double, int);
|
||||
protected:
|
||||
void setWriteError(int err = 1) { write_error = err; }
|
||||
void setWriteError(int err = 1)
|
||||
{
|
||||
write_error = err;
|
||||
}
|
||||
public:
|
||||
Print() : write_error(0) {}
|
||||
|
||||
int getWriteError() { return write_error; }
|
||||
void clearWriteError() { setWriteError(0); }
|
||||
int getWriteError()
|
||||
{
|
||||
return write_error;
|
||||
}
|
||||
void clearWriteError()
|
||||
{
|
||||
setWriteError(0);
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
size_t write(const char *str) {
|
||||
if (str == NULL) return 0;
|
||||
size_t write(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return 0;
|
||||
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
size_t write(const char *buffer, size_t size)
|
||||
{
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
|
||||
// default to zero, meaning "a single write may block"
|
||||
// should be overridden by subclasses with buffering
|
||||
virtual int availableForWrite() { return 0; }
|
||||
virtual int availableForWrite()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t print(const __FlashStringHelper *);
|
||||
size_t print(const String &);
|
||||
@@ -90,14 +106,14 @@ class Print
|
||||
|
||||
size_t printf(const char * format, ...);
|
||||
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim=' ', int byteline = 0)
|
||||
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim=' ', int byteline = 0)
|
||||
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
|
||||
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
|
||||
{
|
||||
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
|
||||
}
|
||||
|
@@ -1,28 +1,28 @@
|
||||
/* Copyright (C) 2012 mbed.org, MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef LWIPOPTS_H
|
||||
#define LWIPOPTS_H
|
||||
|
||||
// Workaround for Linux timeval
|
||||
#if defined (TOOLCHAIN_GCC)
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include "nsapi_types.h"
|
||||
#include "mbed_retarget.h"
|
||||
@@ -35,7 +35,7 @@
|
||||
#define NO_SYS 0
|
||||
|
||||
#if !MBED_CONF_LWIP_IPV4_ENABLED && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#endif
|
||||
|
||||
#define LWIP_IPV4 MBED_CONF_LWIP_IPV4_ENABLED
|
||||
@@ -47,16 +47,16 @@
|
||||
// On dual stack configuration how long to wait for both or preferred stack
|
||||
// addresses before completing bring up.
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
|
||||
|
||||
@@ -68,52 +68,52 @@
|
||||
#define PREF_IPV6 2
|
||||
|
||||
#if MBED_CONF_LWIP_IP_VER_PREF == 6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#elif MBED_CONF_LWIP_IP_VER_PREF == 4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#else
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#endif
|
||||
|
||||
#undef LWIP_DEBUG
|
||||
#if MBED_CONF_LWIP_DEBUG_ENABLED
|
||||
#define LWIP_DEBUG 1
|
||||
#define LWIP_DEBUG 1
|
||||
#endif
|
||||
|
||||
#if NO_SYS == 0
|
||||
#include "cmsis_os2.h"
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -143,16 +143,16 @@
|
||||
#define PBUF_POOL_SIZE MBED_CONF_LWIP_PBUF_POOL_SIZE
|
||||
|
||||
#ifdef MBED_CONF_LWIP_PBUF_POOL_BUFSIZE
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#else
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MEM_SIZE MBED_CONF_LWIP_MEM_SIZE
|
||||
@@ -181,14 +181,14 @@
|
||||
#define MEMP_NUM_NETCONN MBED_CONF_LWIP_SOCKET_MAX
|
||||
|
||||
#if MBED_CONF_LWIP_TCP_ENABLED
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
|
||||
#else
|
||||
#define LWIP_TCP 0
|
||||
#define LWIP_TCP 0
|
||||
#endif
|
||||
|
||||
#define LWIP_DNS 1
|
||||
@@ -251,13 +251,13 @@
|
||||
#define UDP_LPC_EMAC LWIP_DBG_OFF
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#else
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#endif
|
||||
|
||||
#define TRACE_TO_ASCII_HEX_DUMP 0
|
||||
@@ -269,18 +269,18 @@
|
||||
// Interface type configuration
|
||||
|
||||
#if MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#else
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#endif // MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
|
||||
#if MBED_CONF_LWIP_L3IP_ENABLED
|
||||
#define LWIP_L3IP 1
|
||||
#define LWIP_L3IP 1
|
||||
#else
|
||||
#define LWIP_L3IP 0
|
||||
#define LWIP_L3IP 0
|
||||
#endif
|
||||
|
||||
//Maximum size of network interface name
|
||||
@@ -291,27 +291,27 @@
|
||||
// Enable PPP for now either from lwIP PPP configuration (obsolete) or from PPP service configuration
|
||||
#if MBED_CONF_PPP_ENABLED || MBED_CONF_LWIP_PPP_ENABLED
|
||||
|
||||
#define PPP_SUPPORT 1
|
||||
#define PPP_SUPPORT 1
|
||||
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -320,7 +320,7 @@
|
||||
// Make sure we default these to off, so
|
||||
// LWIP doesn't default to on
|
||||
#ifndef LWIP_ARP
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ARP 0
|
||||
#endif
|
||||
|
||||
// Checksum-on-copy disabled due to https://savannah.nongnu.org/bugs/?50914
|
||||
@@ -337,9 +337,9 @@
|
||||
#include "lwip_tcp_isn.h"
|
||||
#define LWIP_HOOK_TCP_ISN lwip_hook_tcp_isn
|
||||
#ifdef MBEDTLS_MD5_C
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#else
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#endif
|
||||
|
||||
#define LWIP_ND6_RDNSS_MAX_DNS_SERVERS MBED_CONF_LWIP_ND6_RDNSS_MAX_DNS_SERVERS
|
||||
|
@@ -1,29 +1,36 @@
|
||||
#include "MbedUdp.h"
|
||||
|
||||
arduino::MbedUDP::MbedUDP() {
|
||||
arduino::MbedUDP::MbedUDP()
|
||||
{
|
||||
_packet_buffer = new uint8_t[WIFI_UDP_BUFFER_SIZE];
|
||||
_current_packet = NULL;
|
||||
_current_packet_size = 0;
|
||||
// if this allocation fails then ::begin will fail
|
||||
}
|
||||
|
||||
arduino::MbedUDP::~MbedUDP() {
|
||||
arduino::MbedUDP::~MbedUDP()
|
||||
{
|
||||
delete[] _packet_buffer;
|
||||
}
|
||||
|
||||
uint8_t arduino::MbedUDP::begin(uint16_t port) {
|
||||
uint8_t arduino::MbedUDP::begin(uint16_t port)
|
||||
{
|
||||
// success = 1, fail = 0
|
||||
|
||||
nsapi_error_t rt = _socket.open(getNetwork());
|
||||
if (rt != NSAPI_ERROR_OK) {
|
||||
|
||||
if (rt != NSAPI_ERROR_OK)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (_socket.bind(port) < 0) {
|
||||
if (_socket.bind(port) < 0)
|
||||
{
|
||||
return 0; //Failed to bind UDP Socket to port
|
||||
}
|
||||
|
||||
if (!_packet_buffer) {
|
||||
if (!_packet_buffer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -33,15 +40,18 @@ uint8_t arduino::MbedUDP::begin(uint16_t port) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port) {
|
||||
uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port)
|
||||
{
|
||||
// success = 1, fail = 0
|
||||
if (begin(port) != 1) {
|
||||
if (begin(port) != 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SocketAddress socketAddress = SocketHelpers::socketAddressFromIpAddress(ip, port);
|
||||
|
||||
if (_socket.join_multicast_group(socketAddress) != NSAPI_ERROR_OK) {
|
||||
if (_socket.join_multicast_group(socketAddress) != NSAPI_ERROR_OK)
|
||||
{
|
||||
printf("Error joining the multicast group\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -49,18 +59,21 @@ uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void arduino::MbedUDP::stop() {
|
||||
void arduino::MbedUDP::stop()
|
||||
{
|
||||
_socket.close();
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::beginPacket(IPAddress ip, uint16_t port) {
|
||||
int arduino::MbedUDP::beginPacket(IPAddress ip, uint16_t port)
|
||||
{
|
||||
_host = SocketHelpers::socketAddressFromIpAddress(ip, port);
|
||||
//If IP is null and port is 0 the initialization failed
|
||||
txBuffer.clear();
|
||||
return (_host.get_ip_address() == nullptr && _host.get_port() == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::beginPacket(const char *host, uint16_t port) {
|
||||
int arduino::MbedUDP::beginPacket(const char *host, uint16_t port)
|
||||
{
|
||||
_host = SocketAddress(host, port);
|
||||
txBuffer.clear();
|
||||
getNetwork()->gethostbyname(host, &_host);
|
||||
@@ -68,54 +81,72 @@ int arduino::MbedUDP::beginPacket(const char *host, uint16_t port) {
|
||||
return (_host.get_ip_address() == nullptr && _host.get_port() == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::endPacket() {
|
||||
int arduino::MbedUDP::endPacket()
|
||||
{
|
||||
_socket.set_blocking(true);
|
||||
_socket.set_timeout(1000);
|
||||
|
||||
size_t size = txBuffer.available();
|
||||
uint8_t buffer[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
buffer[i] = txBuffer.read_char();
|
||||
}
|
||||
|
||||
nsapi_size_or_error_t ret = _socket.sendto(_host, buffer, size);
|
||||
_socket.set_blocking(false);
|
||||
_socket.set_timeout(0);
|
||||
if (ret < 0) {
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
// Write a single byte into the packet
|
||||
size_t arduino::MbedUDP::write(uint8_t byte) {
|
||||
size_t arduino::MbedUDP::write(uint8_t byte)
|
||||
{
|
||||
return write(&byte, 1);
|
||||
}
|
||||
|
||||
// Write size bytes from buffer into the packet
|
||||
size_t arduino::MbedUDP::write(const uint8_t *buffer, size_t size) {
|
||||
for (int i = 0; i<size; i++) {
|
||||
if (txBuffer.availableForStore()) {
|
||||
size_t arduino::MbedUDP::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
if (txBuffer.availableForStore())
|
||||
{
|
||||
txBuffer.store_char(buffer[i]);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::parsePacket() {
|
||||
int arduino::MbedUDP::parsePacket()
|
||||
{
|
||||
nsapi_size_or_error_t ret = _socket.recvfrom(&_remoteHost, _packet_buffer, WIFI_UDP_BUFFER_SIZE);
|
||||
|
||||
if (ret == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
if (ret == NSAPI_ERROR_WOULD_BLOCK)
|
||||
{
|
||||
// no data
|
||||
return 0;
|
||||
} else if (ret == NSAPI_ERROR_NO_SOCKET) {
|
||||
}
|
||||
else if (ret == NSAPI_ERROR_NO_SOCKET)
|
||||
{
|
||||
// socket was not created correctly.
|
||||
return -1;
|
||||
}
|
||||
// error codes below zero are errors
|
||||
else if (ret <= 0) {
|
||||
else if (ret <= 0)
|
||||
{
|
||||
// something else went wrong, need some tracing info...
|
||||
return -1;
|
||||
}
|
||||
@@ -127,27 +158,35 @@ int arduino::MbedUDP::parsePacket() {
|
||||
return _current_packet_size;
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::available() {
|
||||
int arduino::MbedUDP::available()
|
||||
{
|
||||
return _current_packet_size;
|
||||
}
|
||||
|
||||
// Read a single byte from the current packet
|
||||
int arduino::MbedUDP::read() {
|
||||
int arduino::MbedUDP::read()
|
||||
{
|
||||
// no current packet...
|
||||
if (_current_packet == NULL) {
|
||||
if (_current_packet == NULL)
|
||||
{
|
||||
// try reading the next frame, if there is no data return
|
||||
if (parsePacket() == 0) return -1;
|
||||
if (parsePacket() == 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
_current_packet++;
|
||||
|
||||
// check for overflow
|
||||
if (_current_packet > _packet_buffer + _current_packet_size) {
|
||||
if (_current_packet > _packet_buffer + _current_packet_size)
|
||||
{
|
||||
// try reading the next packet...
|
||||
if (parsePacket() > 0) {
|
||||
if (parsePacket() > 0)
|
||||
{
|
||||
// if so, read first byte of next packet;
|
||||
return read();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// no new data... not sure what to return here now
|
||||
return -1;
|
||||
}
|
||||
@@ -158,34 +197,46 @@ int arduino::MbedUDP::read() {
|
||||
|
||||
// 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
|
||||
int arduino::MbedUDP::read(unsigned char *buffer, size_t len) {
|
||||
int arduino::MbedUDP::read(unsigned char *buffer, size_t len)
|
||||
{
|
||||
// Q: does Arduino read() function handle fragmentation? I won't for now...
|
||||
if (_current_packet == NULL) {
|
||||
if (parsePacket() == 0) return 0;
|
||||
if (_current_packet == NULL)
|
||||
{
|
||||
if (parsePacket() == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// how much data do we have in the current packet?
|
||||
int offset = _current_packet - _packet_buffer;
|
||||
if (offset < 0) {
|
||||
|
||||
if (offset < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int max_bytes = _current_packet_size - offset;
|
||||
if (max_bytes < 0) {
|
||||
|
||||
if (max_bytes < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// at the end of the packet?
|
||||
if (max_bytes == 0) {
|
||||
if (max_bytes == 0)
|
||||
{
|
||||
// try read next packet...
|
||||
if (parsePacket() > 0) {
|
||||
if (parsePacket() > 0)
|
||||
{
|
||||
return read(buffer, len);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (len > (size_t)max_bytes) len = max_bytes;
|
||||
if (len > (size_t)max_bytes)
|
||||
len = max_bytes;
|
||||
|
||||
// copy to target buffer
|
||||
memcpy(buffer, _current_packet, len);
|
||||
@@ -195,21 +246,26 @@ int arduino::MbedUDP::read(unsigned char *buffer, size_t len) {
|
||||
return len;
|
||||
}
|
||||
|
||||
IPAddress arduino::MbedUDP::remoteIP() {
|
||||
IPAddress arduino::MbedUDP::remoteIP()
|
||||
{
|
||||
nsapi_addr_t address = _remoteHost.get_addr();
|
||||
return IPAddress(address.bytes[0], address.bytes[1], address.bytes[2], address.bytes[3]);
|
||||
}
|
||||
|
||||
uint16_t arduino::MbedUDP::remotePort() {
|
||||
uint16_t arduino::MbedUDP::remotePort()
|
||||
{
|
||||
return _remoteHost.get_port();
|
||||
}
|
||||
|
||||
void arduino::MbedUDP::flush() {
|
||||
void arduino::MbedUDP::flush()
|
||||
{
|
||||
// TODO: a real check to ensure transmission has been completed
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::peek() {
|
||||
if (_current_packet_size < 1) {
|
||||
int arduino::MbedUDP::peek()
|
||||
{
|
||||
if (_current_packet_size < 1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@@ -25,13 +25,15 @@
|
||||
#include "netsocket/UDPSocket.h"
|
||||
|
||||
#ifndef WIFI_UDP_BUFFER_SIZE
|
||||
#define WIFI_UDP_BUFFER_SIZE 508
|
||||
#define WIFI_UDP_BUFFER_SIZE 508
|
||||
#endif
|
||||
|
||||
namespace arduino {
|
||||
namespace arduino
|
||||
{
|
||||
|
||||
class MbedUDP : public UDP {
|
||||
private:
|
||||
class MbedUDP : public UDP
|
||||
{
|
||||
private:
|
||||
UDPSocket _socket; // Mbed OS socket
|
||||
SocketAddress _host; // Host to be used to send data
|
||||
SocketAddress _remoteHost; // Remote host that sent incoming packets
|
||||
@@ -45,10 +47,10 @@ private:
|
||||
|
||||
RingBufferN<WIFI_UDP_BUFFER_SIZE> txBuffer;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual NetworkInterface* getNetwork() = 0;
|
||||
|
||||
public:
|
||||
public:
|
||||
MbedUDP(); // Constructor
|
||||
~MbedUDP();
|
||||
virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||
@@ -85,7 +87,8 @@ public:
|
||||
virtual int read(unsigned char* buffer, size_t len);
|
||||
// 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) {
|
||||
virtual int read(char* buffer, size_t len)
|
||||
{
|
||||
return read((unsigned char*)buffer, len);
|
||||
};
|
||||
// Return the next byte from the current packet without moving on to the next byte
|
||||
|
@@ -1,28 +1,28 @@
|
||||
/* Copyright (C) 2012 mbed.org, MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef LWIPOPTS_H
|
||||
#define LWIPOPTS_H
|
||||
|
||||
// Workaround for Linux timeval
|
||||
#if defined (TOOLCHAIN_GCC)
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include "nsapi_types.h"
|
||||
#include "mbed_retarget.h"
|
||||
@@ -35,7 +35,7 @@
|
||||
#define NO_SYS 0
|
||||
|
||||
#if !MBED_CONF_LWIP_IPV4_ENABLED && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#endif
|
||||
|
||||
#define LWIP_IPV4 MBED_CONF_LWIP_IPV4_ENABLED
|
||||
@@ -47,16 +47,16 @@
|
||||
// On dual stack configuration how long to wait for both or preferred stack
|
||||
// addresses before completing bring up.
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
|
||||
|
||||
@@ -68,52 +68,52 @@
|
||||
#define PREF_IPV6 2
|
||||
|
||||
#if MBED_CONF_LWIP_IP_VER_PREF == 6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#elif MBED_CONF_LWIP_IP_VER_PREF == 4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#else
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#endif
|
||||
|
||||
#undef LWIP_DEBUG
|
||||
#if MBED_CONF_LWIP_DEBUG_ENABLED
|
||||
#define LWIP_DEBUG 1
|
||||
#define LWIP_DEBUG 1
|
||||
#endif
|
||||
|
||||
#if NO_SYS == 0
|
||||
#include "cmsis_os2.h"
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -143,16 +143,16 @@
|
||||
#define PBUF_POOL_SIZE MBED_CONF_LWIP_PBUF_POOL_SIZE
|
||||
|
||||
#ifdef MBED_CONF_LWIP_PBUF_POOL_BUFSIZE
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#else
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MEM_SIZE MBED_CONF_LWIP_MEM_SIZE
|
||||
@@ -181,14 +181,14 @@
|
||||
#define MEMP_NUM_NETCONN MBED_CONF_LWIP_SOCKET_MAX
|
||||
|
||||
#if MBED_CONF_LWIP_TCP_ENABLED
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
|
||||
#else
|
||||
#define LWIP_TCP 0
|
||||
#define LWIP_TCP 0
|
||||
#endif
|
||||
|
||||
#define LWIP_DNS 1
|
||||
@@ -251,13 +251,13 @@
|
||||
#define UDP_LPC_EMAC LWIP_DBG_OFF
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#else
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#endif
|
||||
|
||||
#define TRACE_TO_ASCII_HEX_DUMP 0
|
||||
@@ -269,18 +269,18 @@
|
||||
// Interface type configuration
|
||||
|
||||
#if MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#else
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#endif // MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
|
||||
#if MBED_CONF_LWIP_L3IP_ENABLED
|
||||
#define LWIP_L3IP 1
|
||||
#define LWIP_L3IP 1
|
||||
#else
|
||||
#define LWIP_L3IP 0
|
||||
#define LWIP_L3IP 0
|
||||
#endif
|
||||
|
||||
//Maximum size of network interface name
|
||||
@@ -291,27 +291,27 @@
|
||||
// Enable PPP for now either from lwIP PPP configuration (obsolete) or from PPP service configuration
|
||||
#if MBED_CONF_PPP_ENABLED || MBED_CONF_LWIP_PPP_ENABLED
|
||||
|
||||
#define PPP_SUPPORT 1
|
||||
#define PPP_SUPPORT 1
|
||||
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -320,7 +320,7 @@
|
||||
// Make sure we default these to off, so
|
||||
// LWIP doesn't default to on
|
||||
#ifndef LWIP_ARP
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ARP 0
|
||||
#endif
|
||||
|
||||
// Checksum-on-copy disabled due to https://savannah.nongnu.org/bugs/?50914
|
||||
@@ -337,9 +337,9 @@
|
||||
#include "lwip_tcp_isn.h"
|
||||
#define LWIP_HOOK_TCP_ISN lwip_hook_tcp_isn
|
||||
#ifdef MBEDTLS_MD5_C
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#else
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#endif
|
||||
|
||||
#define LWIP_ND6_RDNSS_MAX_DNS_SERVERS MBED_CONF_LWIP_ND6_RDNSS_MAX_DNS_SERVERS
|
||||
|
@@ -1,29 +1,36 @@
|
||||
#include "MbedUdp.h"
|
||||
|
||||
arduino::MbedUDP::MbedUDP() {
|
||||
arduino::MbedUDP::MbedUDP()
|
||||
{
|
||||
_packet_buffer = new uint8_t[WIFI_UDP_BUFFER_SIZE];
|
||||
_current_packet = NULL;
|
||||
_current_packet_size = 0;
|
||||
// if this allocation fails then ::begin will fail
|
||||
}
|
||||
|
||||
arduino::MbedUDP::~MbedUDP() {
|
||||
arduino::MbedUDP::~MbedUDP()
|
||||
{
|
||||
delete[] _packet_buffer;
|
||||
}
|
||||
|
||||
uint8_t arduino::MbedUDP::begin(uint16_t port) {
|
||||
uint8_t arduino::MbedUDP::begin(uint16_t port)
|
||||
{
|
||||
// success = 1, fail = 0
|
||||
|
||||
nsapi_error_t rt = _socket.open(getNetwork());
|
||||
if (rt != NSAPI_ERROR_OK) {
|
||||
|
||||
if (rt != NSAPI_ERROR_OK)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (_socket.bind(port) < 0) {
|
||||
if (_socket.bind(port) < 0)
|
||||
{
|
||||
return 0; //Failed to bind UDP Socket to port
|
||||
}
|
||||
|
||||
if (!_packet_buffer) {
|
||||
if (!_packet_buffer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -33,15 +40,18 @@ uint8_t arduino::MbedUDP::begin(uint16_t port) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port) {
|
||||
uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port)
|
||||
{
|
||||
// success = 1, fail = 0
|
||||
if (begin(port) != 1) {
|
||||
if (begin(port) != 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SocketAddress socketAddress = SocketHelpers::socketAddressFromIpAddress(ip, port);
|
||||
|
||||
if (_socket.join_multicast_group(socketAddress) != NSAPI_ERROR_OK) {
|
||||
if (_socket.join_multicast_group(socketAddress) != NSAPI_ERROR_OK)
|
||||
{
|
||||
printf("Error joining the multicast group\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -49,18 +59,21 @@ uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void arduino::MbedUDP::stop() {
|
||||
void arduino::MbedUDP::stop()
|
||||
{
|
||||
_socket.close();
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::beginPacket(IPAddress ip, uint16_t port) {
|
||||
int arduino::MbedUDP::beginPacket(IPAddress ip, uint16_t port)
|
||||
{
|
||||
_host = SocketHelpers::socketAddressFromIpAddress(ip, port);
|
||||
//If IP is null and port is 0 the initialization failed
|
||||
txBuffer.clear();
|
||||
return (_host.get_ip_address() == nullptr && _host.get_port() == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::beginPacket(const char *host, uint16_t port) {
|
||||
int arduino::MbedUDP::beginPacket(const char *host, uint16_t port)
|
||||
{
|
||||
_host = SocketAddress(host, port);
|
||||
txBuffer.clear();
|
||||
getNetwork()->gethostbyname(host, &_host);
|
||||
@@ -68,54 +81,72 @@ int arduino::MbedUDP::beginPacket(const char *host, uint16_t port) {
|
||||
return (_host.get_ip_address() == nullptr && _host.get_port() == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::endPacket() {
|
||||
int arduino::MbedUDP::endPacket()
|
||||
{
|
||||
_socket.set_blocking(true);
|
||||
_socket.set_timeout(1000);
|
||||
|
||||
size_t size = txBuffer.available();
|
||||
uint8_t buffer[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
buffer[i] = txBuffer.read_char();
|
||||
}
|
||||
|
||||
nsapi_size_or_error_t ret = _socket.sendto(_host, buffer, size);
|
||||
_socket.set_blocking(false);
|
||||
_socket.set_timeout(0);
|
||||
if (ret < 0) {
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
// Write a single byte into the packet
|
||||
size_t arduino::MbedUDP::write(uint8_t byte) {
|
||||
size_t arduino::MbedUDP::write(uint8_t byte)
|
||||
{
|
||||
return write(&byte, 1);
|
||||
}
|
||||
|
||||
// Write size bytes from buffer into the packet
|
||||
size_t arduino::MbedUDP::write(const uint8_t *buffer, size_t size) {
|
||||
for (int i = 0; i<size; i++) {
|
||||
if (txBuffer.availableForStore()) {
|
||||
size_t arduino::MbedUDP::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
if (txBuffer.availableForStore())
|
||||
{
|
||||
txBuffer.store_char(buffer[i]);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::parsePacket() {
|
||||
int arduino::MbedUDP::parsePacket()
|
||||
{
|
||||
nsapi_size_or_error_t ret = _socket.recvfrom(&_remoteHost, _packet_buffer, WIFI_UDP_BUFFER_SIZE);
|
||||
|
||||
if (ret == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
if (ret == NSAPI_ERROR_WOULD_BLOCK)
|
||||
{
|
||||
// no data
|
||||
return 0;
|
||||
} else if (ret == NSAPI_ERROR_NO_SOCKET) {
|
||||
}
|
||||
else if (ret == NSAPI_ERROR_NO_SOCKET)
|
||||
{
|
||||
// socket was not created correctly.
|
||||
return -1;
|
||||
}
|
||||
// error codes below zero are errors
|
||||
else if (ret <= 0) {
|
||||
else if (ret <= 0)
|
||||
{
|
||||
// something else went wrong, need some tracing info...
|
||||
return -1;
|
||||
}
|
||||
@@ -127,27 +158,35 @@ int arduino::MbedUDP::parsePacket() {
|
||||
return _current_packet_size;
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::available() {
|
||||
int arduino::MbedUDP::available()
|
||||
{
|
||||
return _current_packet_size;
|
||||
}
|
||||
|
||||
// Read a single byte from the current packet
|
||||
int arduino::MbedUDP::read() {
|
||||
int arduino::MbedUDP::read()
|
||||
{
|
||||
// no current packet...
|
||||
if (_current_packet == NULL) {
|
||||
if (_current_packet == NULL)
|
||||
{
|
||||
// try reading the next frame, if there is no data return
|
||||
if (parsePacket() == 0) return -1;
|
||||
if (parsePacket() == 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
_current_packet++;
|
||||
|
||||
// check for overflow
|
||||
if (_current_packet > _packet_buffer + _current_packet_size) {
|
||||
if (_current_packet > _packet_buffer + _current_packet_size)
|
||||
{
|
||||
// try reading the next packet...
|
||||
if (parsePacket() > 0) {
|
||||
if (parsePacket() > 0)
|
||||
{
|
||||
// if so, read first byte of next packet;
|
||||
return read();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// no new data... not sure what to return here now
|
||||
return -1;
|
||||
}
|
||||
@@ -158,34 +197,46 @@ int arduino::MbedUDP::read() {
|
||||
|
||||
// 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
|
||||
int arduino::MbedUDP::read(unsigned char *buffer, size_t len) {
|
||||
int arduino::MbedUDP::read(unsigned char *buffer, size_t len)
|
||||
{
|
||||
// Q: does Arduino read() function handle fragmentation? I won't for now...
|
||||
if (_current_packet == NULL) {
|
||||
if (parsePacket() == 0) return 0;
|
||||
if (_current_packet == NULL)
|
||||
{
|
||||
if (parsePacket() == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// how much data do we have in the current packet?
|
||||
int offset = _current_packet - _packet_buffer;
|
||||
if (offset < 0) {
|
||||
|
||||
if (offset < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int max_bytes = _current_packet_size - offset;
|
||||
if (max_bytes < 0) {
|
||||
|
||||
if (max_bytes < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// at the end of the packet?
|
||||
if (max_bytes == 0) {
|
||||
if (max_bytes == 0)
|
||||
{
|
||||
// try read next packet...
|
||||
if (parsePacket() > 0) {
|
||||
if (parsePacket() > 0)
|
||||
{
|
||||
return read(buffer, len);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (len > (size_t)max_bytes) len = max_bytes;
|
||||
if (len > (size_t)max_bytes)
|
||||
len = max_bytes;
|
||||
|
||||
// copy to target buffer
|
||||
memcpy(buffer, _current_packet, len);
|
||||
@@ -195,21 +246,26 @@ int arduino::MbedUDP::read(unsigned char *buffer, size_t len) {
|
||||
return len;
|
||||
}
|
||||
|
||||
IPAddress arduino::MbedUDP::remoteIP() {
|
||||
IPAddress arduino::MbedUDP::remoteIP()
|
||||
{
|
||||
nsapi_addr_t address = _remoteHost.get_addr();
|
||||
return IPAddress(address.bytes[0], address.bytes[1], address.bytes[2], address.bytes[3]);
|
||||
}
|
||||
|
||||
uint16_t arduino::MbedUDP::remotePort() {
|
||||
uint16_t arduino::MbedUDP::remotePort()
|
||||
{
|
||||
return _remoteHost.get_port();
|
||||
}
|
||||
|
||||
void arduino::MbedUDP::flush() {
|
||||
void arduino::MbedUDP::flush()
|
||||
{
|
||||
// TODO: a real check to ensure transmission has been completed
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::peek() {
|
||||
if (_current_packet_size < 1) {
|
||||
int arduino::MbedUDP::peek()
|
||||
{
|
||||
if (_current_packet_size < 1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@@ -25,13 +25,15 @@
|
||||
#include "netsocket/UDPSocket.h"
|
||||
|
||||
#ifndef WIFI_UDP_BUFFER_SIZE
|
||||
#define WIFI_UDP_BUFFER_SIZE 508
|
||||
#define WIFI_UDP_BUFFER_SIZE 508
|
||||
#endif
|
||||
|
||||
namespace arduino {
|
||||
namespace arduino
|
||||
{
|
||||
|
||||
class MbedUDP : public UDP {
|
||||
private:
|
||||
class MbedUDP : public UDP
|
||||
{
|
||||
private:
|
||||
UDPSocket _socket; // Mbed OS socket
|
||||
SocketAddress _host; // Host to be used to send data
|
||||
SocketAddress _remoteHost; // Remote host that sent incoming packets
|
||||
@@ -45,10 +47,10 @@ private:
|
||||
|
||||
RingBufferN<WIFI_UDP_BUFFER_SIZE> txBuffer;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual NetworkInterface* getNetwork() = 0;
|
||||
|
||||
public:
|
||||
public:
|
||||
MbedUDP(); // Constructor
|
||||
~MbedUDP();
|
||||
virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||
@@ -85,7 +87,8 @@ public:
|
||||
virtual int read(unsigned char* buffer, size_t len);
|
||||
// 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) {
|
||||
virtual int read(char* buffer, size_t len)
|
||||
{
|
||||
return read((unsigned char*)buffer, len);
|
||||
};
|
||||
// Return the next byte from the current packet without moving on to the next byte
|
||||
|
@@ -1,28 +1,28 @@
|
||||
/* Copyright (C) 2012 mbed.org, MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef LWIPOPTS_H
|
||||
#define LWIPOPTS_H
|
||||
|
||||
// Workaround for Linux timeval
|
||||
#if defined (TOOLCHAIN_GCC)
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include "nsapi_types.h"
|
||||
#include "mbed_retarget.h"
|
||||
@@ -35,7 +35,7 @@
|
||||
#define NO_SYS 0
|
||||
|
||||
#if !MBED_CONF_LWIP_IPV4_ENABLED && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#endif
|
||||
|
||||
#define LWIP_IPV4 MBED_CONF_LWIP_IPV4_ENABLED
|
||||
@@ -47,16 +47,16 @@
|
||||
// On dual stack configuration how long to wait for both or preferred stack
|
||||
// addresses before completing bring up.
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
|
||||
|
||||
@@ -68,52 +68,52 @@
|
||||
#define PREF_IPV6 2
|
||||
|
||||
#if MBED_CONF_LWIP_IP_VER_PREF == 6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#elif MBED_CONF_LWIP_IP_VER_PREF == 4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#else
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#endif
|
||||
|
||||
#undef LWIP_DEBUG
|
||||
#if MBED_CONF_LWIP_DEBUG_ENABLED
|
||||
#define LWIP_DEBUG 1
|
||||
#define LWIP_DEBUG 1
|
||||
#endif
|
||||
|
||||
#if NO_SYS == 0
|
||||
#include "cmsis_os2.h"
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -143,16 +143,16 @@
|
||||
#define PBUF_POOL_SIZE MBED_CONF_LWIP_PBUF_POOL_SIZE
|
||||
|
||||
#ifdef MBED_CONF_LWIP_PBUF_POOL_BUFSIZE
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#else
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MEM_SIZE MBED_CONF_LWIP_MEM_SIZE
|
||||
@@ -181,14 +181,14 @@
|
||||
#define MEMP_NUM_NETCONN MBED_CONF_LWIP_SOCKET_MAX
|
||||
|
||||
#if MBED_CONF_LWIP_TCP_ENABLED
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
|
||||
#else
|
||||
#define LWIP_TCP 0
|
||||
#define LWIP_TCP 0
|
||||
#endif
|
||||
|
||||
#define LWIP_DNS 1
|
||||
@@ -251,13 +251,13 @@
|
||||
#define UDP_LPC_EMAC LWIP_DBG_OFF
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#else
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#endif
|
||||
|
||||
#define TRACE_TO_ASCII_HEX_DUMP 0
|
||||
@@ -269,18 +269,18 @@
|
||||
// Interface type configuration
|
||||
|
||||
#if MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#else
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#endif // MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
|
||||
#if MBED_CONF_LWIP_L3IP_ENABLED
|
||||
#define LWIP_L3IP 1
|
||||
#define LWIP_L3IP 1
|
||||
#else
|
||||
#define LWIP_L3IP 0
|
||||
#define LWIP_L3IP 0
|
||||
#endif
|
||||
|
||||
//Maximum size of network interface name
|
||||
@@ -291,27 +291,27 @@
|
||||
// Enable PPP for now either from lwIP PPP configuration (obsolete) or from PPP service configuration
|
||||
#if MBED_CONF_PPP_ENABLED || MBED_CONF_LWIP_PPP_ENABLED
|
||||
|
||||
#define PPP_SUPPORT 1
|
||||
#define PPP_SUPPORT 1
|
||||
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -320,7 +320,7 @@
|
||||
// Make sure we default these to off, so
|
||||
// LWIP doesn't default to on
|
||||
#ifndef LWIP_ARP
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ARP 0
|
||||
#endif
|
||||
|
||||
// Checksum-on-copy disabled due to https://savannah.nongnu.org/bugs/?50914
|
||||
@@ -337,9 +337,9 @@
|
||||
#include "lwip_tcp_isn.h"
|
||||
#define LWIP_HOOK_TCP_ISN lwip_hook_tcp_isn
|
||||
#ifdef MBEDTLS_MD5_C
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#else
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#endif
|
||||
|
||||
#define LWIP_ND6_RDNSS_MAX_DNS_SERVERS MBED_CONF_LWIP_ND6_RDNSS_MAX_DNS_SERVERS
|
||||
|
@@ -1,29 +1,36 @@
|
||||
#include "MbedUdp.h"
|
||||
|
||||
arduino::MbedUDP::MbedUDP() {
|
||||
arduino::MbedUDP::MbedUDP()
|
||||
{
|
||||
_packet_buffer = new uint8_t[WIFI_UDP_BUFFER_SIZE];
|
||||
_current_packet = NULL;
|
||||
_current_packet_size = 0;
|
||||
// if this allocation fails then ::begin will fail
|
||||
}
|
||||
|
||||
arduino::MbedUDP::~MbedUDP() {
|
||||
arduino::MbedUDP::~MbedUDP()
|
||||
{
|
||||
delete[] _packet_buffer;
|
||||
}
|
||||
|
||||
uint8_t arduino::MbedUDP::begin(uint16_t port) {
|
||||
uint8_t arduino::MbedUDP::begin(uint16_t port)
|
||||
{
|
||||
// success = 1, fail = 0
|
||||
|
||||
nsapi_error_t rt = _socket.open(getNetwork());
|
||||
if (rt != NSAPI_ERROR_OK) {
|
||||
|
||||
if (rt != NSAPI_ERROR_OK)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (_socket.bind(port) < 0) {
|
||||
if (_socket.bind(port) < 0)
|
||||
{
|
||||
return 0; //Failed to bind UDP Socket to port
|
||||
}
|
||||
|
||||
if (!_packet_buffer) {
|
||||
if (!_packet_buffer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -33,15 +40,18 @@ uint8_t arduino::MbedUDP::begin(uint16_t port) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port) {
|
||||
uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port)
|
||||
{
|
||||
// success = 1, fail = 0
|
||||
if (begin(port) != 1) {
|
||||
if (begin(port) != 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SocketAddress socketAddress = SocketHelpers::socketAddressFromIpAddress(ip, port);
|
||||
|
||||
if (_socket.join_multicast_group(socketAddress) != NSAPI_ERROR_OK) {
|
||||
if (_socket.join_multicast_group(socketAddress) != NSAPI_ERROR_OK)
|
||||
{
|
||||
printf("Error joining the multicast group\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -49,18 +59,21 @@ uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void arduino::MbedUDP::stop() {
|
||||
void arduino::MbedUDP::stop()
|
||||
{
|
||||
_socket.close();
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::beginPacket(IPAddress ip, uint16_t port) {
|
||||
int arduino::MbedUDP::beginPacket(IPAddress ip, uint16_t port)
|
||||
{
|
||||
_host = SocketHelpers::socketAddressFromIpAddress(ip, port);
|
||||
//If IP is null and port is 0 the initialization failed
|
||||
txBuffer.clear();
|
||||
return (_host.get_ip_address() == nullptr && _host.get_port() == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::beginPacket(const char *host, uint16_t port) {
|
||||
int arduino::MbedUDP::beginPacket(const char *host, uint16_t port)
|
||||
{
|
||||
_host = SocketAddress(host, port);
|
||||
txBuffer.clear();
|
||||
getNetwork()->gethostbyname(host, &_host);
|
||||
@@ -68,54 +81,72 @@ int arduino::MbedUDP::beginPacket(const char *host, uint16_t port) {
|
||||
return (_host.get_ip_address() == nullptr && _host.get_port() == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::endPacket() {
|
||||
int arduino::MbedUDP::endPacket()
|
||||
{
|
||||
_socket.set_blocking(true);
|
||||
_socket.set_timeout(1000);
|
||||
|
||||
size_t size = txBuffer.available();
|
||||
uint8_t buffer[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
buffer[i] = txBuffer.read_char();
|
||||
}
|
||||
|
||||
nsapi_size_or_error_t ret = _socket.sendto(_host, buffer, size);
|
||||
_socket.set_blocking(false);
|
||||
_socket.set_timeout(0);
|
||||
if (ret < 0) {
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
// Write a single byte into the packet
|
||||
size_t arduino::MbedUDP::write(uint8_t byte) {
|
||||
size_t arduino::MbedUDP::write(uint8_t byte)
|
||||
{
|
||||
return write(&byte, 1);
|
||||
}
|
||||
|
||||
// Write size bytes from buffer into the packet
|
||||
size_t arduino::MbedUDP::write(const uint8_t *buffer, size_t size) {
|
||||
for (int i = 0; i<size; i++) {
|
||||
if (txBuffer.availableForStore()) {
|
||||
size_t arduino::MbedUDP::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
if (txBuffer.availableForStore())
|
||||
{
|
||||
txBuffer.store_char(buffer[i]);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::parsePacket() {
|
||||
int arduino::MbedUDP::parsePacket()
|
||||
{
|
||||
nsapi_size_or_error_t ret = _socket.recvfrom(&_remoteHost, _packet_buffer, WIFI_UDP_BUFFER_SIZE);
|
||||
|
||||
if (ret == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
if (ret == NSAPI_ERROR_WOULD_BLOCK)
|
||||
{
|
||||
// no data
|
||||
return 0;
|
||||
} else if (ret == NSAPI_ERROR_NO_SOCKET) {
|
||||
}
|
||||
else if (ret == NSAPI_ERROR_NO_SOCKET)
|
||||
{
|
||||
// socket was not created correctly.
|
||||
return -1;
|
||||
}
|
||||
// error codes below zero are errors
|
||||
else if (ret <= 0) {
|
||||
else if (ret <= 0)
|
||||
{
|
||||
// something else went wrong, need some tracing info...
|
||||
return -1;
|
||||
}
|
||||
@@ -127,27 +158,35 @@ int arduino::MbedUDP::parsePacket() {
|
||||
return _current_packet_size;
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::available() {
|
||||
int arduino::MbedUDP::available()
|
||||
{
|
||||
return _current_packet_size;
|
||||
}
|
||||
|
||||
// Read a single byte from the current packet
|
||||
int arduino::MbedUDP::read() {
|
||||
int arduino::MbedUDP::read()
|
||||
{
|
||||
// no current packet...
|
||||
if (_current_packet == NULL) {
|
||||
if (_current_packet == NULL)
|
||||
{
|
||||
// try reading the next frame, if there is no data return
|
||||
if (parsePacket() == 0) return -1;
|
||||
if (parsePacket() == 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
_current_packet++;
|
||||
|
||||
// check for overflow
|
||||
if (_current_packet > _packet_buffer + _current_packet_size) {
|
||||
if (_current_packet > _packet_buffer + _current_packet_size)
|
||||
{
|
||||
// try reading the next packet...
|
||||
if (parsePacket() > 0) {
|
||||
if (parsePacket() > 0)
|
||||
{
|
||||
// if so, read first byte of next packet;
|
||||
return read();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// no new data... not sure what to return here now
|
||||
return -1;
|
||||
}
|
||||
@@ -158,34 +197,46 @@ int arduino::MbedUDP::read() {
|
||||
|
||||
// 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
|
||||
int arduino::MbedUDP::read(unsigned char *buffer, size_t len) {
|
||||
int arduino::MbedUDP::read(unsigned char *buffer, size_t len)
|
||||
{
|
||||
// Q: does Arduino read() function handle fragmentation? I won't for now...
|
||||
if (_current_packet == NULL) {
|
||||
if (parsePacket() == 0) return 0;
|
||||
if (_current_packet == NULL)
|
||||
{
|
||||
if (parsePacket() == 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// how much data do we have in the current packet?
|
||||
int offset = _current_packet - _packet_buffer;
|
||||
if (offset < 0) {
|
||||
|
||||
if (offset < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int max_bytes = _current_packet_size - offset;
|
||||
if (max_bytes < 0) {
|
||||
|
||||
if (max_bytes < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// at the end of the packet?
|
||||
if (max_bytes == 0) {
|
||||
if (max_bytes == 0)
|
||||
{
|
||||
// try read next packet...
|
||||
if (parsePacket() > 0) {
|
||||
if (parsePacket() > 0)
|
||||
{
|
||||
return read(buffer, len);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (len > (size_t)max_bytes) len = max_bytes;
|
||||
if (len > (size_t)max_bytes)
|
||||
len = max_bytes;
|
||||
|
||||
// copy to target buffer
|
||||
memcpy(buffer, _current_packet, len);
|
||||
@@ -195,21 +246,26 @@ int arduino::MbedUDP::read(unsigned char *buffer, size_t len) {
|
||||
return len;
|
||||
}
|
||||
|
||||
IPAddress arduino::MbedUDP::remoteIP() {
|
||||
IPAddress arduino::MbedUDP::remoteIP()
|
||||
{
|
||||
nsapi_addr_t address = _remoteHost.get_addr();
|
||||
return IPAddress(address.bytes[0], address.bytes[1], address.bytes[2], address.bytes[3]);
|
||||
}
|
||||
|
||||
uint16_t arduino::MbedUDP::remotePort() {
|
||||
uint16_t arduino::MbedUDP::remotePort()
|
||||
{
|
||||
return _remoteHost.get_port();
|
||||
}
|
||||
|
||||
void arduino::MbedUDP::flush() {
|
||||
void arduino::MbedUDP::flush()
|
||||
{
|
||||
// TODO: a real check to ensure transmission has been completed
|
||||
}
|
||||
|
||||
int arduino::MbedUDP::peek() {
|
||||
if (_current_packet_size < 1) {
|
||||
int arduino::MbedUDP::peek()
|
||||
{
|
||||
if (_current_packet_size < 1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@@ -25,13 +25,15 @@
|
||||
#include "netsocket/UDPSocket.h"
|
||||
|
||||
#ifndef WIFI_UDP_BUFFER_SIZE
|
||||
#define WIFI_UDP_BUFFER_SIZE 508
|
||||
#define WIFI_UDP_BUFFER_SIZE 508
|
||||
#endif
|
||||
|
||||
namespace arduino {
|
||||
namespace arduino
|
||||
{
|
||||
|
||||
class MbedUDP : public UDP {
|
||||
private:
|
||||
class MbedUDP : public UDP
|
||||
{
|
||||
private:
|
||||
UDPSocket _socket; // Mbed OS socket
|
||||
SocketAddress _host; // Host to be used to send data
|
||||
SocketAddress _remoteHost; // Remote host that sent incoming packets
|
||||
@@ -45,10 +47,10 @@ private:
|
||||
|
||||
RingBufferN<WIFI_UDP_BUFFER_SIZE> txBuffer;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
virtual NetworkInterface* getNetwork() = 0;
|
||||
|
||||
public:
|
||||
public:
|
||||
MbedUDP(); // Constructor
|
||||
~MbedUDP();
|
||||
virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||
@@ -85,7 +87,8 @@ public:
|
||||
virtual int read(unsigned char* buffer, size_t len);
|
||||
// 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) {
|
||||
virtual int read(char* buffer, size_t len)
|
||||
{
|
||||
return read((unsigned char*)buffer, len);
|
||||
};
|
||||
// Return the next byte from the current packet without moving on to the next byte
|
||||
|
@@ -1,28 +1,28 @@
|
||||
/* Copyright (C) 2012 mbed.org, MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef LWIPOPTS_H
|
||||
#define LWIPOPTS_H
|
||||
|
||||
// Workaround for Linux timeval
|
||||
#if defined (TOOLCHAIN_GCC)
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include "nsapi_types.h"
|
||||
#include "mbed_retarget.h"
|
||||
@@ -35,7 +35,7 @@
|
||||
#define NO_SYS 0
|
||||
|
||||
#if !MBED_CONF_LWIP_IPV4_ENABLED && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#endif
|
||||
|
||||
#define LWIP_IPV4 MBED_CONF_LWIP_IPV4_ENABLED
|
||||
@@ -47,16 +47,16 @@
|
||||
// On dual stack configuration how long to wait for both or preferred stack
|
||||
// addresses before completing bring up.
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
|
||||
|
||||
@@ -68,52 +68,52 @@
|
||||
#define PREF_IPV6 2
|
||||
|
||||
#if MBED_CONF_LWIP_IP_VER_PREF == 6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#elif MBED_CONF_LWIP_IP_VER_PREF == 4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#else
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#endif
|
||||
|
||||
#undef LWIP_DEBUG
|
||||
#if MBED_CONF_LWIP_DEBUG_ENABLED
|
||||
#define LWIP_DEBUG 1
|
||||
#define LWIP_DEBUG 1
|
||||
#endif
|
||||
|
||||
#if NO_SYS == 0
|
||||
#include "cmsis_os2.h"
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -143,16 +143,16 @@
|
||||
#define PBUF_POOL_SIZE MBED_CONF_LWIP_PBUF_POOL_SIZE
|
||||
|
||||
#ifdef MBED_CONF_LWIP_PBUF_POOL_BUFSIZE
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#else
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MEM_SIZE MBED_CONF_LWIP_MEM_SIZE
|
||||
@@ -181,14 +181,14 @@
|
||||
#define MEMP_NUM_NETCONN MBED_CONF_LWIP_SOCKET_MAX
|
||||
|
||||
#if MBED_CONF_LWIP_TCP_ENABLED
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
|
||||
#else
|
||||
#define LWIP_TCP 0
|
||||
#define LWIP_TCP 0
|
||||
#endif
|
||||
|
||||
#define LWIP_DNS 1
|
||||
@@ -251,13 +251,13 @@
|
||||
#define UDP_LPC_EMAC LWIP_DBG_OFF
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#else
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#endif
|
||||
|
||||
#define TRACE_TO_ASCII_HEX_DUMP 0
|
||||
@@ -269,18 +269,18 @@
|
||||
// Interface type configuration
|
||||
|
||||
#if MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#else
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#endif // MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
|
||||
#if MBED_CONF_LWIP_L3IP_ENABLED
|
||||
#define LWIP_L3IP 1
|
||||
#define LWIP_L3IP 1
|
||||
#else
|
||||
#define LWIP_L3IP 0
|
||||
#define LWIP_L3IP 0
|
||||
#endif
|
||||
|
||||
//Maximum size of network interface name
|
||||
@@ -291,27 +291,27 @@
|
||||
// Enable PPP for now either from lwIP PPP configuration (obsolete) or from PPP service configuration
|
||||
#if MBED_CONF_PPP_ENABLED || MBED_CONF_LWIP_PPP_ENABLED
|
||||
|
||||
#define PPP_SUPPORT 1
|
||||
#define PPP_SUPPORT 1
|
||||
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -320,7 +320,7 @@
|
||||
// Make sure we default these to off, so
|
||||
// LWIP doesn't default to on
|
||||
#ifndef LWIP_ARP
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ARP 0
|
||||
#endif
|
||||
|
||||
// Checksum-on-copy disabled due to https://savannah.nongnu.org/bugs/?50914
|
||||
@@ -337,9 +337,9 @@
|
||||
#include "lwip_tcp_isn.h"
|
||||
#define LWIP_HOOK_TCP_ISN lwip_hook_tcp_isn
|
||||
#ifdef MBEDTLS_MD5_C
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#else
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#endif
|
||||
|
||||
#define LWIP_ND6_RDNSS_MAX_DNS_SERVERS MBED_CONF_LWIP_ND6_RDNSS_MAX_DNS_SERVERS
|
||||
|
@@ -1,28 +1,28 @@
|
||||
/* Copyright (C) 2012 mbed.org, MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef LWIPOPTS_H
|
||||
#define LWIPOPTS_H
|
||||
|
||||
// Workaround for Linux timeval
|
||||
#if defined (TOOLCHAIN_GCC)
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include "nsapi_types.h"
|
||||
#include "mbed_retarget.h"
|
||||
@@ -35,7 +35,7 @@
|
||||
#define NO_SYS 0
|
||||
|
||||
#if !MBED_CONF_LWIP_IPV4_ENABLED && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#endif
|
||||
|
||||
#define LWIP_IPV4 MBED_CONF_LWIP_IPV4_ENABLED
|
||||
@@ -47,16 +47,16 @@
|
||||
// On dual stack configuration how long to wait for both or preferred stack
|
||||
// addresses before completing bring up.
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
|
||||
|
||||
@@ -68,52 +68,52 @@
|
||||
#define PREF_IPV6 2
|
||||
|
||||
#if MBED_CONF_LWIP_IP_VER_PREF == 6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#elif MBED_CONF_LWIP_IP_VER_PREF == 4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#else
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#endif
|
||||
|
||||
#undef LWIP_DEBUG
|
||||
#if MBED_CONF_LWIP_DEBUG_ENABLED
|
||||
#define LWIP_DEBUG 1
|
||||
#define LWIP_DEBUG 1
|
||||
#endif
|
||||
|
||||
#if NO_SYS == 0
|
||||
#include "cmsis_os2.h"
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -143,16 +143,16 @@
|
||||
#define PBUF_POOL_SIZE MBED_CONF_LWIP_PBUF_POOL_SIZE
|
||||
|
||||
#ifdef MBED_CONF_LWIP_PBUF_POOL_BUFSIZE
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#else
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MEM_SIZE MBED_CONF_LWIP_MEM_SIZE
|
||||
@@ -181,14 +181,14 @@
|
||||
#define MEMP_NUM_NETCONN MBED_CONF_LWIP_SOCKET_MAX
|
||||
|
||||
#if MBED_CONF_LWIP_TCP_ENABLED
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
|
||||
#else
|
||||
#define LWIP_TCP 0
|
||||
#define LWIP_TCP 0
|
||||
#endif
|
||||
|
||||
#define LWIP_DNS 1
|
||||
@@ -251,13 +251,13 @@
|
||||
#define UDP_LPC_EMAC LWIP_DBG_OFF
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#else
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#endif
|
||||
|
||||
#define TRACE_TO_ASCII_HEX_DUMP 0
|
||||
@@ -269,18 +269,18 @@
|
||||
// Interface type configuration
|
||||
|
||||
#if MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#else
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#endif // MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
|
||||
#if MBED_CONF_LWIP_L3IP_ENABLED
|
||||
#define LWIP_L3IP 1
|
||||
#define LWIP_L3IP 1
|
||||
#else
|
||||
#define LWIP_L3IP 0
|
||||
#define LWIP_L3IP 0
|
||||
#endif
|
||||
|
||||
//Maximum size of network interface name
|
||||
@@ -291,27 +291,27 @@
|
||||
// Enable PPP for now either from lwIP PPP configuration (obsolete) or from PPP service configuration
|
||||
#if MBED_CONF_PPP_ENABLED || MBED_CONF_LWIP_PPP_ENABLED
|
||||
|
||||
#define PPP_SUPPORT 1
|
||||
#define PPP_SUPPORT 1
|
||||
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -320,7 +320,7 @@
|
||||
// Make sure we default these to off, so
|
||||
// LWIP doesn't default to on
|
||||
#ifndef LWIP_ARP
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ARP 0
|
||||
#endif
|
||||
|
||||
// Checksum-on-copy disabled due to https://savannah.nongnu.org/bugs/?50914
|
||||
@@ -337,9 +337,9 @@
|
||||
#include "lwip_tcp_isn.h"
|
||||
#define LWIP_HOOK_TCP_ISN lwip_hook_tcp_isn
|
||||
#ifdef MBEDTLS_MD5_C
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#else
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#endif
|
||||
|
||||
#define LWIP_ND6_RDNSS_MAX_DNS_SERVERS MBED_CONF_LWIP_ND6_RDNSS_MAX_DNS_SERVERS
|
||||
|
@@ -1,28 +1,28 @@
|
||||
/* Copyright (C) 2012 mbed.org, MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef LWIPOPTS_H
|
||||
#define LWIPOPTS_H
|
||||
|
||||
// Workaround for Linux timeval
|
||||
#if defined (TOOLCHAIN_GCC)
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include "nsapi_types.h"
|
||||
#include "mbed_retarget.h"
|
||||
@@ -35,7 +35,7 @@
|
||||
#define NO_SYS 0
|
||||
|
||||
#if !MBED_CONF_LWIP_IPV4_ENABLED && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#endif
|
||||
|
||||
#define LWIP_IPV4 MBED_CONF_LWIP_IPV4_ENABLED
|
||||
@@ -47,16 +47,16 @@
|
||||
// On dual stack configuration how long to wait for both or preferred stack
|
||||
// addresses before completing bring up.
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
|
||||
|
||||
@@ -68,52 +68,52 @@
|
||||
#define PREF_IPV6 2
|
||||
|
||||
#if MBED_CONF_LWIP_IP_VER_PREF == 6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#elif MBED_CONF_LWIP_IP_VER_PREF == 4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#else
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#endif
|
||||
|
||||
#undef LWIP_DEBUG
|
||||
#if MBED_CONF_LWIP_DEBUG_ENABLED
|
||||
#define LWIP_DEBUG 1
|
||||
#define LWIP_DEBUG 1
|
||||
#endif
|
||||
|
||||
#if NO_SYS == 0
|
||||
#include "cmsis_os2.h"
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -143,16 +143,16 @@
|
||||
#define PBUF_POOL_SIZE MBED_CONF_LWIP_PBUF_POOL_SIZE
|
||||
|
||||
#ifdef MBED_CONF_LWIP_PBUF_POOL_BUFSIZE
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#else
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MEM_SIZE MBED_CONF_LWIP_MEM_SIZE
|
||||
@@ -181,14 +181,14 @@
|
||||
#define MEMP_NUM_NETCONN MBED_CONF_LWIP_SOCKET_MAX
|
||||
|
||||
#if MBED_CONF_LWIP_TCP_ENABLED
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
|
||||
#else
|
||||
#define LWIP_TCP 0
|
||||
#define LWIP_TCP 0
|
||||
#endif
|
||||
|
||||
#define LWIP_DNS 1
|
||||
@@ -251,13 +251,13 @@
|
||||
#define UDP_LPC_EMAC LWIP_DBG_OFF
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#else
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#endif
|
||||
|
||||
#define TRACE_TO_ASCII_HEX_DUMP 0
|
||||
@@ -269,18 +269,18 @@
|
||||
// Interface type configuration
|
||||
|
||||
#if MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#else
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#endif // MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
|
||||
#if MBED_CONF_LWIP_L3IP_ENABLED
|
||||
#define LWIP_L3IP 1
|
||||
#define LWIP_L3IP 1
|
||||
#else
|
||||
#define LWIP_L3IP 0
|
||||
#define LWIP_L3IP 0
|
||||
#endif
|
||||
|
||||
//Maximum size of network interface name
|
||||
@@ -291,27 +291,27 @@
|
||||
// Enable PPP for now either from lwIP PPP configuration (obsolete) or from PPP service configuration
|
||||
#if MBED_CONF_PPP_ENABLED || MBED_CONF_LWIP_PPP_ENABLED
|
||||
|
||||
#define PPP_SUPPORT 1
|
||||
#define PPP_SUPPORT 1
|
||||
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -320,7 +320,7 @@
|
||||
// Make sure we default these to off, so
|
||||
// LWIP doesn't default to on
|
||||
#ifndef LWIP_ARP
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ARP 0
|
||||
#endif
|
||||
|
||||
// Checksum-on-copy disabled due to https://savannah.nongnu.org/bugs/?50914
|
||||
@@ -337,9 +337,9 @@
|
||||
#include "lwip_tcp_isn.h"
|
||||
#define LWIP_HOOK_TCP_ISN lwip_hook_tcp_isn
|
||||
#ifdef MBEDTLS_MD5_C
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#else
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#endif
|
||||
|
||||
#define LWIP_ND6_RDNSS_MAX_DNS_SERVERS MBED_CONF_LWIP_ND6_RDNSS_MAX_DNS_SERVERS
|
||||
|
@@ -1,28 +1,28 @@
|
||||
/* Copyright (C) 2012 mbed.org, MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef LWIPOPTS_H
|
||||
#define LWIPOPTS_H
|
||||
|
||||
// Workaround for Linux timeval
|
||||
#if defined (TOOLCHAIN_GCC)
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include "nsapi_types.h"
|
||||
#include "mbed_retarget.h"
|
||||
@@ -35,7 +35,7 @@
|
||||
#define NO_SYS 0
|
||||
|
||||
#if !MBED_CONF_LWIP_IPV4_ENABLED && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#endif
|
||||
|
||||
#define LWIP_IPV4 MBED_CONF_LWIP_IPV4_ENABLED
|
||||
@@ -47,16 +47,16 @@
|
||||
// On dual stack configuration how long to wait for both or preferred stack
|
||||
// addresses before completing bring up.
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
|
||||
|
||||
@@ -68,52 +68,52 @@
|
||||
#define PREF_IPV6 2
|
||||
|
||||
#if MBED_CONF_LWIP_IP_VER_PREF == 6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#elif MBED_CONF_LWIP_IP_VER_PREF == 4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#else
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#endif
|
||||
|
||||
#undef LWIP_DEBUG
|
||||
#if MBED_CONF_LWIP_DEBUG_ENABLED
|
||||
#define LWIP_DEBUG 1
|
||||
#define LWIP_DEBUG 1
|
||||
#endif
|
||||
|
||||
#if NO_SYS == 0
|
||||
#include "cmsis_os2.h"
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -143,16 +143,16 @@
|
||||
#define PBUF_POOL_SIZE MBED_CONF_LWIP_PBUF_POOL_SIZE
|
||||
|
||||
#ifdef MBED_CONF_LWIP_PBUF_POOL_BUFSIZE
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#else
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MEM_SIZE MBED_CONF_LWIP_MEM_SIZE
|
||||
@@ -181,14 +181,14 @@
|
||||
#define MEMP_NUM_NETCONN MBED_CONF_LWIP_SOCKET_MAX
|
||||
|
||||
#if MBED_CONF_LWIP_TCP_ENABLED
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
|
||||
#else
|
||||
#define LWIP_TCP 0
|
||||
#define LWIP_TCP 0
|
||||
#endif
|
||||
|
||||
#define LWIP_DNS 1
|
||||
@@ -251,13 +251,13 @@
|
||||
#define UDP_LPC_EMAC LWIP_DBG_OFF
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#else
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#endif
|
||||
|
||||
#define TRACE_TO_ASCII_HEX_DUMP 0
|
||||
@@ -269,18 +269,18 @@
|
||||
// Interface type configuration
|
||||
|
||||
#if MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#else
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#endif // MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
|
||||
#if MBED_CONF_LWIP_L3IP_ENABLED
|
||||
#define LWIP_L3IP 1
|
||||
#define LWIP_L3IP 1
|
||||
#else
|
||||
#define LWIP_L3IP 0
|
||||
#define LWIP_L3IP 0
|
||||
#endif
|
||||
|
||||
//Maximum size of network interface name
|
||||
@@ -291,27 +291,27 @@
|
||||
// Enable PPP for now either from lwIP PPP configuration (obsolete) or from PPP service configuration
|
||||
#if MBED_CONF_PPP_ENABLED || MBED_CONF_LWIP_PPP_ENABLED
|
||||
|
||||
#define PPP_SUPPORT 1
|
||||
#define PPP_SUPPORT 1
|
||||
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -320,7 +320,7 @@
|
||||
// Make sure we default these to off, so
|
||||
// LWIP doesn't default to on
|
||||
#ifndef LWIP_ARP
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ARP 0
|
||||
#endif
|
||||
|
||||
// Checksum-on-copy disabled due to https://savannah.nongnu.org/bugs/?50914
|
||||
@@ -337,9 +337,9 @@
|
||||
#include "lwip_tcp_isn.h"
|
||||
#define LWIP_HOOK_TCP_ISN lwip_hook_tcp_isn
|
||||
#ifdef MBEDTLS_MD5_C
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#else
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#endif
|
||||
|
||||
#define LWIP_ND6_RDNSS_MAX_DNS_SERVERS MBED_CONF_LWIP_ND6_RDNSS_MAX_DNS_SERVERS
|
||||
|
@@ -1,28 +1,28 @@
|
||||
/* Copyright (C) 2012 mbed.org, MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef LWIPOPTS_H
|
||||
#define LWIPOPTS_H
|
||||
|
||||
// Workaround for Linux timeval
|
||||
#if defined (TOOLCHAIN_GCC)
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include "nsapi_types.h"
|
||||
#include "mbed_retarget.h"
|
||||
@@ -35,7 +35,7 @@
|
||||
#define NO_SYS 0
|
||||
|
||||
#if !MBED_CONF_LWIP_IPV4_ENABLED && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#error "Either IPv4 or IPv6 must be enabled."
|
||||
#endif
|
||||
|
||||
#define LWIP_IPV4 MBED_CONF_LWIP_IPV4_ENABLED
|
||||
@@ -47,16 +47,16 @@
|
||||
// On dual stack configuration how long to wait for both or preferred stack
|
||||
// addresses before completing bring up.
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#if MBED_CONF_LWIP_ADDR_TIMEOUT_MODE
|
||||
#define BOTH_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT MBED_CONF_LWIP_ADDR_TIMEOUT
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
#else
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#define PREF_ADDR_TIMEOUT 0
|
||||
#define BOTH_ADDR_TIMEOUT 0
|
||||
#endif
|
||||
|
||||
|
||||
@@ -68,52 +68,52 @@
|
||||
#define PREF_IPV6 2
|
||||
|
||||
#if MBED_CONF_LWIP_IP_VER_PREF == 6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#define IP_VERSION_PREF PREF_IPV6
|
||||
#elif MBED_CONF_LWIP_IP_VER_PREF == 4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#define IP_VERSION_PREF PREF_IPV4
|
||||
#else
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#error "Either IPv4 or IPv6 must be preferred."
|
||||
#endif
|
||||
|
||||
#undef LWIP_DEBUG
|
||||
#if MBED_CONF_LWIP_DEBUG_ENABLED
|
||||
#define LWIP_DEBUG 1
|
||||
#define LWIP_DEBUG 1
|
||||
#endif
|
||||
|
||||
#if NO_SYS == 0
|
||||
#include "cmsis_os2.h"
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
#define LWIP_RAW MBED_CONF_LWIP_RAW_SOCKET_ENABLED
|
||||
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT MBED_CONF_LWIP_MEMP_NUM_TCPIP_MSG_INPKT
|
||||
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
// Thread stacks use 8-byte alignment
|
||||
#define LWIP_ALIGN_UP(pos, align) ((pos) % (align) ? (pos) + ((align) - (pos) % (align)) : (pos))
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
// For LWIP debug, double the stack
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE*2, 8)
|
||||
#elif MBED_DEBUG
|
||||
// When debug is enabled on the build increase stack 25 percent
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE + MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE / 4, 8)
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_TCPIP_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
// Thread priority (osPriorityNormal by default)
|
||||
#define TCPIP_THREAD_PRIO (MBED_CONF_LWIP_TCPIP_THREAD_PRIORITY)
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
#ifdef LWIP_DEBUG
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE*2, 8)
|
||||
#else
|
||||
#define DEFAULT_THREAD_STACKSIZE LWIP_ALIGN_UP(MBED_CONF_LWIP_DEFAULT_THREAD_STACKSIZE, 8)
|
||||
#endif
|
||||
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
#define MEMP_NUM_SYS_TIMEOUT 16
|
||||
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
#define sys_msleep(ms) sys_msleep(ms)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -143,16 +143,16 @@
|
||||
#define PBUF_POOL_SIZE MBED_CONF_LWIP_PBUF_POOL_SIZE
|
||||
|
||||
#ifdef MBED_CONF_LWIP_PBUF_POOL_BUFSIZE
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#undef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(MBED_CONF_LWIP_PBUF_POOL_BUFSIZE)
|
||||
#else
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#if LWIP_IPV6
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#elif LWIP_IPV4
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+20+20+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MEM_SIZE MBED_CONF_LWIP_MEM_SIZE
|
||||
@@ -181,14 +181,14 @@
|
||||
#define MEMP_NUM_NETCONN MBED_CONF_LWIP_SOCKET_MAX
|
||||
|
||||
#if MBED_CONF_LWIP_TCP_ENABLED
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
#define LWIP_TCP 1
|
||||
#define TCP_OVERSIZE 0
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
#define TCP_CLOSE_TIMEOUT MBED_CONF_LWIP_TCP_CLOSE_TIMEOUT
|
||||
|
||||
#else
|
||||
#define LWIP_TCP 0
|
||||
#define LWIP_TCP 0
|
||||
#endif
|
||||
|
||||
#define LWIP_DNS 1
|
||||
@@ -251,13 +251,13 @@
|
||||
#define UDP_LPC_EMAC LWIP_DBG_OFF
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#define MEMP_OVERFLOW_CHECK 1
|
||||
#define MEMP_SANITY_CHECK 1
|
||||
#define LWIP_DBG_TYPES_ON LWIP_DBG_ON
|
||||
#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL
|
||||
#else
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#define LWIP_NOASSERT 1
|
||||
#define LWIP_STATS 0
|
||||
#endif
|
||||
|
||||
#define TRACE_TO_ASCII_HEX_DUMP 0
|
||||
@@ -269,18 +269,18 @@
|
||||
// Interface type configuration
|
||||
|
||||
#if MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#define LWIP_ARP 1
|
||||
#define LWIP_ETHERNET 1
|
||||
#define LWIP_DHCP LWIP_IPV4
|
||||
#else
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ETHERNET 0
|
||||
#endif // MBED_CONF_LWIP_ETHERNET_ENABLED
|
||||
|
||||
#if MBED_CONF_LWIP_L3IP_ENABLED
|
||||
#define LWIP_L3IP 1
|
||||
#define LWIP_L3IP 1
|
||||
#else
|
||||
#define LWIP_L3IP 0
|
||||
#define LWIP_L3IP 0
|
||||
#endif
|
||||
|
||||
//Maximum size of network interface name
|
||||
@@ -291,27 +291,27 @@
|
||||
// Enable PPP for now either from lwIP PPP configuration (obsolete) or from PPP service configuration
|
||||
#if MBED_CONF_PPP_ENABLED || MBED_CONF_LWIP_PPP_ENABLED
|
||||
|
||||
#define PPP_SUPPORT 1
|
||||
#define PPP_SUPPORT 1
|
||||
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV4_ENABLED || MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV4_ENABLED
|
||||
#error LWIP: IPv4 PPP enabled but not IPv4
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV4_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
#if MBED_CONF_PPP_IPV6_ENABLED || MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#define LWIP 0x11991199
|
||||
#if (MBED_CONF_NSAPI_DEFAULT_STACK == LWIP) && !MBED_CONF_LWIP_IPV6_ENABLED
|
||||
#error LWIP: IPv6 PPP enabled but not IPv6
|
||||
#endif
|
||||
#undef LWIP
|
||||
#define PPP_IPV6_SUPPORT 1
|
||||
// Later to be dynamic for use for multiple interfaces
|
||||
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -320,7 +320,7 @@
|
||||
// Make sure we default these to off, so
|
||||
// LWIP doesn't default to on
|
||||
#ifndef LWIP_ARP
|
||||
#define LWIP_ARP 0
|
||||
#define LWIP_ARP 0
|
||||
#endif
|
||||
|
||||
// Checksum-on-copy disabled due to https://savannah.nongnu.org/bugs/?50914
|
||||
@@ -337,9 +337,9 @@
|
||||
#include "lwip_tcp_isn.h"
|
||||
#define LWIP_HOOK_TCP_ISN lwip_hook_tcp_isn
|
||||
#ifdef MBEDTLS_MD5_C
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 1
|
||||
#else
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#define LWIP_USE_EXTERNAL_MBEDTLS 0
|
||||
#endif
|
||||
|
||||
#define LWIP_ND6_RDNSS_MAX_DNS_SERVERS MBED_CONF_LWIP_ND6_RDNSS_MAX_DNS_SERVERS
|
||||
|
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
portenta_h7_rules () {
|
||||
echo ""
|
||||
echo "# Portenta H7 bootloader mode UDEV rules"
|
||||
echo ""
|
||||
cat <<EOF
|
||||
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="035b", GROUP="plugdev", MODE="0666"
|
||||
EOF
|
||||
}
|
||||
|
||||
if [ "$EUID" -ne 0 ]
|
||||
then echo "Please run as root"
|
||||
exit
|
||||
fi
|
||||
|
||||
portenta_h7_rules > /etc/udev/rules.d/49-portenta_h7.rules
|
||||
|
||||
# reload udev rules
|
||||
echo "Reload rules..."
|
||||
udevadm trigger
|
||||
udevadm control --reload-rules
|
@@ -44,7 +44,7 @@ typedef uint16_t word;
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
@@ -94,30 +94,30 @@ void loop( void ) ;
|
||||
#include "WInterrupts.h"
|
||||
|
||||
#ifndef __cplusplus
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
#endif // abs
|
||||
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
|
||||
#else
|
||||
//using std::min;
|
||||
//using std::max;
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
//using std::min;
|
||||
//using std::max;
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||
@@ -144,7 +144,7 @@ void loop( void ) ;
|
||||
|
||||
// Allows publishing the Beta core under samd-beta / arduino organization
|
||||
#ifndef ARDUINO_ARCH_SAMD
|
||||
#define ARDUINO_ARCH_SAMD
|
||||
#define ARDUINO_ARCH_SAMD
|
||||
#endif
|
||||
|
||||
// USB Device
|
||||
|
@@ -44,7 +44,7 @@ typedef uint16_t word;
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
@@ -94,30 +94,30 @@ void loop( void ) ;
|
||||
#include "WInterrupts.h"
|
||||
|
||||
#ifndef __cplusplus
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
#endif // abs
|
||||
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
|
||||
#else
|
||||
//using std::min;
|
||||
//using std::max;
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
//using std::min;
|
||||
//using std::max;
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||
@@ -144,7 +144,7 @@ void loop( void ) ;
|
||||
|
||||
// Allows publishing the Beta core under samd-beta / arduino organization
|
||||
#ifndef ARDUINO_ARCH_SAMD
|
||||
#define ARDUINO_ARCH_SAMD
|
||||
#define ARDUINO_ARCH_SAMD
|
||||
#endif
|
||||
|
||||
// USB Device
|
||||
|
@@ -45,7 +45,7 @@ typedef uint16_t word;
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
@@ -99,30 +99,30 @@ void loop( void ) ;
|
||||
#include "WInterrupts.h"
|
||||
|
||||
#ifndef __cplusplus
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
#endif // abs
|
||||
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
|
||||
#else
|
||||
//using std::min;
|
||||
//using std::max;
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
//using std::min;
|
||||
//using std::max;
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||
@@ -149,7 +149,7 @@ void loop( void ) ;
|
||||
|
||||
// Allows publishing the Beta core under samd-beta / arduino organization
|
||||
#ifndef ARDUINO_ARCH_SAMD
|
||||
#define ARDUINO_ARCH_SAMD
|
||||
#define ARDUINO_ARCH_SAMD
|
||||
#endif
|
||||
|
||||
// USB Device
|
||||
|
@@ -45,7 +45,7 @@ typedef uint16_t word;
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
@@ -99,30 +99,30 @@ void loop( void ) ;
|
||||
#include "WInterrupts.h"
|
||||
|
||||
#ifndef __cplusplus
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
#endif // abs
|
||||
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
|
||||
#else
|
||||
//using std::min;
|
||||
//using std::max;
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
//using std::min;
|
||||
//using std::max;
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||
@@ -149,7 +149,7 @@ void loop( void ) ;
|
||||
|
||||
// Allows publishing the Beta core under samd-beta / arduino organization
|
||||
#ifndef ARDUINO_ARCH_SAMD
|
||||
#define ARDUINO_ARCH_SAMD
|
||||
#define ARDUINO_ARCH_SAMD
|
||||
#endif
|
||||
|
||||
// USB Device
|
||||
|
@@ -45,7 +45,7 @@ typedef uint16_t word;
|
||||
#include "itoa.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
// Include Atmel headers
|
||||
@@ -99,30 +99,30 @@ void loop( void ) ;
|
||||
#include "WInterrupts.h"
|
||||
|
||||
#ifndef __cplusplus
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif // abs
|
||||
#endif // abs
|
||||
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#define max(a,b) ((a)>(b)?(a):(b))
|
||||
#define abs(x) ((x)>0?(x):-(x))
|
||||
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
|
||||
#else
|
||||
//using std::min;
|
||||
//using std::max;
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
//using std::min;
|
||||
//using std::max;
|
||||
template<class T, class L>
|
||||
auto min(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (b < a) ? b : a;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
template<class T, class L>
|
||||
auto max(const T& a, const L& b) -> decltype((b < a) ? b : a)
|
||||
{
|
||||
return (a < b) ? b : a;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
|
||||
@@ -149,7 +149,7 @@ void loop( void ) ;
|
||||
|
||||
// Allows publishing the Beta core under samd-beta / arduino organization
|
||||
#ifndef ARDUINO_ARCH_SAMD
|
||||
#define ARDUINO_ARCH_SAMD
|
||||
#define ARDUINO_ARCH_SAMD
|
||||
#endif
|
||||
|
||||
// USB Device
|
||||
|
@@ -18,7 +18,7 @@
|
||||
|
||||
Created July 2011
|
||||
parsing functions based on TextFinder library by Michael Margolis
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
@@ -201,8 +201,7 @@ long Stream::parseInt(char skipChar)
|
||||
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
}
|
||||
while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
@@ -252,8 +251,7 @@ float Stream::parseFloat(char skipChar)
|
||||
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
}
|
||||
while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
|
@@ -18,7 +18,7 @@
|
||||
|
||||
Created July 2011
|
||||
parsing functions based on TextFinder library by Michael Margolis
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
@@ -201,8 +201,7 @@ long Stream::parseInt(char skipChar)
|
||||
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
}
|
||||
while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
@@ -252,8 +251,7 @@ float Stream::parseFloat(char skipChar)
|
||||
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
}
|
||||
while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
|
@@ -18,7 +18,7 @@
|
||||
|
||||
Created July 2011
|
||||
parsing functions based on TextFinder library by Michael Margolis
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
@@ -201,8 +201,7 @@ long Stream::parseInt(char skipChar)
|
||||
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
}
|
||||
while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||
} while ( (c >= '0' && c <= '9') || c == skipChar );
|
||||
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
@@ -252,8 +251,7 @@ float Stream::parseFloat(char skipChar)
|
||||
|
||||
read(); // consume the character we got with peek
|
||||
c = timedPeek();
|
||||
}
|
||||
while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||
} while ( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
|
||||
|
||||
if (isNegative)
|
||||
value = -value;
|
||||
|
@@ -1,36 +1,36 @@
|
||||
/*
|
||||
* Udp.cpp: Library to send/receive UDP packets.
|
||||
*
|
||||
* NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
|
||||
* 1) UDP does not guarantee the order in which assembled UDP packets are received. This
|
||||
* might not happen often in practice, but in larger network topologies, a UDP
|
||||
* packet can be received out of sequence.
|
||||
* 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
|
||||
* aware of it. Again, this may not be a concern in practice on small local networks.
|
||||
* For more information, see http://www.cafeaulait.org/course/week12/35.html
|
||||
*
|
||||
* MIT License:
|
||||
* Copyright (c) 2008 Bjoern Hartmann
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* bjoern@cs.stanford.edu 12/30/2008
|
||||
*/
|
||||
Udp.cpp: Library to send/receive UDP packets.
|
||||
|
||||
NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
|
||||
1) UDP does not guarantee the order in which assembled UDP packets are received. This
|
||||
might not happen often in practice, but in larger network topologies, a UDP
|
||||
packet can be received out of sequence.
|
||||
2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
|
||||
aware of it. Again, this may not be a concern in practice on small local networks.
|
||||
For more information, see http://www.cafeaulait.org/course/week12/35.html
|
||||
|
||||
MIT License:
|
||||
Copyright (c) 2008 Bjoern Hartmann
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
bjoern@cs.stanford.edu 12/30/2008
|
||||
*/
|
||||
|
||||
#ifndef udp_h
|
||||
#define udp_h
|
||||
@@ -38,52 +38,59 @@
|
||||
#include <Stream.h>
|
||||
#include <IPAddress.h>
|
||||
|
||||
class UDP : public Stream {
|
||||
class UDP : public Stream
|
||||
{
|
||||
|
||||
public:
|
||||
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 uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
|
||||
virtual void stop() =0; // Finish with the UDP socket
|
||||
public:
|
||||
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 uint8_t beginMulticast(IPAddress, uint16_t)
|
||||
{
|
||||
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
|
||||
}
|
||||
virtual void stop() = 0; // Finish with the UDP socket
|
||||
|
||||
// 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) =0;
|
||||
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
|
||||
// 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) =0;
|
||||
virtual int beginPacket(const char *host, uint16_t port) = 0;
|
||||
// Finish off this packet and send it
|
||||
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||
virtual int endPacket() =0;
|
||||
virtual int endPacket() = 0;
|
||||
// Write a single byte into the packet
|
||||
virtual size_t write(uint8_t) =0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
// Write size bytes from buffer into the packet
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) =0;
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
|
||||
// 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() =0;
|
||||
virtual int parsePacket() = 0;
|
||||
// Number of bytes remaining in the current packet
|
||||
virtual int available() =0;
|
||||
virtual int available() = 0;
|
||||
// Read a single byte from the current packet
|
||||
virtual int read() =0;
|
||||
virtual int read() = 0;
|
||||
// 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) =0;
|
||||
virtual int read(unsigned char* buffer, size_t len) = 0;
|
||||
// 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) =0;
|
||||
virtual int read(char* buffer, size_t len) = 0;
|
||||
// Return the next byte from the current packet without moving on to the next byte
|
||||
virtual int peek() =0;
|
||||
virtual void flush() =0; // Finish reading the current packet
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0; // Finish reading the current packet
|
||||
|
||||
// Return the IP address of the host who sent the current incoming packet
|
||||
virtual IPAddress remoteIP() =0;
|
||||
virtual IPAddress remoteIP() = 0;
|
||||
// Return the port of the host who sent the current incoming packet
|
||||
virtual uint16_t remotePort() =0;
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
|
||||
virtual uint16_t remotePort() = 0;
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -1,36 +1,36 @@
|
||||
/*
|
||||
* Udp.cpp: Library to send/receive UDP packets.
|
||||
*
|
||||
* NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
|
||||
* 1) UDP does not guarantee the order in which assembled UDP packets are received. This
|
||||
* might not happen often in practice, but in larger network topologies, a UDP
|
||||
* packet can be received out of sequence.
|
||||
* 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
|
||||
* aware of it. Again, this may not be a concern in practice on small local networks.
|
||||
* For more information, see http://www.cafeaulait.org/course/week12/35.html
|
||||
*
|
||||
* MIT License:
|
||||
* Copyright (c) 2008 Bjoern Hartmann
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* bjoern@cs.stanford.edu 12/30/2008
|
||||
*/
|
||||
Udp.cpp: Library to send/receive UDP packets.
|
||||
|
||||
NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
|
||||
1) UDP does not guarantee the order in which assembled UDP packets are received. This
|
||||
might not happen often in practice, but in larger network topologies, a UDP
|
||||
packet can be received out of sequence.
|
||||
2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
|
||||
aware of it. Again, this may not be a concern in practice on small local networks.
|
||||
For more information, see http://www.cafeaulait.org/course/week12/35.html
|
||||
|
||||
MIT License:
|
||||
Copyright (c) 2008 Bjoern Hartmann
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
bjoern@cs.stanford.edu 12/30/2008
|
||||
*/
|
||||
|
||||
#ifndef udp_h
|
||||
#define udp_h
|
||||
@@ -38,52 +38,59 @@
|
||||
#include <Stream.h>
|
||||
#include <IPAddress.h>
|
||||
|
||||
class UDP : public Stream {
|
||||
class UDP : public Stream
|
||||
{
|
||||
|
||||
public:
|
||||
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 uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
|
||||
virtual void stop() =0; // Finish with the UDP socket
|
||||
public:
|
||||
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 uint8_t beginMulticast(IPAddress, uint16_t)
|
||||
{
|
||||
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
|
||||
}
|
||||
virtual void stop() = 0; // Finish with the UDP socket
|
||||
|
||||
// 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) =0;
|
||||
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
|
||||
// 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) =0;
|
||||
virtual int beginPacket(const char *host, uint16_t port) = 0;
|
||||
// Finish off this packet and send it
|
||||
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||
virtual int endPacket() =0;
|
||||
virtual int endPacket() = 0;
|
||||
// Write a single byte into the packet
|
||||
virtual size_t write(uint8_t) =0;
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
// Write size bytes from buffer into the packet
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) =0;
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
|
||||
|
||||
// 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() =0;
|
||||
virtual int parsePacket() = 0;
|
||||
// Number of bytes remaining in the current packet
|
||||
virtual int available() =0;
|
||||
virtual int available() = 0;
|
||||
// Read a single byte from the current packet
|
||||
virtual int read() =0;
|
||||
virtual int read() = 0;
|
||||
// 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) =0;
|
||||
virtual int read(unsigned char* buffer, size_t len) = 0;
|
||||
// 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) =0;
|
||||
virtual int read(char* buffer, size_t len) = 0;
|
||||
// Return the next byte from the current packet without moving on to the next byte
|
||||
virtual int peek() =0;
|
||||
virtual void flush() =0; // Finish reading the current packet
|
||||
virtual int peek() = 0;
|
||||
virtual void flush() = 0; // Finish reading the current packet
|
||||
|
||||
// Return the IP address of the host who sent the current incoming packet
|
||||
virtual IPAddress remoteIP() =0;
|
||||
virtual IPAddress remoteIP() = 0;
|
||||
// Return the port of the host who sent the current incoming packet
|
||||
virtual uint16_t remotePort() =0;
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
|
||||
virtual uint16_t remotePort() = 0;
|
||||
protected:
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -1,22 +1,22 @@
|
||||
/*
|
||||
* Arduino header for the Raspberry Pi Pico RP2040
|
||||
*
|
||||
* Copyright (c) 2021 Earle F. Philhower, III <earlephilhower@yahoo.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
Arduino header for the Raspberry Pi Pico RP2040
|
||||
|
||||
Copyright (c) 2021 Earle F. Philhower, III <earlephilhower@yahoo.com>
|
||||
|
||||
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 Arduino_h
|
||||
#define Arduino_h
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "debug_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
// For compatibility to many platforms and libraries
|
||||
@@ -103,8 +103,9 @@ unsigned long millis();
|
||||
// Template which will evaluate at *compile time* to a single 32b number
|
||||
// with the specified bits set.
|
||||
template <size_t N>
|
||||
constexpr uint32_t __bitset(const int (&a)[N], size_t i = 0U) {
|
||||
return i < N ? (1L << a[i]) | __bitset(a, i+1) : 0;
|
||||
constexpr uint32_t __bitset(const int (&a)[N], size_t i = 0U)
|
||||
{
|
||||
return i < N ? (1L << a[i]) | __bitset(a, i + 1) : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@@ -1,22 +1,22 @@
|
||||
/*
|
||||
* Arduino header for the Raspberry Pi Pico RP2040
|
||||
*
|
||||
* Copyright (c) 2021 Earle F. Philhower, III <earlephilhower@yahoo.com>
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
Arduino header for the Raspberry Pi Pico RP2040
|
||||
|
||||
Copyright (c) 2021 Earle F. Philhower, III <earlephilhower@yahoo.com>
|
||||
|
||||
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 Arduino_h
|
||||
#define Arduino_h
|
||||
@@ -37,7 +37,7 @@
|
||||
#include "debug_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
// For compatibility to many platforms and libraries
|
||||
@@ -103,8 +103,9 @@ unsigned long millis();
|
||||
// Template which will evaluate at *compile time* to a single 32b number
|
||||
// with the specified bits set.
|
||||
template <size_t N>
|
||||
constexpr uint32_t __bitset(const int (&a)[N], size_t i = 0U) {
|
||||
return i < N ? (1L << a[i]) | __bitset(a, i+1) : 0;
|
||||
constexpr uint32_t __bitset(const int (&a)[N], size_t i = 0U)
|
||||
{
|
||||
return i < N ? (1L << a[i]) | __bitset(a, i + 1) : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user