mirror of
https://github.com/khoih-prog/AsyncHTTPRequest_Generic.git
synced 2025-07-31 10:57:15 +02:00
Update Packages' Patches
This commit is contained in:
@ -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,9 +276,11 @@ 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;
|
||||
|
||||
@ -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;
|
||||
@ -324,6 +351,7 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
@ -332,6 +360,7 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
}
|
||||
|
||||
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,6 +397,7 @@ 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)
|
||||
rounding /= 10.0;
|
||||
|
||||
@ -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,12 +428,16 @@ 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++)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
@ -405,12 +447,16 @@ size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int bytel
|
||||
|
||||
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++)
|
||||
{
|
||||
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[len - 1 - i]);
|
||||
}
|
||||
|
@ -37,26 +37,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 &);
|
||||
|
@ -1,35 +1,35 @@
|
||||
/*
|
||||
* 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
|
||||
@ -38,13 +38,18 @@
|
||||
#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 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 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
|
||||
|
||||
@ -86,7 +91,10 @@ public:
|
||||
// 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(); };
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -27,7 +27,8 @@
|
||||
//https://www.u-blox.com/sites/default/files/NINA-B1_DataSheet_UBX-15019243.pdf
|
||||
//https://www.u-blox.com/sites/default/files/EVK-NINA-B1_UserGuide_%28UBX-15028120%29_C1-Public.pdf
|
||||
|
||||
const uint32_t g_ADigitalPinMap[] = {
|
||||
const uint32_t g_ADigitalPinMap[] =
|
||||
{
|
||||
// D0 .. D13
|
||||
5, // D0 is P0.05 (UART RX)
|
||||
6, // D1 is P0.06 (UART TX)
|
||||
|
@ -34,8 +34,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -70,7 +70,7 @@ extern "C"
|
||||
#define PIN_NFC_2 (7) // P0.10
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (16) // P0.03
|
||||
#define PIN_A1 (17) // P0.02
|
||||
@ -125,7 +125,7 @@ static const uint8_t D15 = PIN_D15 ;
|
||||
//#define PIN_VBAT PIN_A7
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
#define PIN_SERIAL_RX (0) // P0.05
|
||||
#define PIN_SERIAL_TX (1) // P0.06
|
||||
@ -135,7 +135,7 @@ static const uint8_t D15 = PIN_D15 ;
|
||||
#define PIN_SERIAL_DSR (29) // P0.29
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -149,7 +149,7 @@ static const uint8_t MISO = PIN_SPI_MISO ;
|
||||
static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -165,8 +165,8 @@ static const uint8_t SCL = PIN_WIRE_SCL;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#endif //_VARIANT_NINA_B112_UBLOX_
|
||||
|
@ -29,8 +29,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -57,12 +57,12 @@ extern "C"
|
||||
#define LED_STATE_ON 1 // State when LED is litted
|
||||
|
||||
/*
|
||||
* Buttons
|
||||
Buttons
|
||||
*/
|
||||
#define PIN_BUTTON1 (7)
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (14)
|
||||
#define PIN_A1 (15)
|
||||
@ -99,13 +99,13 @@ static const uint8_t A5 = PIN_A5 ;
|
||||
#define PIN_NFC2 (2)
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
#define PIN_SERIAL1_RX (0)
|
||||
#define PIN_SERIAL1_TX (1)
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -119,7 +119,7 @@ static const uint8_t MISO = PIN_SPI_MISO;
|
||||
static const uint8_t SCK = PIN_SPI_SCK;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -143,7 +143,7 @@ static const uint8_t SCK = PIN_SPI_SCK;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif //_VARIANT_NINA_B302_UBLOX_
|
||||
|
@ -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,9 +276,11 @@ 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;
|
||||
|
||||
@ -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;
|
||||
@ -324,6 +351,7 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
@ -332,6 +360,7 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
}
|
||||
|
||||
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,6 +397,7 @@ 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)
|
||||
rounding /= 10.0;
|
||||
|
||||
@ -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,12 +428,16 @@ 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++)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
@ -405,12 +447,16 @@ size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int bytel
|
||||
|
||||
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++)
|
||||
{
|
||||
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[len - 1 - i]);
|
||||
}
|
||||
|
@ -37,26 +37,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 &);
|
||||
|
@ -1,35 +1,35 @@
|
||||
/*
|
||||
* 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
|
||||
@ -38,13 +38,18 @@
|
||||
#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 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 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
|
||||
|
||||
@ -86,7 +91,10 @@ public:
|
||||
// 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(); };
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -27,7 +27,8 @@
|
||||
//https://www.u-blox.com/sites/default/files/NINA-B1_DataSheet_UBX-15019243.pdf
|
||||
//https://www.u-blox.com/sites/default/files/EVK-NINA-B1_UserGuide_%28UBX-15028120%29_C1-Public.pdf
|
||||
|
||||
const uint32_t g_ADigitalPinMap[] = {
|
||||
const uint32_t g_ADigitalPinMap[] =
|
||||
{
|
||||
// D0 .. D13
|
||||
5, // D0 is P0.05 (UART RX)
|
||||
6, // D1 is P0.06 (UART TX)
|
||||
|
@ -34,8 +34,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -70,7 +70,7 @@ extern "C"
|
||||
#define PIN_NFC_2 (7) // P0.10
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (16) // P0.03
|
||||
#define PIN_A1 (17) // P0.02
|
||||
@ -125,7 +125,7 @@ static const uint8_t D15 = PIN_D15 ;
|
||||
//#define PIN_VBAT PIN_A7
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
#define PIN_SERIAL_RX (0) // P0.05
|
||||
#define PIN_SERIAL_TX (1) // P0.06
|
||||
@ -135,7 +135,7 @@ static const uint8_t D15 = PIN_D15 ;
|
||||
#define PIN_SERIAL_DSR (29) // P0.29
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -149,7 +149,7 @@ static const uint8_t MISO = PIN_SPI_MISO ;
|
||||
static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -165,8 +165,8 @@ static const uint8_t SCL = PIN_WIRE_SCL;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#endif //_VARIANT_NINA_B112_UBLOX_
|
||||
|
@ -29,8 +29,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -57,12 +57,12 @@ extern "C"
|
||||
#define LED_STATE_ON 1 // State when LED is litted
|
||||
|
||||
/*
|
||||
* Buttons
|
||||
Buttons
|
||||
*/
|
||||
#define PIN_BUTTON1 (7)
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (14)
|
||||
#define PIN_A1 (15)
|
||||
@ -99,13 +99,13 @@ static const uint8_t A5 = PIN_A5 ;
|
||||
#define PIN_NFC2 (2)
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
#define PIN_SERIAL1_RX (0)
|
||||
#define PIN_SERIAL1_TX (1)
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -119,7 +119,7 @@ static const uint8_t MISO = PIN_SPI_MISO;
|
||||
static const uint8_t SCK = PIN_SPI_SCK;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -143,7 +143,7 @@ static const uint8_t SCK = PIN_SPI_SCK;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif //_VARIANT_NINA_B302_UBLOX_
|
||||
|
@ -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,9 +276,11 @@ 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;
|
||||
|
||||
@ -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;
|
||||
@ -324,6 +351,7 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
@ -332,6 +360,7 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
}
|
||||
|
||||
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,6 +397,7 @@ 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)
|
||||
rounding /= 10.0;
|
||||
|
||||
@ -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,12 +428,16 @@ 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++)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
@ -405,12 +447,16 @@ size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int bytel
|
||||
|
||||
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++)
|
||||
{
|
||||
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[len - 1 - i]);
|
||||
}
|
||||
|
@ -37,26 +37,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 &);
|
||||
|
@ -1,35 +1,35 @@
|
||||
/*
|
||||
* 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
|
||||
@ -38,13 +38,18 @@
|
||||
#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 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 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
|
||||
|
||||
@ -86,7 +91,10 @@ public:
|
||||
// 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(); };
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -27,7 +27,8 @@
|
||||
//https://www.u-blox.com/sites/default/files/NINA-B1_DataSheet_UBX-15019243.pdf
|
||||
//https://www.u-blox.com/sites/default/files/EVK-NINA-B1_UserGuide_%28UBX-15028120%29_C1-Public.pdf
|
||||
|
||||
const uint32_t g_ADigitalPinMap[] = {
|
||||
const uint32_t g_ADigitalPinMap[] =
|
||||
{
|
||||
// D0 .. D13
|
||||
5, // D0 is P0.05 (UART RX)
|
||||
6, // D1 is P0.06 (UART TX)
|
||||
|
@ -34,8 +34,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -70,7 +70,7 @@ extern "C"
|
||||
#define PIN_NFC_2 (7) // P0.10
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (16) // P0.03
|
||||
#define PIN_A1 (17) // P0.02
|
||||
@ -125,7 +125,7 @@ static const uint8_t D15 = PIN_D15 ;
|
||||
//#define PIN_VBAT PIN_A7
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
#define PIN_SERIAL_RX (0) // P0.05
|
||||
#define PIN_SERIAL_TX (1) // P0.06
|
||||
@ -135,7 +135,7 @@ static const uint8_t D15 = PIN_D15 ;
|
||||
#define PIN_SERIAL_DSR (29) // P0.29
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -149,7 +149,7 @@ static const uint8_t MISO = PIN_SPI_MISO ;
|
||||
static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -165,8 +165,8 @@ static const uint8_t SCL = PIN_WIRE_SCL;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#endif //_VARIANT_NINA_B112_UBLOX_
|
||||
|
@ -29,8 +29,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -57,12 +57,12 @@ extern "C"
|
||||
#define LED_STATE_ON 1 // State when LED is litted
|
||||
|
||||
/*
|
||||
* Buttons
|
||||
Buttons
|
||||
*/
|
||||
#define PIN_BUTTON1 (7)
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (14)
|
||||
#define PIN_A1 (15)
|
||||
@ -99,13 +99,13 @@ static const uint8_t A5 = PIN_A5 ;
|
||||
#define PIN_NFC2 (2)
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
#define PIN_SERIAL1_RX (0)
|
||||
#define PIN_SERIAL1_TX (1)
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -119,7 +119,7 @@ static const uint8_t MISO = PIN_SPI_MISO;
|
||||
static const uint8_t SCK = PIN_SPI_SCK;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -143,7 +143,7 @@ static const uint8_t SCK = PIN_SPI_SCK;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif //_VARIANT_NINA_B302_UBLOX_
|
||||
|
@ -26,8 +26,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -63,7 +63,7 @@ extern "C"
|
||||
*/
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (2)
|
||||
#define PIN_A1 (3)
|
||||
@ -93,7 +93,7 @@ static const uint8_t A7 = PIN_A7 ;
|
||||
static const uint8_t AREF = PIN_AREF;
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
// Serial
|
||||
//Previous Hardware UART definition for nRF52 Arduino Core, below 0.16.0
|
||||
@ -106,7 +106,7 @@ static const uint8_t AREF = PIN_AREF;
|
||||
#define PIN_SERIAL1_TX (17)
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -120,7 +120,7 @@ static const uint8_t MISO = PIN_SPI_MISO ;
|
||||
static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -128,7 +128,7 @@ static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
#define PIN_WIRE_SCL (11)
|
||||
|
||||
/*
|
||||
* QSPI interface for external flash
|
||||
QSPI interface for external flash
|
||||
*/
|
||||
#define PIN_QSPI_SCK 32
|
||||
#define PIN_QSPI_CS 33
|
||||
@ -146,7 +146,7 @@ static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
@ -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,9 +276,11 @@ 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;
|
||||
|
||||
@ -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;
|
||||
@ -324,6 +351,7 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
@ -332,6 +360,7 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
}
|
||||
|
||||
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,6 +397,7 @@ 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)
|
||||
rounding /= 10.0;
|
||||
|
||||
@ -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,12 +428,16 @@ 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++)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
@ -405,12 +447,16 @@ size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int bytel
|
||||
|
||||
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++)
|
||||
{
|
||||
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[len - 1 - i]);
|
||||
}
|
||||
|
@ -37,26 +37,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 &);
|
||||
|
@ -1,35 +1,35 @@
|
||||
/*
|
||||
* 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
|
||||
@ -38,13 +38,18 @@
|
||||
#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 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 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
|
||||
|
||||
@ -86,7 +91,10 @@ public:
|
||||
// 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(); };
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -27,7 +27,8 @@
|
||||
//https://www.u-blox.com/sites/default/files/NINA-B1_DataSheet_UBX-15019243.pdf
|
||||
//https://www.u-blox.com/sites/default/files/EVK-NINA-B1_UserGuide_%28UBX-15028120%29_C1-Public.pdf
|
||||
|
||||
const uint32_t g_ADigitalPinMap[] = {
|
||||
const uint32_t g_ADigitalPinMap[] =
|
||||
{
|
||||
// D0 .. D13
|
||||
5, // D0 is P0.05 (UART RX)
|
||||
6, // D1 is P0.06 (UART TX)
|
||||
|
@ -34,8 +34,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -70,7 +70,7 @@ extern "C"
|
||||
#define PIN_NFC_2 (7) // P0.10
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (16) // P0.03
|
||||
#define PIN_A1 (17) // P0.02
|
||||
@ -125,7 +125,7 @@ static const uint8_t D15 = PIN_D15 ;
|
||||
//#define PIN_VBAT PIN_A7
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
#define PIN_SERIAL_RX (0) // P0.05
|
||||
#define PIN_SERIAL_TX (1) // P0.06
|
||||
@ -135,7 +135,7 @@ static const uint8_t D15 = PIN_D15 ;
|
||||
#define PIN_SERIAL_DSR (29) // P0.29
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -149,7 +149,7 @@ static const uint8_t MISO = PIN_SPI_MISO ;
|
||||
static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -165,8 +165,8 @@ static const uint8_t SCL = PIN_WIRE_SCL;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#endif //_VARIANT_NINA_B112_UBLOX_
|
||||
|
@ -29,8 +29,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -57,12 +57,12 @@ extern "C"
|
||||
#define LED_STATE_ON 1 // State when LED is litted
|
||||
|
||||
/*
|
||||
* Buttons
|
||||
Buttons
|
||||
*/
|
||||
#define PIN_BUTTON1 (7)
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (14)
|
||||
#define PIN_A1 (15)
|
||||
@ -99,13 +99,13 @@ static const uint8_t A5 = PIN_A5 ;
|
||||
#define PIN_NFC2 (2)
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
#define PIN_SERIAL1_RX (0)
|
||||
#define PIN_SERIAL1_TX (1)
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -119,7 +119,7 @@ static const uint8_t MISO = PIN_SPI_MISO;
|
||||
static const uint8_t SCK = PIN_SPI_SCK;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -143,7 +143,7 @@ static const uint8_t SCK = PIN_SPI_SCK;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif //_VARIANT_NINA_B302_UBLOX_
|
||||
|
@ -26,8 +26,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -63,7 +63,7 @@ extern "C"
|
||||
*/
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (2)
|
||||
#define PIN_A1 (3)
|
||||
@ -93,7 +93,7 @@ static const uint8_t A7 = PIN_A7 ;
|
||||
static const uint8_t AREF = PIN_AREF;
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
// Serial
|
||||
//Previous Hardware UART definition for nRF52 Arduino Core, below 0.16.0
|
||||
@ -106,7 +106,7 @@ static const uint8_t AREF = PIN_AREF;
|
||||
#define PIN_SERIAL1_TX (17)
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -120,7 +120,7 @@ static const uint8_t MISO = PIN_SPI_MISO ;
|
||||
static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -128,7 +128,7 @@ static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
#define PIN_WIRE_SCL (11)
|
||||
|
||||
/*
|
||||
* QSPI interface for external flash
|
||||
QSPI interface for external flash
|
||||
*/
|
||||
#define PIN_QSPI_SCK 32
|
||||
#define PIN_QSPI_CS 33
|
||||
@ -146,7 +146,7 @@ static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
@ -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,9 +276,11 @@ 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;
|
||||
|
||||
@ -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;
|
||||
@ -324,6 +351,7 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
@ -332,6 +360,7 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
}
|
||||
|
||||
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,6 +397,7 @@ 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)
|
||||
rounding /= 10.0;
|
||||
|
||||
@ -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,12 +428,16 @@ 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++)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
@ -405,12 +447,16 @@ size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int bytel
|
||||
|
||||
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++)
|
||||
{
|
||||
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[len - 1 - i]);
|
||||
}
|
||||
|
@ -37,26 +37,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 &);
|
||||
|
@ -1,35 +1,35 @@
|
||||
/*
|
||||
* 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
|
||||
@ -38,13 +38,18 @@
|
||||
#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 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 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
|
||||
|
||||
@ -86,7 +91,10 @@ public:
|
||||
// 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(); };
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -27,7 +27,8 @@
|
||||
//https://www.u-blox.com/sites/default/files/NINA-B1_DataSheet_UBX-15019243.pdf
|
||||
//https://www.u-blox.com/sites/default/files/EVK-NINA-B1_UserGuide_%28UBX-15028120%29_C1-Public.pdf
|
||||
|
||||
const uint32_t g_ADigitalPinMap[] = {
|
||||
const uint32_t g_ADigitalPinMap[] =
|
||||
{
|
||||
// D0 .. D13
|
||||
5, // D0 is P0.05 (UART RX)
|
||||
6, // D1 is P0.06 (UART TX)
|
||||
|
@ -34,8 +34,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -70,7 +70,7 @@ extern "C"
|
||||
#define PIN_NFC_2 (7) // P0.10
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (16) // P0.03
|
||||
#define PIN_A1 (17) // P0.02
|
||||
@ -125,7 +125,7 @@ static const uint8_t D15 = PIN_D15 ;
|
||||
//#define PIN_VBAT PIN_A7
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
#define PIN_SERIAL_RX (0) // P0.05
|
||||
#define PIN_SERIAL_TX (1) // P0.06
|
||||
@ -135,7 +135,7 @@ static const uint8_t D15 = PIN_D15 ;
|
||||
#define PIN_SERIAL_DSR (29) // P0.29
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -149,7 +149,7 @@ static const uint8_t MISO = PIN_SPI_MISO ;
|
||||
static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -165,8 +165,8 @@ static const uint8_t SCL = PIN_WIRE_SCL;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#endif //_VARIANT_NINA_B112_UBLOX_
|
||||
|
@ -29,8 +29,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -57,12 +57,12 @@ extern "C"
|
||||
#define LED_STATE_ON 1 // State when LED is litted
|
||||
|
||||
/*
|
||||
* Buttons
|
||||
Buttons
|
||||
*/
|
||||
#define PIN_BUTTON1 (7)
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (14)
|
||||
#define PIN_A1 (15)
|
||||
@ -99,13 +99,13 @@ static const uint8_t A5 = PIN_A5 ;
|
||||
#define PIN_NFC2 (2)
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
#define PIN_SERIAL1_RX (0)
|
||||
#define PIN_SERIAL1_TX (1)
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -119,7 +119,7 @@ static const uint8_t MISO = PIN_SPI_MISO;
|
||||
static const uint8_t SCK = PIN_SPI_SCK;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -143,7 +143,7 @@ static const uint8_t SCK = PIN_SPI_SCK;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif //_VARIANT_NINA_B302_UBLOX_
|
||||
|
@ -26,8 +26,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -63,7 +63,7 @@ extern "C"
|
||||
*/
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (2)
|
||||
#define PIN_A1 (3)
|
||||
@ -93,7 +93,7 @@ static const uint8_t A7 = PIN_A7 ;
|
||||
static const uint8_t AREF = PIN_AREF;
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
// Serial
|
||||
//Previous Hardware UART definition for nRF52 Arduino Core, below 0.16.0
|
||||
@ -106,7 +106,7 @@ static const uint8_t AREF = PIN_AREF;
|
||||
#define PIN_SERIAL1_TX (17)
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -120,7 +120,7 @@ static const uint8_t MISO = PIN_SPI_MISO ;
|
||||
static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -128,7 +128,7 @@ static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
#define PIN_WIRE_SCL (11)
|
||||
|
||||
/*
|
||||
* QSPI interface for external flash
|
||||
QSPI interface for external flash
|
||||
*/
|
||||
#define PIN_QSPI_SCK 32
|
||||
#define PIN_QSPI_CS 33
|
||||
@ -146,7 +146,7 @@ static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
@ -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,9 +276,11 @@ 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;
|
||||
|
||||
@ -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;
|
||||
@ -324,6 +351,7 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
}
|
||||
|
||||
uint16_t n16 = n64;
|
||||
|
||||
while (n16 > 0)
|
||||
{
|
||||
uint16_t qq = n16 / base;
|
||||
@ -332,6 +360,7 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
|
||||
}
|
||||
|
||||
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,6 +397,7 @@ 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)
|
||||
rounding /= 10.0;
|
||||
|
||||
@ -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,12 +428,16 @@ 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++)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
@ -405,12 +447,16 @@ size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int bytel
|
||||
|
||||
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++)
|
||||
{
|
||||
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[len - 1 - i]);
|
||||
}
|
||||
|
@ -37,26 +37,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 &);
|
||||
|
@ -1,35 +1,35 @@
|
||||
/*
|
||||
* 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
|
||||
@ -38,13 +38,18 @@
|
||||
#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 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 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
|
||||
|
||||
@ -86,7 +91,10 @@ public:
|
||||
// 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(); };
|
||||
uint8_t* rawIPAddress(IPAddress& addr)
|
||||
{
|
||||
return addr.raw_address();
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -27,7 +27,8 @@
|
||||
//https://www.u-blox.com/sites/default/files/NINA-B1_DataSheet_UBX-15019243.pdf
|
||||
//https://www.u-blox.com/sites/default/files/EVK-NINA-B1_UserGuide_%28UBX-15028120%29_C1-Public.pdf
|
||||
|
||||
const uint32_t g_ADigitalPinMap[] = {
|
||||
const uint32_t g_ADigitalPinMap[] =
|
||||
{
|
||||
// D0 .. D13
|
||||
5, // D0 is P0.05 (UART RX)
|
||||
6, // D1 is P0.06 (UART TX)
|
||||
|
@ -34,8 +34,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -70,7 +70,7 @@ extern "C"
|
||||
#define PIN_NFC_2 (7) // P0.10
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (16) // P0.03
|
||||
#define PIN_A1 (17) // P0.02
|
||||
@ -125,7 +125,7 @@ static const uint8_t D15 = PIN_D15 ;
|
||||
//#define PIN_VBAT PIN_A7
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
#define PIN_SERIAL_RX (0) // P0.05
|
||||
#define PIN_SERIAL_TX (1) // P0.06
|
||||
@ -135,7 +135,7 @@ static const uint8_t D15 = PIN_D15 ;
|
||||
#define PIN_SERIAL_DSR (29) // P0.29
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -149,7 +149,7 @@ static const uint8_t MISO = PIN_SPI_MISO ;
|
||||
static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -165,8 +165,8 @@ static const uint8_t SCL = PIN_WIRE_SCL;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#endif //_VARIANT_NINA_B112_UBLOX_
|
||||
|
@ -29,8 +29,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -57,12 +57,12 @@ extern "C"
|
||||
#define LED_STATE_ON 1 // State when LED is litted
|
||||
|
||||
/*
|
||||
* Buttons
|
||||
Buttons
|
||||
*/
|
||||
#define PIN_BUTTON1 (7)
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (14)
|
||||
#define PIN_A1 (15)
|
||||
@ -99,13 +99,13 @@ static const uint8_t A5 = PIN_A5 ;
|
||||
#define PIN_NFC2 (2)
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
#define PIN_SERIAL1_RX (0)
|
||||
#define PIN_SERIAL1_TX (1)
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -119,7 +119,7 @@ static const uint8_t MISO = PIN_SPI_MISO;
|
||||
static const uint8_t SCK = PIN_SPI_SCK;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -143,7 +143,7 @@ static const uint8_t SCK = PIN_SPI_SCK;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif //_VARIANT_NINA_B302_UBLOX_
|
||||
|
@ -26,8 +26,8 @@
|
||||
// define USE_LFRC // Board uses RC for LF
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
*----------------------------------------------------------------------------*/
|
||||
Headers
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include "WVariant.h"
|
||||
|
||||
@ -63,7 +63,7 @@ extern "C"
|
||||
*/
|
||||
|
||||
/*
|
||||
* Analog pins
|
||||
Analog pins
|
||||
*/
|
||||
#define PIN_A0 (2)
|
||||
#define PIN_A1 (3)
|
||||
@ -93,7 +93,7 @@ static const uint8_t A7 = PIN_A7 ;
|
||||
static const uint8_t AREF = PIN_AREF;
|
||||
|
||||
/*
|
||||
* Serial interfaces
|
||||
Serial interfaces
|
||||
*/
|
||||
// Serial
|
||||
//Previous Hardware UART definition for nRF52 Arduino Core, below 0.16.0
|
||||
@ -106,7 +106,7 @@ static const uint8_t AREF = PIN_AREF;
|
||||
#define PIN_SERIAL1_TX (17)
|
||||
|
||||
/*
|
||||
* SPI Interfaces
|
||||
SPI Interfaces
|
||||
*/
|
||||
#define SPI_INTERFACES_COUNT 1
|
||||
|
||||
@ -120,7 +120,7 @@ static const uint8_t MISO = PIN_SPI_MISO ;
|
||||
static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
|
||||
/*
|
||||
* Wire Interfaces
|
||||
Wire Interfaces
|
||||
*/
|
||||
#define WIRE_INTERFACES_COUNT 1
|
||||
|
||||
@ -128,7 +128,7 @@ static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
#define PIN_WIRE_SCL (11)
|
||||
|
||||
/*
|
||||
* QSPI interface for external flash
|
||||
QSPI interface for external flash
|
||||
*/
|
||||
#define PIN_QSPI_SCK 32
|
||||
#define PIN_QSPI_CS 33
|
||||
@ -146,7 +146,7 @@ static const uint8_t SCK = PIN_SPI_SCK ;
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Arduino objects - C++ only
|
||||
*----------------------------------------------------------------------------*/
|
||||
Arduino objects - C++ only
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user