Update Packages' Patches

This commit is contained in:
Khoi Hoang
2022-11-23 17:04:14 -05:00
committed by GitHub
parent ffb8322b5e
commit a94b6658b5
50 changed files with 2378 additions and 1952 deletions

View File

@ -36,10 +36,15 @@
size_t Print::write(const uint8_t *buffer, size_t size)
{
size_t n = 0;
while (size--) {
if (write(*buffer++)) n++;
else break;
while (size--)
{
if (write(*buffer++))
n++;
else
break;
}
return n;
}
@ -80,46 +85,64 @@ size_t Print::print(unsigned int n, int base)
size_t Print::print(long n, int base)
{
if (base == 0) {
if (base == 0)
{
return write(n);
} else if (base == 10) {
if (n < 0) {
}
else if (base == 10)
{
if (n < 0)
{
int t = print('-');
n = -n;
return printNumber(n, 10) + t;
}
return printNumber(n, 10);
} else {
}
else
{
return printNumber(n, base);
}
}
size_t Print::print(unsigned long n, int base)
{
if (base == 0) return write(n);
else return printNumber(n, base);
if (base == 0)
return write(n);
else
return printNumber(n, base);
}
size_t Print::print(long long n, int base)
{
if (base == 0) {
if (base == 0)
{
return write(n);
} else if (base == 10) {
if (n < 0) {
}
else if (base == 10)
{
if (n < 0)
{
int t = print('-');
n = -n;
return printULLNumber(n, 10) + t;
}
return printULLNumber(n, 10);
} else {
}
else
{
return printULLNumber(n, base);
}
}
size_t Print::print(unsigned long long n, int base)
{
if (base == 0) return write(n);
else return printULLNumber(n, base);
if (base == 0)
return write(n);
else
return printULLNumber(n, base);
}
size_t Print::print(double n, int digits)
@ -253,14 +276,16 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
*str = '\0';
// prevent crash if called with base == 1
if (base < 2) base = 10;
if (base < 2)
base = 10;
do {
do
{
char c = n % base;
n /= base;
*--str = c < 10 ? c + '0' : c + 'A' - 10;
} while(n);
} while (n);
return write(str);
}
@ -268,23 +293,23 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
// REFERENCE IMPLEMENTATION FOR ULL
// size_t Print::printULLNumber(unsigned long long n, uint8_t base)
// {
// // if limited to base 10 and 16 the bufsize can be smaller
// char buf[65];
// char *str = &buf[64];
// // if limited to base 10 and 16 the bufsize can be smaller
// char buf[65];
// char *str = &buf[64];
// *str = '\0';
// *str = '\0';
// // prevent crash if called with base == 1
// if (base < 2) base = 10;
// // prevent crash if called with base == 1
// if (base < 2) base = 10;
// do {
// unsigned long long t = n / base;
// char c = n - t * base; // faster than c = n%base;
// n = t;
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
// } while(n);
// do {
// unsigned long long t = n / base;
// char c = n - t * base; // faster than c = n%base;
// n = t;
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
// } while(n);
// return write(str);
// return write(str);
// }
// FAST IMPLEMENTATION FOR ULL
@ -296,11 +321,13 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
uint8_t innerLoops = 0;
// prevent crash if called with base == 1
if (base < 2) base = 10;
if (base < 2)
base = 10;
// process chunks that fit in "16 bit math".
uint16_t top = 0xFFFF / base;
uint16_t th16 = 1;
while (th16 < top)
{
th16 *= base;
@ -311,31 +338,33 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
{
// 64 bit math part
uint64_t q = n64 / th16;
uint16_t r = n64 - q*th16;
uint16_t r = n64 - q * th16;
n64 = q;
// 16 bit math loop to do remainder. (note buffer is filled reverse)
for (uint8_t j=0; j < innerLoops; j++)
for (uint8_t j = 0; j < innerLoops; j++)
{
uint16_t qq = r/base;
buf[i++] = r - qq*base;
uint16_t qq = r / base;
buf[i++] = r - qq * base;
r = qq;
}
}
uint16_t n16 = n64;
while (n16 > 0)
{
uint16_t qq = n16/base;
buf[i++] = n16 - qq*base;
uint16_t qq = n16 / base;
buf[i++] = n16 - qq * base;
n16 = qq;
}
size_t bytes = i;
for (; i > 0; i--)
write((char) (buf[i - 1] < 10 ?
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
return bytes;
}
@ -347,21 +376,29 @@ 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)
{
n += print('-');
number = -number;
n += print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
for (uint8_t i = 0; i < digits; ++i)
rounding /= 10.0;
number += rounding;
@ -372,7 +409,8 @@ size_t Print::printFloat(double number, int digits)
n += print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0) {
if (digits > 0)
{
n += print(".");
}
@ -390,31 +428,39 @@ size_t Print::printFloat(double number, int digits)
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
{
if (buffer == NULL || len == 0) return 0;
if (buffer == NULL || len == 0)
return 0;
for(int i=0; i<len; i++)
for (int i = 0; i < len; i++)
{
if ( i != 0 ) print(delim);
if ( byteline && (i%byteline == 0) ) println();
if ( i != 0 )
print(delim);
if ( byteline && (i % byteline == 0) )
println();
this->printf("%02X", buffer[i]);
}
return (len*3 - 1);
return (len * 3 - 1);
}
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
{
if (buffer == NULL || len == 0) return 0;
if (buffer == NULL || len == 0)
return 0;
for(int i=0; i<len; i++)
for (int i = 0; i < len; i++)
{
if (i != 0) print(delim);
if ( byteline && (i%byteline == 0) ) println();
if (i != 0)
print(delim);
this->printf("%02X", buffer[len-1-i]);
if ( byteline && (i % byteline == 0) )
println();
this->printf("%02X", buffer[len - 1 - i]);
}
return (len*3 - 1);
return (len * 3 - 1);
}

View File

@ -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 &);
@ -89,14 +105,14 @@ class Print
size_t printf(const char * format, ...);
size_t printBuffer(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
size_t printBuffer(char const buffer[], int size, char delim=' ', int byteline = 0)
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
{
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
}
size_t printBufferReverse(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
size_t printBufferReverse(char const buffer[], int size, char delim=' ', int byteline = 0)
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
{
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
}

View File

@ -1,36 +1,36 @@
/*
* Udp.cpp: Library to send/receive UDP packets.
*
* NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
* 1) UDP does not guarantee the order in which assembled UDP packets are received. This
* might not happen often in practice, but in larger network topologies, a UDP
* packet can be received out of sequence.
* 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
* aware of it. Again, this may not be a concern in practice on small local networks.
* For more information, see http://www.cafeaulait.org/course/week12/35.html
*
* MIT License:
* Copyright (c) 2008 Bjoern Hartmann
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* bjoern@cs.stanford.edu 12/30/2008
*/
Udp.cpp: Library to send/receive UDP packets.
NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
1) UDP does not guarantee the order in which assembled UDP packets are received. This
might not happen often in practice, but in larger network topologies, a UDP
packet can be received out of sequence.
2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
aware of it. Again, this may not be a concern in practice on small local networks.
For more information, see http://www.cafeaulait.org/course/week12/35.html
MIT License:
Copyright (c) 2008 Bjoern Hartmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
bjoern@cs.stanford.edu 12/30/2008
*/
#ifndef udp_h
#define udp_h
@ -38,55 +38,63 @@
#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
public:
virtual uint8_t begin(uint16_t) =
0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
virtual uint8_t beginMulticast(IPAddress, uint16_t)
{
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
}
virtual void stop() =0; // Finish with the UDP socket
virtual void stop() = 0; // Finish with the UDP socket
// Sending UDP packets
// Sending UDP packets
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port) =0;
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port) =0;
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket() =0;
// Write a single byte into the packet
virtual size_t write(uint8_t) =0;
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size) =0;
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port) = 0;
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket() = 0;
// Write a single byte into the packet
virtual size_t write(uint8_t) = 0;
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket() =0;
// Number of bytes remaining in the current packet
virtual int available() =0;
// Read a single byte from the current packet
virtual int read() =0;
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len) =0;
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) =0;
// Return the next byte from the current packet without moving on to the next byte
virtual int peek() =0;
virtual void flush() =0; // Finish reading the current packet
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket() = 0;
// Number of bytes remaining in the current packet
virtual int available() = 0;
// Read a single byte from the current packet
virtual int read() = 0;
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len) = 0;
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) = 0;
// Return the next byte from the current packet without moving on to the next byte
virtual int peek() = 0;
virtual void flush() = 0; // Finish reading the current packet
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() =0;
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() =0;
protected:
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() = 0;
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() = 0;
protected:
uint8_t* rawIPAddress(IPAddress& addr)
{
return addr.raw_address();
};
};
#endif

View File

@ -27,8 +27,9 @@
//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[] = {
// D0 .. D13
const uint32_t g_ADigitalPinMap[] =
{
// D0 .. D13
5, // D0 is P0.05 (UART RX)
6, // D1 is P0.06 (UART TX)
7, // D2 is P0.07

View File

@ -34,8 +34,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -66,12 +66,12 @@ extern "C"
#define SW2 (19)
// NFC
#define PIN_NFC_1 (6) // P0.9
#define PIN_NFC_2 (7) // P0.10
#define PIN_NFC_1 (6) // P0.9
#define PIN_NFC_2 (7) // P0.10
/*
* Analog pins
*/
Analog pins
*/
#define PIN_A0 (16) // P0.03
#define PIN_A1 (17) // P0.02
#define PIN_A2 (18) // P0.04
@ -125,8 +125,8 @@ 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
#define PIN_SERIAL_CTS (2) // P0.07
@ -135,8 +135,8 @@ static const uint8_t D15 = PIN_D15 ;
#define PIN_SERIAL_DSR (29) // P0.29
/*
* SPI Interfaces
*/
SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (12) // P0.12
@ -149,8 +149,8 @@ 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
#define PIN_WIRE_SDA (14) // P0.02
@ -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_

View File

@ -27,7 +27,7 @@
const uint32_t g_ADigitalPinMap[] =
{
// D0 .. D13
// D0 .. D13
29, // D0 is P0.29 (UART RX)
45, // D1 is P1.13 (UART TX)
44, // D2 is P1.12 (NFC2)

View File

@ -1,4 +1,4 @@
/*
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
Copyright (c) 2016 Sandeep Mistry All right reserved.
Copyright (c) 2018, Adafruit Industries (adafruit.com)
@ -29,8 +29,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -57,13 +57,13 @@ 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)
#define PIN_A2 (16)
@ -99,14 +99,14 @@ 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
#define PIN_SPI_MISO (22) //24 original
@ -119,8 +119,8 @@ 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
#define PIN_WIRE_SDA (20)
@ -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_

View File

@ -36,10 +36,15 @@
size_t Print::write(const uint8_t *buffer, size_t size)
{
size_t n = 0;
while (size--) {
if (write(*buffer++)) n++;
else break;
while (size--)
{
if (write(*buffer++))
n++;
else
break;
}
return n;
}
@ -80,46 +85,64 @@ size_t Print::print(unsigned int n, int base)
size_t Print::print(long n, int base)
{
if (base == 0) {
if (base == 0)
{
return write(n);
} else if (base == 10) {
if (n < 0) {
}
else if (base == 10)
{
if (n < 0)
{
int t = print('-');
n = -n;
return printNumber(n, 10) + t;
}
return printNumber(n, 10);
} else {
}
else
{
return printNumber(n, base);
}
}
size_t Print::print(unsigned long n, int base)
{
if (base == 0) return write(n);
else return printNumber(n, base);
if (base == 0)
return write(n);
else
return printNumber(n, base);
}
size_t Print::print(long long n, int base)
{
if (base == 0) {
if (base == 0)
{
return write(n);
} else if (base == 10) {
if (n < 0) {
}
else if (base == 10)
{
if (n < 0)
{
int t = print('-');
n = -n;
return printULLNumber(n, 10) + t;
}
return printULLNumber(n, 10);
} else {
}
else
{
return printULLNumber(n, base);
}
}
size_t Print::print(unsigned long long n, int base)
{
if (base == 0) return write(n);
else return printULLNumber(n, base);
if (base == 0)
return write(n);
else
return printULLNumber(n, base);
}
size_t Print::print(double n, int digits)
@ -253,14 +276,16 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
*str = '\0';
// prevent crash if called with base == 1
if (base < 2) base = 10;
if (base < 2)
base = 10;
do {
do
{
char c = n % base;
n /= base;
*--str = c < 10 ? c + '0' : c + 'A' - 10;
} while(n);
} while (n);
return write(str);
}
@ -268,23 +293,23 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
// REFERENCE IMPLEMENTATION FOR ULL
// size_t Print::printULLNumber(unsigned long long n, uint8_t base)
// {
// // if limited to base 10 and 16 the bufsize can be smaller
// char buf[65];
// char *str = &buf[64];
// // if limited to base 10 and 16 the bufsize can be smaller
// char buf[65];
// char *str = &buf[64];
// *str = '\0';
// *str = '\0';
// // prevent crash if called with base == 1
// if (base < 2) base = 10;
// // prevent crash if called with base == 1
// if (base < 2) base = 10;
// do {
// unsigned long long t = n / base;
// char c = n - t * base; // faster than c = n%base;
// n = t;
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
// } while(n);
// do {
// unsigned long long t = n / base;
// char c = n - t * base; // faster than c = n%base;
// n = t;
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
// } while(n);
// return write(str);
// return write(str);
// }
// FAST IMPLEMENTATION FOR ULL
@ -296,11 +321,13 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
uint8_t innerLoops = 0;
// prevent crash if called with base == 1
if (base < 2) base = 10;
if (base < 2)
base = 10;
// process chunks that fit in "16 bit math".
uint16_t top = 0xFFFF / base;
uint16_t th16 = 1;
while (th16 < top)
{
th16 *= base;
@ -311,31 +338,33 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
{
// 64 bit math part
uint64_t q = n64 / th16;
uint16_t r = n64 - q*th16;
uint16_t r = n64 - q * th16;
n64 = q;
// 16 bit math loop to do remainder. (note buffer is filled reverse)
for (uint8_t j=0; j < innerLoops; j++)
for (uint8_t j = 0; j < innerLoops; j++)
{
uint16_t qq = r/base;
buf[i++] = r - qq*base;
uint16_t qq = r / base;
buf[i++] = r - qq * base;
r = qq;
}
}
uint16_t n16 = n64;
while (n16 > 0)
{
uint16_t qq = n16/base;
buf[i++] = n16 - qq*base;
uint16_t qq = n16 / base;
buf[i++] = n16 - qq * base;
n16 = qq;
}
size_t bytes = i;
for (; i > 0; i--)
write((char) (buf[i - 1] < 10 ?
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
return bytes;
}
@ -347,21 +376,29 @@ 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)
{
n += print('-');
number = -number;
n += print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
for (uint8_t i = 0; i < digits; ++i)
rounding /= 10.0;
number += rounding;
@ -372,7 +409,8 @@ size_t Print::printFloat(double number, int digits)
n += print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0) {
if (digits > 0)
{
n += print(".");
}
@ -390,31 +428,39 @@ size_t Print::printFloat(double number, int digits)
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
{
if (buffer == NULL || len == 0) return 0;
if (buffer == NULL || len == 0)
return 0;
for(int i=0; i<len; i++)
for (int i = 0; i < len; i++)
{
if ( i != 0 ) print(delim);
if ( byteline && (i%byteline == 0) ) println();
if ( i != 0 )
print(delim);
if ( byteline && (i % byteline == 0) )
println();
this->printf("%02X", buffer[i]);
}
return (len*3 - 1);
return (len * 3 - 1);
}
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
{
if (buffer == NULL || len == 0) return 0;
if (buffer == NULL || len == 0)
return 0;
for(int i=0; i<len; i++)
for (int i = 0; i < len; i++)
{
if (i != 0) print(delim);
if ( byteline && (i%byteline == 0) ) println();
if (i != 0)
print(delim);
this->printf("%02X", buffer[len-1-i]);
if ( byteline && (i % byteline == 0) )
println();
this->printf("%02X", buffer[len - 1 - i]);
}
return (len*3 - 1);
return (len * 3 - 1);
}

View File

@ -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 &);
@ -89,14 +105,14 @@ class Print
size_t printf(const char * format, ...);
size_t printBuffer(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
size_t printBuffer(char const buffer[], int size, char delim=' ', int byteline = 0)
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
{
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
}
size_t printBufferReverse(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
size_t printBufferReverse(char const buffer[], int size, char delim=' ', int byteline = 0)
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
{
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
}

View File

@ -1,36 +1,36 @@
/*
* Udp.cpp: Library to send/receive UDP packets.
*
* NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
* 1) UDP does not guarantee the order in which assembled UDP packets are received. This
* might not happen often in practice, but in larger network topologies, a UDP
* packet can be received out of sequence.
* 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
* aware of it. Again, this may not be a concern in practice on small local networks.
* For more information, see http://www.cafeaulait.org/course/week12/35.html
*
* MIT License:
* Copyright (c) 2008 Bjoern Hartmann
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* bjoern@cs.stanford.edu 12/30/2008
*/
Udp.cpp: Library to send/receive UDP packets.
NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
1) UDP does not guarantee the order in which assembled UDP packets are received. This
might not happen often in practice, but in larger network topologies, a UDP
packet can be received out of sequence.
2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
aware of it. Again, this may not be a concern in practice on small local networks.
For more information, see http://www.cafeaulait.org/course/week12/35.html
MIT License:
Copyright (c) 2008 Bjoern Hartmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
bjoern@cs.stanford.edu 12/30/2008
*/
#ifndef udp_h
#define udp_h
@ -38,55 +38,63 @@
#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
public:
virtual uint8_t begin(uint16_t) =
0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
virtual uint8_t beginMulticast(IPAddress, uint16_t)
{
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
}
virtual void stop() =0; // Finish with the UDP socket
virtual void stop() = 0; // Finish with the UDP socket
// Sending UDP packets
// Sending UDP packets
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port) =0;
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port) =0;
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket() =0;
// Write a single byte into the packet
virtual size_t write(uint8_t) =0;
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size) =0;
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port) = 0;
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket() = 0;
// Write a single byte into the packet
virtual size_t write(uint8_t) = 0;
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket() =0;
// Number of bytes remaining in the current packet
virtual int available() =0;
// Read a single byte from the current packet
virtual int read() =0;
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len) =0;
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) =0;
// Return the next byte from the current packet without moving on to the next byte
virtual int peek() =0;
virtual void flush() =0; // Finish reading the current packet
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket() = 0;
// Number of bytes remaining in the current packet
virtual int available() = 0;
// Read a single byte from the current packet
virtual int read() = 0;
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len) = 0;
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) = 0;
// Return the next byte from the current packet without moving on to the next byte
virtual int peek() = 0;
virtual void flush() = 0; // Finish reading the current packet
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() =0;
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() =0;
protected:
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() = 0;
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() = 0;
protected:
uint8_t* rawIPAddress(IPAddress& addr)
{
return addr.raw_address();
};
};
#endif

View File

@ -27,8 +27,9 @@
//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[] = {
// D0 .. D13
const uint32_t g_ADigitalPinMap[] =
{
// D0 .. D13
5, // D0 is P0.05 (UART RX)
6, // D1 is P0.06 (UART TX)
7, // D2 is P0.07

View File

@ -34,8 +34,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -66,12 +66,12 @@ extern "C"
#define SW2 (19)
// NFC
#define PIN_NFC_1 (6) // P0.9
#define PIN_NFC_2 (7) // P0.10
#define PIN_NFC_1 (6) // P0.9
#define PIN_NFC_2 (7) // P0.10
/*
* Analog pins
*/
Analog pins
*/
#define PIN_A0 (16) // P0.03
#define PIN_A1 (17) // P0.02
#define PIN_A2 (18) // P0.04
@ -125,8 +125,8 @@ 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
#define PIN_SERIAL_CTS (2) // P0.07
@ -135,8 +135,8 @@ static const uint8_t D15 = PIN_D15 ;
#define PIN_SERIAL_DSR (29) // P0.29
/*
* SPI Interfaces
*/
SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (12) // P0.12
@ -149,8 +149,8 @@ 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
#define PIN_WIRE_SDA (14) // P0.02
@ -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_

View File

@ -27,7 +27,7 @@
const uint32_t g_ADigitalPinMap[] =
{
// D0 .. D13
// D0 .. D13
29, // D0 is P0.29 (UART RX)
45, // D1 is P1.13 (UART TX)
44, // D2 is P1.12 (NFC2)

View File

@ -1,4 +1,4 @@
/*
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
Copyright (c) 2016 Sandeep Mistry All right reserved.
Copyright (c) 2018, Adafruit Industries (adafruit.com)
@ -29,8 +29,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -57,13 +57,13 @@ 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)
#define PIN_A2 (16)
@ -99,14 +99,14 @@ 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
#define PIN_SPI_MISO (22) //24 original
@ -119,8 +119,8 @@ 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
#define PIN_WIRE_SDA (20)
@ -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_

View File

@ -36,10 +36,15 @@
size_t Print::write(const uint8_t *buffer, size_t size)
{
size_t n = 0;
while (size--) {
if (write(*buffer++)) n++;
else break;
while (size--)
{
if (write(*buffer++))
n++;
else
break;
}
return n;
}
@ -80,46 +85,64 @@ size_t Print::print(unsigned int n, int base)
size_t Print::print(long n, int base)
{
if (base == 0) {
if (base == 0)
{
return write(n);
} else if (base == 10) {
if (n < 0) {
}
else if (base == 10)
{
if (n < 0)
{
int t = print('-');
n = -n;
return printNumber(n, 10) + t;
}
return printNumber(n, 10);
} else {
}
else
{
return printNumber(n, base);
}
}
size_t Print::print(unsigned long n, int base)
{
if (base == 0) return write(n);
else return printNumber(n, base);
if (base == 0)
return write(n);
else
return printNumber(n, base);
}
size_t Print::print(long long n, int base)
{
if (base == 0) {
if (base == 0)
{
return write(n);
} else if (base == 10) {
if (n < 0) {
}
else if (base == 10)
{
if (n < 0)
{
int t = print('-');
n = -n;
return printULLNumber(n, 10) + t;
}
return printULLNumber(n, 10);
} else {
}
else
{
return printULLNumber(n, base);
}
}
size_t Print::print(unsigned long long n, int base)
{
if (base == 0) return write(n);
else return printULLNumber(n, base);
if (base == 0)
return write(n);
else
return printULLNumber(n, base);
}
size_t Print::print(double n, int digits)
@ -253,14 +276,16 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
*str = '\0';
// prevent crash if called with base == 1
if (base < 2) base = 10;
if (base < 2)
base = 10;
do {
do
{
char c = n % base;
n /= base;
*--str = c < 10 ? c + '0' : c + 'A' - 10;
} while(n);
} while (n);
return write(str);
}
@ -268,23 +293,23 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
// REFERENCE IMPLEMENTATION FOR ULL
// size_t Print::printULLNumber(unsigned long long n, uint8_t base)
// {
// // if limited to base 10 and 16 the bufsize can be smaller
// char buf[65];
// char *str = &buf[64];
// // if limited to base 10 and 16 the bufsize can be smaller
// char buf[65];
// char *str = &buf[64];
// *str = '\0';
// *str = '\0';
// // prevent crash if called with base == 1
// if (base < 2) base = 10;
// // prevent crash if called with base == 1
// if (base < 2) base = 10;
// do {
// unsigned long long t = n / base;
// char c = n - t * base; // faster than c = n%base;
// n = t;
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
// } while(n);
// do {
// unsigned long long t = n / base;
// char c = n - t * base; // faster than c = n%base;
// n = t;
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
// } while(n);
// return write(str);
// return write(str);
// }
// FAST IMPLEMENTATION FOR ULL
@ -296,11 +321,13 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
uint8_t innerLoops = 0;
// prevent crash if called with base == 1
if (base < 2) base = 10;
if (base < 2)
base = 10;
// process chunks that fit in "16 bit math".
uint16_t top = 0xFFFF / base;
uint16_t th16 = 1;
while (th16 < top)
{
th16 *= base;
@ -311,31 +338,33 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
{
// 64 bit math part
uint64_t q = n64 / th16;
uint16_t r = n64 - q*th16;
uint16_t r = n64 - q * th16;
n64 = q;
// 16 bit math loop to do remainder. (note buffer is filled reverse)
for (uint8_t j=0; j < innerLoops; j++)
for (uint8_t j = 0; j < innerLoops; j++)
{
uint16_t qq = r/base;
buf[i++] = r - qq*base;
uint16_t qq = r / base;
buf[i++] = r - qq * base;
r = qq;
}
}
uint16_t n16 = n64;
while (n16 > 0)
{
uint16_t qq = n16/base;
buf[i++] = n16 - qq*base;
uint16_t qq = n16 / base;
buf[i++] = n16 - qq * base;
n16 = qq;
}
size_t bytes = i;
for (; i > 0; i--)
write((char) (buf[i - 1] < 10 ?
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
return bytes;
}
@ -347,21 +376,29 @@ 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)
{
n += print('-');
number = -number;
n += print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
for (uint8_t i = 0; i < digits; ++i)
rounding /= 10.0;
number += rounding;
@ -372,7 +409,8 @@ size_t Print::printFloat(double number, int digits)
n += print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0) {
if (digits > 0)
{
n += print(".");
}
@ -390,31 +428,39 @@ size_t Print::printFloat(double number, int digits)
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
{
if (buffer == NULL || len == 0) return 0;
if (buffer == NULL || len == 0)
return 0;
for(int i=0; i<len; i++)
for (int i = 0; i < len; i++)
{
if ( i != 0 ) print(delim);
if ( byteline && (i%byteline == 0) ) println();
if ( i != 0 )
print(delim);
if ( byteline && (i % byteline == 0) )
println();
this->printf("%02X", buffer[i]);
}
return (len*3 - 1);
return (len * 3 - 1);
}
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
{
if (buffer == NULL || len == 0) return 0;
if (buffer == NULL || len == 0)
return 0;
for(int i=0; i<len; i++)
for (int i = 0; i < len; i++)
{
if (i != 0) print(delim);
if ( byteline && (i%byteline == 0) ) println();
if (i != 0)
print(delim);
this->printf("%02X", buffer[len-1-i]);
if ( byteline && (i % byteline == 0) )
println();
this->printf("%02X", buffer[len - 1 - i]);
}
return (len*3 - 1);
return (len * 3 - 1);
}

View File

@ -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 &);
@ -89,14 +105,14 @@ class Print
size_t printf(const char * format, ...);
size_t printBuffer(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
size_t printBuffer(char const buffer[], int size, char delim=' ', int byteline = 0)
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
{
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
}
size_t printBufferReverse(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
size_t printBufferReverse(char const buffer[], int size, char delim=' ', int byteline = 0)
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
{
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
}

View File

@ -1,36 +1,36 @@
/*
* Udp.cpp: Library to send/receive UDP packets.
*
* NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
* 1) UDP does not guarantee the order in which assembled UDP packets are received. This
* might not happen often in practice, but in larger network topologies, a UDP
* packet can be received out of sequence.
* 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
* aware of it. Again, this may not be a concern in practice on small local networks.
* For more information, see http://www.cafeaulait.org/course/week12/35.html
*
* MIT License:
* Copyright (c) 2008 Bjoern Hartmann
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* bjoern@cs.stanford.edu 12/30/2008
*/
Udp.cpp: Library to send/receive UDP packets.
NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
1) UDP does not guarantee the order in which assembled UDP packets are received. This
might not happen often in practice, but in larger network topologies, a UDP
packet can be received out of sequence.
2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
aware of it. Again, this may not be a concern in practice on small local networks.
For more information, see http://www.cafeaulait.org/course/week12/35.html
MIT License:
Copyright (c) 2008 Bjoern Hartmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
bjoern@cs.stanford.edu 12/30/2008
*/
#ifndef udp_h
#define udp_h
@ -38,55 +38,63 @@
#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
public:
virtual uint8_t begin(uint16_t) =
0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
virtual uint8_t beginMulticast(IPAddress, uint16_t)
{
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
}
virtual void stop() =0; // Finish with the UDP socket
virtual void stop() = 0; // Finish with the UDP socket
// Sending UDP packets
// Sending UDP packets
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port) =0;
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port) =0;
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket() =0;
// Write a single byte into the packet
virtual size_t write(uint8_t) =0;
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size) =0;
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port) = 0;
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket() = 0;
// Write a single byte into the packet
virtual size_t write(uint8_t) = 0;
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket() =0;
// Number of bytes remaining in the current packet
virtual int available() =0;
// Read a single byte from the current packet
virtual int read() =0;
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len) =0;
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) =0;
// Return the next byte from the current packet without moving on to the next byte
virtual int peek() =0;
virtual void flush() =0; // Finish reading the current packet
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket() = 0;
// Number of bytes remaining in the current packet
virtual int available() = 0;
// Read a single byte from the current packet
virtual int read() = 0;
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len) = 0;
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) = 0;
// Return the next byte from the current packet without moving on to the next byte
virtual int peek() = 0;
virtual void flush() = 0; // Finish reading the current packet
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() =0;
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() =0;
protected:
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() = 0;
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() = 0;
protected:
uint8_t* rawIPAddress(IPAddress& addr)
{
return addr.raw_address();
};
};
#endif

View File

@ -27,8 +27,9 @@
//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[] = {
// D0 .. D13
const uint32_t g_ADigitalPinMap[] =
{
// D0 .. D13
5, // D0 is P0.05 (UART RX)
6, // D1 is P0.06 (UART TX)
7, // D2 is P0.07

View File

@ -34,8 +34,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -66,12 +66,12 @@ extern "C"
#define SW2 (19)
// NFC
#define PIN_NFC_1 (6) // P0.9
#define PIN_NFC_2 (7) // P0.10
#define PIN_NFC_1 (6) // P0.9
#define PIN_NFC_2 (7) // P0.10
/*
* Analog pins
*/
Analog pins
*/
#define PIN_A0 (16) // P0.03
#define PIN_A1 (17) // P0.02
#define PIN_A2 (18) // P0.04
@ -125,8 +125,8 @@ 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
#define PIN_SERIAL_CTS (2) // P0.07
@ -135,8 +135,8 @@ static const uint8_t D15 = PIN_D15 ;
#define PIN_SERIAL_DSR (29) // P0.29
/*
* SPI Interfaces
*/
SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (12) // P0.12
@ -149,8 +149,8 @@ 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
#define PIN_WIRE_SDA (14) // P0.02
@ -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_

View File

@ -27,7 +27,7 @@
const uint32_t g_ADigitalPinMap[] =
{
// D0 .. D13
// D0 .. D13
29, // D0 is P0.29 (UART RX)
45, // D1 is P1.13 (UART TX)
44, // D2 is P1.12 (NFC2)

View File

@ -1,4 +1,4 @@
/*
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
Copyright (c) 2016 Sandeep Mistry All right reserved.
Copyright (c) 2018, Adafruit Industries (adafruit.com)
@ -29,8 +29,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -57,13 +57,13 @@ 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)
#define PIN_A2 (16)
@ -99,14 +99,14 @@ 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
#define PIN_SPI_MISO (22) //24 original
@ -119,8 +119,8 @@ 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
#define PIN_WIRE_SDA (20)
@ -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_

View File

@ -26,8 +26,8 @@
const uint32_t g_ADigitalPinMap[] =
{
// P0
0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
8 , 9 , 10, 11, 12, 13, 14, 15,
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,

View File

@ -1,4 +1,4 @@
/*
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
Copyright (c) 2016 Sandeep Mistry All right reserved.
Copyright (c) 2018, Adafruit Industries (adafruit.com)
@ -26,8 +26,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -56,15 +56,15 @@ extern "C"
// Buttons
/*
#define PIN_BUTTON1 (2)
#define PIN_BUTTON2 (3)
#define PIN_BUTTON3 (4)
#define PIN_BUTTON4 (5)
#define PIN_BUTTON1 (2)
#define PIN_BUTTON2 (3)
#define PIN_BUTTON3 (4)
#define PIN_BUTTON4 (5)
*/
/*
* Analog pins
*/
Analog pins
*/
#define PIN_A0 (2)
#define PIN_A1 (3)
#define PIN_A2 (4)
@ -93,8 +93,8 @@ 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
//Feel free to comment out these two lines below if there are conflicts with latest release
@ -106,8 +106,8 @@ static const uint8_t AREF = PIN_AREF;
#define PIN_SERIAL1_TX (17)
/*
* SPI Interfaces
*/
SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (31)
@ -120,16 +120,16 @@ 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
#define PIN_WIRE_SDA (8)
#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
#define PIN_QSPI_DATA0 34
@ -146,7 +146,7 @@ static const uint8_t SCK = PIN_SPI_SCK ;
#endif
/*----------------------------------------------------------------------------
* Arduino objects - C++ only
*----------------------------------------------------------------------------*/
Arduino objects - C++ only
----------------------------------------------------------------------------*/
#endif

View File

@ -36,10 +36,15 @@
size_t Print::write(const uint8_t *buffer, size_t size)
{
size_t n = 0;
while (size--) {
if (write(*buffer++)) n++;
else break;
while (size--)
{
if (write(*buffer++))
n++;
else
break;
}
return n;
}
@ -80,46 +85,64 @@ size_t Print::print(unsigned int n, int base)
size_t Print::print(long n, int base)
{
if (base == 0) {
if (base == 0)
{
return write(n);
} else if (base == 10) {
if (n < 0) {
}
else if (base == 10)
{
if (n < 0)
{
int t = print('-');
n = -n;
return printNumber(n, 10) + t;
}
return printNumber(n, 10);
} else {
}
else
{
return printNumber(n, base);
}
}
size_t Print::print(unsigned long n, int base)
{
if (base == 0) return write(n);
else return printNumber(n, base);
if (base == 0)
return write(n);
else
return printNumber(n, base);
}
size_t Print::print(long long n, int base)
{
if (base == 0) {
if (base == 0)
{
return write(n);
} else if (base == 10) {
if (n < 0) {
}
else if (base == 10)
{
if (n < 0)
{
int t = print('-');
n = -n;
return printULLNumber(n, 10) + t;
}
return printULLNumber(n, 10);
} else {
}
else
{
return printULLNumber(n, base);
}
}
size_t Print::print(unsigned long long n, int base)
{
if (base == 0) return write(n);
else return printULLNumber(n, base);
if (base == 0)
return write(n);
else
return printULLNumber(n, base);
}
size_t Print::print(double n, int digits)
@ -253,14 +276,16 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
*str = '\0';
// prevent crash if called with base == 1
if (base < 2) base = 10;
if (base < 2)
base = 10;
do {
do
{
char c = n % base;
n /= base;
*--str = c < 10 ? c + '0' : c + 'A' - 10;
} while(n);
} while (n);
return write(str);
}
@ -268,23 +293,23 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
// REFERENCE IMPLEMENTATION FOR ULL
// size_t Print::printULLNumber(unsigned long long n, uint8_t base)
// {
// // if limited to base 10 and 16 the bufsize can be smaller
// char buf[65];
// char *str = &buf[64];
// // if limited to base 10 and 16 the bufsize can be smaller
// char buf[65];
// char *str = &buf[64];
// *str = '\0';
// *str = '\0';
// // prevent crash if called with base == 1
// if (base < 2) base = 10;
// // prevent crash if called with base == 1
// if (base < 2) base = 10;
// do {
// unsigned long long t = n / base;
// char c = n - t * base; // faster than c = n%base;
// n = t;
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
// } while(n);
// do {
// unsigned long long t = n / base;
// char c = n - t * base; // faster than c = n%base;
// n = t;
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
// } while(n);
// return write(str);
// return write(str);
// }
// FAST IMPLEMENTATION FOR ULL
@ -296,11 +321,13 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
uint8_t innerLoops = 0;
// prevent crash if called with base == 1
if (base < 2) base = 10;
if (base < 2)
base = 10;
// process chunks that fit in "16 bit math".
uint16_t top = 0xFFFF / base;
uint16_t th16 = 1;
while (th16 < top)
{
th16 *= base;
@ -311,31 +338,33 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
{
// 64 bit math part
uint64_t q = n64 / th16;
uint16_t r = n64 - q*th16;
uint16_t r = n64 - q * th16;
n64 = q;
// 16 bit math loop to do remainder. (note buffer is filled reverse)
for (uint8_t j=0; j < innerLoops; j++)
for (uint8_t j = 0; j < innerLoops; j++)
{
uint16_t qq = r/base;
buf[i++] = r - qq*base;
uint16_t qq = r / base;
buf[i++] = r - qq * base;
r = qq;
}
}
uint16_t n16 = n64;
while (n16 > 0)
{
uint16_t qq = n16/base;
buf[i++] = n16 - qq*base;
uint16_t qq = n16 / base;
buf[i++] = n16 - qq * base;
n16 = qq;
}
size_t bytes = i;
for (; i > 0; i--)
write((char) (buf[i - 1] < 10 ?
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
return bytes;
}
@ -347,21 +376,29 @@ 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)
{
n += print('-');
number = -number;
n += print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
for (uint8_t i = 0; i < digits; ++i)
rounding /= 10.0;
number += rounding;
@ -372,7 +409,8 @@ size_t Print::printFloat(double number, int digits)
n += print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0) {
if (digits > 0)
{
n += print(".");
}
@ -390,31 +428,39 @@ size_t Print::printFloat(double number, int digits)
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
{
if (buffer == NULL || len == 0) return 0;
if (buffer == NULL || len == 0)
return 0;
for(int i=0; i<len; i++)
for (int i = 0; i < len; i++)
{
if ( i != 0 ) print(delim);
if ( byteline && (i%byteline == 0) ) println();
if ( i != 0 )
print(delim);
if ( byteline && (i % byteline == 0) )
println();
this->printf("%02X", buffer[i]);
}
return (len*3 - 1);
return (len * 3 - 1);
}
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
{
if (buffer == NULL || len == 0) return 0;
if (buffer == NULL || len == 0)
return 0;
for(int i=0; i<len; i++)
for (int i = 0; i < len; i++)
{
if (i != 0) print(delim);
if ( byteline && (i%byteline == 0) ) println();
if (i != 0)
print(delim);
this->printf("%02X", buffer[len-1-i]);
if ( byteline && (i % byteline == 0) )
println();
this->printf("%02X", buffer[len - 1 - i]);
}
return (len*3 - 1);
return (len * 3 - 1);
}

View File

@ -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 &);
@ -89,14 +105,14 @@ class Print
size_t printf(const char * format, ...);
size_t printBuffer(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
size_t printBuffer(char const buffer[], int size, char delim=' ', int byteline = 0)
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
{
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
}
size_t printBufferReverse(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
size_t printBufferReverse(char const buffer[], int size, char delim=' ', int byteline = 0)
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
{
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
}

View File

@ -1,36 +1,36 @@
/*
* Udp.cpp: Library to send/receive UDP packets.
*
* NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
* 1) UDP does not guarantee the order in which assembled UDP packets are received. This
* might not happen often in practice, but in larger network topologies, a UDP
* packet can be received out of sequence.
* 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
* aware of it. Again, this may not be a concern in practice on small local networks.
* For more information, see http://www.cafeaulait.org/course/week12/35.html
*
* MIT License:
* Copyright (c) 2008 Bjoern Hartmann
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* bjoern@cs.stanford.edu 12/30/2008
*/
Udp.cpp: Library to send/receive UDP packets.
NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
1) UDP does not guarantee the order in which assembled UDP packets are received. This
might not happen often in practice, but in larger network topologies, a UDP
packet can be received out of sequence.
2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
aware of it. Again, this may not be a concern in practice on small local networks.
For more information, see http://www.cafeaulait.org/course/week12/35.html
MIT License:
Copyright (c) 2008 Bjoern Hartmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
bjoern@cs.stanford.edu 12/30/2008
*/
#ifndef udp_h
#define udp_h
@ -38,55 +38,63 @@
#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
public:
virtual uint8_t begin(uint16_t) =
0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
virtual uint8_t beginMulticast(IPAddress, uint16_t)
{
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
}
virtual void stop() =0; // Finish with the UDP socket
virtual void stop() = 0; // Finish with the UDP socket
// Sending UDP packets
// Sending UDP packets
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port) =0;
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port) =0;
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket() =0;
// Write a single byte into the packet
virtual size_t write(uint8_t) =0;
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size) =0;
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port) = 0;
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket() = 0;
// Write a single byte into the packet
virtual size_t write(uint8_t) = 0;
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket() =0;
// Number of bytes remaining in the current packet
virtual int available() =0;
// Read a single byte from the current packet
virtual int read() =0;
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len) =0;
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) =0;
// Return the next byte from the current packet without moving on to the next byte
virtual int peek() =0;
virtual void flush() =0; // Finish reading the current packet
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket() = 0;
// Number of bytes remaining in the current packet
virtual int available() = 0;
// Read a single byte from the current packet
virtual int read() = 0;
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len) = 0;
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) = 0;
// Return the next byte from the current packet without moving on to the next byte
virtual int peek() = 0;
virtual void flush() = 0; // Finish reading the current packet
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() =0;
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() =0;
protected:
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() = 0;
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() = 0;
protected:
uint8_t* rawIPAddress(IPAddress& addr)
{
return addr.raw_address();
};
};
#endif

View File

@ -27,8 +27,9 @@
//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[] = {
// D0 .. D13
const uint32_t g_ADigitalPinMap[] =
{
// D0 .. D13
5, // D0 is P0.05 (UART RX)
6, // D1 is P0.06 (UART TX)
7, // D2 is P0.07

View File

@ -34,8 +34,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -66,12 +66,12 @@ extern "C"
#define SW2 (19)
// NFC
#define PIN_NFC_1 (6) // P0.9
#define PIN_NFC_2 (7) // P0.10
#define PIN_NFC_1 (6) // P0.9
#define PIN_NFC_2 (7) // P0.10
/*
* Analog pins
*/
Analog pins
*/
#define PIN_A0 (16) // P0.03
#define PIN_A1 (17) // P0.02
#define PIN_A2 (18) // P0.04
@ -125,8 +125,8 @@ 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
#define PIN_SERIAL_CTS (2) // P0.07
@ -135,8 +135,8 @@ static const uint8_t D15 = PIN_D15 ;
#define PIN_SERIAL_DSR (29) // P0.29
/*
* SPI Interfaces
*/
SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (12) // P0.12
@ -149,8 +149,8 @@ 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
#define PIN_WIRE_SDA (14) // P0.02
@ -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_

View File

@ -27,7 +27,7 @@
const uint32_t g_ADigitalPinMap[] =
{
// D0 .. D13
// D0 .. D13
29, // D0 is P0.29 (UART RX)
45, // D1 is P1.13 (UART TX)
44, // D2 is P1.12 (NFC2)

View File

@ -1,4 +1,4 @@
/*
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
Copyright (c) 2016 Sandeep Mistry All right reserved.
Copyright (c) 2018, Adafruit Industries (adafruit.com)
@ -29,8 +29,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -57,13 +57,13 @@ 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)
#define PIN_A2 (16)
@ -99,14 +99,14 @@ 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
#define PIN_SPI_MISO (22) //24 original
@ -119,8 +119,8 @@ 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
#define PIN_WIRE_SDA (20)
@ -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_

View File

@ -26,8 +26,8 @@
const uint32_t g_ADigitalPinMap[] =
{
// P0
0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
8 , 9 , 10, 11, 12, 13, 14, 15,
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,

View File

@ -1,4 +1,4 @@
/*
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
Copyright (c) 2016 Sandeep Mistry All right reserved.
Copyright (c) 2018, Adafruit Industries (adafruit.com)
@ -26,8 +26,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -56,15 +56,15 @@ extern "C"
// Buttons
/*
#define PIN_BUTTON1 (2)
#define PIN_BUTTON2 (3)
#define PIN_BUTTON3 (4)
#define PIN_BUTTON4 (5)
#define PIN_BUTTON1 (2)
#define PIN_BUTTON2 (3)
#define PIN_BUTTON3 (4)
#define PIN_BUTTON4 (5)
*/
/*
* Analog pins
*/
Analog pins
*/
#define PIN_A0 (2)
#define PIN_A1 (3)
#define PIN_A2 (4)
@ -93,8 +93,8 @@ 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
//Feel free to comment out these two lines below if there are conflicts with latest release
@ -106,8 +106,8 @@ static const uint8_t AREF = PIN_AREF;
#define PIN_SERIAL1_TX (17)
/*
* SPI Interfaces
*/
SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (31)
@ -120,16 +120,16 @@ 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
#define PIN_WIRE_SDA (8)
#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
#define PIN_QSPI_DATA0 34
@ -146,7 +146,7 @@ static const uint8_t SCK = PIN_SPI_SCK ;
#endif
/*----------------------------------------------------------------------------
* Arduino objects - C++ only
*----------------------------------------------------------------------------*/
Arduino objects - C++ only
----------------------------------------------------------------------------*/
#endif

View File

@ -36,10 +36,15 @@
size_t Print::write(const uint8_t *buffer, size_t size)
{
size_t n = 0;
while (size--) {
if (write(*buffer++)) n++;
else break;
while (size--)
{
if (write(*buffer++))
n++;
else
break;
}
return n;
}
@ -80,46 +85,64 @@ size_t Print::print(unsigned int n, int base)
size_t Print::print(long n, int base)
{
if (base == 0) {
if (base == 0)
{
return write(n);
} else if (base == 10) {
if (n < 0) {
}
else if (base == 10)
{
if (n < 0)
{
int t = print('-');
n = -n;
return printNumber(n, 10) + t;
}
return printNumber(n, 10);
} else {
}
else
{
return printNumber(n, base);
}
}
size_t Print::print(unsigned long n, int base)
{
if (base == 0) return write(n);
else return printNumber(n, base);
if (base == 0)
return write(n);
else
return printNumber(n, base);
}
size_t Print::print(long long n, int base)
{
if (base == 0) {
if (base == 0)
{
return write(n);
} else if (base == 10) {
if (n < 0) {
}
else if (base == 10)
{
if (n < 0)
{
int t = print('-');
n = -n;
return printULLNumber(n, 10) + t;
}
return printULLNumber(n, 10);
} else {
}
else
{
return printULLNumber(n, base);
}
}
size_t Print::print(unsigned long long n, int base)
{
if (base == 0) return write(n);
else return printULLNumber(n, base);
if (base == 0)
return write(n);
else
return printULLNumber(n, base);
}
size_t Print::print(double n, int digits)
@ -253,14 +276,16 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
*str = '\0';
// prevent crash if called with base == 1
if (base < 2) base = 10;
if (base < 2)
base = 10;
do {
do
{
char c = n % base;
n /= base;
*--str = c < 10 ? c + '0' : c + 'A' - 10;
} while(n);
} while (n);
return write(str);
}
@ -268,23 +293,23 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
// REFERENCE IMPLEMENTATION FOR ULL
// size_t Print::printULLNumber(unsigned long long n, uint8_t base)
// {
// // if limited to base 10 and 16 the bufsize can be smaller
// char buf[65];
// char *str = &buf[64];
// // if limited to base 10 and 16 the bufsize can be smaller
// char buf[65];
// char *str = &buf[64];
// *str = '\0';
// *str = '\0';
// // prevent crash if called with base == 1
// if (base < 2) base = 10;
// // prevent crash if called with base == 1
// if (base < 2) base = 10;
// do {
// unsigned long long t = n / base;
// char c = n - t * base; // faster than c = n%base;
// n = t;
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
// } while(n);
// do {
// unsigned long long t = n / base;
// char c = n - t * base; // faster than c = n%base;
// n = t;
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
// } while(n);
// return write(str);
// return write(str);
// }
// FAST IMPLEMENTATION FOR ULL
@ -296,11 +321,13 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
uint8_t innerLoops = 0;
// prevent crash if called with base == 1
if (base < 2) base = 10;
if (base < 2)
base = 10;
// process chunks that fit in "16 bit math".
uint16_t top = 0xFFFF / base;
uint16_t th16 = 1;
while (th16 < top)
{
th16 *= base;
@ -311,31 +338,33 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
{
// 64 bit math part
uint64_t q = n64 / th16;
uint16_t r = n64 - q*th16;
uint16_t r = n64 - q * th16;
n64 = q;
// 16 bit math loop to do remainder. (note buffer is filled reverse)
for (uint8_t j=0; j < innerLoops; j++)
for (uint8_t j = 0; j < innerLoops; j++)
{
uint16_t qq = r/base;
buf[i++] = r - qq*base;
uint16_t qq = r / base;
buf[i++] = r - qq * base;
r = qq;
}
}
uint16_t n16 = n64;
while (n16 > 0)
{
uint16_t qq = n16/base;
buf[i++] = n16 - qq*base;
uint16_t qq = n16 / base;
buf[i++] = n16 - qq * base;
n16 = qq;
}
size_t bytes = i;
for (; i > 0; i--)
write((char) (buf[i - 1] < 10 ?
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
return bytes;
}
@ -347,21 +376,29 @@ 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)
{
n += print('-');
number = -number;
n += print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
for (uint8_t i = 0; i < digits; ++i)
rounding /= 10.0;
number += rounding;
@ -372,7 +409,8 @@ size_t Print::printFloat(double number, int digits)
n += print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0) {
if (digits > 0)
{
n += print(".");
}
@ -390,31 +428,39 @@ size_t Print::printFloat(double number, int digits)
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
{
if (buffer == NULL || len == 0) return 0;
if (buffer == NULL || len == 0)
return 0;
for(int i=0; i<len; i++)
for (int i = 0; i < len; i++)
{
if ( i != 0 ) print(delim);
if ( byteline && (i%byteline == 0) ) println();
if ( i != 0 )
print(delim);
if ( byteline && (i % byteline == 0) )
println();
this->printf("%02X", buffer[i]);
}
return (len*3 - 1);
return (len * 3 - 1);
}
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
{
if (buffer == NULL || len == 0) return 0;
if (buffer == NULL || len == 0)
return 0;
for(int i=0; i<len; i++)
for (int i = 0; i < len; i++)
{
if (i != 0) print(delim);
if ( byteline && (i%byteline == 0) ) println();
if (i != 0)
print(delim);
this->printf("%02X", buffer[len-1-i]);
if ( byteline && (i % byteline == 0) )
println();
this->printf("%02X", buffer[len - 1 - i]);
}
return (len*3 - 1);
return (len * 3 - 1);
}

View File

@ -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 &);
@ -89,14 +105,14 @@ class Print
size_t printf(const char * format, ...);
size_t printBuffer(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
size_t printBuffer(char const buffer[], int size, char delim=' ', int byteline = 0)
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
{
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
}
size_t printBufferReverse(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
size_t printBufferReverse(char const buffer[], int size, char delim=' ', int byteline = 0)
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
{
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
}

View File

@ -1,36 +1,36 @@
/*
* Udp.cpp: Library to send/receive UDP packets.
*
* NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
* 1) UDP does not guarantee the order in which assembled UDP packets are received. This
* might not happen often in practice, but in larger network topologies, a UDP
* packet can be received out of sequence.
* 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
* aware of it. Again, this may not be a concern in practice on small local networks.
* For more information, see http://www.cafeaulait.org/course/week12/35.html
*
* MIT License:
* Copyright (c) 2008 Bjoern Hartmann
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* bjoern@cs.stanford.edu 12/30/2008
*/
Udp.cpp: Library to send/receive UDP packets.
NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
1) UDP does not guarantee the order in which assembled UDP packets are received. This
might not happen often in practice, but in larger network topologies, a UDP
packet can be received out of sequence.
2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
aware of it. Again, this may not be a concern in practice on small local networks.
For more information, see http://www.cafeaulait.org/course/week12/35.html
MIT License:
Copyright (c) 2008 Bjoern Hartmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
bjoern@cs.stanford.edu 12/30/2008
*/
#ifndef udp_h
#define udp_h
@ -38,55 +38,63 @@
#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
public:
virtual uint8_t begin(uint16_t) =
0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
virtual uint8_t beginMulticast(IPAddress, uint16_t)
{
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
}
virtual void stop() =0; // Finish with the UDP socket
virtual void stop() = 0; // Finish with the UDP socket
// Sending UDP packets
// Sending UDP packets
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port) =0;
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port) =0;
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket() =0;
// Write a single byte into the packet
virtual size_t write(uint8_t) =0;
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size) =0;
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port) = 0;
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket() = 0;
// Write a single byte into the packet
virtual size_t write(uint8_t) = 0;
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket() =0;
// Number of bytes remaining in the current packet
virtual int available() =0;
// Read a single byte from the current packet
virtual int read() =0;
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len) =0;
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) =0;
// Return the next byte from the current packet without moving on to the next byte
virtual int peek() =0;
virtual void flush() =0; // Finish reading the current packet
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket() = 0;
// Number of bytes remaining in the current packet
virtual int available() = 0;
// Read a single byte from the current packet
virtual int read() = 0;
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len) = 0;
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) = 0;
// Return the next byte from the current packet without moving on to the next byte
virtual int peek() = 0;
virtual void flush() = 0; // Finish reading the current packet
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() =0;
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() =0;
protected:
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() = 0;
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() = 0;
protected:
uint8_t* rawIPAddress(IPAddress& addr)
{
return addr.raw_address();
};
};
#endif

View File

@ -27,8 +27,9 @@
//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[] = {
// D0 .. D13
const uint32_t g_ADigitalPinMap[] =
{
// D0 .. D13
5, // D0 is P0.05 (UART RX)
6, // D1 is P0.06 (UART TX)
7, // D2 is P0.07

View File

@ -34,8 +34,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -66,12 +66,12 @@ extern "C"
#define SW2 (19)
// NFC
#define PIN_NFC_1 (6) // P0.9
#define PIN_NFC_2 (7) // P0.10
#define PIN_NFC_1 (6) // P0.9
#define PIN_NFC_2 (7) // P0.10
/*
* Analog pins
*/
Analog pins
*/
#define PIN_A0 (16) // P0.03
#define PIN_A1 (17) // P0.02
#define PIN_A2 (18) // P0.04
@ -125,8 +125,8 @@ 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
#define PIN_SERIAL_CTS (2) // P0.07
@ -135,8 +135,8 @@ static const uint8_t D15 = PIN_D15 ;
#define PIN_SERIAL_DSR (29) // P0.29
/*
* SPI Interfaces
*/
SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (12) // P0.12
@ -149,8 +149,8 @@ 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
#define PIN_WIRE_SDA (14) // P0.02
@ -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_

View File

@ -27,7 +27,7 @@
const uint32_t g_ADigitalPinMap[] =
{
// D0 .. D13
// D0 .. D13
29, // D0 is P0.29 (UART RX)
45, // D1 is P1.13 (UART TX)
44, // D2 is P1.12 (NFC2)

View File

@ -1,4 +1,4 @@
/*
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
Copyright (c) 2016 Sandeep Mistry All right reserved.
Copyright (c) 2018, Adafruit Industries (adafruit.com)
@ -29,8 +29,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -57,13 +57,13 @@ 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)
#define PIN_A2 (16)
@ -99,14 +99,14 @@ 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
#define PIN_SPI_MISO (22) //24 original
@ -119,8 +119,8 @@ 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
#define PIN_WIRE_SDA (20)
@ -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_

View File

@ -26,8 +26,8 @@
const uint32_t g_ADigitalPinMap[] =
{
// P0
0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
8 , 9 , 10, 11, 12, 13, 14, 15,
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,

View File

@ -1,4 +1,4 @@
/*
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
Copyright (c) 2016 Sandeep Mistry All right reserved.
Copyright (c) 2018, Adafruit Industries (adafruit.com)
@ -26,8 +26,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -56,15 +56,15 @@ extern "C"
// Buttons
/*
#define PIN_BUTTON1 (2)
#define PIN_BUTTON2 (3)
#define PIN_BUTTON3 (4)
#define PIN_BUTTON4 (5)
#define PIN_BUTTON1 (2)
#define PIN_BUTTON2 (3)
#define PIN_BUTTON3 (4)
#define PIN_BUTTON4 (5)
*/
/*
* Analog pins
*/
Analog pins
*/
#define PIN_A0 (2)
#define PIN_A1 (3)
#define PIN_A2 (4)
@ -93,8 +93,8 @@ 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
//Feel free to comment out these two lines below if there are conflicts with latest release
@ -106,8 +106,8 @@ static const uint8_t AREF = PIN_AREF;
#define PIN_SERIAL1_TX (17)
/*
* SPI Interfaces
*/
SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (31)
@ -120,16 +120,16 @@ 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
#define PIN_WIRE_SDA (8)
#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
#define PIN_QSPI_DATA0 34
@ -146,7 +146,7 @@ static const uint8_t SCK = PIN_SPI_SCK ;
#endif
/*----------------------------------------------------------------------------
* Arduino objects - C++ only
*----------------------------------------------------------------------------*/
Arduino objects - C++ only
----------------------------------------------------------------------------*/
#endif

View File

@ -36,10 +36,15 @@
size_t Print::write(const uint8_t *buffer, size_t size)
{
size_t n = 0;
while (size--) {
if (write(*buffer++)) n++;
else break;
while (size--)
{
if (write(*buffer++))
n++;
else
break;
}
return n;
}
@ -80,46 +85,64 @@ size_t Print::print(unsigned int n, int base)
size_t Print::print(long n, int base)
{
if (base == 0) {
if (base == 0)
{
return write(n);
} else if (base == 10) {
if (n < 0) {
}
else if (base == 10)
{
if (n < 0)
{
int t = print('-');
n = -n;
return printNumber(n, 10) + t;
}
return printNumber(n, 10);
} else {
}
else
{
return printNumber(n, base);
}
}
size_t Print::print(unsigned long n, int base)
{
if (base == 0) return write(n);
else return printNumber(n, base);
if (base == 0)
return write(n);
else
return printNumber(n, base);
}
size_t Print::print(long long n, int base)
{
if (base == 0) {
if (base == 0)
{
return write(n);
} else if (base == 10) {
if (n < 0) {
}
else if (base == 10)
{
if (n < 0)
{
int t = print('-');
n = -n;
return printULLNumber(n, 10) + t;
}
return printULLNumber(n, 10);
} else {
}
else
{
return printULLNumber(n, base);
}
}
size_t Print::print(unsigned long long n, int base)
{
if (base == 0) return write(n);
else return printULLNumber(n, base);
if (base == 0)
return write(n);
else
return printULLNumber(n, base);
}
size_t Print::print(double n, int digits)
@ -253,14 +276,16 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
*str = '\0';
// prevent crash if called with base == 1
if (base < 2) base = 10;
if (base < 2)
base = 10;
do {
do
{
char c = n % base;
n /= base;
*--str = c < 10 ? c + '0' : c + 'A' - 10;
} while(n);
} while (n);
return write(str);
}
@ -268,23 +293,23 @@ size_t Print::printNumber(unsigned long n, uint8_t base)
// REFERENCE IMPLEMENTATION FOR ULL
// size_t Print::printULLNumber(unsigned long long n, uint8_t base)
// {
// // if limited to base 10 and 16 the bufsize can be smaller
// char buf[65];
// char *str = &buf[64];
// // if limited to base 10 and 16 the bufsize can be smaller
// char buf[65];
// char *str = &buf[64];
// *str = '\0';
// *str = '\0';
// // prevent crash if called with base == 1
// if (base < 2) base = 10;
// // prevent crash if called with base == 1
// if (base < 2) base = 10;
// do {
// unsigned long long t = n / base;
// char c = n - t * base; // faster than c = n%base;
// n = t;
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
// } while(n);
// do {
// unsigned long long t = n / base;
// char c = n - t * base; // faster than c = n%base;
// n = t;
// *--str = c < 10 ? c + '0' : c + 'A' - 10;
// } while(n);
// return write(str);
// return write(str);
// }
// FAST IMPLEMENTATION FOR ULL
@ -296,11 +321,13 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
uint8_t innerLoops = 0;
// prevent crash if called with base == 1
if (base < 2) base = 10;
if (base < 2)
base = 10;
// process chunks that fit in "16 bit math".
uint16_t top = 0xFFFF / base;
uint16_t th16 = 1;
while (th16 < top)
{
th16 *= base;
@ -311,31 +338,33 @@ size_t Print::printULLNumber(unsigned long long n64, uint8_t base)
{
// 64 bit math part
uint64_t q = n64 / th16;
uint16_t r = n64 - q*th16;
uint16_t r = n64 - q * th16;
n64 = q;
// 16 bit math loop to do remainder. (note buffer is filled reverse)
for (uint8_t j=0; j < innerLoops; j++)
for (uint8_t j = 0; j < innerLoops; j++)
{
uint16_t qq = r/base;
buf[i++] = r - qq*base;
uint16_t qq = r / base;
buf[i++] = r - qq * base;
r = qq;
}
}
uint16_t n16 = n64;
while (n16 > 0)
{
uint16_t qq = n16/base;
buf[i++] = n16 - qq*base;
uint16_t qq = n16 / base;
buf[i++] = n16 - qq * base;
n16 = qq;
}
size_t bytes = i;
for (; i > 0; i--)
write((char) (buf[i - 1] < 10 ?
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
return bytes;
}
@ -347,21 +376,29 @@ 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)
{
n += print('-');
number = -number;
n += print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
for (uint8_t i = 0; i < digits; ++i)
rounding /= 10.0;
number += rounding;
@ -372,7 +409,8 @@ size_t Print::printFloat(double number, int digits)
n += print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0) {
if (digits > 0)
{
n += print(".");
}
@ -390,31 +428,39 @@ size_t Print::printFloat(double number, int digits)
size_t Print::printBuffer(uint8_t const buffer[], int len, char delim, int byteline)
{
if (buffer == NULL || len == 0) return 0;
if (buffer == NULL || len == 0)
return 0;
for(int i=0; i<len; i++)
for (int i = 0; i < len; i++)
{
if ( i != 0 ) print(delim);
if ( byteline && (i%byteline == 0) ) println();
if ( i != 0 )
print(delim);
if ( byteline && (i % byteline == 0) )
println();
this->printf("%02X", buffer[i]);
}
return (len*3 - 1);
return (len * 3 - 1);
}
size_t Print::printBufferReverse(uint8_t const buffer[], int len, char delim, int byteline)
{
if (buffer == NULL || len == 0) return 0;
if (buffer == NULL || len == 0)
return 0;
for(int i=0; i<len; i++)
for (int i = 0; i < len; i++)
{
if (i != 0) print(delim);
if ( byteline && (i%byteline == 0) ) println();
if (i != 0)
print(delim);
this->printf("%02X", buffer[len-1-i]);
if ( byteline && (i % byteline == 0) )
println();
this->printf("%02X", buffer[len - 1 - i]);
}
return (len*3 - 1);
return (len * 3 - 1);
}

View File

@ -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 &);
@ -89,14 +105,14 @@ class Print
size_t printf(const char * format, ...);
size_t printBuffer(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
size_t printBuffer(char const buffer[], int size, char delim=' ', int byteline = 0)
size_t printBuffer(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
size_t printBuffer(char const buffer[], int size, char delim = ' ', int byteline = 0)
{
return printBuffer((uint8_t const*) buffer, size, delim, byteline);
}
size_t printBufferReverse(uint8_t const buffer[], int len, char delim=' ', int byteline = 0);
size_t printBufferReverse(char const buffer[], int size, char delim=' ', int byteline = 0)
size_t printBufferReverse(uint8_t const buffer[], int len, char delim = ' ', int byteline = 0);
size_t printBufferReverse(char const buffer[], int size, char delim = ' ', int byteline = 0)
{
return printBufferReverse((uint8_t const*) buffer, size, delim, byteline);
}

View File

@ -1,36 +1,36 @@
/*
* Udp.cpp: Library to send/receive UDP packets.
*
* NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
* 1) UDP does not guarantee the order in which assembled UDP packets are received. This
* might not happen often in practice, but in larger network topologies, a UDP
* packet can be received out of sequence.
* 2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
* aware of it. Again, this may not be a concern in practice on small local networks.
* For more information, see http://www.cafeaulait.org/course/week12/35.html
*
* MIT License:
* Copyright (c) 2008 Bjoern Hartmann
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* bjoern@cs.stanford.edu 12/30/2008
*/
Udp.cpp: Library to send/receive UDP packets.
NOTE: UDP is fast, but has some important limitations (thanks to Warren Gray for mentioning these)
1) UDP does not guarantee the order in which assembled UDP packets are received. This
might not happen often in practice, but in larger network topologies, a UDP
packet can be received out of sequence.
2) UDP does not guard against lost packets - so packets *can* disappear without the sender being
aware of it. Again, this may not be a concern in practice on small local networks.
For more information, see http://www.cafeaulait.org/course/week12/35.html
MIT License:
Copyright (c) 2008 Bjoern Hartmann
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
bjoern@cs.stanford.edu 12/30/2008
*/
#ifndef udp_h
#define udp_h
@ -38,55 +38,63 @@
#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
public:
virtual uint8_t begin(uint16_t) =
0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
// KH, add virtual function to support Multicast, necessary for many services (MDNS, UPnP, etc.)
virtual uint8_t beginMulticast(IPAddress, uint16_t)
{
return 0; // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure
}
virtual void stop() =0; // Finish with the UDP socket
virtual void stop() = 0; // Finish with the UDP socket
// Sending UDP packets
// Sending UDP packets
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port) =0;
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port) =0;
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket() =0;
// Write a single byte into the packet
virtual size_t write(uint8_t) =0;
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size) =0;
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port) = 0;
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port) = 0;
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket() = 0;
// Write a single byte into the packet
virtual size_t write(uint8_t) = 0;
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size) = 0;
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket() =0;
// Number of bytes remaining in the current packet
virtual int available() =0;
// Read a single byte from the current packet
virtual int read() =0;
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len) =0;
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) =0;
// Return the next byte from the current packet without moving on to the next byte
virtual int peek() =0;
virtual void flush() =0; // Finish reading the current packet
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket() = 0;
// Number of bytes remaining in the current packet
virtual int available() = 0;
// Read a single byte from the current packet
virtual int read() = 0;
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len) = 0;
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) = 0;
// Return the next byte from the current packet without moving on to the next byte
virtual int peek() = 0;
virtual void flush() = 0; // Finish reading the current packet
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() =0;
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() =0;
protected:
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP() = 0;
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort() = 0;
protected:
uint8_t* rawIPAddress(IPAddress& addr)
{
return addr.raw_address();
};
};
#endif

View File

@ -27,8 +27,9 @@
//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[] = {
// D0 .. D13
const uint32_t g_ADigitalPinMap[] =
{
// D0 .. D13
5, // D0 is P0.05 (UART RX)
6, // D1 is P0.06 (UART TX)
7, // D2 is P0.07

View File

@ -34,8 +34,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -66,12 +66,12 @@ extern "C"
#define SW2 (19)
// NFC
#define PIN_NFC_1 (6) // P0.9
#define PIN_NFC_2 (7) // P0.10
#define PIN_NFC_1 (6) // P0.9
#define PIN_NFC_2 (7) // P0.10
/*
* Analog pins
*/
Analog pins
*/
#define PIN_A0 (16) // P0.03
#define PIN_A1 (17) // P0.02
#define PIN_A2 (18) // P0.04
@ -125,8 +125,8 @@ 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
#define PIN_SERIAL_CTS (2) // P0.07
@ -135,8 +135,8 @@ static const uint8_t D15 = PIN_D15 ;
#define PIN_SERIAL_DSR (29) // P0.29
/*
* SPI Interfaces
*/
SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (12) // P0.12
@ -149,8 +149,8 @@ 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
#define PIN_WIRE_SDA (14) // P0.02
@ -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_

View File

@ -27,7 +27,7 @@
const uint32_t g_ADigitalPinMap[] =
{
// D0 .. D13
// D0 .. D13
29, // D0 is P0.29 (UART RX)
45, // D1 is P1.13 (UART TX)
44, // D2 is P1.12 (NFC2)

View File

@ -1,4 +1,4 @@
/*
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
Copyright (c) 2016 Sandeep Mistry All right reserved.
Copyright (c) 2018, Adafruit Industries (adafruit.com)
@ -29,8 +29,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -57,13 +57,13 @@ 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)
#define PIN_A2 (16)
@ -99,14 +99,14 @@ 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
#define PIN_SPI_MISO (22) //24 original
@ -119,8 +119,8 @@ 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
#define PIN_WIRE_SDA (20)
@ -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_

View File

@ -26,8 +26,8 @@
const uint32_t g_ADigitalPinMap[] =
{
// P0
0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ,
8 , 9 , 10, 11, 12, 13, 14, 15,
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31,

View File

@ -1,4 +1,4 @@
/*
/*
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
Copyright (c) 2016 Sandeep Mistry All right reserved.
Copyright (c) 2018, Adafruit Industries (adafruit.com)
@ -26,8 +26,8 @@
// define USE_LFRC // Board uses RC for LF
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
Headers
----------------------------------------------------------------------------*/
#include "WVariant.h"
@ -56,15 +56,15 @@ extern "C"
// Buttons
/*
#define PIN_BUTTON1 (2)
#define PIN_BUTTON2 (3)
#define PIN_BUTTON3 (4)
#define PIN_BUTTON4 (5)
#define PIN_BUTTON1 (2)
#define PIN_BUTTON2 (3)
#define PIN_BUTTON3 (4)
#define PIN_BUTTON4 (5)
*/
/*
* Analog pins
*/
Analog pins
*/
#define PIN_A0 (2)
#define PIN_A1 (3)
#define PIN_A2 (4)
@ -93,8 +93,8 @@ 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
//Feel free to comment out these two lines below if there are conflicts with latest release
@ -106,8 +106,8 @@ static const uint8_t AREF = PIN_AREF;
#define PIN_SERIAL1_TX (17)
/*
* SPI Interfaces
*/
SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (31)
@ -120,16 +120,16 @@ 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
#define PIN_WIRE_SDA (8)
#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
#define PIN_QSPI_DATA0 34
@ -146,7 +146,7 @@ static const uint8_t SCK = PIN_SPI_SCK ;
#endif
/*----------------------------------------------------------------------------
* Arduino objects - C++ only
*----------------------------------------------------------------------------*/
Arduino objects - C++ only
----------------------------------------------------------------------------*/
#endif