From d06ebf61a6dd8619a040a2ce94aa222c241ee18c Mon Sep 17 00:00:00 2001 From: Phil Schatzmann Date: Thu, 2 Oct 2025 16:51:01 +0200 Subject: [PATCH 1/4] using String.h --- ArduinoCore-API/api/ArduinoAPI.h | 2 +- ArduinoCore-API/api/IPAddress.h | 2 +- ArduinoCore-API/api/Print.h | 3 +- ArduinoCore-API/api/String.cpp | 2 +- ArduinoCore-API/api/{WString.h => String.h} | 0 .../test/src/IPAddress/test_fromString.cpp | 2 +- .../test/src/IPAddress/test_fromString6.cpp | 2 +- .../test/src/IPAddress/test_toString.cpp | 2 +- .../test/src/String/StringPrinter.h | 2 +- .../test/src/String/test_String.cpp | 2 +- .../src/String/test_characterAccessFunc.cpp | 2 +- .../test/src/String/test_compareTo.cpp | 2 +- .../test/src/String/test_comparisonFunc.cpp | 2 +- .../test/src/String/test_concat.cpp | 2 +- .../test/src/String/test_indexOf.cpp | 2 +- .../test/src/String/test_isEmpty.cpp | 2 +- .../test/src/String/test_lastIndexOf.cpp | 2 +- .../test/src/String/test_length.cpp | 2 +- ArduinoCore-API/test/src/String/test_move.cpp | 2 +- .../test/src/String/test_operators.cpp | 2 +- .../test/src/String/test_remove.cpp | 2 +- .../test/src/String/test_replace.cpp | 2 +- .../test/src/String/test_substring.cpp | 2 +- .../test/src/String/test_toDouble.cpp | 2 +- .../test/src/String/test_toFloat.cpp | 2 +- .../test/src/String/test_toInt.cpp | 2 +- .../test/src/String/test_toLowerCase.cpp | 2 +- .../test/src/String/test_toUpperCase.cpp | 2 +- ArduinoCore-API/test/src/String/test_trim.cpp | 2 +- ArduinoCore-Linux/cores/arduino/Arduino.cpp | 10 +- ArduinoCore-Linux/cores/arduino/Arduino.h | 2 +- .../cores/arduino/ArduinoLogger.h | 2 +- ArduinoCore-Linux/cores/arduino/Ethernet.h | 6 +- .../cores/arduino/EthernetServer.h | 2 +- ArduinoCore-Linux/cores/arduino/EthernetUDP.h | 4 +- .../cores/arduino/HardwareGPIO.cpp | 2 +- .../cores/arduino/HardwareGPIO.h | 2 +- .../cores/arduino/HardwareI2CEx.h | 2 +- .../cores/arduino/HardwareSPI.cpp | 2 +- .../cores/arduino/HardwareService.h | 2 +- ArduinoCore-Linux/cores/arduino/RemoteSPI.h | 2 +- .../cores/arduino/RemoteSerial.h | 2 +- ArduinoCore-Linux/cores/arduino/StdioDevice.h | 4 +- ArduinoCore-Linux/cores/arduino/UDP.h | 99 ------------------- .../cores/arduino/Unsupported.cpp | 2 +- ArduinoCore-Linux/cores/arduino/WMath.cpp | 2 +- .../cores/arduino/WiFiUdpStream.h | 4 +- ArduinoCore-Linux/cores/arduino/itoa.cpp | 2 +- ArduinoCore-Linux/libraries/SPI.h | 2 +- CMakeLists.txt | 7 +- 50 files changed, 62 insertions(+), 157 deletions(-) rename ArduinoCore-API/api/{WString.h => String.h} (100%) delete mode 100644 ArduinoCore-Linux/cores/arduino/UDP.h diff --git a/ArduinoCore-API/api/ArduinoAPI.h b/ArduinoCore-API/api/ArduinoAPI.h index 40af6cc..a7d8c0b 100644 --- a/ArduinoCore-API/api/ArduinoAPI.h +++ b/ArduinoCore-API/api/ArduinoAPI.h @@ -32,7 +32,7 @@ #include "Printable.h" #include "PluggableUSB.h" #include "Server.h" -#include "WString.h" +#include "String.h" #include "Stream.h" #include "Udp.h" #include "USBAPI.h" diff --git a/ArduinoCore-API/api/IPAddress.h b/ArduinoCore-API/api/IPAddress.h index 5c7a3b2..31a2d06 100644 --- a/ArduinoCore-API/api/IPAddress.h +++ b/ArduinoCore-API/api/IPAddress.h @@ -21,7 +21,7 @@ #include #include "Printable.h" -#include "WString.h" +#include "String.h" #define IPADDRESS_V4_BYTES_INDEX 12 #define IPADDRESS_V4_DWORD_INDEX 3 diff --git a/ArduinoCore-API/api/Print.h b/ArduinoCore-API/api/Print.h index 2a059b0..7e1d431 100644 --- a/ArduinoCore-API/api/Print.h +++ b/ArduinoCore-API/api/Print.h @@ -21,8 +21,9 @@ #include #include // for size_t +#include -#include "WString.h" +#include "api/String.h" #include "Printable.h" #define DEC 10 diff --git a/ArduinoCore-API/api/String.cpp b/ArduinoCore-API/api/String.cpp index 88b569c..4f17637 100644 --- a/ArduinoCore-API/api/String.cpp +++ b/ArduinoCore-API/api/String.cpp @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "WString.h" +#include "String.h" #include "Common.h" #include "itoa.h" #include "deprecated-avr-comp/avr/dtostrf.h" diff --git a/ArduinoCore-API/api/WString.h b/ArduinoCore-API/api/String.h similarity index 100% rename from ArduinoCore-API/api/WString.h rename to ArduinoCore-API/api/String.h diff --git a/ArduinoCore-API/test/src/IPAddress/test_fromString.cpp b/ArduinoCore-API/test/src/IPAddress/test_fromString.cpp index a11a520..1e7795a 100644 --- a/ArduinoCore-API/test/src/IPAddress/test_fromString.cpp +++ b/ArduinoCore-API/test/src/IPAddress/test_fromString.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include /************************************************************************************** diff --git a/ArduinoCore-API/test/src/IPAddress/test_fromString6.cpp b/ArduinoCore-API/test/src/IPAddress/test_fromString6.cpp index 24e5a07..bb9f01b 100644 --- a/ArduinoCore-API/test/src/IPAddress/test_fromString6.cpp +++ b/ArduinoCore-API/test/src/IPAddress/test_fromString6.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include /************************************************************************************** diff --git a/ArduinoCore-API/test/src/IPAddress/test_toString.cpp b/ArduinoCore-API/test/src/IPAddress/test_toString.cpp index 40f0717..1bd8d74 100644 --- a/ArduinoCore-API/test/src/IPAddress/test_toString.cpp +++ b/ArduinoCore-API/test/src/IPAddress/test_toString.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include /************************************************************************************** diff --git a/ArduinoCore-API/test/src/String/StringPrinter.h b/ArduinoCore-API/test/src/String/StringPrinter.h index f39928e..1785f98 100644 --- a/ArduinoCore-API/test/src/String/StringPrinter.h +++ b/ArduinoCore-API/test/src/String/StringPrinter.h @@ -7,7 +7,7 @@ #pragma once #include -#include +#include namespace Catch { /** diff --git a/ArduinoCore-API/test/src/String/test_String.cpp b/ArduinoCore-API/test/src/String/test_String.cpp index 0e9fbf6..d6ef725 100644 --- a/ArduinoCore-API/test/src/String/test_String.cpp +++ b/ArduinoCore-API/test/src/String/test_String.cpp @@ -12,7 +12,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_characterAccessFunc.cpp b/ArduinoCore-API/test/src/String/test_characterAccessFunc.cpp index 16855f4..e191f1d 100644 --- a/ArduinoCore-API/test/src/String/test_characterAccessFunc.cpp +++ b/ArduinoCore-API/test/src/String/test_characterAccessFunc.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_compareTo.cpp b/ArduinoCore-API/test/src/String/test_compareTo.cpp index bbe3a7e..b567320 100644 --- a/ArduinoCore-API/test/src/String/test_compareTo.cpp +++ b/ArduinoCore-API/test/src/String/test_compareTo.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_comparisonFunc.cpp b/ArduinoCore-API/test/src/String/test_comparisonFunc.cpp index 19c24f9..558012d 100644 --- a/ArduinoCore-API/test/src/String/test_comparisonFunc.cpp +++ b/ArduinoCore-API/test/src/String/test_comparisonFunc.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_concat.cpp b/ArduinoCore-API/test/src/String/test_concat.cpp index 56087fd..8113659 100644 --- a/ArduinoCore-API/test/src/String/test_concat.cpp +++ b/ArduinoCore-API/test/src/String/test_concat.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_indexOf.cpp b/ArduinoCore-API/test/src/String/test_indexOf.cpp index 439e41a..12de054 100644 --- a/ArduinoCore-API/test/src/String/test_indexOf.cpp +++ b/ArduinoCore-API/test/src/String/test_indexOf.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_isEmpty.cpp b/ArduinoCore-API/test/src/String/test_isEmpty.cpp index 14ce691..a6e30f9 100644 --- a/ArduinoCore-API/test/src/String/test_isEmpty.cpp +++ b/ArduinoCore-API/test/src/String/test_isEmpty.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_lastIndexOf.cpp b/ArduinoCore-API/test/src/String/test_lastIndexOf.cpp index d4f01ca..13e850c 100644 --- a/ArduinoCore-API/test/src/String/test_lastIndexOf.cpp +++ b/ArduinoCore-API/test/src/String/test_lastIndexOf.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_length.cpp b/ArduinoCore-API/test/src/String/test_length.cpp index cb26418..062ba81 100644 --- a/ArduinoCore-API/test/src/String/test_length.cpp +++ b/ArduinoCore-API/test/src/String/test_length.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_move.cpp b/ArduinoCore-API/test/src/String/test_move.cpp index ec135f9..fda0a0d 100644 --- a/ArduinoCore-API/test/src/String/test_move.cpp +++ b/ArduinoCore-API/test/src/String/test_move.cpp @@ -6,7 +6,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_operators.cpp b/ArduinoCore-API/test/src/String/test_operators.cpp index e77b88d..14f826b 100644 --- a/ArduinoCore-API/test/src/String/test_operators.cpp +++ b/ArduinoCore-API/test/src/String/test_operators.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_remove.cpp b/ArduinoCore-API/test/src/String/test_remove.cpp index 6a0f41a..6281d77 100644 --- a/ArduinoCore-API/test/src/String/test_remove.cpp +++ b/ArduinoCore-API/test/src/String/test_remove.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_replace.cpp b/ArduinoCore-API/test/src/String/test_replace.cpp index 2451801..36b4413 100644 --- a/ArduinoCore-API/test/src/String/test_replace.cpp +++ b/ArduinoCore-API/test/src/String/test_replace.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_substring.cpp b/ArduinoCore-API/test/src/String/test_substring.cpp index f1f3239..6397b90 100644 --- a/ArduinoCore-API/test/src/String/test_substring.cpp +++ b/ArduinoCore-API/test/src/String/test_substring.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_toDouble.cpp b/ArduinoCore-API/test/src/String/test_toDouble.cpp index 8f0bbe9..3bb1ba5 100644 --- a/ArduinoCore-API/test/src/String/test_toDouble.cpp +++ b/ArduinoCore-API/test/src/String/test_toDouble.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_toFloat.cpp b/ArduinoCore-API/test/src/String/test_toFloat.cpp index 5de964f..28fca21 100644 --- a/ArduinoCore-API/test/src/String/test_toFloat.cpp +++ b/ArduinoCore-API/test/src/String/test_toFloat.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_toInt.cpp b/ArduinoCore-API/test/src/String/test_toInt.cpp index 3f6b279..c93fcc4 100644 --- a/ArduinoCore-API/test/src/String/test_toInt.cpp +++ b/ArduinoCore-API/test/src/String/test_toInt.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_toLowerCase.cpp b/ArduinoCore-API/test/src/String/test_toLowerCase.cpp index 6f2d608..ec0f9eb 100644 --- a/ArduinoCore-API/test/src/String/test_toLowerCase.cpp +++ b/ArduinoCore-API/test/src/String/test_toLowerCase.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_toUpperCase.cpp b/ArduinoCore-API/test/src/String/test_toUpperCase.cpp index 1337615..937fa52 100644 --- a/ArduinoCore-API/test/src/String/test_toUpperCase.cpp +++ b/ArduinoCore-API/test/src/String/test_toUpperCase.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-API/test/src/String/test_trim.cpp b/ArduinoCore-API/test/src/String/test_trim.cpp index b1a1373..eddc9fd 100644 --- a/ArduinoCore-API/test/src/String/test_trim.cpp +++ b/ArduinoCore-API/test/src/String/test_trim.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include "StringPrinter.h" diff --git a/ArduinoCore-Linux/cores/arduino/Arduino.cpp b/ArduinoCore-Linux/cores/arduino/Arduino.cpp index f93ceb0..98ca9a3 100644 --- a/ArduinoCore-Linux/cores/arduino/Arduino.cpp +++ b/ArduinoCore-Linux/cores/arduino/Arduino.cpp @@ -5,9 +5,9 @@ #include #include #include "Arduino.h" -#include "Common.h" -#include "Stream.h" -#include "PluggableUSB.h" +#include "api/Common.h" +#include "api/Stream.h" +#include "api/PluggableUSB.h" #include "RemoteSerial.h" #include "Hardware.h" #if !defined(SKIP_HARDWARE_SETUP) @@ -21,8 +21,8 @@ # include "HardwareGPIO_RPI.h" # include "HardwareI2C_RPI.h" #endif -#include "PluggableUSB.h" -#include "deprecated-avr-comp/avr/dtostrf.h" +#include "api/PluggableUSB.h" +#include "api/deprecated-avr-comp/avr/dtostrf.h" #include "ArduinoLogger.h" #include "StdioDevice.h" #include "Serial.h" diff --git a/ArduinoCore-Linux/cores/arduino/Arduino.h b/ArduinoCore-Linux/cores/arduino/Arduino.h index 4fb8a75..c48c879 100644 --- a/ArduinoCore-Linux/cores/arduino/Arduino.h +++ b/ArduinoCore-Linux/cores/arduino/Arduino.h @@ -36,7 +36,7 @@ #include "Serial.h" #include "StdioDevice.h" #include "ArduinoLogger.h" -#include "ArduinoAPI.h" +#include "api/ArduinoAPI.h" #include "RemoteSerial.h" #include "HardwareSetup.h" diff --git a/ArduinoCore-Linux/cores/arduino/ArduinoLogger.h b/ArduinoCore-Linux/cores/arduino/ArduinoLogger.h index 4b06dec..0a8f82e 100644 --- a/ArduinoCore-Linux/cores/arduino/ArduinoLogger.h +++ b/ArduinoCore-Linux/cores/arduino/ArduinoLogger.h @@ -1,7 +1,7 @@ #pragma once #include "StdioDevice.h" -#include "Stream.h" +#include "api/Stream.h" namespace arduino { diff --git a/ArduinoCore-Linux/cores/arduino/Ethernet.h b/ArduinoCore-Linux/cores/arduino/Ethernet.h index 09dfa43..675adf1 100644 --- a/ArduinoCore-Linux/cores/arduino/Ethernet.h +++ b/ArduinoCore-Linux/cores/arduino/Ethernet.h @@ -6,9 +6,9 @@ #include // for close #include "ArduinoLogger.h" -#include "Client.h" -#include "Common.h" -#include "IPAddress.h" +#include "api/Client.h" +#include "api/Common.h" +#include "api/IPAddress.h" #include "RingBufferExt.h" #include "SocketImpl.h" diff --git a/ArduinoCore-Linux/cores/arduino/EthernetServer.h b/ArduinoCore-Linux/cores/arduino/EthernetServer.h index b4c8370..a8e42a7 100644 --- a/ArduinoCore-Linux/cores/arduino/EthernetServer.h +++ b/ArduinoCore-Linux/cores/arduino/EthernetServer.h @@ -4,7 +4,7 @@ #include #include "Ethernet.h" -#include "Server.h" +#include "api/Server.h" #include "SignalHandler.h" namespace arduino { diff --git a/ArduinoCore-Linux/cores/arduino/EthernetUDP.h b/ArduinoCore-Linux/cores/arduino/EthernetUDP.h index 5e86add..9edc2f0 100644 --- a/ArduinoCore-Linux/cores/arduino/EthernetUDP.h +++ b/ArduinoCore-Linux/cores/arduino/EthernetUDP.h @@ -34,9 +34,9 @@ * bjoern@cs.stanford.edu 12/30/2008 */ -#include +#include +#include #include -#include #include "SignalHandler.h" #include "ArduinoLogger.h" diff --git a/ArduinoCore-Linux/cores/arduino/HardwareGPIO.cpp b/ArduinoCore-Linux/cores/arduino/HardwareGPIO.cpp index f8f24a8..828a202 100644 --- a/ArduinoCore-Linux/cores/arduino/HardwareGPIO.cpp +++ b/ArduinoCore-Linux/cores/arduino/HardwareGPIO.cpp @@ -1,5 +1,5 @@ -#include "Common.h" +#include "api/Common.h" #include "Hardware.h" #include "HardwareGPIO.h" #include "HardwareService.h" diff --git a/ArduinoCore-Linux/cores/arduino/HardwareGPIO.h b/ArduinoCore-Linux/cores/arduino/HardwareGPIO.h index def543a..9893f85 100644 --- a/ArduinoCore-Linux/cores/arduino/HardwareGPIO.h +++ b/ArduinoCore-Linux/cores/arduino/HardwareGPIO.h @@ -1,6 +1,6 @@ #pragma once -#include "Common.h" +#include "api/Common.h" namespace arduino { diff --git a/ArduinoCore-Linux/cores/arduino/HardwareI2CEx.h b/ArduinoCore-Linux/cores/arduino/HardwareI2CEx.h index 11722a6..d77a62d 100644 --- a/ArduinoCore-Linux/cores/arduino/HardwareI2CEx.h +++ b/ArduinoCore-Linux/cores/arduino/HardwareI2CEx.h @@ -1,6 +1,6 @@ #pragma once -#include "HardwareI2C.h" +#include "api/HardwareI2C.h" namespace arduino { diff --git a/ArduinoCore-Linux/cores/arduino/HardwareSPI.cpp b/ArduinoCore-Linux/cores/arduino/HardwareSPI.cpp index 05d60aa..57da951 100644 --- a/ArduinoCore-Linux/cores/arduino/HardwareSPI.cpp +++ b/ArduinoCore-Linux/cores/arduino/HardwareSPI.cpp @@ -1,4 +1,4 @@ -#include "HardwareSPI.h" +#include "api/HardwareSPI.h" #include "HardwareService.h" #include "Hardware.h" /** diff --git a/ArduinoCore-Linux/cores/arduino/HardwareService.h b/ArduinoCore-Linux/cores/arduino/HardwareService.h index a705c1a..be3c6e4 100644 --- a/ArduinoCore-Linux/cores/arduino/HardwareService.h +++ b/ArduinoCore-Linux/cores/arduino/HardwareService.h @@ -1,6 +1,6 @@ #pragma once -#include "Stream.h" +#include "api/Stream.h" namespace arduino { diff --git a/ArduinoCore-Linux/cores/arduino/RemoteSPI.h b/ArduinoCore-Linux/cores/arduino/RemoteSPI.h index 9310348..b1279bf 100644 --- a/ArduinoCore-Linux/cores/arduino/RemoteSPI.h +++ b/ArduinoCore-Linux/cores/arduino/RemoteSPI.h @@ -1,6 +1,6 @@ #pragma once -#include "HardwareSPI.h" +#include "api/HardwareSPI.h" /** * We virtualize the hardware and send the requests and replys over diff --git a/ArduinoCore-Linux/cores/arduino/RemoteSerial.h b/ArduinoCore-Linux/cores/arduino/RemoteSerial.h index c4eaafc..7b37cc7 100644 --- a/ArduinoCore-Linux/cores/arduino/RemoteSerial.h +++ b/ArduinoCore-Linux/cores/arduino/RemoteSerial.h @@ -1,6 +1,6 @@ #pragma once -#include "Stream.h" +#include "api/Stream.h" #include "HardwareService.h" #include "RingBufferExt.h" diff --git a/ArduinoCore-Linux/cores/arduino/StdioDevice.h b/ArduinoCore-Linux/cores/arduino/StdioDevice.h index d70b571..db9aa73 100644 --- a/ArduinoCore-Linux/cores/arduino/StdioDevice.h +++ b/ArduinoCore-Linux/cores/arduino/StdioDevice.h @@ -2,8 +2,8 @@ #include #include -#include "Stream.h" -#include "Printable.h" +#include "api/Stream.h" +#include "api/Printable.h" namespace arduino { diff --git a/ArduinoCore-Linux/cores/arduino/UDP.h b/ArduinoCore-Linux/cores/arduino/UDP.h deleted file mode 100644 index 32a2a75..0000000 --- a/ArduinoCore-Linux/cores/arduino/UDP.h +++ /dev/null @@ -1,99 +0,0 @@ -#pragma once - -/* - * Udp.h: 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 - */ - - -#include -#include - -namespace arduino { - -class UDP: public Stream { - - public: - virtual ~UDP() {}; - virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use - virtual void stop() =0; // Finish with the UDP socket - - // Sending UDP packets - - // Start building up a packet to send to the remote host specific in ip and port - // Returns 1 if successful, 0 if there was a problem with the supplied IP address or port - virtual int beginPacket(IPAddress ip, uint16_t port) =0; - // Start building up a packet to send to the remote host specific in host and port - // Returns 1 if successful, 0 if there was a problem resolving the hostname or port - virtual int beginPacket(const char *host, uint16_t port) =0; - // Finish off this packet and send it - // Returns 1 if the packet was sent successfully, 0 if there was an error - virtual int endPacket() =0; - // Write a single byte into the packet - virtual size_t write(uint8_t) =0; - // Write size bytes from buffer into the packet - virtual size_t write(const uint8_t *buffer, size_t size) =0; - - // Start processing the next available incoming packet - // Returns the size of the packet in bytes, or 0 if no packets are available - virtual int parsePacket() =0; - // Number of bytes remaining in the current packet - virtual int available() =0; - // Read a single byte from the current packet - virtual int read() =0; - // Read up to len bytes from the current packet and place them into buffer - // Returns the number of bytes read, or 0 if none are available - virtual int read(unsigned char* buffer, size_t len) =0; - // Read up to len characters from the current packet and place them into buffer - // Returns the number of characters read, or 0 if none are available - virtual int read(char* buffer, size_t len) =0; - // Return the next byte from the current packet without moving on to the next byte - virtual int peek() =0; - virtual void flush() =0; // Finish reading the current packet - - // Return the IP address of the host who sent the current incoming packet - virtual IPAddress remoteIP() =0; - // Return the port of the host who sent the current incoming packet - virtual uint16_t remotePort() =0; - protected: - - uint8_t* rawIPAddress(IPAddress& addr) { - return addr.raw_address(); - } - - const uint8_t* rawIPAddress(const IPAddress& addr) { - return addr.raw_address(); - } -}; - -} - diff --git a/ArduinoCore-Linux/cores/arduino/Unsupported.cpp b/ArduinoCore-Linux/cores/arduino/Unsupported.cpp index 0e82f40..7ef414b 100644 --- a/ArduinoCore-Linux/cores/arduino/Unsupported.cpp +++ b/ArduinoCore-Linux/cores/arduino/Unsupported.cpp @@ -1,4 +1,4 @@ -#include "Common.h" +#include "api/Common.h" #include "ArduinoLogger.h" void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode){ diff --git a/ArduinoCore-Linux/cores/arduino/WMath.cpp b/ArduinoCore-Linux/cores/arduino/WMath.cpp index 11835b6..a993f1f 100644 --- a/ArduinoCore-Linux/cores/arduino/WMath.cpp +++ b/ArduinoCore-Linux/cores/arduino/WMath.cpp @@ -1,5 +1,5 @@ // WMath.cpp -#include "Common.h" +#include "api/Common.h" extern "C" { #include } diff --git a/ArduinoCore-Linux/cores/arduino/WiFiUdpStream.h b/ArduinoCore-Linux/cores/arduino/WiFiUdpStream.h index 30ce6d0..58e186e 100644 --- a/ArduinoCore-Linux/cores/arduino/WiFiUdpStream.h +++ b/ArduinoCore-Linux/cores/arduino/WiFiUdpStream.h @@ -2,9 +2,9 @@ #include #include -#include "ArduinoAPI.h" +#include "api/ArduinoAPI.h" +#include "api/IPAddress.h" #include "WiFiUDP.h" -#include "IPAddress.h" #include "ArduinoLogger.h" namespace arduino { diff --git a/ArduinoCore-Linux/cores/arduino/itoa.cpp b/ArduinoCore-Linux/cores/arduino/itoa.cpp index b7822e1..2996e50 100644 --- a/ArduinoCore-Linux/cores/arduino/itoa.cpp +++ b/ArduinoCore-Linux/cores/arduino/itoa.cpp @@ -6,7 +6,7 @@ * INCLUDE **************************************************************************************/ -#include +#include #include #include #include diff --git a/ArduinoCore-Linux/libraries/SPI.h b/ArduinoCore-Linux/libraries/SPI.h index e7f9fd0..748f7ce 100644 --- a/ArduinoCore-Linux/libraries/SPI.h +++ b/ArduinoCore-Linux/libraries/SPI.h @@ -1,5 +1,5 @@ #pragma once -#include "HardwareSPI.h" +#include "api/HardwareSPI.h" #include "HardwareSetup.h" // this usually needs PIN_CS defined diff --git a/CMakeLists.txt b/CMakeLists.txt index 8509fc2..fe69c7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,10 +34,13 @@ file(GLOB SRC_LIST CONFIGURE_DEPENDS add_library(arduino_emulator ${SRC_LIST} ${HEADER_LIST}) # Define the directories with the h files -target_include_directories (arduino_emulator PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/ArduinoCore-API/api" +target_include_directories (arduino_emulator PUBLIC + "${CMAKE_CURRENT_SOURCE_DIR}/ArduinoCore-API" "${CMAKE_CURRENT_SOURCE_DIR}/ArduinoCore-Linux/cores/arduino" "${CMAKE_CURRENT_SOURCE_DIR}/ArduinoCore-Linux/cores/rasperry_pi" - "${CMAKE_CURRENT_SOURCE_DIR}/ArduinoCore-Linux/libraries" ) + "${CMAKE_CURRENT_SOURCE_DIR}/ArduinoCore-Linux/libraries" + "${CMAKE_CURRENT_SOURCE_DIR}/ArduinoCore-API/api/deprecated" + ) # Install header files install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/ArduinoCore-API/api/" # source directory From ec670a90139d57541262672c9ce9c87c66766a2a Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 2 Oct 2025 17:36:42 +0200 Subject: [PATCH 2/4] SD, SDFAT,: readBytes w/o override --- ArduinoCore-Linux/libraries/SD.h | 2 +- ArduinoCore-Linux/libraries/SdFat.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ArduinoCore-Linux/libraries/SD.h b/ArduinoCore-Linux/libraries/SD.h index 6229485..cba2cf9 100644 --- a/ArduinoCore-Linux/libraries/SD.h +++ b/ArduinoCore-Linux/libraries/SD.h @@ -112,7 +112,7 @@ class File : public Stream { return readBytes((char *)buffer, length); } - size_t readBytes(char *buffer, size_t length) override { + size_t readBytes(char *buffer, size_t length) { file.read(buffer, length); return static_cast(file.gcount()); } diff --git a/ArduinoCore-Linux/libraries/SdFat.h b/ArduinoCore-Linux/libraries/SdFat.h index 8fe17ed..772a925 100644 --- a/ArduinoCore-Linux/libraries/SdFat.h +++ b/ArduinoCore-Linux/libraries/SdFat.h @@ -116,7 +116,7 @@ class SdFile : public Stream { return !isOpen(); } - size_t readBytes(uint8_t *buffer, size_t length) override { + size_t readBytes(uint8_t *buffer, size_t length) { return file.readsome((char *)buffer, length); } size_t write(const uint8_t *buffer, size_t size) override { From d4ee9fe90397df24c44c3df31a645107cd893929 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 2 Oct 2025 17:48:22 +0200 Subject: [PATCH 3/4] ArduinoCore-API delete --- ArduinoCore-API/README.md | 35 - ArduinoCore-API/api/ArduinoAPI.h | 57 -- ArduinoCore-API/api/Binary.h | 552 ------------- ArduinoCore-API/api/CanMsg.cpp | 46 -- ArduinoCore-API/api/CanMsg.h | 156 ---- ArduinoCore-API/api/CanMsgRingbuffer.cpp | 74 -- ArduinoCore-API/api/CanMsgRingbuffer.h | 72 -- ArduinoCore-API/api/Client.h | 46 -- ArduinoCore-API/api/Common.cpp | 29 - ArduinoCore-API/api/Common.h | 190 ----- ArduinoCore-API/api/Compat.h | 35 - ArduinoCore-API/api/DMAPool.h | 316 -------- ArduinoCore-API/api/HardwareCAN.h | 118 --- ArduinoCore-API/api/HardwareI2C.h | 48 -- ArduinoCore-API/api/HardwareSPI.h | 145 ---- ArduinoCore-API/api/HardwareSerial.h | 106 --- ArduinoCore-API/api/IPAddress.cpp | 368 --------- ArduinoCore-API/api/IPAddress.h | 122 --- ArduinoCore-API/api/Interrupts.h | 63 -- ArduinoCore-API/api/PluggableUSB.cpp | 101 --- ArduinoCore-API/api/PluggableUSB.h | 78 -- ArduinoCore-API/api/Print.cpp | 388 --------- ArduinoCore-API/api/Print.h | 99 --- ArduinoCore-API/api/Printable.h | 40 - ArduinoCore-API/api/RingBuffer.h | 142 ---- ArduinoCore-API/api/Server.h | 31 - ArduinoCore-API/api/Stream.cpp | 321 -------- ArduinoCore-API/api/Stream.h | 133 ---- ArduinoCore-API/api/String.cpp | 750 ------------------ ArduinoCore-API/api/String.h | 255 ------ ArduinoCore-API/api/USBAPI.h | 64 -- ArduinoCore-API/api/Udp.h | 92 --- ArduinoCore-API/api/WCharacter.h | 171 ---- .../deprecated-avr-comp/avr/dtostrf.c.impl | 40 - .../api/deprecated-avr-comp/avr/dtostrf.h | 34 - .../api/deprecated-avr-comp/avr/interrupt.h | 23 - .../api/deprecated-avr-comp/avr/pgmspace.h | 124 --- ArduinoCore-API/api/deprecated/Client.h | 25 - .../api/deprecated/HardwareSerial.h | 25 - ArduinoCore-API/api/deprecated/IPAddress.h | 25 - ArduinoCore-API/api/deprecated/Print.h | 24 - ArduinoCore-API/api/deprecated/Printable.h | 24 - ArduinoCore-API/api/deprecated/Server.h | 25 - ArduinoCore-API/api/deprecated/Stream.h | 25 - ArduinoCore-API/api/deprecated/Udp.h | 25 - ArduinoCore-API/api/itoa.h | 38 - ArduinoCore-API/test/.gitignore | 19 - ArduinoCore-API/test/CMakeLists.txt | 158 ---- ArduinoCore-API/test/include/MillisFake.h | 32 - ArduinoCore-API/test/include/PrintMock.h | 31 - ArduinoCore-API/test/include/PrintableMock.h | 35 - ArduinoCore-API/test/include/StreamMock.h | 38 - .../test/src/CanMsg/test_CanExtendedId.cpp | 43 - .../test/src/CanMsg/test_CanMsg.cpp | 68 -- .../test/src/CanMsg/test_CanMsg_CopyCtor.cpp | 39 - .../test/src/CanMsg/test_CanStandardId.cpp | 42 - .../test/src/CanMsg/test_isExtendedId.cpp | 35 - .../test/src/CanMsg/test_isStandardId.cpp | 35 - .../src/CanMsg/test_operator_assignment.cpp | 41 - .../test/src/CanMsg/test_printTo.cpp | 46 -- .../src/CanMsgRingbuffer/test_available.cpp | 35 - .../test/src/Common/test_makeWord.cpp | 34 - ArduinoCore-API/test/src/Common/test_map.cpp | 48 -- ArduinoCore-API/test/src/Common/test_max.cpp | 78 -- ArduinoCore-API/test/src/Common/test_min.cpp | 78 -- .../test/src/IPAddress/test_IPAddress.cpp | 55 -- .../test/src/IPAddress/test_IPAddress6.cpp | 87 -- .../test/src/IPAddress/test_fromString.cpp | 62 -- .../test/src/IPAddress/test_fromString6.cpp | 397 --------- .../IPAddress/test_operator_assignment.cpp | 36 - .../IPAddress/test_operator_comparison.cpp | 55 -- .../IPAddress/test_operator_comparison6.cpp | 74 -- .../IPAddress/test_operator_parentheses.cpp | 26 - .../IPAddress/test_operator_parentheses6.cpp | 46 -- .../test/src/IPAddress/test_printTo.cpp | 28 - .../test/src/IPAddress/test_printTo6.cpp | 139 ---- .../test/src/IPAddress/test_toString.cpp | 39 - ArduinoCore-API/test/src/MillisFake.cpp | 65 -- .../test/src/Print/test_availableForWrite.cpp | 25 - .../test/src/Print/test_clearWriteError.cpp | 27 - .../test/src/Print/test_getWriteError.cpp | 32 - ArduinoCore-API/test/src/Print/test_print.cpp | 198 ----- .../test/src/Print/test_println.cpp | 150 ---- ArduinoCore-API/test/src/PrintMock.cpp | 21 - .../test/src/Ringbuffer/test_available.cpp | 32 - .../src/Ringbuffer/test_availableForStore.cpp | 32 - .../test/src/Ringbuffer/test_clear.cpp | 34 - .../test/src/Ringbuffer/test_isFull.cpp | 38 - .../test/src/Ringbuffer/test_peek.cpp | 37 - .../test/src/Ringbuffer/test_read_char.cpp | 37 - .../test/src/Ringbuffer/test_store_char.cpp | 26 - ArduinoCore-API/test/src/Stream/test_find.cpp | 80 -- .../test/src/Stream/test_findUntil.cpp | 51 -- .../test/src/Stream/test_getTimeout.cpp | 23 - .../test/src/Stream/test_parseFloat.cpp | 126 --- .../test/src/Stream/test_parseInt.cpp | 105 --- .../test/src/Stream/test_readBytes.cpp | 51 -- .../test/src/Stream/test_readBytesUntil.cpp | 52 -- .../test/src/Stream/test_readString.cpp | 28 - .../test/src/Stream/test_readStringUntil.cpp | 38 - .../test/src/Stream/test_setTimeout.cpp | 26 - ArduinoCore-API/test/src/StreamMock.cpp | 53 -- .../test/src/String/StringPrinter.h | 30 - .../test/src/String/test_String.cpp | 164 ---- .../src/String/test_characterAccessFunc.cpp | 71 -- .../test/src/String/test_compareTo.cpp | 104 --- .../test/src/String/test_comparisonFunc.cpp | 159 ---- .../test/src/String/test_concat.cpp | 106 --- .../test/src/String/test_indexOf.cpp | 104 --- .../test/src/String/test_isEmpty.cpp | 31 - .../test/src/String/test_lastIndexOf.cpp | 104 --- .../test/src/String/test_length.cpp | 31 - ArduinoCore-API/test/src/String/test_move.cpp | 52 -- .../test/src/String/test_operators.cpp | 168 ---- .../test/src/String/test_remove.cpp | 68 -- .../test/src/String/test_replace.cpp | 91 --- .../test/src/String/test_substring.cpp | 42 - .../test/src/String/test_toDouble.cpp | 47 -- .../test/src/String/test_toFloat.cpp | 40 - .../test/src/String/test_toInt.cpp | 47 -- .../test/src/String/test_toLowerCase.cpp | 26 - .../test/src/String/test_toUpperCase.cpp | 26 - ArduinoCore-API/test/src/String/test_trim.cpp | 47 -- .../test/src/WCharacter/test_isAscii.cpp | 52 -- .../test/src/WCharacter/test_isControl.cpp | 41 - .../test/src/WCharacter/test_isDigit.cpp | 41 - .../WCharacter/test_isHexadecimalDigit.cpp | 41 - .../test/src/WCharacter/test_isLowerCase.cpp | 33 - .../test/src/WCharacter/test_isPunct.cpp | 41 - .../test/src/WCharacter/test_isSpace.cpp | 41 - .../test/src/WCharacter/test_isUpperCase.cpp | 33 - .../test/src/WCharacter/test_isWhitespace.cpp | 33 - .../test/src/WCharacter/test_toAscii.cpp | 51 -- ArduinoCore-API/test/src/dtostrf.cpp | 27 - ArduinoCore-API/test/src/itoa.cpp | 64 -- 135 files changed, 11122 deletions(-) delete mode 100644 ArduinoCore-API/README.md delete mode 100644 ArduinoCore-API/api/ArduinoAPI.h delete mode 100644 ArduinoCore-API/api/Binary.h delete mode 100644 ArduinoCore-API/api/CanMsg.cpp delete mode 100644 ArduinoCore-API/api/CanMsg.h delete mode 100644 ArduinoCore-API/api/CanMsgRingbuffer.cpp delete mode 100644 ArduinoCore-API/api/CanMsgRingbuffer.h delete mode 100644 ArduinoCore-API/api/Client.h delete mode 100644 ArduinoCore-API/api/Common.cpp delete mode 100644 ArduinoCore-API/api/Common.h delete mode 100644 ArduinoCore-API/api/Compat.h delete mode 100644 ArduinoCore-API/api/DMAPool.h delete mode 100644 ArduinoCore-API/api/HardwareCAN.h delete mode 100644 ArduinoCore-API/api/HardwareI2C.h delete mode 100644 ArduinoCore-API/api/HardwareSPI.h delete mode 100644 ArduinoCore-API/api/HardwareSerial.h delete mode 100644 ArduinoCore-API/api/IPAddress.cpp delete mode 100644 ArduinoCore-API/api/IPAddress.h delete mode 100644 ArduinoCore-API/api/Interrupts.h delete mode 100644 ArduinoCore-API/api/PluggableUSB.cpp delete mode 100644 ArduinoCore-API/api/PluggableUSB.h delete mode 100644 ArduinoCore-API/api/Print.cpp delete mode 100644 ArduinoCore-API/api/Print.h delete mode 100644 ArduinoCore-API/api/Printable.h delete mode 100644 ArduinoCore-API/api/RingBuffer.h delete mode 100644 ArduinoCore-API/api/Server.h delete mode 100644 ArduinoCore-API/api/Stream.cpp delete mode 100644 ArduinoCore-API/api/Stream.h delete mode 100644 ArduinoCore-API/api/String.cpp delete mode 100644 ArduinoCore-API/api/String.h delete mode 100644 ArduinoCore-API/api/USBAPI.h delete mode 100644 ArduinoCore-API/api/Udp.h delete mode 100644 ArduinoCore-API/api/WCharacter.h delete mode 100644 ArduinoCore-API/api/deprecated-avr-comp/avr/dtostrf.c.impl delete mode 100644 ArduinoCore-API/api/deprecated-avr-comp/avr/dtostrf.h delete mode 100644 ArduinoCore-API/api/deprecated-avr-comp/avr/interrupt.h delete mode 100644 ArduinoCore-API/api/deprecated-avr-comp/avr/pgmspace.h delete mode 100644 ArduinoCore-API/api/deprecated/Client.h delete mode 100644 ArduinoCore-API/api/deprecated/HardwareSerial.h delete mode 100644 ArduinoCore-API/api/deprecated/IPAddress.h delete mode 100644 ArduinoCore-API/api/deprecated/Print.h delete mode 100644 ArduinoCore-API/api/deprecated/Printable.h delete mode 100644 ArduinoCore-API/api/deprecated/Server.h delete mode 100644 ArduinoCore-API/api/deprecated/Stream.h delete mode 100644 ArduinoCore-API/api/deprecated/Udp.h delete mode 100644 ArduinoCore-API/api/itoa.h delete mode 100644 ArduinoCore-API/test/.gitignore delete mode 100644 ArduinoCore-API/test/CMakeLists.txt delete mode 100644 ArduinoCore-API/test/include/MillisFake.h delete mode 100644 ArduinoCore-API/test/include/PrintMock.h delete mode 100644 ArduinoCore-API/test/include/PrintableMock.h delete mode 100644 ArduinoCore-API/test/include/StreamMock.h delete mode 100644 ArduinoCore-API/test/src/CanMsg/test_CanExtendedId.cpp delete mode 100644 ArduinoCore-API/test/src/CanMsg/test_CanMsg.cpp delete mode 100644 ArduinoCore-API/test/src/CanMsg/test_CanMsg_CopyCtor.cpp delete mode 100644 ArduinoCore-API/test/src/CanMsg/test_CanStandardId.cpp delete mode 100644 ArduinoCore-API/test/src/CanMsg/test_isExtendedId.cpp delete mode 100644 ArduinoCore-API/test/src/CanMsg/test_isStandardId.cpp delete mode 100644 ArduinoCore-API/test/src/CanMsg/test_operator_assignment.cpp delete mode 100644 ArduinoCore-API/test/src/CanMsg/test_printTo.cpp delete mode 100644 ArduinoCore-API/test/src/CanMsgRingbuffer/test_available.cpp delete mode 100644 ArduinoCore-API/test/src/Common/test_makeWord.cpp delete mode 100644 ArduinoCore-API/test/src/Common/test_map.cpp delete mode 100644 ArduinoCore-API/test/src/Common/test_max.cpp delete mode 100644 ArduinoCore-API/test/src/Common/test_min.cpp delete mode 100644 ArduinoCore-API/test/src/IPAddress/test_IPAddress.cpp delete mode 100644 ArduinoCore-API/test/src/IPAddress/test_IPAddress6.cpp delete mode 100644 ArduinoCore-API/test/src/IPAddress/test_fromString.cpp delete mode 100644 ArduinoCore-API/test/src/IPAddress/test_fromString6.cpp delete mode 100644 ArduinoCore-API/test/src/IPAddress/test_operator_assignment.cpp delete mode 100644 ArduinoCore-API/test/src/IPAddress/test_operator_comparison.cpp delete mode 100644 ArduinoCore-API/test/src/IPAddress/test_operator_comparison6.cpp delete mode 100644 ArduinoCore-API/test/src/IPAddress/test_operator_parentheses.cpp delete mode 100644 ArduinoCore-API/test/src/IPAddress/test_operator_parentheses6.cpp delete mode 100644 ArduinoCore-API/test/src/IPAddress/test_printTo.cpp delete mode 100644 ArduinoCore-API/test/src/IPAddress/test_printTo6.cpp delete mode 100644 ArduinoCore-API/test/src/IPAddress/test_toString.cpp delete mode 100644 ArduinoCore-API/test/src/MillisFake.cpp delete mode 100644 ArduinoCore-API/test/src/Print/test_availableForWrite.cpp delete mode 100644 ArduinoCore-API/test/src/Print/test_clearWriteError.cpp delete mode 100644 ArduinoCore-API/test/src/Print/test_getWriteError.cpp delete mode 100644 ArduinoCore-API/test/src/Print/test_print.cpp delete mode 100644 ArduinoCore-API/test/src/Print/test_println.cpp delete mode 100644 ArduinoCore-API/test/src/PrintMock.cpp delete mode 100644 ArduinoCore-API/test/src/Ringbuffer/test_available.cpp delete mode 100644 ArduinoCore-API/test/src/Ringbuffer/test_availableForStore.cpp delete mode 100644 ArduinoCore-API/test/src/Ringbuffer/test_clear.cpp delete mode 100644 ArduinoCore-API/test/src/Ringbuffer/test_isFull.cpp delete mode 100644 ArduinoCore-API/test/src/Ringbuffer/test_peek.cpp delete mode 100644 ArduinoCore-API/test/src/Ringbuffer/test_read_char.cpp delete mode 100644 ArduinoCore-API/test/src/Ringbuffer/test_store_char.cpp delete mode 100644 ArduinoCore-API/test/src/Stream/test_find.cpp delete mode 100644 ArduinoCore-API/test/src/Stream/test_findUntil.cpp delete mode 100644 ArduinoCore-API/test/src/Stream/test_getTimeout.cpp delete mode 100644 ArduinoCore-API/test/src/Stream/test_parseFloat.cpp delete mode 100644 ArduinoCore-API/test/src/Stream/test_parseInt.cpp delete mode 100644 ArduinoCore-API/test/src/Stream/test_readBytes.cpp delete mode 100644 ArduinoCore-API/test/src/Stream/test_readBytesUntil.cpp delete mode 100644 ArduinoCore-API/test/src/Stream/test_readString.cpp delete mode 100644 ArduinoCore-API/test/src/Stream/test_readStringUntil.cpp delete mode 100644 ArduinoCore-API/test/src/Stream/test_setTimeout.cpp delete mode 100644 ArduinoCore-API/test/src/StreamMock.cpp delete mode 100644 ArduinoCore-API/test/src/String/StringPrinter.h delete mode 100644 ArduinoCore-API/test/src/String/test_String.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_characterAccessFunc.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_compareTo.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_comparisonFunc.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_concat.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_indexOf.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_isEmpty.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_lastIndexOf.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_length.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_move.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_operators.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_remove.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_replace.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_substring.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_toDouble.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_toFloat.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_toInt.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_toLowerCase.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_toUpperCase.cpp delete mode 100644 ArduinoCore-API/test/src/String/test_trim.cpp delete mode 100644 ArduinoCore-API/test/src/WCharacter/test_isAscii.cpp delete mode 100644 ArduinoCore-API/test/src/WCharacter/test_isControl.cpp delete mode 100644 ArduinoCore-API/test/src/WCharacter/test_isDigit.cpp delete mode 100644 ArduinoCore-API/test/src/WCharacter/test_isHexadecimalDigit.cpp delete mode 100644 ArduinoCore-API/test/src/WCharacter/test_isLowerCase.cpp delete mode 100644 ArduinoCore-API/test/src/WCharacter/test_isPunct.cpp delete mode 100644 ArduinoCore-API/test/src/WCharacter/test_isSpace.cpp delete mode 100644 ArduinoCore-API/test/src/WCharacter/test_isUpperCase.cpp delete mode 100644 ArduinoCore-API/test/src/WCharacter/test_isWhitespace.cpp delete mode 100644 ArduinoCore-API/test/src/WCharacter/test_toAscii.cpp delete mode 100644 ArduinoCore-API/test/src/dtostrf.cpp delete mode 100644 ArduinoCore-API/test/src/itoa.cpp diff --git a/ArduinoCore-API/README.md b/ArduinoCore-API/README.md deleted file mode 100644 index 2533520..0000000 --- a/ArduinoCore-API/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# ArduinoCore-API - -[![Unit Tests](https://github.com/arduino/ArduinoCore-API/workflows/Unit%20Tests/badge.svg)](https://github.com/arduino/ArduinoCore-API/actions?workflow=Unit+Tests) -[![codecov](https://codecov.io/gh/arduino/ArduinoCore-API/branch/master/graph/badge.svg)](https://codecov.io/gh/arduino/ArduinoCore-API) - -This repository hosts the hardware independent layer of Arduino core. - -All Arduino official cores are being ported to the new structure so they take advantage of this single repo. - -Including this repo in your existing Arduino core will allow the language to grow and include new features. -For backwards compatibility, every revision of this repo will increase `ARDUINO_API_VERSION` define. - -Some cores have been ported to the new structure, for example: -* megaAVR (https://github.com/arduino/ArduinoCore-megaAVR) -* nRF52-mbedos (https://github.com/arduino/ArduinoCore-nRF528x-mbedos) -* classic AVR (https://github.com/arduino/ArduinoCore-avr/tree/api) -* SAMD (https://github.com/arduino/ArduinoCore-samd/tree/api) - -These repositories **don't** contain the needed `api` subfolder; to "complete" the core you need to copy or symlink the `api` folder from this repo to the target's `cores/arduino` folder. - -### Porting tips - -In the future, core apis will be updated independently from the core, so all the compatible cores will seamlessly adopt new features. -This requires support from all the IDEs, so in the meantime we suggest to release the core by copying a snapshot of this `api` folder. - -The most elegant and effective solution is to develop the core with `api` symlinked and produce the distributable archive by telling `tar` to follow symlinks. -Example command: -``` -tar --exclude='*.git*' -cjhvf $yourcore-$version.tar.bz2 $yourcore/ -``` - -### Arduino Emulator - -I used a copy of V1.2.0 from https://github.com/arduino/ArduinoCore-API. Unfortunatly I could not use this project as a git submodule because the WString.h class is causing that the compilation is failing on non case sentsitive file systems - so I had to rename WString.h and String.cpp to WWString.h and WString.cpp! - diff --git a/ArduinoCore-API/api/ArduinoAPI.h b/ArduinoCore-API/api/ArduinoAPI.h deleted file mode 100644 index a7d8c0b..0000000 --- a/ArduinoCore-API/api/ArduinoAPI.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - Arduino API main include - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef ARDUINO_API_H -#define ARDUINO_API_H - -// version 1.5.2 -#define ARDUINO_API_VERSION 10502 - -#include "Binary.h" - -#ifdef __cplusplus -#include "Interrupts.h" -#include "IPAddress.h" -#include "Print.h" -#include "Printable.h" -#include "PluggableUSB.h" -#include "Server.h" -#include "String.h" -#include "Stream.h" -#include "Udp.h" -#include "USBAPI.h" -#include "WCharacter.h" -#endif - -/* Standard C library includes */ -#include -#include -#include -#include -#include - -// Misc Arduino core functions -#include "Common.h" - -#ifdef __cplusplus -// Compatibility layer for older code -#include "Compat.h" -#endif - -#endif diff --git a/ArduinoCore-API/api/Binary.h b/ArduinoCore-API/api/Binary.h deleted file mode 100644 index 947542e..0000000 --- a/ArduinoCore-API/api/Binary.h +++ /dev/null @@ -1,552 +0,0 @@ -/* - binary.h - Definitions for binary constants - Deprecated -- use 0b binary literals instead - Copyright (c) 2006 David A. Mellis. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef Binary_h -#define Binary_h - -/* If supported, 0b binary literals are preferable to these constants. - * In that case, warn the user about these being deprecated (if possible). */ -#if __cplusplus >= 201402L - /* C++14 introduces binary literals; C++11 introduces [[deprecated()]] */ - #define DEPRECATED(x) [[deprecated("use " #x " instead")]] -#elif __GNUC__ >= 6 - /* GCC 4.3 supports binary literals; GCC 6 supports __deprecated__ on enums*/ - #define DEPRECATED(x) __attribute__ ((__deprecated__ ("use " #x " instead"))) -#else - /* binary literals not supported, or "deprecated" warning not displayable */ - #define DEPRECATED(x) -#endif - -enum { - B0 DEPRECATED(0b0 ) = 0, - B00 DEPRECATED(0b00 ) = 0, - B000 DEPRECATED(0b000 ) = 0, - B0000 DEPRECATED(0b0000 ) = 0, - B00000 DEPRECATED(0b00000 ) = 0, - B000000 DEPRECATED(0b000000 ) = 0, - B0000000 DEPRECATED(0b0000000 ) = 0, - B00000000 DEPRECATED(0b00000000) = 0, - B1 DEPRECATED(0b1 ) = 1, - B01 DEPRECATED(0b01 ) = 1, - B001 DEPRECATED(0b001 ) = 1, - B0001 DEPRECATED(0b0001 ) = 1, - B00001 DEPRECATED(0b00001 ) = 1, - B000001 DEPRECATED(0b000001 ) = 1, - B0000001 DEPRECATED(0b0000001 ) = 1, - B00000001 DEPRECATED(0b00000001) = 1, - B10 DEPRECATED(0b10 ) = 2, - B010 DEPRECATED(0b010 ) = 2, - B0010 DEPRECATED(0b0010 ) = 2, - B00010 DEPRECATED(0b00010 ) = 2, - B000010 DEPRECATED(0b000010 ) = 2, - B0000010 DEPRECATED(0b0000010 ) = 2, - B00000010 DEPRECATED(0b00000010) = 2, - B11 DEPRECATED(0b11 ) = 3, - B011 DEPRECATED(0b011 ) = 3, - B0011 DEPRECATED(0b0011 ) = 3, - B00011 DEPRECATED(0b00011 ) = 3, - B000011 DEPRECATED(0b000011 ) = 3, - B0000011 DEPRECATED(0b0000011 ) = 3, - B00000011 DEPRECATED(0b00000011) = 3, - B100 DEPRECATED(0b100 ) = 4, - B0100 DEPRECATED(0b0100 ) = 4, - B00100 DEPRECATED(0b00100 ) = 4, - B000100 DEPRECATED(0b000100 ) = 4, - B0000100 DEPRECATED(0b0000100 ) = 4, - B00000100 DEPRECATED(0b00000100) = 4, - B101 DEPRECATED(0b101 ) = 5, - B0101 DEPRECATED(0b0101 ) = 5, - B00101 DEPRECATED(0b00101 ) = 5, - B000101 DEPRECATED(0b000101 ) = 5, - B0000101 DEPRECATED(0b0000101 ) = 5, - B00000101 DEPRECATED(0b00000101) = 5, - B110 DEPRECATED(0b110 ) = 6, - B0110 DEPRECATED(0b0110 ) = 6, - B00110 DEPRECATED(0b00110 ) = 6, - B000110 DEPRECATED(0b000110 ) = 6, - B0000110 DEPRECATED(0b0000110 ) = 6, - B00000110 DEPRECATED(0b00000110) = 6, - B111 DEPRECATED(0b111 ) = 7, - B0111 DEPRECATED(0b0111 ) = 7, - B00111 DEPRECATED(0b00111 ) = 7, - B000111 DEPRECATED(0b000111 ) = 7, - B0000111 DEPRECATED(0b0000111 ) = 7, - B00000111 DEPRECATED(0b00000111) = 7, - B1000 DEPRECATED(0b1000 ) = 8, - B01000 DEPRECATED(0b01000 ) = 8, - B001000 DEPRECATED(0b001000 ) = 8, - B0001000 DEPRECATED(0b0001000 ) = 8, - B00001000 DEPRECATED(0b00001000) = 8, - B1001 DEPRECATED(0b1001 ) = 9, - B01001 DEPRECATED(0b01001 ) = 9, - B001001 DEPRECATED(0b001001 ) = 9, - B0001001 DEPRECATED(0b0001001 ) = 9, - B00001001 DEPRECATED(0b00001001) = 9, - B1010 DEPRECATED(0b1010 ) = 10, - B01010 DEPRECATED(0b01010 ) = 10, - B001010 DEPRECATED(0b001010 ) = 10, - B0001010 DEPRECATED(0b0001010 ) = 10, - B00001010 DEPRECATED(0b00001010) = 10, - B1011 DEPRECATED(0b1011 ) = 11, - B01011 DEPRECATED(0b01011 ) = 11, - B001011 DEPRECATED(0b001011 ) = 11, - B0001011 DEPRECATED(0b0001011 ) = 11, - B00001011 DEPRECATED(0b00001011) = 11, - B1100 DEPRECATED(0b1100 ) = 12, - B01100 DEPRECATED(0b01100 ) = 12, - B001100 DEPRECATED(0b001100 ) = 12, - B0001100 DEPRECATED(0b0001100 ) = 12, - B00001100 DEPRECATED(0b00001100) = 12, - B1101 DEPRECATED(0b1101 ) = 13, - B01101 DEPRECATED(0b01101 ) = 13, - B001101 DEPRECATED(0b001101 ) = 13, - B0001101 DEPRECATED(0b0001101 ) = 13, - B00001101 DEPRECATED(0b00001101) = 13, - B1110 DEPRECATED(0b1110 ) = 14, - B01110 DEPRECATED(0b01110 ) = 14, - B001110 DEPRECATED(0b001110 ) = 14, - B0001110 DEPRECATED(0b0001110 ) = 14, - B00001110 DEPRECATED(0b00001110) = 14, - B1111 DEPRECATED(0b1111 ) = 15, - B01111 DEPRECATED(0b01111 ) = 15, - B001111 DEPRECATED(0b001111 ) = 15, - B0001111 DEPRECATED(0b0001111 ) = 15, - B00001111 DEPRECATED(0b00001111) = 15, - B10000 DEPRECATED(0b10000 ) = 16, - B010000 DEPRECATED(0b010000 ) = 16, - B0010000 DEPRECATED(0b0010000 ) = 16, - B00010000 DEPRECATED(0b00010000) = 16, - B10001 DEPRECATED(0b10001 ) = 17, - B010001 DEPRECATED(0b010001 ) = 17, - B0010001 DEPRECATED(0b0010001 ) = 17, - B00010001 DEPRECATED(0b00010001) = 17, - B10010 DEPRECATED(0b10010 ) = 18, - B010010 DEPRECATED(0b010010 ) = 18, - B0010010 DEPRECATED(0b0010010 ) = 18, - B00010010 DEPRECATED(0b00010010) = 18, - B10011 DEPRECATED(0b10011 ) = 19, - B010011 DEPRECATED(0b010011 ) = 19, - B0010011 DEPRECATED(0b0010011 ) = 19, - B00010011 DEPRECATED(0b00010011) = 19, - B10100 DEPRECATED(0b10100 ) = 20, - B010100 DEPRECATED(0b010100 ) = 20, - B0010100 DEPRECATED(0b0010100 ) = 20, - B00010100 DEPRECATED(0b00010100) = 20, - B10101 DEPRECATED(0b10101 ) = 21, - B010101 DEPRECATED(0b010101 ) = 21, - B0010101 DEPRECATED(0b0010101 ) = 21, - B00010101 DEPRECATED(0b00010101) = 21, - B10110 DEPRECATED(0b10110 ) = 22, - B010110 DEPRECATED(0b010110 ) = 22, - B0010110 DEPRECATED(0b0010110 ) = 22, - B00010110 DEPRECATED(0b00010110) = 22, - B10111 DEPRECATED(0b10111 ) = 23, - B010111 DEPRECATED(0b010111 ) = 23, - B0010111 DEPRECATED(0b0010111 ) = 23, - B00010111 DEPRECATED(0b00010111) = 23, - B11000 DEPRECATED(0b11000 ) = 24, - B011000 DEPRECATED(0b011000 ) = 24, - B0011000 DEPRECATED(0b0011000 ) = 24, - B00011000 DEPRECATED(0b00011000) = 24, - B11001 DEPRECATED(0b11001 ) = 25, - B011001 DEPRECATED(0b011001 ) = 25, - B0011001 DEPRECATED(0b0011001 ) = 25, - B00011001 DEPRECATED(0b00011001) = 25, - B11010 DEPRECATED(0b11010 ) = 26, - B011010 DEPRECATED(0b011010 ) = 26, - B0011010 DEPRECATED(0b0011010 ) = 26, - B00011010 DEPRECATED(0b00011010) = 26, - B11011 DEPRECATED(0b11011 ) = 27, - B011011 DEPRECATED(0b011011 ) = 27, - B0011011 DEPRECATED(0b0011011 ) = 27, - B00011011 DEPRECATED(0b00011011) = 27, - B11100 DEPRECATED(0b11100 ) = 28, - B011100 DEPRECATED(0b011100 ) = 28, - B0011100 DEPRECATED(0b0011100 ) = 28, - B00011100 DEPRECATED(0b00011100) = 28, - B11101 DEPRECATED(0b11101 ) = 29, - B011101 DEPRECATED(0b011101 ) = 29, - B0011101 DEPRECATED(0b0011101 ) = 29, - B00011101 DEPRECATED(0b00011101) = 29, - B11110 DEPRECATED(0b11110 ) = 30, - B011110 DEPRECATED(0b011110 ) = 30, - B0011110 DEPRECATED(0b0011110 ) = 30, - B00011110 DEPRECATED(0b00011110) = 30, - B11111 DEPRECATED(0b11111 ) = 31, - B011111 DEPRECATED(0b011111 ) = 31, - B0011111 DEPRECATED(0b0011111 ) = 31, - B00011111 DEPRECATED(0b00011111) = 31, - B100000 DEPRECATED(0b100000 ) = 32, - B0100000 DEPRECATED(0b0100000 ) = 32, - B00100000 DEPRECATED(0b00100000) = 32, - B100001 DEPRECATED(0b100001 ) = 33, - B0100001 DEPRECATED(0b0100001 ) = 33, - B00100001 DEPRECATED(0b00100001) = 33, - B100010 DEPRECATED(0b100010 ) = 34, - B0100010 DEPRECATED(0b0100010 ) = 34, - B00100010 DEPRECATED(0b00100010) = 34, - B100011 DEPRECATED(0b100011 ) = 35, - B0100011 DEPRECATED(0b0100011 ) = 35, - B00100011 DEPRECATED(0b00100011) = 35, - B100100 DEPRECATED(0b100100 ) = 36, - B0100100 DEPRECATED(0b0100100 ) = 36, - B00100100 DEPRECATED(0b00100100) = 36, - B100101 DEPRECATED(0b100101 ) = 37, - B0100101 DEPRECATED(0b0100101 ) = 37, - B00100101 DEPRECATED(0b00100101) = 37, - B100110 DEPRECATED(0b100110 ) = 38, - B0100110 DEPRECATED(0b0100110 ) = 38, - B00100110 DEPRECATED(0b00100110) = 38, - B100111 DEPRECATED(0b100111 ) = 39, - B0100111 DEPRECATED(0b0100111 ) = 39, - B00100111 DEPRECATED(0b00100111) = 39, - B101000 DEPRECATED(0b101000 ) = 40, - B0101000 DEPRECATED(0b0101000 ) = 40, - B00101000 DEPRECATED(0b00101000) = 40, - B101001 DEPRECATED(0b101001 ) = 41, - B0101001 DEPRECATED(0b0101001 ) = 41, - B00101001 DEPRECATED(0b00101001) = 41, - B101010 DEPRECATED(0b101010 ) = 42, - B0101010 DEPRECATED(0b0101010 ) = 42, - B00101010 DEPRECATED(0b00101010) = 42, - B101011 DEPRECATED(0b101011 ) = 43, - B0101011 DEPRECATED(0b0101011 ) = 43, - B00101011 DEPRECATED(0b00101011) = 43, - B101100 DEPRECATED(0b101100 ) = 44, - B0101100 DEPRECATED(0b0101100 ) = 44, - B00101100 DEPRECATED(0b00101100) = 44, - B101101 DEPRECATED(0b101101 ) = 45, - B0101101 DEPRECATED(0b0101101 ) = 45, - B00101101 DEPRECATED(0b00101101) = 45, - B101110 DEPRECATED(0b101110 ) = 46, - B0101110 DEPRECATED(0b0101110 ) = 46, - B00101110 DEPRECATED(0b00101110) = 46, - B101111 DEPRECATED(0b101111 ) = 47, - B0101111 DEPRECATED(0b0101111 ) = 47, - B00101111 DEPRECATED(0b00101111) = 47, - B110000 DEPRECATED(0b110000 ) = 48, - B0110000 DEPRECATED(0b0110000 ) = 48, - B00110000 DEPRECATED(0b00110000) = 48, - B110001 DEPRECATED(0b110001 ) = 49, - B0110001 DEPRECATED(0b0110001 ) = 49, - B00110001 DEPRECATED(0b00110001) = 49, - B110010 DEPRECATED(0b110010 ) = 50, - B0110010 DEPRECATED(0b0110010 ) = 50, - B00110010 DEPRECATED(0b00110010) = 50, - B110011 DEPRECATED(0b110011 ) = 51, - B0110011 DEPRECATED(0b0110011 ) = 51, - B00110011 DEPRECATED(0b00110011) = 51, - B110100 DEPRECATED(0b110100 ) = 52, - B0110100 DEPRECATED(0b0110100 ) = 52, - B00110100 DEPRECATED(0b00110100) = 52, - B110101 DEPRECATED(0b110101 ) = 53, - B0110101 DEPRECATED(0b0110101 ) = 53, - B00110101 DEPRECATED(0b00110101) = 53, - B110110 DEPRECATED(0b110110 ) = 54, - B0110110 DEPRECATED(0b0110110 ) = 54, - B00110110 DEPRECATED(0b00110110) = 54, - B110111 DEPRECATED(0b110111 ) = 55, - B0110111 DEPRECATED(0b0110111 ) = 55, - B00110111 DEPRECATED(0b00110111) = 55, - B111000 DEPRECATED(0b111000 ) = 56, - B0111000 DEPRECATED(0b0111000 ) = 56, - B00111000 DEPRECATED(0b00111000) = 56, - B111001 DEPRECATED(0b111001 ) = 57, - B0111001 DEPRECATED(0b0111001 ) = 57, - B00111001 DEPRECATED(0b00111001) = 57, - B111010 DEPRECATED(0b111010 ) = 58, - B0111010 DEPRECATED(0b0111010 ) = 58, - B00111010 DEPRECATED(0b00111010) = 58, - B111011 DEPRECATED(0b111011 ) = 59, - B0111011 DEPRECATED(0b0111011 ) = 59, - B00111011 DEPRECATED(0b00111011) = 59, - B111100 DEPRECATED(0b111100 ) = 60, - B0111100 DEPRECATED(0b0111100 ) = 60, - B00111100 DEPRECATED(0b00111100) = 60, - B111101 DEPRECATED(0b111101 ) = 61, - B0111101 DEPRECATED(0b0111101 ) = 61, - B00111101 DEPRECATED(0b00111101) = 61, - B111110 DEPRECATED(0b111110 ) = 62, - B0111110 DEPRECATED(0b0111110 ) = 62, - B00111110 DEPRECATED(0b00111110) = 62, - B111111 DEPRECATED(0b111111 ) = 63, - B0111111 DEPRECATED(0b0111111 ) = 63, - B00111111 DEPRECATED(0b00111111) = 63, - B1000000 DEPRECATED(0b1000000 ) = 64, - B01000000 DEPRECATED(0b01000000) = 64, - B1000001 DEPRECATED(0b1000001 ) = 65, - B01000001 DEPRECATED(0b01000001) = 65, - B1000010 DEPRECATED(0b1000010 ) = 66, - B01000010 DEPRECATED(0b01000010) = 66, - B1000011 DEPRECATED(0b1000011 ) = 67, - B01000011 DEPRECATED(0b01000011) = 67, - B1000100 DEPRECATED(0b1000100 ) = 68, - B01000100 DEPRECATED(0b01000100) = 68, - B1000101 DEPRECATED(0b1000101 ) = 69, - B01000101 DEPRECATED(0b01000101) = 69, - B1000110 DEPRECATED(0b1000110 ) = 70, - B01000110 DEPRECATED(0b01000110) = 70, - B1000111 DEPRECATED(0b1000111 ) = 71, - B01000111 DEPRECATED(0b01000111) = 71, - B1001000 DEPRECATED(0b1001000 ) = 72, - B01001000 DEPRECATED(0b01001000) = 72, - B1001001 DEPRECATED(0b1001001 ) = 73, - B01001001 DEPRECATED(0b01001001) = 73, - B1001010 DEPRECATED(0b1001010 ) = 74, - B01001010 DEPRECATED(0b01001010) = 74, - B1001011 DEPRECATED(0b1001011 ) = 75, - B01001011 DEPRECATED(0b01001011) = 75, - B1001100 DEPRECATED(0b1001100 ) = 76, - B01001100 DEPRECATED(0b01001100) = 76, - B1001101 DEPRECATED(0b1001101 ) = 77, - B01001101 DEPRECATED(0b01001101) = 77, - B1001110 DEPRECATED(0b1001110 ) = 78, - B01001110 DEPRECATED(0b01001110) = 78, - B1001111 DEPRECATED(0b1001111 ) = 79, - B01001111 DEPRECATED(0b01001111) = 79, - B1010000 DEPRECATED(0b1010000 ) = 80, - B01010000 DEPRECATED(0b01010000) = 80, - B1010001 DEPRECATED(0b1010001 ) = 81, - B01010001 DEPRECATED(0b01010001) = 81, - B1010010 DEPRECATED(0b1010010 ) = 82, - B01010010 DEPRECATED(0b01010010) = 82, - B1010011 DEPRECATED(0b1010011 ) = 83, - B01010011 DEPRECATED(0b01010011) = 83, - B1010100 DEPRECATED(0b1010100 ) = 84, - B01010100 DEPRECATED(0b01010100) = 84, - B1010101 DEPRECATED(0b1010101 ) = 85, - B01010101 DEPRECATED(0b01010101) = 85, - B1010110 DEPRECATED(0b1010110 ) = 86, - B01010110 DEPRECATED(0b01010110) = 86, - B1010111 DEPRECATED(0b1010111 ) = 87, - B01010111 DEPRECATED(0b01010111) = 87, - B1011000 DEPRECATED(0b1011000 ) = 88, - B01011000 DEPRECATED(0b01011000) = 88, - B1011001 DEPRECATED(0b1011001 ) = 89, - B01011001 DEPRECATED(0b01011001) = 89, - B1011010 DEPRECATED(0b1011010 ) = 90, - B01011010 DEPRECATED(0b01011010) = 90, - B1011011 DEPRECATED(0b1011011 ) = 91, - B01011011 DEPRECATED(0b01011011) = 91, - B1011100 DEPRECATED(0b1011100 ) = 92, - B01011100 DEPRECATED(0b01011100) = 92, - B1011101 DEPRECATED(0b1011101 ) = 93, - B01011101 DEPRECATED(0b01011101) = 93, - B1011110 DEPRECATED(0b1011110 ) = 94, - B01011110 DEPRECATED(0b01011110) = 94, - B1011111 DEPRECATED(0b1011111 ) = 95, - B01011111 DEPRECATED(0b01011111) = 95, - B1100000 DEPRECATED(0b1100000 ) = 96, - B01100000 DEPRECATED(0b01100000) = 96, - B1100001 DEPRECATED(0b1100001 ) = 97, - B01100001 DEPRECATED(0b01100001) = 97, - B1100010 DEPRECATED(0b1100010 ) = 98, - B01100010 DEPRECATED(0b01100010) = 98, - B1100011 DEPRECATED(0b1100011 ) = 99, - B01100011 DEPRECATED(0b01100011) = 99, - B1100100 DEPRECATED(0b1100100 ) = 100, - B01100100 DEPRECATED(0b01100100) = 100, - B1100101 DEPRECATED(0b1100101 ) = 101, - B01100101 DEPRECATED(0b01100101) = 101, - B1100110 DEPRECATED(0b1100110 ) = 102, - B01100110 DEPRECATED(0b01100110) = 102, - B1100111 DEPRECATED(0b1100111 ) = 103, - B01100111 DEPRECATED(0b01100111) = 103, - B1101000 DEPRECATED(0b1101000 ) = 104, - B01101000 DEPRECATED(0b01101000) = 104, - B1101001 DEPRECATED(0b1101001 ) = 105, - B01101001 DEPRECATED(0b01101001) = 105, - B1101010 DEPRECATED(0b1101010 ) = 106, - B01101010 DEPRECATED(0b01101010) = 106, - B1101011 DEPRECATED(0b1101011 ) = 107, - B01101011 DEPRECATED(0b01101011) = 107, - B1101100 DEPRECATED(0b1101100 ) = 108, - B01101100 DEPRECATED(0b01101100) = 108, - B1101101 DEPRECATED(0b1101101 ) = 109, - B01101101 DEPRECATED(0b01101101) = 109, - B1101110 DEPRECATED(0b1101110 ) = 110, - B01101110 DEPRECATED(0b01101110) = 110, - B1101111 DEPRECATED(0b1101111 ) = 111, - B01101111 DEPRECATED(0b01101111) = 111, - B1110000 DEPRECATED(0b1110000 ) = 112, - B01110000 DEPRECATED(0b01110000) = 112, - B1110001 DEPRECATED(0b1110001 ) = 113, - B01110001 DEPRECATED(0b01110001) = 113, - B1110010 DEPRECATED(0b1110010 ) = 114, - B01110010 DEPRECATED(0b01110010) = 114, - B1110011 DEPRECATED(0b1110011 ) = 115, - B01110011 DEPRECATED(0b01110011) = 115, - B1110100 DEPRECATED(0b1110100 ) = 116, - B01110100 DEPRECATED(0b01110100) = 116, - B1110101 DEPRECATED(0b1110101 ) = 117, - B01110101 DEPRECATED(0b01110101) = 117, - B1110110 DEPRECATED(0b1110110 ) = 118, - B01110110 DEPRECATED(0b01110110) = 118, - B1110111 DEPRECATED(0b1110111 ) = 119, - B01110111 DEPRECATED(0b01110111) = 119, - B1111000 DEPRECATED(0b1111000 ) = 120, - B01111000 DEPRECATED(0b01111000) = 120, - B1111001 DEPRECATED(0b1111001 ) = 121, - B01111001 DEPRECATED(0b01111001) = 121, - B1111010 DEPRECATED(0b1111010 ) = 122, - B01111010 DEPRECATED(0b01111010) = 122, - B1111011 DEPRECATED(0b1111011 ) = 123, - B01111011 DEPRECATED(0b01111011) = 123, - B1111100 DEPRECATED(0b1111100 ) = 124, - B01111100 DEPRECATED(0b01111100) = 124, - B1111101 DEPRECATED(0b1111101 ) = 125, - B01111101 DEPRECATED(0b01111101) = 125, - B1111110 DEPRECATED(0b1111110 ) = 126, - B01111110 DEPRECATED(0b01111110) = 126, - B1111111 DEPRECATED(0b1111111 ) = 127, - B01111111 DEPRECATED(0b01111111) = 127, - B10000000 DEPRECATED(0b10000000) = 128, - B10000001 DEPRECATED(0b10000001) = 129, - B10000010 DEPRECATED(0b10000010) = 130, - B10000011 DEPRECATED(0b10000011) = 131, - B10000100 DEPRECATED(0b10000100) = 132, - B10000101 DEPRECATED(0b10000101) = 133, - B10000110 DEPRECATED(0b10000110) = 134, - B10000111 DEPRECATED(0b10000111) = 135, - B10001000 DEPRECATED(0b10001000) = 136, - B10001001 DEPRECATED(0b10001001) = 137, - B10001010 DEPRECATED(0b10001010) = 138, - B10001011 DEPRECATED(0b10001011) = 139, - B10001100 DEPRECATED(0b10001100) = 140, - B10001101 DEPRECATED(0b10001101) = 141, - B10001110 DEPRECATED(0b10001110) = 142, - B10001111 DEPRECATED(0b10001111) = 143, - B10010000 DEPRECATED(0b10010000) = 144, - B10010001 DEPRECATED(0b10010001) = 145, - B10010010 DEPRECATED(0b10010010) = 146, - B10010011 DEPRECATED(0b10010011) = 147, - B10010100 DEPRECATED(0b10010100) = 148, - B10010101 DEPRECATED(0b10010101) = 149, - B10010110 DEPRECATED(0b10010110) = 150, - B10010111 DEPRECATED(0b10010111) = 151, - B10011000 DEPRECATED(0b10011000) = 152, - B10011001 DEPRECATED(0b10011001) = 153, - B10011010 DEPRECATED(0b10011010) = 154, - B10011011 DEPRECATED(0b10011011) = 155, - B10011100 DEPRECATED(0b10011100) = 156, - B10011101 DEPRECATED(0b10011101) = 157, - B10011110 DEPRECATED(0b10011110) = 158, - B10011111 DEPRECATED(0b10011111) = 159, - B10100000 DEPRECATED(0b10100000) = 160, - B10100001 DEPRECATED(0b10100001) = 161, - B10100010 DEPRECATED(0b10100010) = 162, - B10100011 DEPRECATED(0b10100011) = 163, - B10100100 DEPRECATED(0b10100100) = 164, - B10100101 DEPRECATED(0b10100101) = 165, - B10100110 DEPRECATED(0b10100110) = 166, - B10100111 DEPRECATED(0b10100111) = 167, - B10101000 DEPRECATED(0b10101000) = 168, - B10101001 DEPRECATED(0b10101001) = 169, - B10101010 DEPRECATED(0b10101010) = 170, - B10101011 DEPRECATED(0b10101011) = 171, - B10101100 DEPRECATED(0b10101100) = 172, - B10101101 DEPRECATED(0b10101101) = 173, - B10101110 DEPRECATED(0b10101110) = 174, - B10101111 DEPRECATED(0b10101111) = 175, - B10110000 DEPRECATED(0b10110000) = 176, - B10110001 DEPRECATED(0b10110001) = 177, - B10110010 DEPRECATED(0b10110010) = 178, - B10110011 DEPRECATED(0b10110011) = 179, - B10110100 DEPRECATED(0b10110100) = 180, - B10110101 DEPRECATED(0b10110101) = 181, - B10110110 DEPRECATED(0b10110110) = 182, - B10110111 DEPRECATED(0b10110111) = 183, - B10111000 DEPRECATED(0b10111000) = 184, - B10111001 DEPRECATED(0b10111001) = 185, - B10111010 DEPRECATED(0b10111010) = 186, - B10111011 DEPRECATED(0b10111011) = 187, - B10111100 DEPRECATED(0b10111100) = 188, - B10111101 DEPRECATED(0b10111101) = 189, - B10111110 DEPRECATED(0b10111110) = 190, - B10111111 DEPRECATED(0b10111111) = 191, - B11000000 DEPRECATED(0b11000000) = 192, - B11000001 DEPRECATED(0b11000001) = 193, - B11000010 DEPRECATED(0b11000010) = 194, - B11000011 DEPRECATED(0b11000011) = 195, - B11000100 DEPRECATED(0b11000100) = 196, - B11000101 DEPRECATED(0b11000101) = 197, - B11000110 DEPRECATED(0b11000110) = 198, - B11000111 DEPRECATED(0b11000111) = 199, - B11001000 DEPRECATED(0b11001000) = 200, - B11001001 DEPRECATED(0b11001001) = 201, - B11001010 DEPRECATED(0b11001010) = 202, - B11001011 DEPRECATED(0b11001011) = 203, - B11001100 DEPRECATED(0b11001100) = 204, - B11001101 DEPRECATED(0b11001101) = 205, - B11001110 DEPRECATED(0b11001110) = 206, - B11001111 DEPRECATED(0b11001111) = 207, - B11010000 DEPRECATED(0b11010000) = 208, - B11010001 DEPRECATED(0b11010001) = 209, - B11010010 DEPRECATED(0b11010010) = 210, - B11010011 DEPRECATED(0b11010011) = 211, - B11010100 DEPRECATED(0b11010100) = 212, - B11010101 DEPRECATED(0b11010101) = 213, - B11010110 DEPRECATED(0b11010110) = 214, - B11010111 DEPRECATED(0b11010111) = 215, - B11011000 DEPRECATED(0b11011000) = 216, - B11011001 DEPRECATED(0b11011001) = 217, - B11011010 DEPRECATED(0b11011010) = 218, - B11011011 DEPRECATED(0b11011011) = 219, - B11011100 DEPRECATED(0b11011100) = 220, - B11011101 DEPRECATED(0b11011101) = 221, - B11011110 DEPRECATED(0b11011110) = 222, - B11011111 DEPRECATED(0b11011111) = 223, - B11100000 DEPRECATED(0b11100000) = 224, - B11100001 DEPRECATED(0b11100001) = 225, - B11100010 DEPRECATED(0b11100010) = 226, - B11100011 DEPRECATED(0b11100011) = 227, - B11100100 DEPRECATED(0b11100100) = 228, - B11100101 DEPRECATED(0b11100101) = 229, - B11100110 DEPRECATED(0b11100110) = 230, - B11100111 DEPRECATED(0b11100111) = 231, - B11101000 DEPRECATED(0b11101000) = 232, - B11101001 DEPRECATED(0b11101001) = 233, - B11101010 DEPRECATED(0b11101010) = 234, - B11101011 DEPRECATED(0b11101011) = 235, - B11101100 DEPRECATED(0b11101100) = 236, - B11101101 DEPRECATED(0b11101101) = 237, - B11101110 DEPRECATED(0b11101110) = 238, - B11101111 DEPRECATED(0b11101111) = 239, - B11110000 DEPRECATED(0b11110000) = 240, - B11110001 DEPRECATED(0b11110001) = 241, - B11110010 DEPRECATED(0b11110010) = 242, - B11110011 DEPRECATED(0b11110011) = 243, - B11110100 DEPRECATED(0b11110100) = 244, - B11110101 DEPRECATED(0b11110101) = 245, - B11110110 DEPRECATED(0b11110110) = 246, - B11110111 DEPRECATED(0b11110111) = 247, - B11111000 DEPRECATED(0b11111000) = 248, - B11111001 DEPRECATED(0b11111001) = 249, - B11111010 DEPRECATED(0b11111010) = 250, - B11111011 DEPRECATED(0b11111011) = 251, - B11111100 DEPRECATED(0b11111100) = 252, - B11111101 DEPRECATED(0b11111101) = 253, - B11111110 DEPRECATED(0b11111110) = 254, - B11111111 DEPRECATED(0b11111111) = 255 -}; - -#undef DEPRECATED - -#endif diff --git a/ArduinoCore-API/api/CanMsg.cpp b/ArduinoCore-API/api/CanMsg.cpp deleted file mode 100644 index f4f93ce..0000000 --- a/ArduinoCore-API/api/CanMsg.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - CanMsg.cpp - Library for CAN message handling - Copyright (c) 2023 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include "CanMsg.h" - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -namespace arduino -{ - -/************************************************************************************** - * STATIC CONST DEFINITION - **************************************************************************************/ - -uint8_t const CanMsg::MAX_DATA_LENGTH; -uint32_t const CanMsg::CAN_EFF_FLAG; -uint32_t const CanMsg::CAN_SFF_MASK; -uint32_t const CanMsg::CAN_EFF_MASK; - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -} /* arduino */ diff --git a/ArduinoCore-API/api/CanMsg.h b/ArduinoCore-API/api/CanMsg.h deleted file mode 100644 index a8e32e5..0000000 --- a/ArduinoCore-API/api/CanMsg.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - CanMsg.h - Library for CAN message handling - Copyright (c) 2023 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef ARDUINOCORE_API_CAN_MSG_H_ -#define ARDUINOCORE_API_CAN_MSG_H_ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include "Print.h" -#include "Printable.h" -#include "Common.h" - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -namespace arduino -{ - -/************************************************************************************** - * CLASS DECLARATION - **************************************************************************************/ - -class CanMsg : public Printable -{ -public: - static uint8_t constexpr MAX_DATA_LENGTH = 8; - - static uint32_t constexpr CAN_EFF_FLAG = 0x80000000U; - static uint32_t constexpr CAN_SFF_MASK = 0x000007FFU; /* standard frame format (SFF) */ - static uint32_t constexpr CAN_EFF_MASK = 0x1FFFFFFFU; /* extended frame format (EFF) */ - - - CanMsg(uint32_t const can_id, uint8_t const can_data_len, uint8_t const * can_data_ptr) - : id{can_id} - , data_length{min(can_data_len, MAX_DATA_LENGTH)} - , data{0} - { - if (data_length && can_data_ptr) - memcpy(data, can_data_ptr, data_length); - } - - CanMsg() : CanMsg(0, 0, nullptr) { } - - CanMsg(CanMsg const & other) - { - id = other.id; - data_length = other.data_length; - if (data_length > 0) - memcpy(data, other.data, data_length); - } - - virtual ~CanMsg() { } - - CanMsg & operator = (CanMsg const & other) - { - if (this != &other) - { - id = other.id; - data_length = other.data_length; - if (data_length > 0) - memcpy(data, other.data, data_length); - } - return (*this); - } - - virtual size_t printTo(Print & p) const override - { - char buf[20] = {0}; - size_t len = 0; - - /* Print the header. */ - if (isStandardId()) - len = snprintf(buf, sizeof(buf), "[%03" PRIX32 "] (%d) : ", getStandardId(), data_length); - else - len = snprintf(buf, sizeof(buf), "[%08" PRIX32 "] (%d) : ", getExtendedId(), data_length); - size_t n = p.write(buf, len); - - /* Print the data. */ - for (size_t d = 0; d < data_length; d++) - { - len = snprintf(buf, sizeof(buf), "%02X", data[d]); - n += p.write(buf, len); - } - - /* Wrap up. */ - return n; - } - - - uint32_t getStandardId() const { - return (id & CAN_SFF_MASK); - } - uint32_t getExtendedId() const { - return (id & CAN_EFF_MASK); - } - bool isStandardId() const { - return ((id & CAN_EFF_FLAG) == 0); - } - bool isExtendedId() const { - return ((id & CAN_EFF_FLAG) == CAN_EFF_FLAG); - } - - - /* - * CAN ID semantics (mirroring definition by linux/can.h): - * |- Bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit) - * |- Bit 30 : reserved (future remote transmission request flag) - * |- Bit 29 : reserved (future error frame flag) - * |- Bit 0-28 : CAN identifier (11/29 bit) - */ - uint32_t id; - uint8_t data_length; - uint8_t data[MAX_DATA_LENGTH]; -}; - -/************************************************************************************** - * FREE FUNCTIONS - **************************************************************************************/ - -inline uint32_t CanStandardId(uint32_t const id) { - return (id & CanMsg::CAN_SFF_MASK); -} - -inline uint32_t CanExtendedId(uint32_t const id) { - return (CanMsg::CAN_EFF_FLAG | (id & CanMsg::CAN_EFF_MASK)); -} - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -} /* arduino */ - -#endif /* ARDUINOCORE_API_CAN_MSG_H_ */ diff --git a/ArduinoCore-API/api/CanMsgRingbuffer.cpp b/ArduinoCore-API/api/CanMsgRingbuffer.cpp deleted file mode 100644 index 56abbac..0000000 --- a/ArduinoCore-API/api/CanMsgRingbuffer.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - CanMsgRingbuffer.cpp - Library for CAN message handling - Copyright (c) 2023 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include "CanMsgRingbuffer.h" - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -namespace arduino -{ - -/************************************************************************************** - * CTOR/DTOR - **************************************************************************************/ - -CanMsgRingbuffer::CanMsgRingbuffer() -: _head{0} -, _tail{0} -, _num_elems{0} -{ -} - -/************************************************************************************** - * PUBLIC MEMBER FUNCTIONS - **************************************************************************************/ - -void CanMsgRingbuffer::enqueue(CanMsg const & msg) -{ - if (isFull()) - return; - - _buf[_head] = msg; - _head = next(_head); - _num_elems = _num_elems + 1; -} - -CanMsg CanMsgRingbuffer::dequeue() -{ - if (isEmpty()) - return CanMsg(); - - CanMsg const msg = _buf[_tail]; - _tail = next(_tail); - _num_elems = _num_elems - 1; - - return msg; -} - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -} /* arduino */ diff --git a/ArduinoCore-API/api/CanMsgRingbuffer.h b/ArduinoCore-API/api/CanMsgRingbuffer.h deleted file mode 100644 index 9eb6baf..0000000 --- a/ArduinoCore-API/api/CanMsgRingbuffer.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - CanMsgRingbuffer.h - Library for CAN message handling - Copyright (c) 2023 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef ARDUINOCORE_API_CAN_MSG_RING_BUFFER_H_ -#define ARDUINOCORE_API_CAN_MSG_RING_BUFFER_H_ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include "CanMsg.h" - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -namespace arduino -{ - -/************************************************************************************** - * CLASS DECLARATION - **************************************************************************************/ - -class CanMsgRingbuffer -{ -public: - static size_t constexpr RING_BUFFER_SIZE = 32U; - - CanMsgRingbuffer(); - - inline bool isFull() const { return (_num_elems == RING_BUFFER_SIZE); } - void enqueue(CanMsg const & msg); - - inline bool isEmpty() const { return (_num_elems == 0); } - CanMsg dequeue(); - - inline size_t available() const { return _num_elems; } - -private: - CanMsg _buf[RING_BUFFER_SIZE]; - volatile size_t _head; - volatile size_t _tail; - volatile size_t _num_elems; - - inline size_t next(size_t const idx) const { return ((idx + 1) % RING_BUFFER_SIZE); } -}; - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -} /* arduino */ - -#endif /* ARDUINOCORE_API_CAN_MSG_RING_BUFFER_H_ */ diff --git a/ArduinoCore-API/api/Client.h b/ArduinoCore-API/api/Client.h deleted file mode 100644 index 5a1d99f..0000000 --- a/ArduinoCore-API/api/Client.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - Client.h - Base class that provides Client - Copyright (c) 2011 Adrian McEwen. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -#include "Stream.h" -#include "IPAddress.h" - -namespace arduino { - -class Client : public Stream { - -public: - virtual int connect(IPAddress ip, uint16_t port) =0; - virtual int connect(const char *host, uint16_t port) =0; - virtual size_t write(uint8_t) =0; - virtual size_t write(const uint8_t *buf, size_t size) =0; - virtual int available() = 0; - virtual int read() = 0; - virtual int read(uint8_t *buf, size_t size) = 0; - virtual int peek() = 0; - virtual void flush() = 0; - virtual void stop() = 0; - virtual uint8_t connected() = 0; - virtual operator bool() = 0; -protected: - uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; -}; - -} \ No newline at end of file diff --git a/ArduinoCore-API/api/Common.cpp b/ArduinoCore-API/api/Common.cpp deleted file mode 100644 index 8299247..0000000 --- a/ArduinoCore-API/api/Common.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - Common.cpp - Common function implementations - Copyright (c) 2017 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "Common.h" - -/* C++ prototypes */ -long map(long x, long in_min, long in_max, long out_min, long out_max) -{ - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; -} - -uint16_t makeWord(uint16_t w) { return w; } -uint16_t makeWord(uint8_t h, uint8_t l) { return (h << 8) | l; } \ No newline at end of file diff --git a/ArduinoCore-API/api/Common.h b/ArduinoCore-API/api/Common.h deleted file mode 100644 index 9b28f40..0000000 --- a/ArduinoCore-API/api/Common.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - Common.h - Common definitions for Arduino core - Copyright (c) 2017 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once -#include -#include - -#ifdef __cplusplus -extern "C"{ -#endif - -void yield(void); - -typedef enum { - LOW = 0, - HIGH = 1, - CHANGE = 2, - FALLING = 3, - RISING = 4, -} PinStatus; - -typedef enum { - INPUT = 0x0, - OUTPUT = 0x1, - INPUT_PULLUP = 0x2, - INPUT_PULLDOWN = 0x3, - OUTPUT_OPENDRAIN = 0x4, -} PinMode; - -typedef enum { - LSBFIRST = 0, - MSBFIRST = 1, -} BitOrder; - -#define PI 3.1415926535897932384626433832795 -#define HALF_PI 1.5707963267948966192313216916398 -#define TWO_PI 6.283185307179586476925286766559 -#define DEG_TO_RAD 0.017453292519943295769236907684886 -#define RAD_TO_DEG 57.295779513082320876798154814105 -#define EULER 2.718281828459045235360287471352 - -#define SERIAL 0x0 -#define DISPLAY 0x1 - -#ifndef constrain -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) -#endif - -#ifndef radians -#define radians(deg) ((deg)*DEG_TO_RAD) -#endif - -#ifndef degrees -#define degrees(rad) ((rad)*RAD_TO_DEG) -#endif - -#ifndef sq -#define sq(x) ((x)*(x)) -#endif - -typedef void (*voidFuncPtr)(void); -typedef void (*voidFuncPtrParam)(void*); - -// interrupts() / noInterrupts() must be defined by the core - -#define lowByte(w) ((uint8_t) ((w) & 0xff)) -#define highByte(w) ((uint8_t) ((w) >> 8)) - -#define bitRead(value, bit) (((value) >> (bit)) & 0x01) -#define bitSet(value, bit) ((value) |= (1UL << (bit))) -#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) -#define bitToggle(value, bit) ((value) ^= (1UL << (bit))) -#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet((value), (bit)) : bitClear((value), (bit))) - -#ifndef bit -#define bit(b) (1UL << (b)) -#endif - -/* TODO: request for removal */ -typedef bool boolean; -typedef uint8_t byte; -typedef uint16_t word; - -void init(void); -void initVariant(void); - -#ifndef HOST -int atexit(void (*func)()) __attribute__((weak)); -#endif -int main() __attribute__((weak)); - -#ifdef EXTENDED_PIN_MODE -// Platforms who want to declare more than 256 pins need to define EXTENDED_PIN_MODE globally -typedef uint32_t pin_size_t; -#else -typedef uint8_t pin_size_t; -#endif - -void pinMode(pin_size_t pinNumber, PinMode pinMode); -void digitalWrite(pin_size_t pinNumber, PinStatus status); -PinStatus digitalRead(pin_size_t pinNumber); -int analogRead(pin_size_t pinNumber); -void analogReference(uint8_t mode); -void analogWrite(pin_size_t pinNumber, int value); - -unsigned long millis(void); -unsigned long micros(void); -void delay(unsigned long); -void delayMicroseconds(unsigned int us); -unsigned long pulseIn(pin_size_t pin, uint8_t state, unsigned long timeout); -unsigned long pulseInLong(pin_size_t pin, uint8_t state, unsigned long timeout); - -void shiftOut(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder, uint8_t val); -uint8_t shiftIn(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder); - -void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode); -void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void* param); -void detachInterrupt(pin_size_t interruptNumber); - -void setup(void); -void loop(void); - -#ifdef __cplusplus -} // extern "C" -#endif - -#ifdef __cplusplus - template - auto min(const T& a, const L& b) -> decltype((b < a) ? b : a) - { - return (b < a) ? b : a; - } - - template - auto max(const T& a, const L& b) -> decltype((b < a) ? b : a) - { - return (a < b) ? b : a; - } -#else -#ifndef min -#define min(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a < _b ? _a : _b; }) -#endif -#ifndef max -#define max(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a > _b ? _a : _b; }) -#endif -#endif - -#ifdef __cplusplus - -/* C++ prototypes */ -uint16_t makeWord(uint16_t w); -uint16_t makeWord(byte h, byte l); - -#define word(...) makeWord(__VA_ARGS__) - -unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); -unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); - -void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); -void noTone(uint8_t _pin); - -// WMath prototypes -long random(long); -long random(long, long); -void randomSeed(unsigned long); -long map(long, long, long, long, long); - -#endif // __cplusplus diff --git a/ArduinoCore-API/api/Compat.h b/ArduinoCore-API/api/Compat.h deleted file mode 100644 index 564170c..0000000 --- a/ArduinoCore-API/api/Compat.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - Compat.h - Compatibility layer for Arduino API - Copyright (c) 2018 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef __COMPAT_H__ -#define __COMPAT_H__ - -namespace arduino { - -inline void pinMode(pin_size_t pinNumber, int mode) { - pinMode(pinNumber, (PinMode)mode); -}; - -inline void digitalWrite(pin_size_t pinNumber, int status) { - digitalWrite(pinNumber, (PinStatus)status); -}; - -} - -#endif \ No newline at end of file diff --git a/ArduinoCore-API/api/DMAPool.h b/ArduinoCore-API/api/DMAPool.h deleted file mode 100644 index 815f5d3..0000000 --- a/ArduinoCore-API/api/DMAPool.h +++ /dev/null @@ -1,316 +0,0 @@ -/* - This file is part of the Arduino_AdvancedAnalog library. - Copyright (c) 2023-2024 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef __DMA_POOL_H__ -#define __DMA_POOL_H__ - -#include -#include - -namespace arduino { - -#if defined(__DCACHE_PRESENT) -#define __CACHE_LINE_SIZE__ __SCB_DCACHE_LINE_SIZE -#elif defined(__cpp_lib_hardware_interference_size) -#define __CACHE_LINE_SIZE__ std::hardware_constructive_interference_size -#else // No cache. -#define __CACHE_LINE_SIZE__ alignof(int) -#endif - -// Single-producer, single-consumer, lock-free bounded Queue. -template class SPSCQueue { - private: - size_t capacity; - std::atomic head; - std::atomic tail; - std::unique_ptr buff; - - public: - SPSCQueue(size_t size=0): - capacity(0), tail(0), head(0), buff(nullptr) { - if (size) { - T *mem = new T[size + 1]; - if (mem) { - buff.reset(mem); - capacity = size + 1; - } - } - } - - void reset() { - tail = head = 0; - } - - size_t empty() { - return tail == head; - } - - operator bool() const { - return buff.get() != nullptr; - } - - bool push(T data) { - size_t curr = head.load(std::memory_order_relaxed); - size_t next = (curr + 1) % capacity; - if (!buff || (next == tail.load(std::memory_order_acquire))) { - return false; - } - buff[curr] = data; - head.store(next, std::memory_order_release); - return true; - } - - T pop(bool peek=false) { - size_t curr = tail.load(std::memory_order_relaxed); - if (!buff || (curr == head.load(std::memory_order_acquire))) { - return nullptr; - } - T data = buff[curr]; - if (!peek) { - size_t next = (curr + 1) % capacity; - tail.store(next, std::memory_order_release); - } - return data; - } -}; - -enum { - DMA_BUFFER_READ = (1 << 0), - DMA_BUFFER_WRITE = (1 << 1), - DMA_BUFFER_DISCONT = (1 << 2), - DMA_BUFFER_INTRLVD = (1 << 3), -} DMABufferFlags; - -// Forward declaration of DMAPool class. -template class DMAPool; - -template class DMABuffer { - private: - DMAPool *pool; - size_t n_samples; - size_t n_channels; - T *ptr; - uint32_t ts; - uint32_t flags; - - public: - DMABuffer(DMAPool *pool=nullptr, size_t samples=0, size_t channels=0, T *mem=nullptr): - pool(pool), n_samples(samples), n_channels(channels), ptr(mem), ts(0), flags(0) { - } - - T *data() { - return ptr; - } - - size_t size() { - return n_samples * n_channels; - } - - size_t bytes() { - return n_samples * n_channels * sizeof(T); - } - - void flush() { - #if __DCACHE_PRESENT - if (ptr) { - SCB_CleanDCache_by_Addr(data(), bytes()); - } - #endif - } - - void invalidate() { - #if __DCACHE_PRESENT - if (ptr) { - SCB_InvalidateDCache_by_Addr(data(), bytes()); - } - #endif - } - - uint32_t timestamp() { - return ts; - } - - void timestamp(uint32_t ts) { - this->ts = ts; - } - - uint32_t channels() { - return n_channels; - } - - void release() { - if (pool && ptr) { - pool->free(this, flags); - } - } - - void set_flags(uint32_t f) { - flags |= f; - } - - bool get_flags(uint32_t f=0xFFFFFFFFU) { - return flags & f; - } - - void clr_flags(uint32_t f=0xFFFFFFFFU) { - flags &= (~f); - } - - T& operator[](size_t i) { - assert(ptr && i < size()); - return ptr[i]; - } - - const T& operator[](size_t i) const { - assert(ptr && i < size()); - return ptr[i]; - } - - operator bool() const { - return (ptr != nullptr); - } -}; - -template class DMAPool { - private: - uint8_t *mem; - bool managed; - SPSCQueue*> wqueue; - SPSCQueue*> rqueue; - - // Allocates dynamic aligned memory. - // Note this memory must be free'd with aligned_free. - static void *aligned_malloc(size_t size) { - void **ptr, *stashed; - size_t offset = A - 1 + sizeof(void *); - if ((A % 2) || !((stashed = ::malloc(size + offset)))) { - return nullptr; - } - ptr = (void **) (((uintptr_t) stashed + offset) & ~(A - 1)); - ptr[-1] = stashed; - return ptr; - } - - // Frees dynamic aligned memory allocated with aligned_malloc. - static void aligned_free(void *ptr) { - if (ptr != nullptr) { - ::free(((void **) ptr)[-1]); - } - } - - public: - DMAPool(size_t n_samples, size_t n_channels, size_t n_buffers, void *mem_in=nullptr): - mem((uint8_t *) mem_in), managed(mem_in==nullptr), wqueue(n_buffers), rqueue(n_buffers) { - // Round up to the next multiple of the alignment. - size_t bufsize = (((n_samples * n_channels * sizeof(T)) + (A-1)) & ~(A-1)); - if (bufsize && rqueue && wqueue) { - if (mem == nullptr) { - // Allocate an aligned memory block for the DMA buffers' memory. - mem = (uint8_t *) aligned_malloc(n_buffers * bufsize); - if (!mem) { - // Failed to allocate memory. - return; - } - } - // Allocate the DMA buffers, initialize them using aligned - // pointers from the pool, and add them to the write queue. - for (size_t i=0; i *buf = new DMABuffer( - this, n_samples, n_channels, (T *) &mem[i * bufsize] - ); - if (buf == nullptr) { - break; - } - wqueue.push(buf); - } - } - } - - ~DMAPool() { - while (readable()) { - delete alloc(DMA_BUFFER_READ); - } - - while (writable()) { - delete alloc(DMA_BUFFER_WRITE); - } - - if (mem && managed) { - aligned_free(mem); - } - } - - bool writable() { - return !(wqueue.empty()); - } - - bool readable() { - return !(rqueue.empty()); - } - - void flush() { - while (readable()) { - DMABuffer *buf = alloc(DMA_BUFFER_READ); - if (buf) { - buf->release(); - } - } - } - - DMABuffer *alloc(uint32_t flags) { - DMABuffer *buf = nullptr; - if (flags & DMA_BUFFER_READ) { - // Get a DMA buffer from the read/ready queue. - buf = rqueue.pop(); - } else { - // Get a DMA buffer from the write/free queue. - buf = wqueue.pop(); - } - if (buf) { - buf->clr_flags(DMA_BUFFER_READ | DMA_BUFFER_WRITE); - buf->set_flags(flags); - } - return buf; - } - - void free(DMABuffer *buf, uint32_t flags=0) { - if (buf == nullptr) { - return; - } - if (flags == 0) { - flags = buf->get_flags(); - } - if (flags & DMA_BUFFER_READ) { - // Return the DMA buffer to the write/free queue. - buf->clr_flags(); - wqueue.push(buf); - } else { - // Return the DMA buffer to the read/ready queue. - rqueue.push(buf); - } - } - -}; - -} // namespace arduino - -using arduino::DMAPool; -using arduino::DMABuffer; -using arduino::SPSCQueue; -#endif //__DMA_POOL_H__ diff --git a/ArduinoCore-API/api/HardwareCAN.h b/ArduinoCore-API/api/HardwareCAN.h deleted file mode 100644 index 57d9d58..0000000 --- a/ArduinoCore-API/api/HardwareCAN.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - HardwareCAN.h - CAN bus interface for Arduino core - Copyright (c) 2023 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef ARDUINOCORE_API_HARDWARECAN_H -#define ARDUINOCORE_API_HARDWARECAN_H - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include "CanMsg.h" -#include "CanMsgRingbuffer.h" - -/************************************************************************************** - * TYPEDEF - **************************************************************************************/ - -enum class CanBitRate : int -{ - BR_125k = 125000, - BR_250k = 250000, - BR_500k = 500000, - BR_1000k = 1000000, -}; - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -namespace arduino -{ - -/************************************************************************************** - * CLASS DECLARATION - **************************************************************************************/ - -class HardwareCAN -{ -public: - virtual ~HardwareCAN() {} - - - /** - * Initialize the CAN controller. - * - * @param can_bitrate the bus bit rate - * @return true if initialization succeeded and the controller is operational - */ - virtual bool begin(CanBitRate const can_bitrate) = 0; - - /** - * Disable the CAN controller. - * - * Whether any messages that are buffered will be sent is _implementation defined_. - */ - virtual void end() = 0; - - /** - * Enqueue a message for transmission to the CAN bus. - * - * This call returns when the message has been enqueued for transmission. - * Due to bus arbitration and error recovery there may be a substantial delay - * before the message is actually sent. - * - * An implementation must ensure that all messages with the same CAN priority - * are sent in the order in which they are enqueued. - * - * It is _implementation defined_ whether multiple messages can be enqueued - * for transmission, and if messages with higher CAN priority can preempt the - * transmission of previously enqueued messages. The default configuration for - * and implementation should not allow multiple messages to be enqueued. - * - * @param msg the message to send - * @return 1 if the message was enqueued, an _implementation defined_ error code < 0 if there was an error - * @todo define specific error codes, especially "message already pending" - */ - virtual int write(CanMsg const &msg) = 0; - - /** - * Determine if any messages have been received and buffered. - * - * @return the number of unread messages that have been received - */ - virtual size_t available() = 0; - - /** - * Returns the first message received, or an empty message if none are available. - * - * Messages must be returned in the order received. - * - * @return the first message in the receive buffer - */ - virtual CanMsg read() = 0; -}; - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -} /* arduino */ - -#endif /* ARDUINOCORE_API_HARDWARECAN_H */ diff --git a/ArduinoCore-API/api/HardwareI2C.h b/ArduinoCore-API/api/HardwareI2C.h deleted file mode 100644 index 98c6bfd..0000000 --- a/ArduinoCore-API/api/HardwareI2C.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - HardwareI2C.h - Hardware I2C interface for Arduino - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -#include -#include "Stream.h" - -namespace arduino { - -class HardwareI2C : public Stream -{ - public: - virtual void begin() = 0; - virtual void begin(uint8_t address) = 0; - virtual void end() = 0; - - virtual void setClock(uint32_t freq) = 0; - - virtual void beginTransmission(uint8_t address) = 0; - virtual uint8_t endTransmission(bool stopBit) = 0; - virtual uint8_t endTransmission(void) = 0; - - virtual size_t requestFrom(uint8_t address, size_t len, bool stopBit) = 0; - virtual size_t requestFrom(uint8_t address, size_t len) = 0; - - virtual void onReceive(void(*)(int)) = 0; - virtual void onRequest(void(*)(void)) = 0; -}; - -} - diff --git a/ArduinoCore-API/api/HardwareSPI.h b/ArduinoCore-API/api/HardwareSPI.h deleted file mode 100644 index 6be2b92..0000000 --- a/ArduinoCore-API/api/HardwareSPI.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - HardwareSPI.h - Hardware SPI interface for Arduino - Copyright (c) 2018 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -#include "Common.h" -#include -#include "Stream.h" - -#define SPI_HAS_TRANSACTION - -namespace arduino { - -typedef enum { - SPI_MODE0 = 0, - SPI_MODE1 = 1, - SPI_MODE2 = 2, - SPI_MODE3 = 3, -} SPIMode; - -// Platforms should define SPI_HAS_PERIPHERAL_MODE if SPI peripheral -// mode is supported, to allow applications to check whether peripheral -// mode is available or not. -typedef enum { - SPI_CONTROLLER = 0, - SPI_PERIPHERAL = 1, -} SPIBusMode; - - -class SPISettings { - public: - SPISettings(uint32_t clock, BitOrder bitOrder, SPIMode dataMode, SPIBusMode busMode = SPI_CONTROLLER) { - if (__builtin_constant_p(clock)) { - init_AlwaysInline(clock, bitOrder, dataMode, busMode); - } else { - init_MightInline(clock, bitOrder, dataMode, busMode); - } - } - - SPISettings(uint32_t clock, BitOrder bitOrder, int dataMode, SPIBusMode busMode = SPI_CONTROLLER) { - if (__builtin_constant_p(clock)) { - init_AlwaysInline(clock, bitOrder, (SPIMode)dataMode, busMode); - } else { - init_MightInline(clock, bitOrder, (SPIMode)dataMode, busMode); - } - } - - // Default speed set to 4MHz, SPI mode set to MODE 0 and Bit order set to MSB first. - SPISettings() { init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0, SPI_CONTROLLER); } - - bool operator==(const SPISettings& rhs) const - { - if ((this->clockFreq == rhs.clockFreq) && - (this->bitOrder == rhs.bitOrder) && - (this->dataMode == rhs.dataMode) && - (this->busMode == rhs.busMode)) { - return true; - } - return false; - } - - bool operator!=(const SPISettings& rhs) const - { - return !(*this == rhs); - } - - uint32_t getClockFreq() const { - return clockFreq; - } - SPIMode getDataMode() const { - return dataMode; - } - BitOrder getBitOrder() const { - return (bitOrder); - } - SPIBusMode getBusMode() const { - return busMode; - } - - private: - void init_MightInline(uint32_t clock, BitOrder bitOrder, SPIMode dataMode, SPIBusMode busMode) { - init_AlwaysInline(clock, bitOrder, dataMode, busMode); - } - - // Core developer MUST use an helper function in beginTransaction() to use this data - void init_AlwaysInline(uint32_t clock, BitOrder bitOrder, SPIMode dataMode, SPIBusMode busMode) __attribute__((__always_inline__)) { - this->clockFreq = clock; - this->dataMode = dataMode; - this->bitOrder = bitOrder; - this->busMode = busMode; - } - - uint32_t clockFreq; - SPIMode dataMode; - BitOrder bitOrder; - SPIBusMode busMode; - - friend class HardwareSPI; -}; - -const SPISettings DEFAULT_SPI_SETTINGS = SPISettings(); - -class HardwareSPI -{ - public: - virtual ~HardwareSPI() { } - - virtual uint8_t transfer(uint8_t data) = 0; - virtual uint16_t transfer16(uint16_t data) = 0; - virtual void transfer(void *buf, size_t count) = 0; - - // Transaction Functions - virtual void usingInterrupt(int interruptNumber) = 0; - virtual void notUsingInterrupt(int interruptNumber) = 0; - virtual void beginTransaction(SPISettings settings) = 0; - virtual void endTransaction(void) = 0; - - // SPI Configuration methods - virtual void attachInterrupt() = 0; - virtual void detachInterrupt() = 0; - - virtual void begin() = 0; - virtual void end() = 0; -}; - -// Alias SPIClass to HardwareSPI since it's already the defacto standard for SPI class name -typedef HardwareSPI SPIClass; - -} diff --git a/ArduinoCore-API/api/HardwareSerial.h b/ArduinoCore-API/api/HardwareSerial.h deleted file mode 100644 index b687cdf..0000000 --- a/ArduinoCore-API/api/HardwareSerial.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - HardwareSerial.h - Hardware serial interface for Arduino - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -#include -#include "Stream.h" - -namespace arduino { - -// XXX: Those constants should be defined as const int / enums? -// XXX: shall we use namespaces too? -#define SERIAL_PARITY_EVEN (0x1ul) -#define SERIAL_PARITY_ODD (0x2ul) -#define SERIAL_PARITY_NONE (0x3ul) -#define SERIAL_PARITY_MARK (0x4ul) -#define SERIAL_PARITY_SPACE (0x5ul) -#define SERIAL_PARITY_MASK (0xFul) - -#define SERIAL_STOP_BIT_1 (0x10ul) -#define SERIAL_STOP_BIT_1_5 (0x20ul) -#define SERIAL_STOP_BIT_2 (0x30ul) -#define SERIAL_STOP_BIT_MASK (0xF0ul) - -#define SERIAL_DATA_5 (0x100ul) -#define SERIAL_DATA_6 (0x200ul) -#define SERIAL_DATA_7 (0x300ul) -#define SERIAL_DATA_8 (0x400ul) -#define SERIAL_DATA_MASK (0xF00ul) - -#define SERIAL_5N1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_NONE | SERIAL_DATA_5) -#define SERIAL_6N1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_NONE | SERIAL_DATA_6) -#define SERIAL_7N1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_NONE | SERIAL_DATA_7) -#define SERIAL_8N1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_NONE | SERIAL_DATA_8) -#define SERIAL_5N2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_NONE | SERIAL_DATA_5) -#define SERIAL_6N2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_NONE | SERIAL_DATA_6) -#define SERIAL_7N2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_NONE | SERIAL_DATA_7) -#define SERIAL_8N2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_NONE | SERIAL_DATA_8) -#define SERIAL_5E1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_EVEN | SERIAL_DATA_5) -#define SERIAL_6E1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_EVEN | SERIAL_DATA_6) -#define SERIAL_7E1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_EVEN | SERIAL_DATA_7) -#define SERIAL_8E1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_EVEN | SERIAL_DATA_8) -#define SERIAL_5E2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_EVEN | SERIAL_DATA_5) -#define SERIAL_6E2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_EVEN | SERIAL_DATA_6) -#define SERIAL_7E2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_EVEN | SERIAL_DATA_7) -#define SERIAL_8E2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_EVEN | SERIAL_DATA_8) -#define SERIAL_5O1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_ODD | SERIAL_DATA_5) -#define SERIAL_6O1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_ODD | SERIAL_DATA_6) -#define SERIAL_7O1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_ODD | SERIAL_DATA_7) -#define SERIAL_8O1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_ODD | SERIAL_DATA_8) -#define SERIAL_5O2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_ODD | SERIAL_DATA_5) -#define SERIAL_6O2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_ODD | SERIAL_DATA_6) -#define SERIAL_7O2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_ODD | SERIAL_DATA_7) -#define SERIAL_8O2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_ODD | SERIAL_DATA_8) -#define SERIAL_5M1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_MARK | SERIAL_DATA_5) -#define SERIAL_6M1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_MARK | SERIAL_DATA_6) -#define SERIAL_7M1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_MARK | SERIAL_DATA_7) -#define SERIAL_8M1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_MARK | SERIAL_DATA_8) -#define SERIAL_5M2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_MARK | SERIAL_DATA_5) -#define SERIAL_6M2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_MARK | SERIAL_DATA_6) -#define SERIAL_7M2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_MARK | SERIAL_DATA_7) -#define SERIAL_8M2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_MARK | SERIAL_DATA_8) -#define SERIAL_5S1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_SPACE | SERIAL_DATA_5) -#define SERIAL_6S1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_SPACE | SERIAL_DATA_6) -#define SERIAL_7S1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_SPACE | SERIAL_DATA_7) -#define SERIAL_8S1 (SERIAL_STOP_BIT_1 | SERIAL_PARITY_SPACE | SERIAL_DATA_8) -#define SERIAL_5S2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_SPACE | SERIAL_DATA_5) -#define SERIAL_6S2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_SPACE | SERIAL_DATA_6) -#define SERIAL_7S2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_SPACE | SERIAL_DATA_7) -#define SERIAL_8S2 (SERIAL_STOP_BIT_2 | SERIAL_PARITY_SPACE | SERIAL_DATA_8) - -class HardwareSerial : public Stream -{ - public: - virtual void begin(unsigned long) = 0; - virtual void begin(unsigned long baudrate, uint16_t config) = 0; - virtual void end() = 0; - virtual int available(void) = 0; - virtual int peek(void) = 0; - virtual int read(void) = 0; - virtual void flush(void) = 0; - virtual size_t write(uint8_t) = 0; - using Print::write; // pull in write(str) and write(buf, size) from Print - virtual operator bool() = 0; -}; - -// XXX: Are we keeping the serialEvent API? -extern void serialEventRun(void) __attribute__((weak)); - -} \ No newline at end of file diff --git a/ArduinoCore-API/api/IPAddress.cpp b/ArduinoCore-API/api/IPAddress.cpp deleted file mode 100644 index 05b41bc..0000000 --- a/ArduinoCore-API/api/IPAddress.cpp +++ /dev/null @@ -1,368 +0,0 @@ -/* - IPAddress.cpp - Base class that provides IPAddress - Copyright (c) 2011 Adrian McEwen. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "IPAddress.h" -#include "Print.h" - -using namespace arduino; - -IPAddress::IPAddress() : IPAddress(IPv4) {} - -IPAddress::IPAddress(IPType ip_type) -{ - _type = ip_type; - memset(_address.bytes, 0, sizeof(_address.bytes)); -} - -IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet) -{ - _type = IPv4; - memset(_address.bytes, 0, sizeof(_address.bytes)); - _address.bytes[IPADDRESS_V4_BYTES_INDEX] = first_octet; - _address.bytes[IPADDRESS_V4_BYTES_INDEX + 1] = second_octet; - _address.bytes[IPADDRESS_V4_BYTES_INDEX + 2] = third_octet; - _address.bytes[IPADDRESS_V4_BYTES_INDEX + 3] = fourth_octet; -} - -IPAddress::IPAddress(uint8_t o1, uint8_t o2, uint8_t o3, uint8_t o4, uint8_t o5, uint8_t o6, uint8_t o7, uint8_t o8, uint8_t o9, uint8_t o10, uint8_t o11, uint8_t o12, uint8_t o13, uint8_t o14, uint8_t o15, uint8_t o16) { - _type = IPv6; - _address.bytes[0] = o1; - _address.bytes[1] = o2; - _address.bytes[2] = o3; - _address.bytes[3] = o4; - _address.bytes[4] = o5; - _address.bytes[5] = o6; - _address.bytes[6] = o7; - _address.bytes[7] = o8; - _address.bytes[8] = o9; - _address.bytes[9] = o10; - _address.bytes[10] = o11; - _address.bytes[11] = o12; - _address.bytes[12] = o13; - _address.bytes[13] = o14; - _address.bytes[14] = o15; - _address.bytes[15] = o16; -} - -IPAddress::IPAddress(uint32_t address) -{ - // IPv4 only - _type = IPv4; - memset(_address.bytes, 0, sizeof(_address.bytes)); - _address.dword[IPADDRESS_V4_DWORD_INDEX] = address; - - // NOTE on conversion/comparison and uint32_t: - // These conversions are host platform dependent. - // There is a defined integer representation of IPv4 addresses, - // based on network byte order (will be the value on big endian systems), - // e.g. http://2398766798 is the same as http://142.250.70.206, - // However on little endian systems the octets 0x83, 0xFA, 0x46, 0xCE, - // in that order, will form the integer (uint32_t) 3460758158 . -} - -IPAddress::IPAddress(const uint8_t *address) : IPAddress(IPv4, address) {} - -IPAddress::IPAddress(IPType ip_type, const uint8_t *address) -{ - _type = ip_type; - if (ip_type == IPv4) { - memset(_address.bytes, 0, sizeof(_address.bytes)); - memcpy(&_address.bytes[IPADDRESS_V4_BYTES_INDEX], address, sizeof(uint32_t)); - } else { - memcpy(_address.bytes, address, sizeof(_address.bytes)); - } -} - -IPAddress::IPAddress(const char *address) -{ - fromString(address); -} - -String IPAddress::toString4() const -{ - char szRet[16]; - snprintf(szRet, sizeof(szRet), "%u.%u.%u.%u", _address.bytes[IPADDRESS_V4_BYTES_INDEX], _address.bytes[IPADDRESS_V4_BYTES_INDEX + 1], _address.bytes[IPADDRESS_V4_BYTES_INDEX + 2], _address.bytes[IPADDRESS_V4_BYTES_INDEX + 3]); - return String(szRet); -} - -String IPAddress::toString6() const -{ - char szRet[40]; - snprintf(szRet, sizeof(szRet), "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", - _address.bytes[0], _address.bytes[1], _address.bytes[2], _address.bytes[3], - _address.bytes[4], _address.bytes[5], _address.bytes[6], _address.bytes[7], - _address.bytes[8], _address.bytes[9], _address.bytes[10], _address.bytes[11], - _address.bytes[12], _address.bytes[13], _address.bytes[14], _address.bytes[15]); - return String(szRet); -} - -String IPAddress::toString() const -{ - if (_type == IPv4) { - return toString4(); - } else { - return toString6(); - } -} - -bool IPAddress::fromString(const char *address) { - if (!fromString4(address)) { - return fromString6(address); - } - return true; -} - -bool IPAddress::fromString4(const char *address) -{ - // TODO: add support for "a", "a.b", "a.b.c" formats - - int16_t acc = -1; // Accumulator - uint8_t dots = 0; - - memset(_address.bytes, 0, sizeof(_address.bytes)); - while (*address) - { - char c = *address++; - if (c >= '0' && c <= '9') - { - acc = (acc < 0) ? (c - '0') : acc * 10 + (c - '0'); - if (acc > 255) { - // Value out of [0..255] range - return false; - } - } - else if (c == '.') - { - if (dots == 3) { - // Too many dots (there must be 3 dots) - return false; - } - if (acc < 0) { - /* No value between dots, e.g. '1..' */ - return false; - } - _address.bytes[IPADDRESS_V4_BYTES_INDEX + dots++] = acc; - acc = -1; - } - else - { - // Invalid char - return false; - } - } - - if (dots != 3) { - // Too few dots (there must be 3 dots) - return false; - } - if (acc < 0) { - /* No value between dots, e.g. '1..' */ - return false; - } - _address.bytes[IPADDRESS_V4_BYTES_INDEX + 3] = acc; - _type = IPv4; - return true; -} - -bool IPAddress::fromString6(const char *address) { - uint32_t acc = 0; // Accumulator - int colons = 0, double_colons = -1; - - while (*address) - { - char c = tolower(*address++); - if (isalnum(c) && c <= 'f') { - if (c >= 'a') - c -= 'a' - '0' - 10; - acc = acc * 16 + (c - '0'); - if (acc > 0xffff) - // Value out of range - return false; - } - else if (c == ':') { - if (*address == ':') { - if (double_colons >= 0) { - // :: allowed once - return false; - } - if (*address != '\0' && *(address + 1) == ':') { - // ::: not allowed - return false; - } - // remember location - double_colons = colons + !!acc; - address++; - } else if (*address == '\0') { - // can't end with a single colon - return false; - } - if (colons == 7) - // too many separators - return false; - _address.bytes[colons * 2] = acc >> 8; - _address.bytes[colons * 2 + 1] = acc & 0xff; - colons++; - acc = 0; - } - else - // Invalid char - return false; - } - - if (double_colons == -1 && colons != 7) { - // Too few separators - return false; - } - if (double_colons > -1 && colons > 6) { - // Too many segments (double colon must be at least one zero field) - return false; - } - _address.bytes[colons * 2] = acc >> 8; - _address.bytes[colons * 2 + 1] = acc & 0xff; - colons++; - - if (double_colons != -1) { - for (int i = colons * 2 - double_colons * 2 - 1; i >= 0; i--) - _address.bytes[16 - colons * 2 + double_colons * 2 + i] = _address.bytes[double_colons * 2 + i]; - for (int i = double_colons * 2; i < 16 - colons * 2 + double_colons * 2; i++) - _address.bytes[i] = 0; - } - - _type = IPv6; - return true; -} - -IPAddress& IPAddress::operator=(const uint8_t *address) -{ - // IPv4 only conversion from byte pointer - _type = IPv4; - memset(_address.bytes, 0, sizeof(_address.bytes)); - memcpy(&_address.bytes[IPADDRESS_V4_BYTES_INDEX], address, sizeof(uint32_t)); - return *this; -} - -IPAddress& IPAddress::operator=(const char *address) -{ - fromString(address); - return *this; -} - -IPAddress& IPAddress::operator=(uint32_t address) -{ - // IPv4 conversion - // See note on conversion/comparison and uint32_t - _type = IPv4; - memset(_address.bytes, 0, sizeof(_address.bytes)); - _address.dword[IPADDRESS_V4_DWORD_INDEX] = address; - return *this; -} - -bool IPAddress::operator==(const IPAddress& addr) const { - return (addr._type == _type) - && (memcmp(addr._address.bytes, _address.bytes, sizeof(_address.bytes)) == 0); -} - -bool IPAddress::operator==(const uint8_t* addr) const -{ - // IPv4 only comparison to byte pointer - // Can't support IPv6 as we know our type, but not the length of the pointer - return _type == IPv4 && memcmp(addr, &_address.bytes[IPADDRESS_V4_BYTES_INDEX], sizeof(uint32_t)) == 0; -} - -uint8_t IPAddress::operator[](int index) const { - if (_type == IPv4) { - return _address.bytes[IPADDRESS_V4_BYTES_INDEX + index]; - } - return _address.bytes[index]; -} - -uint8_t& IPAddress::operator[](int index) { - if (_type == IPv4) { - return _address.bytes[IPADDRESS_V4_BYTES_INDEX + index]; - } - return _address.bytes[index]; -} - -size_t IPAddress::printTo(Print& p) const -{ - size_t n = 0; - - if (_type == IPv6) { - // IPv6 IETF canonical format: compress left-most longest run of two or more zero fields, lower case - int8_t longest_start = -1; - int8_t longest_length = 1; - int8_t current_start = -1; - int8_t current_length = 0; - for (int8_t f = 0; f < 8; f++) { - if (_address.bytes[f * 2] == 0 && _address.bytes[f * 2 + 1] == 0) { - if (current_start == -1) { - current_start = f; - current_length = 1; - } else { - current_length++; - } - if (current_length > longest_length) { - longest_start = current_start; - longest_length = current_length; - } - } else { - current_start = -1; - } - } - for (int f = 0; f < 8; f++) { - if (f < longest_start || f >= longest_start + longest_length) { - uint8_t c1 = _address.bytes[f * 2] >> 4; - uint8_t c2 = _address.bytes[f * 2] & 0xf; - uint8_t c3 = _address.bytes[f * 2 + 1] >> 4; - uint8_t c4 = _address.bytes[f * 2 + 1] & 0xf; - if (c1 > 0) { - n += p.print((char)(c1 < 10 ? '0' + c1 : 'a' + c1 - 10)); - } - if (c1 > 0 || c2 > 0) { - n += p.print((char)(c2 < 10 ? '0' + c2 : 'a' + c2 - 10)); - } - if (c1 > 0 || c2 > 0 || c3 > 0) { - n += p.print((char)(c3 < 10 ? '0' + c3 : 'a' + c3 - 10)); - } - n += p.print((char)(c4 < 10 ? '0' + c4 : 'a' + c4 - 10)); - if (f < 7) { - n += p.print(':'); - } - } else if (f == longest_start) { - if (longest_start == 0) { - n += p.print(':'); - } - n += p.print(':'); - } - } - return n; - } - - // IPv4 - for (int i =0; i < 3; i++) - { - n += p.print(_address.bytes[IPADDRESS_V4_BYTES_INDEX + i], DEC); - n += p.print('.'); - } - n += p.print(_address.bytes[IPADDRESS_V4_BYTES_INDEX + 3], DEC); - return n; -} - -const IPAddress arduino::IN6ADDR_ANY(IPv6); -const IPAddress arduino::INADDR_NONE(0,0,0,0); diff --git a/ArduinoCore-API/api/IPAddress.h b/ArduinoCore-API/api/IPAddress.h deleted file mode 100644 index 31a2d06..0000000 --- a/ArduinoCore-API/api/IPAddress.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - IPAddress.h - Base class that provides IPAddress - Copyright (c) 2011 Adrian McEwen. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -#include -#include "Printable.h" -#include "String.h" - -#define IPADDRESS_V4_BYTES_INDEX 12 -#define IPADDRESS_V4_DWORD_INDEX 3 - -// forward declarations of global name space friend classes -class EthernetClass; -class DhcpClass; -class DNSClient; - -namespace arduino { - -// A class to make it easier to handle and pass around IP addresses - -enum IPType { - IPv4, - IPv6 -}; - -class IPAddress : public Printable { -private: - union { - uint8_t bytes[16]; - uint32_t dword[4]; - } _address; - IPType _type; - - // Access the raw byte array containing the address. Because this returns a pointer - // to the internal structure rather than a copy of the address this function should only - // be used when you know that the usage of the returned uint8_t* will be transient and not - // stored. - uint8_t* raw_address() { return _type == IPv4 ? &_address.bytes[IPADDRESS_V4_BYTES_INDEX] : _address.bytes; } - -public: - // Constructors - - // Default IPv4 - IPAddress(); - IPAddress(IPType ip_type); - IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet); - IPAddress(uint8_t o1, uint8_t o2, uint8_t o3, uint8_t o4, uint8_t o5, uint8_t o6, uint8_t o7, uint8_t o8, uint8_t o9, uint8_t o10, uint8_t o11, uint8_t o12, uint8_t o13, uint8_t o14, uint8_t o15, uint8_t o16); - // IPv4; see implementation note - IPAddress(uint32_t address); - // Default IPv4 - IPAddress(const uint8_t *address); - IPAddress(IPType ip_type, const uint8_t *address); - // If IPv4 fails tries IPv6 see fromString function - IPAddress(const char *address); - - bool fromString(const char *address); - bool fromString(const String &address) { return fromString(address.c_str()); } - - // Overloaded cast operator to allow IPAddress objects to be used where a uint32_t is expected - // NOTE: IPv4 only; see implementation note - operator uint32_t() const { return _type == IPv4 ? _address.dword[IPADDRESS_V4_DWORD_INDEX] : 0; }; - - bool operator==(const IPAddress& addr) const; - bool operator!=(const IPAddress& addr) const { return !(*this == addr); }; - - // NOTE: IPv4 only; we don't know the length of the pointer - bool operator==(const uint8_t* addr) const; - - // Overloaded index operator to allow getting and setting individual octets of the address - uint8_t operator[](int index) const; - uint8_t& operator[](int index); - - // Overloaded copy operators to allow initialisation of IPAddress objects from other types - // NOTE: IPv4 only - IPAddress& operator=(const uint8_t *address); - // NOTE: IPv4 only; see implementation note - IPAddress& operator=(uint32_t address); - // If IPv4 fails tries IPv6 see fromString function - IPAddress& operator=(const char *address); - - virtual size_t printTo(Print& p) const; - String toString() const; - - IPType type() const { return _type; } - - friend class UDP; - friend class Client; - friend class Server; - - friend ::EthernetClass; - friend ::DhcpClass; - friend ::DNSClient; - -protected: - bool fromString4(const char *address); - bool fromString6(const char *address); - String toString4() const; - String toString6() const; -}; - -extern const IPAddress IN6ADDR_ANY; -extern const IPAddress INADDR_NONE; -} - -using arduino::IPAddress; \ No newline at end of file diff --git a/ArduinoCore-API/api/Interrupts.h b/ArduinoCore-API/api/Interrupts.h deleted file mode 100644 index c3e37ad..0000000 --- a/ArduinoCore-API/api/Interrupts.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - Interrupts.h - Arduino interrupt management functions - Copyright (c) 2018 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef W_INTERRUPTS_CPP -#define W_INTERRUPTS_CPP -#ifdef __cplusplus - -#include -#include -#include -#include "Common.h" - -namespace arduino { - -template -using voidTemplateFuncPtrParam = void (*)(T param); - -template struct __container__ { - void* param; - voidTemplateFuncPtrParam function; -}; - -// C++ only overloaded version of attachInterrupt function -template void attachInterrupt(pin_size_t interruptNum, voidTemplateFuncPtrParam userFunc, PinStatus mode, T& param) { - - struct __container__ *cont = new __container__(); - cont->param = ¶m; - cont->function = userFunc; - - // TODO: check lambda scope - // TODO: add structure to delete(__container__) when detachInterrupt() is called - auto f = [](void* a) -> void - { - T param = *(T*)((struct __container__*)a)->param; - (((struct __container__*)a)->function)(param); - }; - - attachInterruptParam(interruptNum, f, mode, cont); -} - -template void attachInterrupt(pin_size_t interruptNum, voidTemplateFuncPtrParam userFunc, PinStatus mode, T* param) { - attachInterruptParam(interruptNum, (voidFuncPtrParam)userFunc, mode, (void*)param); -} - -} -#endif -#endif diff --git a/ArduinoCore-API/api/PluggableUSB.cpp b/ArduinoCore-API/api/PluggableUSB.cpp deleted file mode 100644 index ca19d65..0000000 --- a/ArduinoCore-API/api/PluggableUSB.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - PluggableUSB.cpp - Copyright (c) 2015 Arduino LLC - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "USBAPI.h" -#include "PluggableUSB.h" - -using namespace arduino; - -int PluggableUSB_::getInterface(uint8_t* interfaceCount) -{ - int sent = 0; - PluggableUSBModule* node; - for (node = rootNode; node; node = node->next) { - int res = node->getInterface(interfaceCount); - if (res < 0) - return -1; - sent += res; - } - return sent; -} - -int PluggableUSB_::getDescriptor(USBSetup& setup) -{ - PluggableUSBModule* node; - for (node = rootNode; node; node = node->next) { - int ret = node->getDescriptor(setup); - // ret!=0 -> request has been processed - if (ret) - return ret; - } - return 0; -} - -void PluggableUSB_::getShortName(char *iSerialNum) -{ - PluggableUSBModule* node; - for (node = rootNode; node; node = node->next) { - iSerialNum += node->getShortName(iSerialNum); - } - *iSerialNum = 0; -} - -bool PluggableUSB_::setup(USBSetup& setup) -{ - PluggableUSBModule* node; - for (node = rootNode; node; node = node->next) { - if (node->setup(setup)) { - return true; - } - } - return false; -} - -bool PluggableUSB_::plug(PluggableUSBModule *node) -{ - if ((lastEp + node->numEndpoints) > totalEP) { - return false; - } - - if (!rootNode) { - rootNode = node; - } else { - PluggableUSBModule *current = rootNode; - while (current->next) { - current = current->next; - } - current->next = node; - } - - node->pluggedInterface = lastIf; - node->pluggedEndpoint = lastEp; - lastIf += node->numInterfaces; - for (uint8_t i = 0; i < node->numEndpoints; i++) { - *(unsigned int*)(epBuffer(lastEp)) = node->endpointType[i]; - lastEp++; - } - return true; - // restart USB layer??? -} - -PluggableUSB_& PluggableUSB() -{ - static PluggableUSB_ obj; - return obj; -} \ No newline at end of file diff --git a/ArduinoCore-API/api/PluggableUSB.h b/ArduinoCore-API/api/PluggableUSB.h deleted file mode 100644 index 9018f6c..0000000 --- a/ArduinoCore-API/api/PluggableUSB.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - PluggableUSB.h - Copyright (c) 2015 Arduino LLC - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef PUSB_h -#define PUSB_h - -#include "USBAPI.h" -#include -#include - -namespace arduino { - -class PluggableUSBModule { -public: - PluggableUSBModule(uint8_t numEps, uint8_t numIfs, unsigned int *epType) : - numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType) - { } - -protected: - virtual bool setup(USBSetup& setup) = 0; - virtual int getInterface(uint8_t* interfaceCount) = 0; - virtual int getDescriptor(USBSetup& setup) = 0; - virtual uint8_t getShortName(char *name) { name[0] = 'A'+pluggedInterface; return 1; } - - uint8_t pluggedInterface; - uint8_t pluggedEndpoint; - - const uint8_t numEndpoints; - const uint8_t numInterfaces; - const unsigned int *endpointType; - - PluggableUSBModule *next = NULL; - - friend class PluggableUSB_; -}; - -class PluggableUSB_ { -public: - PluggableUSB_(); - bool plug(PluggableUSBModule *node); - int getInterface(uint8_t* interfaceCount); - int getDescriptor(USBSetup& setup); - bool setup(USBSetup& setup); - void getShortName(char *iSerialNum); - -private: - uint8_t lastIf; - uint8_t lastEp; - PluggableUSBModule* rootNode; - uint8_t totalEP; -}; -} - -// core need to define -void* epBuffer(unsigned int n); // -> returns a pointer to the Nth element of the EP buffer structure - -// Replacement for global singleton. -// This function prevents static-initialization-order-fiasco -// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use -arduino::PluggableUSB_& PluggableUSB(); - -#endif \ No newline at end of file diff --git a/ArduinoCore-API/api/Print.cpp b/ArduinoCore-API/api/Print.cpp deleted file mode 100644 index 4a6e942..0000000 --- a/ArduinoCore-API/api/Print.cpp +++ /dev/null @@ -1,388 +0,0 @@ -/* - Print.cpp - Base class that provides print() and println() - Copyright (c) 2014 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include -#include -#include -#include - -#include "Print.h" - -using namespace arduino; - -// Public Methods ////////////////////////////////////////////////////////////// - -/* default implementation: may be overridden */ -size_t Print::write(const uint8_t *buffer, size_t size) -{ - size_t n = 0; - while (size--) { - if (write(*buffer++)) n++; - else break; - } - return n; -} - -size_t Print::print(const __FlashStringHelper *ifsh) -{ -#if defined(__AVR__) - PGM_P p = reinterpret_cast(ifsh); - size_t n = 0; - while (1) { - unsigned char c = pgm_read_byte(p++); - if (c == 0) break; - if (write(c)) n++; - else break; - } - return n; -#else - return print(reinterpret_cast(ifsh)); -#endif -} - -size_t Print::print(const String &s) -{ - return write(s.c_str(), s.length()); -} - -size_t Print::print(const char str[]) -{ - return write(str); -} - -size_t Print::print(char c) -{ - return write(c); -} - -size_t Print::print(unsigned char b, int base) -{ - return print((unsigned long) b, base); -} - -size_t Print::print(int n, int base) -{ - return print((long) n, base); -} - -size_t Print::print(unsigned int n, int base) -{ - return print((unsigned long) n, base); -} - -size_t Print::print(long n, int base) -{ - if (base == 0) { - return write(n); - } else if (base == 10) { - if (n < 0) { - int t = print('-'); - n = -n; - return printNumber(n, 10) + t; - } - return printNumber(n, 10); - } else { - return printNumber(n, base); - } -} - -size_t Print::print(unsigned long n, int base) -{ - if (base == 0) return write(n); - else return printNumber(n, base); -} - -size_t Print::print(long long n, int base) -{ - if (base == 0) { - return write(n); - } else if (base == 10) { - if (n < 0) { - int t = print('-'); - n = -n; - return printULLNumber(n, 10) + t; - } - return printULLNumber(n, 10); - } else { - return printULLNumber(n, base); - } -} - -size_t Print::print(unsigned long long n, int base) -{ - if (base == 0) return write(n); - else return printULLNumber(n, base); -} - -size_t Print::print(double n, int digits) -{ - return printFloat(n, digits); -} - -size_t Print::println(const __FlashStringHelper *ifsh) -{ - size_t n = print(ifsh); - n += println(); - return n; -} - -size_t Print::print(const Printable& x) -{ - return x.printTo(*this); -} - -size_t Print::println(void) -{ - return write("\r\n"); -} - -size_t Print::println(const String &s) -{ - size_t n = print(s); - n += println(); - return n; -} - -size_t Print::println(const char c[]) -{ - size_t n = print(c); - n += println(); - return n; -} - -size_t Print::println(char c) -{ - size_t n = print(c); - n += println(); - return n; -} - -size_t Print::println(unsigned char b, int base) -{ - size_t n = print(b, base); - n += println(); - return n; -} - -size_t Print::println(int num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; -} - -size_t Print::println(unsigned int num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; -} - -size_t Print::println(long num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; -} - -size_t Print::println(unsigned long num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; -} - -size_t Print::println(long long num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; -} - -size_t Print::println(unsigned long long num, int base) -{ - size_t n = print(num, base); - n += println(); - return n; -} - -size_t Print::println(double num, int digits) -{ - size_t n = print(num, digits); - n += println(); - return n; -} - -size_t Print::println(const Printable& x) -{ - size_t n = print(x); - n += println(); - return n; -} - -// Private Methods ///////////////////////////////////////////////////////////// - -size_t Print::printNumber(unsigned long n, uint8_t base) -{ - char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. - char *str = &buf[sizeof(buf) - 1]; - - *str = '\0'; - - // prevent crash if called with base == 1 - if (base < 2) base = 10; - - do { - char c = n % base; - n /= base; - - *--str = c < 10 ? c + '0' : c + 'A' - 10; - } while(n); - - return write(str); -} - -// REFERENCE IMPLEMENTATION FOR ULL -// size_t Print::printULLNumber(unsigned long long n, uint8_t base) -// { - // // if limited to base 10 and 16 the bufsize can be smaller - // char buf[65]; - // char *str = &buf[64]; - - // *str = '\0'; - - // // prevent crash if called with base == 1 - // if (base < 2) base = 10; - - // do { - // unsigned long long t = n / base; - // char c = n - t * base; // faster than c = n%base; - // n = t; - // *--str = c < 10 ? c + '0' : c + 'A' - 10; - // } while(n); - - // return write(str); -// } - -// FAST IMPLEMENTATION FOR ULL -size_t Print::printULLNumber(unsigned long long n64, uint8_t base) -{ - // if limited to base 10 and 16 the bufsize can be 20 - char buf[64]; - uint8_t i = 0; - uint8_t innerLoops = 0; - - // Special case workaround https://github.com/arduino/ArduinoCore-API/issues/178 - if (n64 == 0) { - write('0'); - return 1; - } - - // prevent crash if called with base == 1 - if (base < 2) base = 10; - - // process chunks that fit in "16 bit math". - uint16_t top = 0xFFFF / base; - uint16_t th16 = 1; - while (th16 < top) - { - th16 *= base; - innerLoops++; - } - - while (n64 > th16) - { - // 64 bit math part - uint64_t q = n64 / th16; - uint16_t r = n64 - q*th16; - n64 = q; - - // 16 bit math loop to do remainder. (note buffer is filled reverse) - for (uint8_t j=0; j < innerLoops; j++) - { - uint16_t qq = r/base; - buf[i++] = r - qq*base; - r = qq; - } - } - - uint16_t n16 = n64; - while (n16 > 0) - { - uint16_t qq = n16/base; - buf[i++] = n16 - qq*base; - n16 = qq; - } - - size_t bytes = i; - for (; i > 0; i--) - write((char) (buf[i - 1] < 10 ? - '0' + buf[i - 1] : - 'A' + buf[i - 1] - 10)); - - return bytes; -} - -size_t Print::printFloat(double number, int digits) -{ - if (digits < 0) - digits = 2; - - size_t n = 0; - - if (isnan(number)) return print("nan"); - if (isinf(number)) return print("inf"); - if (number > 4294967040.0) return print ("ovf"); // constant determined empirically - if (number <-4294967040.0) return print ("ovf"); // constant determined empirically - - // Handle negative numbers - if (number < 0.0) - { - n += print('-'); - number = -number; - } - - // Round correctly so that print(1.999, 2) prints as "2.00" - double rounding = 0.5; - for (uint8_t i=0; i 0) { - n += print("."); - } - - // Extract digits from the remainder one at a time - while (digits-- > 0) - { - remainder *= 10.0; - unsigned int toPrint = (unsigned int)remainder; - n += print(toPrint); - remainder -= toPrint; - } - - return n; -} diff --git a/ArduinoCore-API/api/Print.h b/ArduinoCore-API/api/Print.h deleted file mode 100644 index 7e1d431..0000000 --- a/ArduinoCore-API/api/Print.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - Print.h - Base class that provides print() and println() - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -#include -#include // for size_t -#include - -#include "api/String.h" -#include "Printable.h" - -#define DEC 10 -#define HEX 16 -#define OCT 8 -#define BIN 2 - -namespace arduino { - -class Print -{ - private: - int write_error; - size_t printNumber(unsigned long, uint8_t); - size_t printULLNumber(unsigned long long, uint8_t); - size_t printFloat(double, int); - protected: - void setWriteError(int err = 1) { write_error = err; } - public: - Print() : write_error(0) {} - - int getWriteError() { return write_error; } - void clearWriteError() { setWriteError(0); } - - virtual size_t write(uint8_t) = 0; - size_t write(const char *str) { - if (str == NULL) return 0; - int len = strlen(str); - return write((const uint8_t *)str, len); - } - virtual size_t write(const uint8_t *buffer, size_t size); - size_t write(const char *buffer, size_t size) { - return write((const uint8_t *)buffer, size); - } - - // default to zero, meaning "a single write may block" - // should be overridden by subclasses with buffering - virtual int availableForWrite() { return 0; } - - size_t print(const __FlashStringHelper *); - size_t print(const String &); - size_t print(const char[]); - size_t print(char); - size_t print(unsigned char, int = DEC); - size_t print(int, int = DEC); - size_t print(unsigned int, int = DEC); - size_t print(long, int = DEC); - size_t print(unsigned long, int = DEC); - size_t print(long long, int = DEC); - size_t print(unsigned long long, int = DEC); - size_t print(double, int = 2); - size_t print(const Printable&); - - size_t println(const __FlashStringHelper *); - size_t println(const String &s); - size_t println(const char[]); - size_t println(char); - size_t println(unsigned char, int = DEC); - size_t println(int, int = DEC); - size_t println(unsigned int, int = DEC); - size_t println(long, int = DEC); - size_t println(unsigned long, int = DEC); - size_t println(long long, int = DEC); - size_t println(unsigned long long, int = DEC); - size_t println(double, int = 2); - size_t println(const Printable&); - size_t println(void); - - virtual void flush() { /* Empty implementation for backward compatibility */ } -}; - -} -using arduino::Print; \ No newline at end of file diff --git a/ArduinoCore-API/api/Printable.h b/ArduinoCore-API/api/Printable.h deleted file mode 100644 index 850c8d2..0000000 --- a/ArduinoCore-API/api/Printable.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Printable.h - Interface for classes that can be printed via Print - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -#include - -namespace arduino { - -class Print; - -/** The Printable class provides a way for new classes to allow themselves to be printed. - By deriving from Printable and implementing the printTo method, it will then be possible - for users to print out instances of this class by passing them into the usual - Print::print and Print::println methods. -*/ - -class Printable -{ - public: - virtual size_t printTo(Print& p) const = 0; -}; - -} \ No newline at end of file diff --git a/ArduinoCore-API/api/RingBuffer.h b/ArduinoCore-API/api/RingBuffer.h deleted file mode 100644 index b69c20d..0000000 --- a/ArduinoCore-API/api/RingBuffer.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - RingBuffer.h - Ring buffer implementation - Copyright (c) 2014 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifdef __cplusplus - -#ifndef _RING_BUFFER_ -#define _RING_BUFFER_ - -#include -#include - -namespace arduino { - -// Define constants and variables for buffering incoming serial data. We're -// using a ring buffer (I think), in which head is the index of the location -// to which to write the next incoming character and tail is the index of the -// location from which to read. -#define SERIAL_BUFFER_SIZE 64 - -template -class RingBufferN -{ - public: - uint8_t _aucBuffer[N] ; - volatile int _iHead ; - volatile int _iTail ; - volatile int _numElems; - - public: - RingBufferN( void ) ; - void store_char( uint8_t c ) ; - void clear(); - int read_char(); - int available(); - int availableForStore(); - int peek(); - bool isFull(); - - private: - int nextIndex(int index); - inline bool isEmpty() const { return (_numElems == 0); } -}; - -typedef RingBufferN RingBuffer; - - -template -RingBufferN::RingBufferN( void ) -{ - memset( _aucBuffer, 0, N ) ; - clear(); -} - -template -void RingBufferN::store_char( uint8_t c ) -{ - // if we should be storing the received character into the location - // just before the tail (meaning that the head would advance to the - // current location of the tail), we're about to overflow the buffer - // and so we don't write the character or advance the head. - if (!isFull()) - { - _aucBuffer[_iHead] = c ; - _iHead = nextIndex(_iHead); - _numElems = _numElems + 1; - } -} - -template -void RingBufferN::clear() -{ - _iHead = 0; - _iTail = 0; - _numElems = 0; -} - -template -int RingBufferN::read_char() -{ - if (isEmpty()) - return -1; - - uint8_t value = _aucBuffer[_iTail]; - _iTail = nextIndex(_iTail); - _numElems = _numElems - 1; - - return value; -} - -template -int RingBufferN::available() -{ - return _numElems; -} - -template -int RingBufferN::availableForStore() -{ - return (N - _numElems); -} - -template -int RingBufferN::peek() -{ - if (isEmpty()) - return -1; - - return _aucBuffer[_iTail]; -} - -template -int RingBufferN::nextIndex(int index) -{ - return (uint32_t)(index + 1) % N; -} - -template -bool RingBufferN::isFull() -{ - return (_numElems == N); -} - -} - -#endif /* _RING_BUFFER_ */ -#endif /* __cplusplus */ diff --git a/ArduinoCore-API/api/Server.h b/ArduinoCore-API/api/Server.h deleted file mode 100644 index 83d0cd3..0000000 --- a/ArduinoCore-API/api/Server.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - Server.h - Base class that provides Server - Copyright (c) 2011 Adrian McEwen. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -#include "Print.h" - -namespace arduino { - -class Server : public Print { - public: - virtual void begin() = 0; -}; - -} \ No newline at end of file diff --git a/ArduinoCore-API/api/Stream.cpp b/ArduinoCore-API/api/Stream.cpp deleted file mode 100644 index f6f9bda..0000000 --- a/ArduinoCore-API/api/Stream.cpp +++ /dev/null @@ -1,321 +0,0 @@ -/* - Stream.cpp - adds parsing methods to Stream class - Copyright (c) 2008 David A. Mellis. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Created July 2011 - parsing functions based on TextFinder library by Michael Margolis - - findMulti/findUntil routines written by Jim Leonard/Xuth - */ - -#include "Common.h" -#include "Stream.h" - -#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait - -using namespace arduino; - -// private method to read stream with timeout -int Stream::timedRead() -{ - int c; - _startMillis = millis(); - do { - c = read(); - if (c >= 0) return c; - } while(millis() - _startMillis < _timeout); - return -1; // -1 indicates timeout -} - -// private method to peek stream with timeout -int Stream::timedPeek() -{ - int c; - _startMillis = millis(); - do { - c = peek(); - if (c >= 0) return c; - } while(millis() - _startMillis < _timeout); - return -1; // -1 indicates timeout -} - -// returns peek of the next digit in the stream or -1 if timeout -// discards non-numeric characters -int Stream::peekNextDigit(LookaheadMode lookahead, bool detectDecimal) -{ - int c; - while (1) { - c = timedPeek(); - - if( c < 0 || - c == '-' || - (c >= '0' && c <= '9') || - (detectDecimal && c == '.')) return c; - - switch( lookahead ){ - case SKIP_NONE: return -1; // Fail code. - case SKIP_WHITESPACE: - switch( c ){ - case ' ': - case '\t': - case '\r': - case '\n': break; - default: return -1; // Fail code. - } - case SKIP_ALL: - break; - } - read(); // discard non-numeric - } -} - -// Public Methods -////////////////////////////////////////////////////////////// - -void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait -{ - _timeout = timeout; -} - - // find returns true if the target string is found -bool Stream::find(const char *target) -{ - return findUntil(target, strlen(target), NULL, 0); -} - -// reads data from the stream until the target string of given length is found -// returns true if target string is found, false if timed out -bool Stream::find(const char *target, size_t length) -{ - return findUntil(target, length, NULL, 0); -} - -// as find but search ends if the terminator string is found -bool Stream::findUntil(const char *target, const char *terminator) -{ - return findUntil(target, strlen(target), terminator, strlen(terminator)); -} - -// reads data from the stream until the target string of the given length is found -// search terminated if the terminator string is found -// returns true if target string is found, false if terminated or timed out -bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen) -{ - if (terminator == NULL) { - MultiTarget t[1] = {{target, targetLen, 0}}; - return findMulti(t, 1) == 0; - } else { - MultiTarget t[2] = {{target, targetLen, 0}, {terminator, termLen, 0}}; - return findMulti(t, 2) == 0; - } -} - -// returns the first valid (long) integer value from the current position. -// lookahead determines how parseInt looks ahead in the stream. -// See LookaheadMode enumeration at the top of the file. -// Lookahead is terminated by the first character that is not a valid part of an integer. -// Once parsing commences, 'ignore' will be skipped in the stream. -long Stream::parseInt(LookaheadMode lookahead, char ignore) -{ - bool isNegative = false; - long value = 0; - int c; - - c = peekNextDigit(lookahead, false); - // ignore non numeric leading characters - if(c < 0) - return 0; // zero returned if timeout - - do{ - if((char)c == ignore) - ; // ignore this character - else if(c == '-') - isNegative = true; - else if(c >= '0' && c <= '9') // is c a digit? - value = value * 10 + c - '0'; - read(); // consume the character we got with peek - c = timedPeek(); - } - while( (c >= '0' && c <= '9') || (char)c == ignore ); - - if(isNegative) - value = -value; - return value; -} - -// as parseInt but returns a floating point value -float Stream::parseFloat(LookaheadMode lookahead, char ignore) -{ - bool isNegative = false; - bool isFraction = false; - double value = 0.0; - int c; - double fraction = 1.0; - - c = peekNextDigit(lookahead, true); - // ignore non numeric leading characters - if(c < 0) - return 0; // zero returned if timeout - - do{ - if((char)c == ignore) - ; // ignore - else if(c == '-') - isNegative = true; - else if (c == '.') - isFraction = true; - else if(c >= '0' && c <= '9') { // is c a digit? - if(isFraction) { - fraction *= 0.1; - value = value + fraction * (c - '0'); - } else { - value = value * 10 + c - '0'; - } - } - read(); // consume the character we got with peek - c = timedPeek(); - } - while( (c >= '0' && c <= '9') || (c == '.' && !isFraction) || (char)c == ignore ); - - if(isNegative) - value = -value; - - return value; -} - -// read characters from stream into buffer -// terminates if length characters have been read, or timeout (see setTimeout) -// returns the number of characters placed in the buffer -// the buffer is NOT null terminated. -// -size_t Stream::readBytes(char *buffer, size_t length) -{ - size_t count = 0; - while (count < length) { - int c = timedRead(); - if (c < 0) break; - *buffer++ = (char)c; - count++; - } - return count; -} - - -// as readBytes with terminator character -// terminates if length characters have been read, timeout, or if the terminator character detected -// returns the number of characters placed in the buffer (0 means no valid data found) - -size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length) -{ - size_t index = 0; - while (index < length) { - int c = timedRead(); - if (c < 0 || (char)c == terminator) break; - *buffer++ = (char)c; - index++; - } - return index; // return number of characters, not including null terminator -} - -String Stream::readString() -{ - String ret; - int c = timedRead(); - while (c >= 0) - { - ret += (char)c; - c = timedRead(); - } - return ret; -} - -String Stream::readStringUntil(char terminator) -{ - String ret; - int c = timedRead(); - while (c >= 0 && (char)c != terminator) - { - ret += (char)c; - c = timedRead(); - } - return ret; -} - -int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) { - // any zero length target string automatically matches and would make - // a mess of the rest of the algorithm. - for (struct MultiTarget *t = targets; t < targets+tCount; ++t) { - if (t->len <= 0) - return t - targets; - } - - while (1) { - int c = timedRead(); - if (c < 0) - return -1; - - for (struct MultiTarget *t = targets; t < targets+tCount; ++t) { - // the simple case is if we match, deal with that first. - if ((char)c == t->str[t->index]) { - if (++t->index == t->len) - return t - targets; - else - continue; - } - - // if not we need to walk back and see if we could have matched further - // down the stream (ie '1112' doesn't match the first position in '11112' - // but it will match the second position so we can't just reset the current - // index to 0 when we find a mismatch. - if (t->index == 0) - continue; - - int origIndex = t->index; - do { - --t->index; - // first check if current char works against the new current index - if ((char)c != t->str[t->index]) - continue; - - // if it's the only char then we're good, nothing more to check - if (t->index == 0) { - t->index++; - break; - } - - // otherwise we need to check the rest of the found string - int diff = origIndex - t->index; - size_t i; - for (i = 0; i < t->index; ++i) { - if (t->str[i] != t->str[i + diff]) - break; - } - - // if we successfully got through the previous loop then our current - // index is good. - if (i == t->index) { - t->index++; - break; - } - - // otherwise we just try the next index - } while (t->index); - } - } - // unreachable - return -1; -} diff --git a/ArduinoCore-API/api/Stream.h b/ArduinoCore-API/api/Stream.h deleted file mode 100644 index e81c71b..0000000 --- a/ArduinoCore-API/api/Stream.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - Stream.h - base class for character-based streams. - Copyright (c) 2010 David A. Mellis. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - parsing functions based on TextFinder library by Michael Margolis -*/ - -#pragma once - -#include -#include "Print.h" - -// compatibility macros for testing -/* -#define getInt() parseInt() -#define getInt(ignore) parseInt(ignore) -#define getFloat() parseFloat() -#define getFloat(ignore) parseFloat(ignore) -#define getString( pre_string, post_string, buffer, length) -readBytesBetween( pre_string, terminator, buffer, length) -*/ - -namespace arduino { - -// This enumeration provides the lookahead options for parseInt(), parseFloat() -// The rules set out here are used until either the first valid character is found -// or a time out occurs due to lack of input. -enum LookaheadMode{ - SKIP_ALL, // All invalid characters are ignored. - SKIP_NONE, // Nothing is skipped, and the stream is not touched unless the first waiting character is valid. - SKIP_WHITESPACE // Only tabs, spaces, line feeds & carriage returns are skipped. -}; - -#define NO_IGNORE_CHAR '\x01' // a char not found in a valid ASCII numeric field - -class Stream : public Print -{ - protected: - unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read - unsigned long _startMillis; // used for timeout measurement - int timedRead(); // private method to read stream with timeout - int timedPeek(); // private method to peek stream with timeout - int peekNextDigit(LookaheadMode lookahead, bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout - - public: - virtual int available() = 0; - virtual int read() = 0; - virtual int peek() = 0; - - Stream() {_timeout=1000;} - -// parsing methods - - void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second - unsigned long getTimeout(void) { return _timeout; } - - bool find(const char *target); // reads data from the stream until the target string is found - bool find(const uint8_t *target) { return find ((const char *)target); } - // returns true if target string is found, false if timed out (see setTimeout) - - bool find(const char *target, size_t length); // reads data from the stream until the target string of given length is found - bool find(const uint8_t *target, size_t length) { return find ((const char *)target, length); } - // returns true if target string is found, false if timed out - - bool find(char target) { return find (&target, 1); } - - bool findUntil(const char *target, const char *terminator); // as find but search ends if the terminator string is found - bool findUntil(const uint8_t *target, const char *terminator) { return findUntil((const char *)target, terminator); } - - bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); // as above but search ends if the terminate string is found - bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) {return findUntil((const char *)target, targetLen, terminate, termLen); } - - long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR); - // returns the first valid (long) integer value from the current position. - // lookahead determines how parseInt looks ahead in the stream. - // See LookaheadMode enumeration at the top of the file. - // Lookahead is terminated by the first character that is not a valid part of an integer. - // Once parsing commences, 'ignore' will be skipped in the stream. - - float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR); - // float version of parseInt - - size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer - size_t readBytes( uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); } - // terminates if length characters have been read or timeout (see setTimeout) - // returns the number of characters placed in the buffer (0 means no valid data found) - - size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character - size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); } - // terminates if length characters have been read, timeout, or if the terminator character detected - // returns the number of characters placed in the buffer (0 means no valid data found) - - // Arduino String functions to be added here - String readString(); - String readStringUntil(char terminator); - - protected: - long parseInt(char ignore) { return parseInt(SKIP_ALL, ignore); } - float parseFloat(char ignore) { return parseFloat(SKIP_ALL, ignore); } - // These overload exists for compatibility with any class that has derived - // Stream and used parseFloat/Int with a custom ignore character. To keep - // the public API simple, these overload remains protected. - - struct MultiTarget { - const char *str; // string you're searching for - size_t len; // length of string you're searching for - size_t index; // index used by the search routine. - }; - - // This allows you to search for an arbitrary number of strings. - // Returns index of the target that is found first or -1 if timeout occurs. - int findMulti(struct MultiTarget *targets, int tCount); -}; - -#undef NO_IGNORE_CHAR - -} - -using arduino::Stream; \ No newline at end of file diff --git a/ArduinoCore-API/api/String.cpp b/ArduinoCore-API/api/String.cpp deleted file mode 100644 index 4f17637..0000000 --- a/ArduinoCore-API/api/String.cpp +++ /dev/null @@ -1,750 +0,0 @@ -/* - String library for Wiring & Arduino - ...mostly rewritten by Paul Stoffregen... - Copyright (c) 2009-10 Hernando Barragan. All rights reserved. - Copyright 2011, Paul Stoffregen, paul@pjrc.com - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "String.h" -#include "Common.h" -#include "itoa.h" -#include "deprecated-avr-comp/avr/dtostrf.h" - -#include - -namespace arduino { - -/*********************************************/ -/* Static Member Initialisation */ -/*********************************************/ - -size_t const String::FLT_MAX_DECIMAL_PLACES; -size_t const String::DBL_MAX_DECIMAL_PLACES; - -/*********************************************/ -/* Constructors */ -/*********************************************/ - -String::String(const char *cstr) -{ - init(); - if (cstr) copy(cstr, strlen(cstr)); -} - -String::String(const char *cstr, unsigned int length) -{ - init(); - if (cstr) copy(cstr, length); -} - -String::String(const String &value) -{ - init(); - *this = value; -} - -String::String(const __FlashStringHelper *pstr) -{ - init(); - *this = pstr; -} - -String::String(String &&rval) - : buffer(rval.buffer) - , capacity(rval.capacity) - , len(rval.len) -{ - rval.buffer = NULL; - rval.capacity = 0; - rval.len = 0; -} - -String::String(char c) -{ - init(); - char buf[2]; - buf[0] = c; - buf[1] = 0; - *this = buf; -} - -String::String(unsigned char value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned char)]; - utoa(value, buf, base); - *this = buf; -} - -String::String(int value, unsigned char base) -{ - init(); - char buf[2 + 8 * sizeof(int)]; - itoa(value, buf, base); - *this = buf; -} - -String::String(unsigned int value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned int)]; - utoa(value, buf, base); - *this = buf; -} - -String::String(long value, unsigned char base) -{ - init(); - char buf[2 + 8 * sizeof(long)]; - ltoa(value, buf, base); - *this = buf; -} - -String::String(unsigned long value, unsigned char base) -{ - init(); - char buf[1 + 8 * sizeof(unsigned long)]; - ultoa(value, buf, base); - *this = buf; -} - -String::String(float value, unsigned char decimalPlaces) -{ - static size_t const FLOAT_BUF_SIZE = FLT_MAX_10_EXP + FLT_MAX_DECIMAL_PLACES + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */; - init(); - char buf[FLOAT_BUF_SIZE]; - decimalPlaces = min(decimalPlaces, FLT_MAX_DECIMAL_PLACES); - *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); -} - -String::String(double value, unsigned char decimalPlaces) -{ - static size_t const DOUBLE_BUF_SIZE = DBL_MAX_10_EXP + DBL_MAX_DECIMAL_PLACES + 1 /* '-' */ + 1 /* '.' */ + 1 /* '\0' */; - init(); - char buf[DOUBLE_BUF_SIZE]; - decimalPlaces = min(decimalPlaces, DBL_MAX_DECIMAL_PLACES); - *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf); -} - -String::~String() -{ - if (buffer) free(buffer); -} - -/*********************************************/ -/* Memory Management */ -/*********************************************/ - -inline void String::init(void) -{ - buffer = NULL; - capacity = 0; - len = 0; -} - -void String::invalidate(void) -{ - if (buffer) free(buffer); - buffer = NULL; - capacity = len = 0; -} - -bool String::reserve(unsigned int size) -{ - if (buffer && capacity >= size) return 1; - if (changeBuffer(size)) { - if (len == 0) buffer[0] = 0; - return true; - } - return false; -} - -bool String::changeBuffer(unsigned int maxStrLen) -{ - char *newbuffer = (char *)realloc(buffer, maxStrLen + 1); - if (newbuffer) { - buffer = newbuffer; - capacity = maxStrLen; - return true; - } - return false; -} - -/*********************************************/ -/* Copy and Move */ -/*********************************************/ - -String & String::copy(const char *cstr, unsigned int length) -{ - if (!reserve(length)) { - invalidate(); - return *this; - } - len = length; - memcpy(buffer, cstr, length); - buffer[len] = '\0'; - return *this; -} - -String & String::copy(const __FlashStringHelper *pstr, unsigned int length) -{ - if (!reserve(length)) { - invalidate(); - return *this; - } - len = length; - strcpy_P(buffer, (PGM_P)pstr); - return *this; -} - -void String::move(String &rhs) -{ - if (this != &rhs) - { - free(buffer); - - buffer = rhs.buffer; - len = rhs.len; - capacity = rhs.capacity; - - rhs.buffer = NULL; - rhs.len = 0; - rhs.capacity = 0; - } -} - -String & String::operator = (const String &rhs) -{ - if (this == &rhs) return *this; - - if (rhs.buffer) copy(rhs.buffer, rhs.len); - else invalidate(); - - return *this; -} - -String & String::operator = (String &&rval) -{ - move(rval); - return *this; -} - -String & String::operator = (const char *cstr) -{ - if (cstr) copy(cstr, strlen(cstr)); - else invalidate(); - - return *this; -} - -String & String::operator = (const __FlashStringHelper *pstr) -{ - if (pstr) copy(pstr, strlen_P((PGM_P)pstr)); - else invalidate(); - - return *this; -} - -/*********************************************/ -/* concat */ -/*********************************************/ - -bool String::concat(const String &s) -{ - return concat(s.buffer, s.len); -} - -bool String::concat(const char *cstr, unsigned int length) -{ - unsigned int newlen = len + length; - if (!cstr) return false; - if (length == 0) return true; - if (!reserve(newlen)) return false; - memcpy(buffer + len, cstr, length); - len = newlen; - buffer[len] = '\0'; - return true; -} - -bool String::concat(const char *cstr) -{ - if (!cstr) return false; - return concat(cstr, strlen(cstr)); -} - -bool String::concat(char c) -{ - return concat(&c, 1); -} - -bool String::concat(unsigned char num) -{ - char buf[1 + 3 * sizeof(unsigned char)]; - itoa(num, buf, 10); - return concat(buf); -} - -bool String::concat(int num) -{ - char buf[2 + 3 * sizeof(int)]; - itoa(num, buf, 10); - return concat(buf); -} - -bool String::concat(unsigned int num) -{ - char buf[1 + 3 * sizeof(unsigned int)]; - utoa(num, buf, 10); - return concat(buf); -} - -bool String::concat(long num) -{ - char buf[2 + 3 * sizeof(long)]; - ltoa(num, buf, 10); - return concat(buf); -} - -bool String::concat(unsigned long num) -{ - char buf[1 + 3 * sizeof(unsigned long)]; - ultoa(num, buf, 10); - return concat(buf); -} - -bool String::concat(float num) -{ - char buf[20]; - char* string = dtostrf(num, 4, 2, buf); - return concat(string); -} - -bool String::concat(double num) -{ - char buf[20]; - char* string = dtostrf(num, 4, 2, buf); - return concat(string); -} - -bool String::concat(const __FlashStringHelper * str) -{ - if (!str) return false; - int length = strlen_P((const char *) str); - if (length == 0) return true; - unsigned int newlen = len + length; - if (!reserve(newlen)) return false; - strcpy_P(buffer + len, (const char *) str); - len = newlen; - return true; -} - -/*********************************************/ -/* Concatenate */ -/*********************************************/ - -StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(rhs.buffer, rhs.len)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr) -{ - StringSumHelper &a = const_cast(lhs); - if (!cstr || !a.concat(cstr)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, char c) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(c)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, int num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, long num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, float num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, double num) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(num)) a.invalidate(); - return a; -} - -StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs) -{ - StringSumHelper &a = const_cast(lhs); - if (!a.concat(rhs)) a.invalidate(); - return a; -} - -/*********************************************/ -/* Comparison */ -/*********************************************/ - -int String::compareTo(const String &s) const -{ - if (!buffer || !s.buffer) { - if (s.buffer && s.len > 0) return 0 - *(unsigned char *)s.buffer; - if (buffer && len > 0) return *(unsigned char *)buffer; - return 0; - } - return strcmp(buffer, s.buffer); -} - -int String::compareTo(const char *cstr) const -{ - if (!buffer || !cstr) { - if (cstr && *cstr) return 0 - *(unsigned char *)cstr; - if (buffer && len > 0) return *(unsigned char *)buffer; - return 0; - } - return strcmp(buffer, cstr); -} - -bool String::equals(const String &s2) const -{ - return (len == s2.len && compareTo(s2) == 0); -} - -bool String::equals(const char *cstr) const -{ - if (len == 0) return (cstr == NULL || *cstr == 0); - if (cstr == NULL) return buffer[0] == 0; - return strcmp(buffer, cstr) == 0; -} - -bool String::equalsIgnoreCase( const String &s2 ) const -{ - if (this == &s2) return true; - if (len != s2.len) return false; - if (len == 0) return true; - const char *p1 = buffer; - const char *p2 = s2.buffer; - while (*p1) { - if (tolower(*p1++) != tolower(*p2++)) return false; - } - return true; -} - -bool String::startsWith( const String &s2 ) const -{ - if (len < s2.len) return false; - return startsWith(s2, 0); -} - -bool String::startsWith( const String &s2, unsigned int offset ) const -{ - if (offset > len - s2.len || !buffer || !s2.buffer) return false; - return strncmp( &buffer[offset], s2.buffer, s2.len ) == 0; -} - -bool String::endsWith( const String &s2 ) const -{ - if ( len < s2.len || !buffer || !s2.buffer) return false; - return strcmp(&buffer[len - s2.len], s2.buffer) == 0; -} - -/*********************************************/ -/* Character Access */ -/*********************************************/ - -char String::charAt(unsigned int loc) const -{ - return operator[](loc); -} - -void String::setCharAt(unsigned int loc, char c) -{ - if (loc < len) buffer[loc] = c; -} - -char & String::operator[](unsigned int index) -{ - static char dummy_writable_char; - if (index >= len || !buffer) { - dummy_writable_char = 0; - return dummy_writable_char; - } - return buffer[index]; -} - -char String::operator[]( unsigned int index ) const -{ - if (index >= len || !buffer) return 0; - return buffer[index]; -} - -void String::getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index) const -{ - if (!bufsize || !buf) return; - if (index >= len) { - buf[0] = 0; - return; - } - unsigned int n = bufsize - 1; - if (n > len - index) n = len - index; - strncpy((char *)buf, buffer + index, n); - buf[n] = 0; -} - -/*********************************************/ -/* Search */ -/*********************************************/ - -int String::indexOf(char c) const -{ - return indexOf(c, 0); -} - -int String::indexOf( char ch, unsigned int fromIndex ) const -{ - if (fromIndex >= len) return -1; - const char* temp = strchr(buffer + fromIndex, ch); - if (temp == NULL) return -1; - return temp - buffer; -} - -int String::indexOf(const String &s2) const -{ - return indexOf(s2, 0); -} - -int String::indexOf(const String &s2, unsigned int fromIndex) const -{ - if (fromIndex >= len) return -1; - const char *found = strstr(buffer + fromIndex, s2.buffer); - if (found == NULL) return -1; - return found - buffer; -} - -int String::lastIndexOf( char theChar ) const -{ - return lastIndexOf(theChar, len - 1); -} - -int String::lastIndexOf(char ch, unsigned int fromIndex) const -{ - if (fromIndex >= len) return -1; - char tempchar = buffer[fromIndex + 1]; - buffer[fromIndex + 1] = '\0'; - char* temp = strrchr( buffer, ch ); - buffer[fromIndex + 1] = tempchar; - if (temp == NULL) return -1; - return temp - buffer; -} - -int String::lastIndexOf(const String &s2) const -{ - return lastIndexOf(s2, len - s2.len); -} - -int String::lastIndexOf(const String &s2, unsigned int fromIndex) const -{ - if (s2.len == 0 || len == 0 || s2.len > len) return -1; - if (fromIndex >= len) fromIndex = len - 1; - int found = -1; - for (char *p = buffer; p <= buffer + fromIndex; p++) { - p = strstr(p, s2.buffer); - if (!p) break; - if ((unsigned int)(p - buffer) <= fromIndex) found = p - buffer; - } - return found; -} - -String String::substring(unsigned int left, unsigned int right) const -{ - if (left > right) { - unsigned int temp = right; - right = left; - left = temp; - } - String out; - if (left >= len) return out; - if (right > len) right = len; - out.copy(buffer + left, right - left); - return out; -} - -/*********************************************/ -/* Modification */ -/*********************************************/ - -void String::replace(char find, char replace) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - if (*p == find) *p = replace; - } -} - -void String::replace(const String& find, const String& replace) -{ - if (len == 0 || find.len == 0) return; - int diff = replace.len - find.len; - char *readFrom = buffer; - char *foundAt; - if (diff == 0) { - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - memcpy(foundAt, replace.buffer, replace.len); - readFrom = foundAt + replace.len; - } - } else if (diff < 0) { - unsigned int size = len; // compute size needed for result - diff = 0 - diff; - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - readFrom = foundAt + find.len; - size -= diff; - } - if (size == len) return; - int index = len - 1; - while (index >= 0 && (index = lastIndexOf(find, index)) >= 0) { - readFrom = buffer + index + find.len; - memmove(readFrom - diff, readFrom, len - (readFrom - buffer)); - len -= diff; - buffer[len] = 0; - memcpy(buffer + index, replace.buffer, replace.len); - index--; - } - } else { - unsigned int size = len; // compute size needed for result - while ((foundAt = strstr(readFrom, find.buffer)) != NULL) { - readFrom = foundAt + find.len; - size += diff; - } - if (size == len) return; - if (size > capacity && !changeBuffer(size)) return; // XXX: tell user! - int index = len - 1; - while (index >= 0 && (index = lastIndexOf(find, index)) >= 0) { - readFrom = buffer + index + find.len; - memmove(readFrom + diff, readFrom, len - (readFrom - buffer)); - len += diff; - buffer[len] = 0; - memcpy(buffer + index, replace.buffer, replace.len); - index--; - } - } -} - -void String::remove(unsigned int index){ - // Pass the biggest integer as the count. The remove method - // below will take care of truncating it at the end of the - // string. - remove(index, (unsigned int)-1); -} - -void String::remove(unsigned int index, unsigned int count){ - if (index >= len) { return; } - if (count <= 0) { return; } - if (count > len - index) { count = len - index; } - char *writeTo = buffer + index; - len = len - count; - memmove(writeTo, buffer + index + count,len - index); - buffer[len] = 0; -} - -void String::toLowerCase(void) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - *p = tolower(*p); - } -} - -void String::toUpperCase(void) -{ - if (!buffer) return; - for (char *p = buffer; *p; p++) { - *p = toupper(*p); - } -} - -void String::trim(void) -{ - if (!buffer || len == 0) return; - char *begin = buffer; - while (isspace(*begin)) begin++; - char *end = buffer + len - 1; - while (isspace(*end) && end >= begin) end--; - len = end + 1 - begin; - if (begin > buffer) memmove(buffer, begin, len); - buffer[len] = 0; -} - -/*********************************************/ -/* Parsing / Conversion */ -/*********************************************/ - -long String::toInt(void) const -{ - if (buffer) return atol(buffer); - return 0; -} - -float String::toFloat(void) const -{ - return float(toDouble()); -} - -double String::toDouble(void) const -{ - if (buffer) return atof(buffer); - return 0; -} - -} // namespace arduino diff --git a/ArduinoCore-API/api/String.h b/ArduinoCore-API/api/String.h deleted file mode 100644 index 0bafd35..0000000 --- a/ArduinoCore-API/api/String.h +++ /dev/null @@ -1,255 +0,0 @@ -/* - String library for Wiring & Arduino - ...mostly rewritten by Paul Stoffregen... - Copyright (c) 2009-10 Hernando Barragan. All right reserved. - Copyright 2011, Paul Stoffregen, paul@pjrc.com - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifdef __cplusplus - -#ifndef __ARDUINO_STRINGS__ -#define __ARDUINO_STRINGS__ - -#include -#include -#include -#if defined(__AVR__) -#include "avr/pgmspace.h" -#else -#include "deprecated-avr-comp/avr/pgmspace.h" -#endif - -namespace arduino { - -// When compiling programs with this class, the following gcc parameters -// dramatically increase performance and memory (RAM) efficiency, typically -// with little or no increase in code size. -// -felide-constructors -// -std=c++0x - -class __FlashStringHelper; -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - -// An inherited class for holding the result of a concatenation. These -// result objects are assumed to be writable by subsequent concatenations. -class StringSumHelper; - -// The string class -class String -{ - friend class StringSumHelper; - // use a function pointer to allow for "if (s)" without the - // complications of an operator bool(). for more information, see: - // http://www.artima.com/cppsource/safebool.html - typedef void (String::*StringIfHelperType)() const; - void StringIfHelper() const {} - - static size_t const FLT_MAX_DECIMAL_PLACES = 10; - static size_t const DBL_MAX_DECIMAL_PLACES = FLT_MAX_DECIMAL_PLACES; - -public: - // constructors - // creates a copy of the initial value. - // if the initial value is null or invalid, or if memory allocation - // fails, the string will be marked as invalid (i.e. "if (s)" will - // be false). - String(const char *cstr = ""); - String(const char *cstr, unsigned int length); - String(const uint8_t *cstr, unsigned int length) : String((const char*)cstr, length) {} - String(const String &str); - String(const __FlashStringHelper *str); - String(String &&rval); - explicit String(char c); - explicit String(unsigned char, unsigned char base=10); - explicit String(int, unsigned char base=10); - explicit String(unsigned int, unsigned char base=10); - explicit String(long, unsigned char base=10); - explicit String(unsigned long, unsigned char base=10); - explicit String(float, unsigned char decimalPlaces=2); - explicit String(double, unsigned char decimalPlaces=2); - ~String(void); - - // memory management - // return true on success, false on failure (in which case, the string - // is left unchanged). reserve(0), if successful, will validate an - // invalid string (i.e., "if (s)" will be true afterwards) - bool reserve(unsigned int size); - inline unsigned int length(void) const {return len;} - inline bool isEmpty(void) const { return length() == 0; } - - // creates a copy of the assigned value. if the value is null or - // invalid, or if the memory allocation fails, the string will be - // marked as invalid ("if (s)" will be false). - String & operator = (const String &rhs); - String & operator = (const char *cstr); - String & operator = (const __FlashStringHelper *str); - String & operator = (String &&rval); - - // concatenate (works w/ built-in types) - - // returns true on success, false on failure (in which case, the string - // is left unchanged). if the argument is null or invalid, the - // concatenation is considered unsuccessful. - bool concat(const String &str); - bool concat(const char *cstr); - bool concat(const char *cstr, unsigned int length); - bool concat(const uint8_t *cstr, unsigned int length) {return concat((const char*)cstr, length);} - bool concat(char c); - bool concat(unsigned char num); - bool concat(int num); - bool concat(unsigned int num); - bool concat(long num); - bool concat(unsigned long num); - bool concat(float num); - bool concat(double num); - bool concat(const __FlashStringHelper * str); - - // if there's not enough memory for the concatenated value, the string - // will be left unchanged (but this isn't signalled in any way) - String & operator += (const String &rhs) {concat(rhs); return (*this);} - String & operator += (const char *cstr) {concat(cstr); return (*this);} - String & operator += (char c) {concat(c); return (*this);} - String & operator += (unsigned char num) {concat(num); return (*this);} - String & operator += (int num) {concat(num); return (*this);} - String & operator += (unsigned int num) {concat(num); return (*this);} - String & operator += (long num) {concat(num); return (*this);} - String & operator += (unsigned long num) {concat(num); return (*this);} - String & operator += (float num) {concat(num); return (*this);} - String & operator += (double num) {concat(num); return (*this);} - String & operator += (const __FlashStringHelper *str){concat(str); return (*this);} - - friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs); - friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr); - friend StringSumHelper & operator + (const StringSumHelper &lhs, char c); - friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, int num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, long num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, float num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, double num); - friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs); - - // comparison (only works w/ Strings and "strings") - operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; } - int compareTo(const String &s) const; - int compareTo(const char *cstr) const; - bool equals(const String &s) const; - bool equals(const char *cstr) const; - - friend bool operator == (const String &a, const String &b) { return a.equals(b); } - friend bool operator == (const String &a, const char *b) { return a.equals(b); } - friend bool operator == (const char *a, const String &b) { return b == a; } - friend bool operator < (const String &a, const String &b) { return a.compareTo(b) < 0; } - friend bool operator < (const String &a, const char *b) { return a.compareTo(b) < 0; } - friend bool operator < (const char *a, const String &b) { return b.compareTo(a) > 0; } - - friend bool operator != (const String &a, const String &b) { return !(a == b); } - friend bool operator != (const String &a, const char *b) { return !(a == b); } - friend bool operator != (const char *a, const String &b) { return !(a == b); } - friend bool operator > (const String &a, const String &b) { return b < a; } - friend bool operator > (const String &a, const char *b) { return b < a; } - friend bool operator > (const char *a, const String &b) { return b < a; } - friend bool operator <= (const String &a, const String &b) { return !(b < a); } - friend bool operator <= (const String &a, const char *b) { return !(b < a); } - friend bool operator <= (const char *a, const String &b) { return !(b < a); } - friend bool operator >= (const String &a, const String &b) { return !(a < b); } - friend bool operator >= (const String &a, const char *b) { return !(a < b); } - friend bool operator >= (const char *a, const String &b) { return !(a < b); } - - bool equalsIgnoreCase(const String &s) const; - bool startsWith( const String &prefix) const; - bool startsWith(const String &prefix, unsigned int offset) const; - bool endsWith(const String &suffix) const; - - // character access - char charAt(unsigned int index) const; - void setCharAt(unsigned int index, char c); - char operator [] (unsigned int index) const; - char& operator [] (unsigned int index); - void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const; - void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const - { getBytes((unsigned char *)buf, bufsize, index); } - const char* c_str() const { return buffer; } - char* begin() { return buffer; } - char* end() { return buffer + length(); } - const char* begin() const { return c_str(); } - const char* end() const { return c_str() + length(); } - - // search - int indexOf( char ch ) const; - int indexOf( char ch, unsigned int fromIndex ) const; - int indexOf( const String &str ) const; - int indexOf( const String &str, unsigned int fromIndex ) const; - int lastIndexOf( char ch ) const; - int lastIndexOf( char ch, unsigned int fromIndex ) const; - int lastIndexOf( const String &str ) const; - int lastIndexOf( const String &str, unsigned int fromIndex ) const; - String substring( unsigned int beginIndex ) const { return substring(beginIndex, len); }; - String substring( unsigned int beginIndex, unsigned int endIndex ) const; - - // modification - void replace(char find, char replace); - void replace(const String& find, const String& replace); - void remove(unsigned int index); - void remove(unsigned int index, unsigned int count); - void toLowerCase(void); - void toUpperCase(void); - void trim(void); - - // parsing/conversion - long toInt(void) const; - float toFloat(void) const; - double toDouble(void) const; - -protected: - char *buffer; // the actual char array - unsigned int capacity; // the array length minus one (for the '\0') - unsigned int len; // the String length (not counting the '\0') -protected: - void init(void); - void invalidate(void); - bool changeBuffer(unsigned int maxStrLen); - - // copy and move - String & copy(const char *cstr, unsigned int length); - String & copy(const __FlashStringHelper *pstr, unsigned int length); - void move(String &rhs); -}; - -class StringSumHelper : public String -{ -public: - StringSumHelper(const String &s) : String(s) {} - StringSumHelper(const char *p) : String(p) {} - StringSumHelper(char c) : String(c) {} - StringSumHelper(unsigned char num) : String(num) {} - StringSumHelper(int num) : String(num) {} - StringSumHelper(unsigned int num) : String(num) {} - StringSumHelper(long num) : String(num) {} - StringSumHelper(unsigned long num) : String(num) {} - StringSumHelper(float num) : String(num) {} - StringSumHelper(double num) : String(num) {} -}; - -} // namespace arduino - -using arduino::__FlashStringHelper; -using arduino::String; - -#endif // __cplusplus -#endif // __ARDUINO_STRINGS__ diff --git a/ArduinoCore-API/api/USBAPI.h b/ArduinoCore-API/api/USBAPI.h deleted file mode 100644 index ba5e87c..0000000 --- a/ArduinoCore-API/api/USBAPI.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - USBAPI.h - Copyright (c) 2005-2014 Arduino. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef __USBAPI__ -#define __USBAPI__ - -#include - -namespace arduino { -//================================================================================ -//================================================================================ -// Low level API - -typedef struct __attribute__((packed)) -{ - union { - uint8_t bmRequestType; - struct { - uint8_t direction : 5; - uint8_t type : 2; - uint8_t transferDirection : 1; - }; - }; - uint8_t bRequest; - uint8_t wValueL; - uint8_t wValueH; - uint16_t wIndex; - uint16_t wLength; -} USBSetup; - -} - -//================================================================================ -// USB APIs (C scope) -//================================================================================ - -int USB_SendControl(uint8_t flags, const void* d, int len); -int USB_RecvControl(void* d, int len); -int USB_RecvControlLong(void* d, int len); - -uint8_t USB_Available(uint8_t ep); -uint8_t USB_SendSpace(uint8_t ep); -int USB_Send(uint8_t ep, const void* data, int len); // blocking -int USB_Recv(uint8_t ep, void* data, int len); // non-blocking -int USB_Recv(uint8_t ep); // non-blocking -void USB_Flush(uint8_t ep); - -#endif \ No newline at end of file diff --git a/ArduinoCore-API/api/Udp.h b/ArduinoCore-API/api/Udp.h deleted file mode 100644 index 20117a6..0000000 --- a/ArduinoCore-API/api/Udp.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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 - */ - -#pragma once - -#include "Stream.h" -#include "IPAddress.h" - -namespace arduino { - -class UDP : public Stream { - -public: - virtual uint8_t begin(uint16_t) =0; // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use - virtual uint8_t beginMulticast(IPAddress, uint16_t) { return 0; } // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 on failure - virtual void stop() =0; // Finish with the UDP socket - - // Sending UDP packets - - // Start building up a packet to send to the remote host specified 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 specified in host and port - // Returns 1 if successful, 0 if there was a problem resolving the hostname or port - virtual int beginPacket(const char *host, uint16_t port) =0; - // Finish off this packet and send it - // Returns 1 if the packet was sent successfully, 0 if there was an error - virtual int endPacket() =0; - // Write a single byte into the packet - virtual size_t write(uint8_t) =0; - // Write size bytes from buffer into the packet - virtual size_t write(const uint8_t *buffer, size_t size) =0; - - // Start processing the next available incoming packet - // Returns the size of the packet in bytes, or 0 if no packets are available - virtual int parsePacket() =0; - // Number of bytes remaining in the current packet - virtual int available() =0; - // Read a single byte from the current packet - virtual int read() =0; - // Read up to len bytes from the current packet and place them into buffer - // Returns the number of bytes read, or 0 if none are available - virtual int read(unsigned char* buffer, size_t len) =0; - // Read up to len characters from the current packet and place them into buffer - // Returns the number of characters read, or 0 if none are available - virtual int read(char* buffer, size_t len) =0; - // Return the next byte from the current packet without moving on to the next byte - virtual int peek() =0; - virtual void flush() =0; // Finish reading the current packet - - // Return the IP address of the host who sent the current incoming packet - virtual IPAddress remoteIP() =0; - // Return the port of the host who sent the current incoming packet - virtual uint16_t remotePort() =0; -protected: - uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; -}; - -} - -using arduino::UDP; \ No newline at end of file diff --git a/ArduinoCore-API/api/WCharacter.h b/ArduinoCore-API/api/WCharacter.h deleted file mode 100644 index d050842..0000000 --- a/ArduinoCore-API/api/WCharacter.h +++ /dev/null @@ -1,171 +0,0 @@ -/* - WCharacter.h - Character utility functions for Wiring & Arduino - Copyright (c) 2010 Hernando Barragan. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef Character_h -#define Character_h - -#include - -namespace arduino { - -// WCharacter.h prototypes -inline bool isAlphaNumeric(int c) __attribute__((always_inline)); -inline bool isAlpha(int c) __attribute__((always_inline)); -inline bool isAscii(int c) __attribute__((always_inline)); -inline bool isWhitespace(int c) __attribute__((always_inline)); -inline bool isControl(int c) __attribute__((always_inline)); -inline bool isDigit(int c) __attribute__((always_inline)); -inline bool isGraph(int c) __attribute__((always_inline)); -inline bool isLowerCase(int c) __attribute__((always_inline)); -inline bool isPrintable(int c) __attribute__((always_inline)); -inline bool isPunct(int c) __attribute__((always_inline)); -inline bool isSpace(int c) __attribute__((always_inline)); -inline bool isUpperCase(int c) __attribute__((always_inline)); -inline bool isHexadecimalDigit(int c) __attribute__((always_inline)); -inline int toAscii(int c) __attribute__((always_inline)); -inline int toLowerCase(int c) __attribute__((always_inline)); -inline int toUpperCase(int c)__attribute__((always_inline)); - - -// Checks for an alphanumeric character. -// It is equivalent to (isalpha(c) || isdigit(c)). -inline bool isAlphaNumeric(int c) -{ - return ( isalnum(c) == 0 ? false : true); -} - - -// Checks for an alphabetic character. -// It is equivalent to (isupper(c) || islower(c)). -inline bool isAlpha(int c) -{ - return ( isalpha(c) == 0 ? false : true); -} - - -// Checks whether c is a 7-bit unsigned char value -// that fits into the ASCII character set. -inline bool isAscii(int c) -{ - return ((c & ~0x7f) != 0 ? false : true ); -} - - -// Checks for a blank character, that is, a space or a tab. -inline bool isWhitespace(int c) -{ - return ( c == '\t' || c == ' '); -} - - -// Checks for a control character. -inline bool isControl(int c) -{ - return ( iscntrl (c) == 0 ? false : true); -} - - -// Checks for a digit (0 through 9). -inline bool isDigit(int c) -{ - return ( isdigit (c) == 0 ? false : true); -} - - -// Checks for any printable character except space. -inline bool isGraph(int c) -{ - return ( isgraph (c) == 0 ? false : true); -} - - -// Checks for a lower-case character. -inline bool isLowerCase(int c) -{ - return ( c >= 'a' && c <= 'z' ); -} - - -// Checks for any printable character including space. -inline bool isPrintable(int c) -{ - return ( isprint (c) == 0 ? false : true); -} - - -// Checks for any printable character which is not a space -// or an alphanumeric character. -inline bool isPunct(int c) -{ - return ( isPrintable(c) && !isSpace(c) && !isAlphaNumeric(c) ); -} - - -// Checks for white-space characters. For the avr-libc library, -// these are: space, formfeed ('\f'), newline ('\n'), carriage -// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). -inline bool isSpace(int c) -{ - return ( isspace (c) == 0 ? false : true); -} - - -// Checks for an uppercase letter. -inline bool isUpperCase(int c) -{ - return ( isupper (c) == 0 ? false : true); -} - - -// Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7 -// 8 9 a b c d e f A B C D E F. -inline bool isHexadecimalDigit(int c) -{ - return ( isxdigit (c) == 0 ? false : true); -} - - -// Converts c to a 7-bit unsigned char value that fits into the -// ASCII character set, by clearing the high-order bits. -inline int toAscii(int c) -{ - return (c & 0x7f); -} - - -// Warning: -// Many people will be unhappy if you use this function. -// This function will convert accented letters into random -// characters. - -// Converts the letter c to lower case, if possible. -inline int toLowerCase(int c) -{ - return tolower (c); -} - - -// Converts the letter c to upper case, if possible. -inline int toUpperCase(int c) -{ - return toupper (c); -} - -} -#endif \ No newline at end of file diff --git a/ArduinoCore-API/api/deprecated-avr-comp/avr/dtostrf.c.impl b/ArduinoCore-API/api/deprecated-avr-comp/avr/dtostrf.c.impl deleted file mode 100644 index f410886..0000000 --- a/ArduinoCore-API/api/deprecated-avr-comp/avr/dtostrf.c.impl +++ /dev/null @@ -1,40 +0,0 @@ -/* - dtostrf - Emulation for dtostrf function from avr-libc - Copyright (c) 2016 Arduino LLC. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -// This is a default implementation for dtostrf function. -// This file should be used if the standard lib doesn't provide an -// implementation of dtostrf. - -// Create a file called "dtostrf.c" with the following include: -// #include "api/deprecated-avr-comp/avr/dtostrf.c.impl" - -#include - -char *dtostrf (double val, signed char width, unsigned char prec, char *sout) { - asm(".global _printf_float"); - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - char fmt[20]; - sprintf(fmt, "%%%d.%df", width, prec); - sprintf(sout, fmt, val); - return sout; -#pragma GCC diagnostic pop -} - diff --git a/ArduinoCore-API/api/deprecated-avr-comp/avr/dtostrf.h b/ArduinoCore-API/api/deprecated-avr-comp/avr/dtostrf.h deleted file mode 100644 index 2d287ca..0000000 --- a/ArduinoCore-API/api/deprecated-avr-comp/avr/dtostrf.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - dtostrf - Emulation for dtostrf function from avr-libc - Copyright (c) 2015 Arduino LLC. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -#if !defined(ARDUINO_ARCH_AVR) - -#ifdef __cplusplus -extern "C" { -#endif - -char *dtostrf(double val, signed char width, unsigned char prec, char *sout); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ArduinoCore-API/api/deprecated-avr-comp/avr/interrupt.h b/ArduinoCore-API/api/deprecated-avr-comp/avr/interrupt.h deleted file mode 100644 index a2873cf..0000000 --- a/ArduinoCore-API/api/deprecated-avr-comp/avr/interrupt.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - Copyright (c) 2015 Arduino LCC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -/* - Empty file. - This file is here to allow compatibility with sketches (made for AVR) - that include -*/ diff --git a/ArduinoCore-API/api/deprecated-avr-comp/avr/pgmspace.h b/ArduinoCore-API/api/deprecated-avr-comp/avr/pgmspace.h deleted file mode 100644 index a80e4a5..0000000 --- a/ArduinoCore-API/api/deprecated-avr-comp/avr/pgmspace.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - pgmspace.h - Definitions for compatibility with AVR pgmspace macros - - Copyright (c) 2015 Arduino LLC - - Based on work of Paul Stoffregen on Teensy 3 (http://pjrc.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE -*/ - -#ifndef __PGMSPACE_H_ -#define __PGMSPACE_H_ 1 - -#include - -#define PROGMEM -#define __ATTR_PROGMEM__ -#define PGM_P const char * -#define PGM_VOID_P const void * -#define PSTR(str) (str) - -#define _SFR_BYTE(n) (n) - -typedef void prog_void; -typedef char prog_char; -typedef unsigned char prog_uchar; -typedef int8_t prog_int8_t; -typedef uint8_t prog_uint8_t; -typedef int16_t prog_int16_t; -typedef uint16_t prog_uint16_t; -typedef int32_t prog_int32_t; -typedef uint32_t prog_uint32_t; -typedef int64_t prog_int64_t; -typedef uint64_t prog_uint64_t; - -typedef const void* int_farptr_t; -typedef const void* uint_farptr_t; - -#define memchr_P(s, c, n) memchr((s), (c), (n)) -#define memcmp_P(s1, s2, n) memcmp((s1), (s2), (n)) -#define memccpy_P(dest, src, c, n) memccpy((dest), (src), (c), (n)) -#define memcpy_P(dest, src, n) memcpy((dest), (src), (n)) -#define memmem_P(haystack, haystacklen, needle, needlelen) memmem((haystack), (haystacklen), (needle), (needlelen)) -#define memrchr_P(s, c, n) memrchr((s), (c), (n)) -#define strcat_P(dest, src) strcat((dest), (src)) -#define strchr_P(s, c) strchr((s), (c)) -#define strchrnul_P(s, c) strchrnul((s), (c)) -#define strcmp_P(a, b) strcmp((a), (b)) -#define strcpy_P(dest, src) strcpy((dest), (src)) -#define strcasecmp_P(s1, s2) strcasecmp((s1), (s2)) -#define strcasestr_P(haystack, needle) strcasestr((haystack), (needle)) -#define strcspn_P(s, accept) strcspn((s), (accept)) -#define strlcat_P(s1, s2, n) strlcat((s1), (s2), (n)) -#define strlcpy_P(s1, s2, n) strlcpy((s1), (s2), (n)) -#define strlen_P(a) strlen((a)) -#define strnlen_P(s, n) strnlen((s), (n)) -#define strncmp_P(s1, s2, n) strncmp((s1), (s2), (n)) -#define strncasecmp_P(s1, s2, n) strncasecmp((s1), (s2), (n)) -#define strncat_P(s1, s2, n) strncat((s1), (s2), (n)) -#define strncpy_P(s1, s2, n) strncpy((s1), (s2), (n)) -#define strpbrk_P(s, accept) strpbrk((s), (accept)) -#define strrchr_P(s, c) strrchr((s), (c)) -#define strsep_P(sp, delim) strsep((sp), (delim)) -#define strspn_P(s, accept) strspn((s), (accept)) -#define strstr_P(a, b) strstr((a), (b)) -#define strtok_P(s, delim) strtok((s), (delim)) -#define strtok_rP(s, delim, last) strtok((s), (delim), (last)) - -#define strlen_PF(a) strlen((a)) -#define strnlen_PF(src, len) strnlen((src), (len)) -#define memcpy_PF(dest, src, len) memcpy((dest), (src), (len)) -#define strcpy_PF(dest, src) strcpy((dest), (src)) -#define strncpy_PF(dest, src, len) strncpy((dest), (src), (len)) -#define strcat_PF(dest, src) strcat((dest), (src)) -#define strlcat_PF(dest, src, len) strlcat((dest), (src), (len)) -#define strncat_PF(dest, src, len) strncat((dest), (src), (len)) -#define strcmp_PF(s1, s2) strcmp((s1), (s2)) -#define strncmp_PF(s1, s2, n) strncmp((s1), (s2), (n)) -#define strcasecmp_PF(s1, s2) strcasecmp((s1), (s2)) -#define strncasecmp_PF(s1, s2, n) strncasecmp((s1), (s2), (n)) -#define strstr_PF(s1, s2) strstr((s1), (s2)) -#define strlcpy_PF(dest, src, n) strlcpy((dest), (src), (n)) -#define memcmp_PF(s1, s2, n) memcmp((s1), (s2), (n)) - -#define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__) -#define snprintf_P(s, f, ...) snprintf((s), (f), __VA_ARGS__) - -#define pgm_read_byte(addr) (*(const unsigned char *)(addr)) -#define pgm_read_word(addr) (*(const unsigned short *)(addr)) -#define pgm_read_dword(addr) (*(const unsigned long *)(addr)) -#define pgm_read_float(addr) (*(const float *)(addr)) -#define pgm_read_ptr(addr) (*(void *const *)(addr)) - -#define pgm_read_byte_near(addr) pgm_read_byte(addr) -#define pgm_read_word_near(addr) pgm_read_word(addr) -#define pgm_read_dword_near(addr) pgm_read_dword(addr) -#define pgm_read_float_near(addr) pgm_read_float(addr) -#define pgm_read_ptr_near(addr) pgm_read_ptr(addr) - -#define pgm_read_byte_far(addr) pgm_read_byte(addr) -#define pgm_read_word_far(addr) pgm_read_word(addr) -#define pgm_read_dword_far(addr) pgm_read_dword(addr) -#define pgm_read_float_far(addr) pgm_read_float(addr) -#define pgm_read_ptr_far(addr) pgm_read_ptr(addr) - -#define pgm_get_far_address(addr) (&(addr)) - -#endif diff --git a/ArduinoCore-API/api/deprecated/Client.h b/ArduinoCore-API/api/deprecated/Client.h deleted file mode 100644 index 84981c7..0000000 --- a/ArduinoCore-API/api/deprecated/Client.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -// including Client.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be removed on the next -// major release of the API -#include "../Client.h" - - diff --git a/ArduinoCore-API/api/deprecated/HardwareSerial.h b/ArduinoCore-API/api/deprecated/HardwareSerial.h deleted file mode 100644 index 0ed7d7a..0000000 --- a/ArduinoCore-API/api/deprecated/HardwareSerial.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -// including HardwareSerial.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be removed on the next -// major release of the API -#include "../HardwareSerial.h" - - diff --git a/ArduinoCore-API/api/deprecated/IPAddress.h b/ArduinoCore-API/api/deprecated/IPAddress.h deleted file mode 100644 index 4c03574..0000000 --- a/ArduinoCore-API/api/deprecated/IPAddress.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -// including IPAddress.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be removed on the next -// major release of the API -#include "../IPAddress.h" - - diff --git a/ArduinoCore-API/api/deprecated/Print.h b/ArduinoCore-API/api/deprecated/Print.h deleted file mode 100644 index a0d1bd1..0000000 --- a/ArduinoCore-API/api/deprecated/Print.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -// including Print.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be removed on the next -// major release of the API -#include "../Print.h" - diff --git a/ArduinoCore-API/api/deprecated/Printable.h b/ArduinoCore-API/api/deprecated/Printable.h deleted file mode 100644 index b6888c1..0000000 --- a/ArduinoCore-API/api/deprecated/Printable.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -// including Printable.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be removed on the next -// major release of the API -#include "../Printable.h" - diff --git a/ArduinoCore-API/api/deprecated/Server.h b/ArduinoCore-API/api/deprecated/Server.h deleted file mode 100644 index 65b544b..0000000 --- a/ArduinoCore-API/api/deprecated/Server.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -// including Server.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be removed on the next -// major release of the API -#include "../Server.h" - - diff --git a/ArduinoCore-API/api/deprecated/Stream.h b/ArduinoCore-API/api/deprecated/Stream.h deleted file mode 100644 index 4118ccb..0000000 --- a/ArduinoCore-API/api/deprecated/Stream.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -// including Stream.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be removed on the next -// major release of the API -#include "../Stream.h" - - diff --git a/ArduinoCore-API/api/deprecated/Udp.h b/ArduinoCore-API/api/deprecated/Udp.h deleted file mode 100644 index f03a64b..0000000 --- a/ArduinoCore-API/api/deprecated/Udp.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -// including Udp.h is deprecated, for all future projects use Arduino.h instead - -// This include is added for compatibility, it will be removed on the next -// major release of the API -#include "../Udp.h" - - diff --git a/ArduinoCore-API/api/itoa.h b/ArduinoCore-API/api/itoa.h deleted file mode 100644 index c207783..0000000 --- a/ArduinoCore-API/api/itoa.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - itoa.h - Integer to ASCII conversion - Copyright (c) 2016 Arduino LLC. All right reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#pragma once - -// Standard C functions required in Arduino API -// If these functions are not provided by the standard library, the -// core should supply an implementation of them. - -#ifdef __cplusplus -extern "C" { -#endif - -extern char* itoa(int value, char *string, int radix); -extern char* ltoa(long value, char *string, int radix); -extern char* utoa(unsigned value, char *string, int radix); -extern char* ultoa(unsigned long value, char *string, int radix); - -#ifdef __cplusplus -} // extern "C" -#endif - diff --git a/ArduinoCore-API/test/.gitignore b/ArduinoCore-API/test/.gitignore deleted file mode 100644 index faa6a97..0000000 --- a/ArduinoCore-API/test/.gitignore +++ /dev/null @@ -1,19 +0,0 @@ -build -### CMake ### -CMakeLists.txt.user -CMakeCache.txt -CMakeFiles -CMakeScripts -Testing -Makefile -cmake_install.cmake -install_manifest.txt -compile_commands.json -CTestTestfile.cmake -_deps - -### CMake Patch ### -CMakeUserPresets.json - -# External projects -*-prefix/ diff --git a/ArduinoCore-API/test/CMakeLists.txt b/ArduinoCore-API/test/CMakeLists.txt deleted file mode 100644 index 072b590..0000000 --- a/ArduinoCore-API/test/CMakeLists.txt +++ /dev/null @@ -1,158 +0,0 @@ -# SPDX-License-Identifier: LGPL-2.1-or-later - -########################################################################## - -cmake_minimum_required(VERSION 2.8) - -########################################################################## - -project(test-ArduinoCore-API) - -Include(FetchContent) - -FetchContent_Declare( - Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.4.0 -) - -FetchContent_MakeAvailable(Catch2) - -########################################################################## - -include_directories(..) -include_directories(include) - -########################################################################## - -set(CMAKE_CXX_STANDARD 11) - -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) - -########################################################################## - -set(TEST_TARGET ${CMAKE_PROJECT_NAME}) - -########################################################################## - -set(TEST_SRCS - src/CanMsg/test_CanMsg.cpp - src/CanMsg/test_CanMsg_CopyCtor.cpp - src/CanMsg/test_CanExtendedId.cpp - src/CanMsg/test_CanStandardId.cpp - src/CanMsg/test_isExtendedId.cpp - src/CanMsg/test_isStandardId.cpp - src/CanMsg/test_operator_assignment.cpp - src/CanMsg/test_printTo.cpp - src/CanMsgRingbuffer/test_available.cpp - src/Common/test_makeWord.cpp - src/Common/test_map.cpp - src/Common/test_max.cpp - src/Common/test_min.cpp - src/IPAddress/test_toString.cpp - src/IPAddress/test_fromString.cpp - src/IPAddress/test_fromString6.cpp - src/IPAddress/test_IPAddress.cpp - src/IPAddress/test_IPAddress6.cpp - src/IPAddress/test_operator_assignment.cpp - src/IPAddress/test_operator_comparison.cpp - src/IPAddress/test_operator_comparison6.cpp - src/IPAddress/test_operator_parentheses.cpp - src/IPAddress/test_operator_parentheses6.cpp - src/IPAddress/test_printTo.cpp - src/IPAddress/test_printTo6.cpp - src/Print/test_clearWriteError.cpp - src/Print/test_getWriteError.cpp - src/Print/test_print.cpp - src/Print/test_println.cpp - src/Print/test_availableForWrite.cpp - src/Ringbuffer/test_available.cpp - src/Ringbuffer/test_availableForStore.cpp - src/Ringbuffer/test_clear.cpp - src/Ringbuffer/test_isFull.cpp - src/Ringbuffer/test_peek.cpp - src/Ringbuffer/test_read_char.cpp - src/Ringbuffer/test_store_char.cpp - src/Stream/test_find.cpp - src/Stream/test_findUntil.cpp - src/Stream/test_getTimeout.cpp - src/Stream/test_parseFloat.cpp - src/Stream/test_parseInt.cpp - src/Stream/test_readBytes.cpp - src/Stream/test_readBytesUntil.cpp - src/Stream/test_readString.cpp - src/Stream/test_readStringUntil.cpp - src/Stream/test_setTimeout.cpp - src/String/test_concat.cpp - src/String/test_operators.cpp - src/String/test_compareTo.cpp - src/String/test_comparisonFunc.cpp - src/String/test_characterAccessFunc.cpp - src/String/test_substring.cpp - src/String/test_indexOf.cpp - src/String/test_lastIndexOf.cpp - src/String/test_length.cpp - src/String/test_move.cpp - src/String/test_remove.cpp - src/String/test_replace.cpp - src/String/test_String.cpp - src/String/test_toDouble.cpp - src/String/test_toFloat.cpp - src/String/test_toInt.cpp - src/String/test_toLowerCase.cpp - src/String/test_toUpperCase.cpp - src/String/test_trim.cpp - src/WCharacter/test_isAscii.cpp - src/WCharacter/test_isControl.cpp - src/WCharacter/test_isDigit.cpp - src/WCharacter/test_isHexadecimalDigit.cpp - src/WCharacter/test_isLowerCase.cpp - src/WCharacter/test_isPunct.cpp - src/WCharacter/test_isSpace.cpp - src/WCharacter/test_isUpperCase.cpp - src/WCharacter/test_isWhitespace.cpp - src/WCharacter/test_toAscii.cpp -) - -set(TEST_DUT_SRCS - ../api/CanMsg.cpp - ../api/CanMsgRingbuffer.cpp - ../api/Common.cpp - ../api/IPAddress.cpp - ../api/String.cpp - ../api/Stream.cpp - ../api/Print.cpp -) - -########################################################################## - -set(TEST_TARGET_SRCS - src/dtostrf.cpp - src/itoa.cpp - src/MillisFake.cpp - src/PrintMock.cpp - src/StreamMock.cpp - ${TEST_SRCS} - ${TEST_DUT_SRCS} -) - -########################################################################## - -add_compile_definitions(HOST) -add_compile_options(-Wall -Wextra -Wpedantic -Werror -Wno-self-move) -#add_compile_options(-Wno-cast-function-type) - -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -Wno-deprecated-copy") - -########################################################################## - -add_executable( - ${TEST_TARGET} - ${TEST_TARGET_SRCS} -) - -target_link_libraries( ${TEST_TARGET} Catch2WithMain ) - -########################################################################## - diff --git a/ArduinoCore-API/test/include/MillisFake.h b/ArduinoCore-API/test/include/MillisFake.h deleted file mode 100644 index bdb3f14..0000000 --- a/ArduinoCore-API/test/include/MillisFake.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#ifndef MILLIS_FAKE_H_ -#define MILLIS_FAKE_H_ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -/************************************************************************************** - * FUNCTION DECLARATION - **************************************************************************************/ - -#ifdef __cplusplus -extern "C" { -#endif - -void millis_autoOn(); -void millis_autoOff(); -void set_millis(unsigned long const val); - -#ifdef __cplusplus -} -#endif - -#endif /* MILLIS_FAKE_H_ */ \ No newline at end of file diff --git a/ArduinoCore-API/test/include/PrintMock.h b/ArduinoCore-API/test/include/PrintMock.h deleted file mode 100644 index 9a10384..0000000 --- a/ArduinoCore-API/test/include/PrintMock.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#ifndef PRINT_MOCK_H_ -#define PRINT_MOCK_H_ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * CLASS DECLARATION - **************************************************************************************/ - -class PrintMock : public Print -{ -public: - std::string _str; - virtual size_t write(uint8_t b) override; - void mock_setWriteError() { setWriteError(); } - void mock_setWriteError(int err) { setWriteError(err); } -}; - -#endif /* PRINT_MOCK_H_ */ diff --git a/ArduinoCore-API/test/include/PrintableMock.h b/ArduinoCore-API/test/include/PrintableMock.h deleted file mode 100644 index f55540d..0000000 --- a/ArduinoCore-API/test/include/PrintableMock.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#ifndef PRINTABLE_MOCK_H_ -#define PRINTABLE_MOCK_H_ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * CLASS DECLARATION - **************************************************************************************/ - -class PrintableMock : public arduino::Printable -{ -public: - int _i; - virtual size_t printTo(arduino::Print& p) const override - { - size_t written = 0; - written += p.print("PrintableMock i = "); - written += p.print(_i); - return written; - } -}; - -#endif /* PRINTABLE_MOCK_H_ */ diff --git a/ArduinoCore-API/test/include/StreamMock.h b/ArduinoCore-API/test/include/StreamMock.h deleted file mode 100644 index afa4b48..0000000 --- a/ArduinoCore-API/test/include/StreamMock.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#ifndef STREAM_MOCK_H_ -#define STREAM_MOCK_H_ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * CLASS DECLARATION - **************************************************************************************/ - -class StreamMock : public arduino::Stream -{ -public: - - void operator << (char const * str); - - virtual size_t write(uint8_t ch) override; - virtual int available() override; - virtual int read() override; - virtual int peek() override; - -private: - std::deque _stream; - -}; - -#endif /* STREAM_MOCK_H_ */ diff --git a/ArduinoCore-API/test/src/CanMsg/test_CanExtendedId.cpp b/ArduinoCore-API/test/src/CanMsg/test_CanExtendedId.cpp deleted file mode 100644 index caf7bcc..0000000 --- a/ArduinoCore-API/test/src/CanMsg/test_CanExtendedId.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Verify correct conversion to 29-Bit CAN ID for lowest valid 29-Bit CAN ID", "[CanMsg-CanExtendedId-01]") -{ - REQUIRE(CanExtendedId(0) == (CanMsg::CAN_EFF_FLAG | 0U)); -} - -TEST_CASE ("Verify correct conversion to 29-Bit CAN ID for highest valid 29-Bit CAN ID", "[CanMsg-CanExtendedId-02]") -{ - REQUIRE(CanExtendedId(0x1FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU)); -} - -TEST_CASE ("Verify capping of CAN IDs exceeding 29-Bit CAN ID range", "[CanMsg-CanExtendedId-03]") -{ - REQUIRE(CanExtendedId(0x2FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x0FFFFFFFU)); - REQUIRE(CanExtendedId(0x3FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU)); - REQUIRE(CanExtendedId(0x4FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x0FFFFFFFU)); - REQUIRE(CanExtendedId(0x5FFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU)); - /* ... */ - REQUIRE(CanExtendedId(0xFFFFFFFFU) == (CanMsg::CAN_EFF_FLAG | 0x1FFFFFFFU)); -} diff --git a/ArduinoCore-API/test/src/CanMsg/test_CanMsg.cpp b/ArduinoCore-API/test/src/CanMsg/test_CanMsg.cpp deleted file mode 100644 index 1394eee..0000000 --- a/ArduinoCore-API/test/src/CanMsg/test_CanMsg.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Test constructor with no data (data length = 0)", "[CanMsg-CanMsg-01]") -{ - CanMsg const msg(CanStandardId(0x20), 0, nullptr); - - REQUIRE(msg.data_length == 0); - for (size_t i = 0; i < CanMsg::MAX_DATA_LENGTH; i++) - REQUIRE(msg.data[i] == 0); -} - -TEST_CASE ("Test constructor with data (data length < CanMsg::MAX_DATA_LENGTH)", "[CanMsg-CanMsg-02]") -{ - uint8_t const msg_data[4] = {0xDE, 0xAD, 0xC0, 0xDE}; - - CanMsg const msg(CanStandardId(0x20), sizeof(msg_data), msg_data); - - REQUIRE(msg.data_length == 4); - for (size_t i = 0; i < msg.data_length; i++) - REQUIRE(msg.data[i] == msg_data[i]); -} - -TEST_CASE ("Test constructor with data (data length > CanMsg::MAX_DATA_LENGTH)", "[CanMsg-CanMsg-03]") -{ - uint8_t const msg_data[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; - - CanMsg const msg(CanStandardId(0x20), sizeof(msg_data), msg_data); - - REQUIRE(msg.data_length == 8); - for (size_t i = 0; i < msg.data_length; i++) - REQUIRE(msg.data[i] == msg_data[i]); -} - -TEST_CASE ("Test constructor constructing a CAN frame with standard ID", "[CanMsg-CanMsg-04]") -{ - CanMsg const msg(CanStandardId(0x20), 0, nullptr); - - REQUIRE(msg.id == 0x20); -} - -TEST_CASE ("Test constructor constructing a CAN frame with extended ID", "[CanMsg-CanMsg-05]") -{ - CanMsg const msg(CanExtendedId(0x20), 0, nullptr); - - REQUIRE(msg.id == (CanMsg::CAN_EFF_FLAG | 0x20)); -} diff --git a/ArduinoCore-API/test/src/CanMsg/test_CanMsg_CopyCtor.cpp b/ArduinoCore-API/test/src/CanMsg/test_CanMsg_CopyCtor.cpp deleted file mode 100644 index c787815..0000000 --- a/ArduinoCore-API/test/src/CanMsg/test_CanMsg_CopyCtor.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Test copy constructor", "[CanMsg-CopyCtor-01]") -{ - uint8_t const msg_data[4] = {0xDE, 0xAD, 0xC0, 0xDE}; - - CanMsg const msg_1(CanStandardId(0x20), sizeof(msg_data), msg_data); - CanMsg const msg_2(msg_1); - - REQUIRE(msg_1.data_length == msg_2.data_length); - - for (size_t i = 0; i < msg_1.data_length; i++) - { - REQUIRE(msg_1.data[i] == msg_data[i]); - REQUIRE(msg_2.data[i] == msg_data[i]); - } -} diff --git a/ArduinoCore-API/test/src/CanMsg/test_CanStandardId.cpp b/ArduinoCore-API/test/src/CanMsg/test_CanStandardId.cpp deleted file mode 100644 index 23b862f..0000000 --- a/ArduinoCore-API/test/src/CanMsg/test_CanStandardId.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Verify correct conversion to 11-Bit CAN ID for lowest valid 11-Bit CAN ID", "[CanMsg-CanStandardId-01]") -{ - REQUIRE(CanStandardId(0) == 0U); -} - -TEST_CASE ("Verify correct conversion to 11-Bit CAN ID for highest valid 11-Bit CAN ID", "[CanMsg-CanStandardId-02]") -{ - REQUIRE(CanStandardId(0x7FF) == 0x7FF); -} - -TEST_CASE ("Verify capping of CAN IDs exceeding 11-Bit CAN ID range", "[CanMsg-CanStandardId-03]") -{ - REQUIRE(CanStandardId(0x800U) == 0x000U); - REQUIRE(CanStandardId(0x801U) == 0x001U); - REQUIRE(CanStandardId(0x8FFU) == 0x0FFU); - REQUIRE(CanStandardId(0x1FFFFFFFU) == 0x7FFU); - REQUIRE(CanStandardId(0xFFFFFFFFU) == 0x7FFU); -} diff --git a/ArduinoCore-API/test/src/CanMsg/test_isExtendedId.cpp b/ArduinoCore-API/test/src/CanMsg/test_isExtendedId.cpp deleted file mode 100644 index 7c3dd47..0000000 --- a/ArduinoCore-API/test/src/CanMsg/test_isExtendedId.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("\"isExtendedId\" should return true for extended CAN ID", "[CanMsg-isExtendedId-01]") -{ - CanMsg const msg_ext_id(CanExtendedId(0x020), 0, nullptr); - REQUIRE(msg_ext_id.isExtendedId() == true); -} - -TEST_CASE ("\"isExtendedId\" should return false for standard CAN ID", "[CanMsg-isExtendedId-02]") -{ - CanMsg const msg_std_id(CanStandardId(0x020), 0, nullptr); - REQUIRE(msg_std_id.isExtendedId() == false); -} diff --git a/ArduinoCore-API/test/src/CanMsg/test_isStandardId.cpp b/ArduinoCore-API/test/src/CanMsg/test_isStandardId.cpp deleted file mode 100644 index 00fee64..0000000 --- a/ArduinoCore-API/test/src/CanMsg/test_isStandardId.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("\"isStandardId\" should return true for standard CAN ID", "[CanMsg-isStandardId-01]") -{ - CanMsg const msg_std_id(CanStandardId(0x020), 0, nullptr); - REQUIRE(msg_std_id.isStandardId() == true); -} - -TEST_CASE ("\"isStandardId\" should return false for extended CAN ID", "[CanMsg-isStandardId-02]") -{ - CanMsg const msg_ext_id(CanExtendedId(0x020), 0, nullptr); - REQUIRE(msg_ext_id.isStandardId() == false); -} diff --git a/ArduinoCore-API/test/src/CanMsg/test_operator_assignment.cpp b/ArduinoCore-API/test/src/CanMsg/test_operator_assignment.cpp deleted file mode 100644 index 7bdde6c..0000000 --- a/ArduinoCore-API/test/src/CanMsg/test_operator_assignment.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing CanMsg::operator = (CanMsg const &)", "[CanMsg-Operator-=-1]") -{ - uint8_t const msg_data[4] = {0xDE, 0xAD, 0xC0, 0xDE}; - - CanMsg const msg_1(CanStandardId(0x20), sizeof(msg_data), msg_data); - CanMsg msg_2(CanStandardId(0x21), 0, nullptr); - - msg_2 = msg_1; - - REQUIRE(msg_1.data_length == msg_2.data_length); - - for (size_t i = 0; i < msg_1.data_length; i++) - { - REQUIRE(msg_1.data[i] == msg_data[i]); - REQUIRE(msg_2.data[i] == msg_data[i]); - } -} diff --git a/ArduinoCore-API/test/src/CanMsg/test_printTo.cpp b/ArduinoCore-API/test/src/CanMsg/test_printTo.cpp deleted file mode 100644 index a434bdf..0000000 --- a/ArduinoCore-API/test/src/CanMsg/test_printTo.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * NAMESPACE - **************************************************************************************/ - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print CAN frame with standard ID", "[CanMsg-printTo-1]") -{ - uint8_t const std_msg_data[] = {0xBE, 0xEF}; - CanMsg const std_msg(CanStandardId(0x20), sizeof(std_msg_data), std_msg_data); - - PrintMock mock; - mock.print(std_msg); - - REQUIRE(mock._str == "[020] (2) : BEEF"); -} - -TEST_CASE ("Print CAN frame with extended ID", "[CanMsg-printTo-2]") -{ - uint8_t const ext_msg_data[] = {0xDE, 0xAD, 0xC0, 0xDE}; - CanMsg const ext_msg(CanExtendedId(0x20), sizeof(ext_msg_data), ext_msg_data); - - PrintMock mock; - mock.print(ext_msg); - - REQUIRE(mock._str == "[00000020] (4) : DEADC0DE"); -} diff --git a/ArduinoCore-API/test/src/CanMsgRingbuffer/test_available.cpp b/ArduinoCore-API/test/src/CanMsgRingbuffer/test_available.cpp deleted file mode 100644 index f843a67..0000000 --- a/ArduinoCore-API/test/src/CanMsgRingbuffer/test_available.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("'available' should return 0 for empty CanMsg ring buffer", "[CanMsgRingbuffer-available-01]") -{ - arduino::CanMsgRingbuffer ringbuffer; - REQUIRE(ringbuffer.available() == 0); -} - -TEST_CASE ("'available' should return number of elements in CanMsg ringbuffer", "[CanMsgRingbuffer-available-02]") -{ - arduino::CanMsgRingbuffer ringbuffer; - arduino::CanMsg msg; - ringbuffer.enqueue(msg); - REQUIRE(ringbuffer.available() == 1); - ringbuffer.enqueue(msg); - REQUIRE(ringbuffer.available() == 2); - ringbuffer.dequeue(); - REQUIRE(ringbuffer.available() == 1); -} diff --git a/ArduinoCore-API/test/src/Common/test_makeWord.cpp b/ArduinoCore-API/test/src/Common/test_makeWord.cpp deleted file mode 100644 index 2f1e706..0000000 --- a/ArduinoCore-API/test/src/Common/test_makeWord.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Calling 'makeWord(w)'", "[makeWord-01]") -{ - REQUIRE(makeWord(0xDEAD) == 0xDEAD); - REQUIRE(makeWord(0xDE) == 0x00DE); -} - -TEST_CASE ("Calling 'makeWord(h,l)'", "[makeWord-02]") -{ - REQUIRE(makeWord(0xDE, 0xAD) == 0xDEAD); -} - -TEST_CASE ("Calling 'word(...)'", "[makeWord-03]") -{ - REQUIRE(word(0xDEAD) == 0xDEAD); - REQUIRE(word(0xDE, 0xAD) == 0xDEAD); -} diff --git a/ArduinoCore-API/test/src/Common/test_map.cpp b/ArduinoCore-API/test/src/Common/test_map.cpp deleted file mode 100644 index bd2b584..0000000 --- a/ArduinoCore-API/test/src/Common/test_map.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' usage with reduction of output", "[map-01]") -{ - REQUIRE(map(50, 0, 100, 0, 10) == 5); -} - -TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' usage with increase of output", "[map-02]") -{ - REQUIRE(map(5, 0, 10, 0, 100) == 50); -} - -TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' where output is reduced to a value < 0", "[map-03]") -{ - REQUIRE(map(1, 0, 100, 0, 10) == 0); /* Would be 0.1 if we'd be using floating point. */ -} - -TEST_CASE ("Testing 'map(val, fromLow, fromHigh, toLow, toHigh)' default usage with negative values", "[map-04]") -{ - WHEN ("Negative 'from' values") - { - REQUIRE(map(0, 0, -256, 0, 1024) == 0); - REQUIRE(map(-256, 0, -256, 0, 1024) == 1024); - REQUIRE(map(-128, 0, -256, 0, 1024) == 512); - } - WHEN ("Negative 'to' values") - { - REQUIRE(map(0, 0, 256, 0, -1024) == 0); - REQUIRE(map(256, 0, 256, 0, -1024) == -1024); - REQUIRE(map(128, 0, 256, 0, -1024) == -512); - } -} diff --git a/ArduinoCore-API/test/src/Common/test_max.cpp b/ArduinoCore-API/test/src/Common/test_max.cpp deleted file mode 100644 index 815f0ec..0000000 --- a/ArduinoCore-API/test/src/Common/test_max.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Calling 'max(a,b)' with a < b", "[max-01]") -{ - WHEN("a > 0 and b > 0") REQUIRE(max(1,5) == 5); - WHEN("a < 0 and b > 0") REQUIRE(max(-1,5) == 5); - WHEN("a < 0 and b < 0") REQUIRE(max(-5,-1) == -1); -} - -TEST_CASE ("Calling 'max(a,b)' with a > b", "[max-02]") -{ - WHEN("a > 0 and b > 0") REQUIRE(max(5,1) == 5); - WHEN("a > 0 and b < 0") REQUIRE(max(5,-1) == 5); - WHEN("a < 0 and b < 0") REQUIRE(max(-1,-5) == -1); -} - -TEST_CASE ("Calling 'max(a,b)' with a == b", "[max-03]") -{ - WHEN("a = b > 0") REQUIRE(max(5,5) == 5); - WHEN("a = b < 0") REQUIRE(max(-5,-5) == -5); - WHEN("a = b = 0") REQUIRE(max(0,0) == 0); -} - -TEST_CASE ("Calling 'max(a,b)' with type(a) != type(b)", "[max-04]") -{ - WHEN("type(A) = uint8_t, type(b) = uint16_t") - { - uint8_t const a = 32; - uint16_t const b = 10; - REQUIRE(typeid(max(a,b)) == typeid(int)); - } - WHEN("type(A) = uint16_t, type(b) = uint32_t") - { - uint16_t const a = 32; - uint32_t const b = 10; - REQUIRE(typeid(max(a,b)) == typeid(unsigned int)); - } - WHEN("type(A) = uint32_t, type(b) = uint64_t") - { - uint32_t const a = 32; - uint64_t const b = 10; - REQUIRE(typeid(max(a,b)) == typeid(uint64_t)); - } - WHEN("type(A) = int8_t, type(b) = int16_t") - { - int8_t const a = -32; - int16_t const b = -10; - REQUIRE(typeid(max(a,b)) == typeid(int)); - } - WHEN("type(A) = int16_t, type(b) = int32_t") - { - int16_t const a = -32; - int32_t const b = -10; - REQUIRE(typeid(max(a,b)) == typeid(int)); - } - WHEN("type(A) = int32_t, type(b) = int64_t") - { - int32_t const a = -32; - int64_t const b = -10; - REQUIRE(typeid(max(a,b)) == typeid(int64_t)); - } -} diff --git a/ArduinoCore-API/test/src/Common/test_min.cpp b/ArduinoCore-API/test/src/Common/test_min.cpp deleted file mode 100644 index b37158f..0000000 --- a/ArduinoCore-API/test/src/Common/test_min.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Calling 'min(a,b)' with a < b", "[min-01]") -{ - WHEN("a > 0 and b > 0") REQUIRE(min(1,5) == 1); - WHEN("a < 0 and b > 0") REQUIRE(min(-1,5) == -1); - WHEN("a < 0 and b < 0") REQUIRE(min(-5,-1) == -5); -} - -TEST_CASE ("Calling 'min(a,b)' with a > b", "[min-02]") -{ - WHEN("a > 0 and b > 0") REQUIRE(min(5,1) == 1); - WHEN("a > 0 and b < 0") REQUIRE(min(5,-1) == -1); - WHEN("a < 0 and b < 0") REQUIRE(min(-1,-5) == -5); -} - -TEST_CASE ("Calling 'min(a,b)' with a == b", "[min-03]") -{ - WHEN("a = b > 0") REQUIRE(min(5,5) == 5); - WHEN("a = b < 0") REQUIRE(min(-5,-5) == -5); - WHEN("a = b = 0") REQUIRE(min(0,0) == 0); -} - -TEST_CASE ("Calling 'min(a,b)' with type(a) != type(b)", "[min-04]") -{ - WHEN("type(A) = uint8_t, type(b) = uint16_t") - { - uint8_t const a = 32; - uint16_t const b = 10; - REQUIRE(typeid(min(a,b)) == typeid(int)); - } - WHEN("type(A) = uint16_t, type(b) = uint32_t") - { - uint16_t const a = 32; - uint32_t const b = 10; - REQUIRE(typeid(min(a,b)) == typeid(unsigned int)); - } - WHEN("type(A) = uint32_t, type(b) = uint64_t") - { - uint32_t const a = 32; - uint64_t const b = 10; - REQUIRE(typeid(min(a,b)) == typeid(uint64_t)); - } - WHEN("type(A) = int8_t, type(b) = int16_t") - { - int8_t const a = -32; - int16_t const b = -10; - REQUIRE(typeid(min(a,b)) == typeid(int)); - } - WHEN("type(A) = int16_t, type(b) = int32_t") - { - int16_t const a = -32; - int32_t const b = -10; - REQUIRE(typeid(min(a,b)) == typeid(int)); - } - WHEN("type(A) = int32_t, type(b) = int64_t") - { - int32_t const a = -32; - int64_t const b = -10; - REQUIRE(typeid(min(a,b)) == typeid(int64_t)); - } -} diff --git a/ArduinoCore-API/test/src/IPAddress/test_IPAddress.cpp b/ArduinoCore-API/test/src/IPAddress/test_IPAddress.cpp deleted file mode 100644 index 848a2c7..0000000 --- a/ArduinoCore-API/test/src/IPAddress/test_IPAddress.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress() default constructor()", "[IPAddress-Ctor-01]") -{ - arduino::IPAddress ip; - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); -} - -TEST_CASE ("Testing IPAddress(o,o,o,o) constructor", "[IPAddress-Ctor-02]") -{ - arduino::IPAddress ip(129,168,1,2); - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} - -TEST_CASE ("Testing IPAddress(a) constructor", "[IPAddress-Ctor-03]") -{ - arduino::IPAddress ip(129 | (168 << 8) | (1 << 16) | (2 << 24)); - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} - -TEST_CASE ("Testing IPAddress(a *) constructor", "[IPAddress-Ctor-04]") -{ - uint8_t const ip_addr_array[] = {129,168,1,2}; - - arduino::IPAddress ip(ip_addr_array); - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} diff --git a/ArduinoCore-API/test/src/IPAddress/test_IPAddress6.cpp b/ArduinoCore-API/test/src/IPAddress/test_IPAddress6.cpp deleted file mode 100644 index fc48f4c..0000000 --- a/ArduinoCore-API/test/src/IPAddress/test_IPAddress6.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress(type) constructor()", "[IPAddress6-Ctor-01]") -{ - arduino::IPAddress ip (arduino::IPType::IPv6); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Testing IPAddress(o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o) constructor", "[IPAddress-Ctor6-02]") -{ - arduino::IPAddress ip(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} - -TEST_CASE ("Testing IPAddress(type, a *) constructor", "[IPAddress6-Ctor-03]") -{ - uint8_t const ip_addr_array[] = {0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc}; - arduino::IPAddress ip(arduino::IPType::IPv6, ip_addr_array); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} diff --git a/ArduinoCore-API/test/src/IPAddress/test_fromString.cpp b/ArduinoCore-API/test/src/IPAddress/test_fromString.cpp deleted file mode 100644 index 1e7795a..0000000 --- a/ArduinoCore-API/test/src/IPAddress/test_fromString.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Extract valid IP address 'fromString(const char *)'", "[IPAddress-fromString-01]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("129.168.1.2") == true); - - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} - -TEST_CASE ("Extract valid IP address 'fromString(const String &)'", "[IPAddress-fromString-02]") -{ - arduino::IPAddress ip; - - arduino::String const ip_addr_str("129.168.1.2"); - - REQUIRE(ip.fromString(ip_addr_str) == true); - - REQUIRE(ip[0] == 129); - REQUIRE(ip[1] == 168); - REQUIRE(ip[2] == 1); - REQUIRE(ip[3] == 2); -} - -TEST_CASE ("Extract invalid IP address 'fromString(const char *)'", "[IPAddress-fromString-03]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("") == false); - REQUIRE(ip.fromString("1") == false); - REQUIRE(ip.fromString("1.") == false); - REQUIRE(ip.fromString("1.1") == false); - REQUIRE(ip.fromString("1.1.") == false); - REQUIRE(ip.fromString("1.1.1") == false); - REQUIRE(ip.fromString("1.1.1.") == false); - REQUIRE(ip.fromString("...") == false); - REQUIRE(ip.fromString("256.1.1.1") == false); - REQUIRE(ip.fromString("a.1.1.1") == false); - REQUIRE(ip.fromString("-.1.1.1") == false); - REQUIRE(ip.fromString("-1.1.1.1") == false); -} diff --git a/ArduinoCore-API/test/src/IPAddress/test_fromString6.cpp b/ArduinoCore-API/test/src/IPAddress/test_fromString6.cpp deleted file mode 100644 index bb9f01b..0000000 --- a/ArduinoCore-API/test/src/IPAddress/test_fromString6.cpp +++ /dev/null @@ -1,397 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Extract valid IPv6 address 'fromString(const char *)'", "[IPAddress-fromString-01]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("2001:db8:102:304:506:708:90a:b0c") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} - -TEST_CASE ("Extract valid IPv6 address 'fromString(const String &)'", "[IPAddress-fromString-02]") -{ - arduino::IPAddress ip; - - arduino::String const ip_addr_str("2001:db8:102:304:506:708:90a:b0c"); - - REQUIRE(ip.fromString(ip_addr_str) == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} - -TEST_CASE ("Extract valid IPv6 any address", "[IPAddress-fromString-03]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("::") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Extract valid IPv6 localhost address", "[IPAddress-fromString-04]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("::1") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 1); -} - -TEST_CASE ("Extract valid IPv6 different length segments", "[IPAddress-fromString-05]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("abcd:ef1:23:0:4::") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0xab); - REQUIRE(ip[1] == 0xcd); - REQUIRE(ip[2] == 0xe); - REQUIRE(ip[3] == 0xf1); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0x23); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 4); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - - -TEST_CASE ("Extract valid IPv6 zero start", "[IPAddress-fromString-06]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("0:2:3:4:5:6:7:8") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 2); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 7); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 8); -} - - -TEST_CASE ("Extract valid IPv6 zero end", "[IPAddress-fromString-07]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("1:2:3:4:5:6:7:0") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 1); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 2); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 7); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - - -TEST_CASE ("Extract valid IPv6 two zero start", "[IPAddress-fromString-08]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("::3:4:5:6:7:0") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 7); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - - -TEST_CASE ("Extract valid IPv6 two zero end", "[IPAddress-fromString-9]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("0:2:3:4:5:6::") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 2); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -// Non-canonical - -TEST_CASE ("Extract valid IPv6 any full long form", "[IPAddress-fromString-10]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("0:0:0:0:0:0:0:0") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Extract valid IPv6 upper case", "[IPAddress-fromString-11]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("2001:DB8:102:304:506:708:90A:B0C") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0x20); - REQUIRE(ip[1] == 0x01); - REQUIRE(ip[2] == 0xd); - REQUIRE(ip[3] == 0xb8); - REQUIRE(ip[4] == 1); - REQUIRE(ip[5] == 2); - REQUIRE(ip[6] == 3); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 5); - REQUIRE(ip[9] == 6); - REQUIRE(ip[10] == 7); - REQUIRE(ip[11] == 8); - REQUIRE(ip[12] == 9); - REQUIRE(ip[13] == 0xa); - REQUIRE(ip[14] == 0xb); - REQUIRE(ip[15] == 0xc); -} - -TEST_CASE ("Extract valid IPv6 explicit start zero", "[IPAddress-fromString-10]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("0::") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Extract valid IPv6 explicit end zero", "[IPAddress-fromString-10]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("::0") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 0); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 0); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 0); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 0); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 0); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 0); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 0); -} - -TEST_CASE ("Extract valid IPv6 compression of one group of zero", "[IPAddress-fromString-10]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString("1::3:4:5:6:7:8") == true); - - REQUIRE(ip.type() == arduino::IPType::IPv6); - REQUIRE(ip[0] == 0); - REQUIRE(ip[1] == 1); - REQUIRE(ip[2] == 0); - REQUIRE(ip[3] == 0); - REQUIRE(ip[4] == 0); - REQUIRE(ip[5] == 3); - REQUIRE(ip[6] == 0); - REQUIRE(ip[7] == 4); - REQUIRE(ip[8] == 0); - REQUIRE(ip[9] == 5); - REQUIRE(ip[10] == 0); - REQUIRE(ip[11] == 6); - REQUIRE(ip[12] == 0); - REQUIRE(ip[13] == 7); - REQUIRE(ip[14] == 0); - REQUIRE(ip[15] == 8); -} - -// Invalid cases - -TEST_CASE ("Extract invalid IPv6 address", "[IPAddress-fromString-12]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.fromString(":::") == false); // three colons by self - REQUIRE(ip.fromString("::3:4:5:6::") == false); // two compressions - REQUIRE(ip.fromString("2001:db8:102:10304:506:708:90a:b0c") == false); // 5 character field - REQUIRE(ip.fromString("200x:db8:102:304:506:708:90a:b0c") == false); // invalid character - REQUIRE(ip.fromString("2001:db8:102:304::506:708:90a:b0c") == false); // double colon with 8 other fields (so not a compression) - REQUIRE(ip.fromString("2001:db8:102:304:::708:90a:b0c") == false); // three colons in middle - REQUIRE(ip.fromString("2001:db8:102:304:506:708:90a:b0c:d0e") == false); // 9 fields - REQUIRE(ip.fromString("2001:db8:102:304:506:708:90a:") == false); // missing last group (but has a colon) - REQUIRE(ip.fromString("2001:db8:102:304:506:708:90a") == false); // only seven groups - REQUIRE(ip.fromString("0:0:0:0:0:0:0:0:0") == false); // nine zeros - REQUIRE(ip.fromString("0:0:0:0:0:0:0:0:") == false); // extra colon - REQUIRE(ip.fromString("0:0:0:0:0:0:0:") == false); // missing last group (but has a colon) - REQUIRE(ip.fromString("0:0:0:0:0:0:0") == false); // only seven groups -} diff --git a/ArduinoCore-API/test/src/IPAddress/test_operator_assignment.cpp b/ArduinoCore-API/test/src/IPAddress/test_operator_assignment.cpp deleted file mode 100644 index 0d4e004..0000000 --- a/ArduinoCore-API/test/src/IPAddress/test_operator_assignment.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress::operator = (const uint8_t * a)", "[IPAddress-Operator-=-01]") -{ - arduino::IPAddress ip1; - uint8_t const ip2[] = {192,168,1,2}; - - ip1 = ip2; - REQUIRE(ip1 == arduino::IPAddress(192,168,1,2)); -} - -TEST_CASE ("Testing IPAddress::operator = (uint32_t a)", "[IPAddress-Operator-=-02]") -{ - arduino::IPAddress ip1; - uint32_t const ip2 = 192 | (168 << 8) | (1 << 16) | (2 << 24); - - ip1 = ip2; - // NOTE: Only correct on little-endian systems - REQUIRE(ip1 == arduino::IPAddress(192,168,1,2)); -} diff --git a/ArduinoCore-API/test/src/IPAddress/test_operator_comparison.cpp b/ArduinoCore-API/test/src/IPAddress/test_operator_comparison.cpp deleted file mode 100644 index 75139bf..0000000 --- a/ArduinoCore-API/test/src/IPAddress/test_operator_comparison.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress::operator == (IPAddress ip1, IPAddress ip2) with ip1 == ip2", "[IPAddress-Operator-==-01]") -{ - arduino::IPAddress ip1(129,168,1,2), ip2(129,168,1,2); - REQUIRE((ip1 == ip2) == true); -} - -TEST_CASE ("Testing IPAddress::operator == (IPAddress ip1, IPAddress ip2) with ip1 != ip2", "[IPAddress-Operator-==-02]") -{ - arduino::IPAddress ip1(129,168,1,2), ip2(10,0,0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPAddress::operator == (IPAddress ip1, uint8_t const * ip2) with ip1 == ip2", "[IPAddress-Operator-==-03]") -{ - arduino::IPAddress ip1(129,168,1,2); - uint8_t const ip2[] = {129,168,1,2}; - REQUIRE((ip1 == ip2) == true); -} - -TEST_CASE ("Testing IPAddress::operator == (IPAddress ip1, uint8_t const * ip2) with ip1 != ip2", "[IPAddress-Operator-==-04]") -{ - arduino::IPAddress ip1(129,168,1,2); - uint8_t const ip2[] = {10,0,0,1}; - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPAddress::operator != (IPAddress ip1, uint8_t const * ip2) with ip1 != ip2", "[IPAddress-Operator-==-05]") -{ - arduino::IPAddress ip1(129,168,1,2), ip2(10,0,0,1); - REQUIRE((ip1 != ip2) == true); -} - -TEST_CASE ("Testing IPAddress::operator != (IPAddress ip1, uint8_t const * ip2) with ip1 == ip2", "[IPAddress-Operator-==-05]") -{ - arduino::IPAddress ip1(129,168,1,2), ip2(129,168,1,2); - REQUIRE((ip1 != ip2) == false); -} diff --git a/ArduinoCore-API/test/src/IPAddress/test_operator_comparison6.cpp b/ArduinoCore-API/test/src/IPAddress/test_operator_comparison6.cpp deleted file mode 100644 index 1a50f25..0000000 --- a/ArduinoCore-API/test/src/IPAddress/test_operator_comparison6.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing two basic constructs the same", "[IPAddress6-Operator-==-01]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc), ip2(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - REQUIRE((ip1 == ip2) == true); -} - -TEST_CASE ("Testing two addresses different", "[IPAddress-Operator-==-02]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc), ip2(0xfd,0x12, 0x34,0x56, 0x78,0x9a, 0,1, 0,0, 0,0, 0,0, 0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing not equals different address is true", "[IPAddress-Operator-==-03]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc), ip2(0xfd,0x12, 0x34,0x56, 0x78,0x9a, 0,1, 0,0, 0,0, 0,0, 0,1); - REQUIRE((ip1 != ip2) == true); -} - -TEST_CASE ("Testing not equals same address is false", "[IPAddress-Operator-==-04]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc), ip2(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - REQUIRE((ip1 != ip2) == false); -} - -// IPv4 and IPv6 differ based on type (irrespective of bytes) - -TEST_CASE ("Testing IPv4 vs IPv6", "[IPAddress6-Operator-==-05]") -{ - arduino::IPAddress ip1(10, 0, 0, 1), ip2(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPv4 vs IPv6 equivalent IPv4-compatible address (deprecated)", "[IPAddress6-Operator-==-05]") -{ - arduino::IPAddress ip1(10, 0, 0, 1), ip2(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 10,0, 0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPv4 vs IPv6 localhost", "[IPAddress6-Operator-==-05]") -{ - arduino::IPAddress ip1(127, 0, 0, 1), ip2(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 10,0, 0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPv4 equivalent compatible address vs IPv6 localhost", "[IPAddress6-Operator-==-05]") -{ - arduino::IPAddress ip1(0, 0, 0, 1), ip2(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,1); - REQUIRE((ip1 == ip2) == false); -} - -TEST_CASE ("Testing IPv6 never matches as raw byte sequence assumed to be length 4", "[IPAddress6-Operator-==-06]") -{ - arduino::IPAddress ip1(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - uint8_t const ip2[] = {0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc}; - REQUIRE((ip1 == ip2) == false); -} diff --git a/ArduinoCore-API/test/src/IPAddress/test_operator_parentheses.cpp b/ArduinoCore-API/test/src/IPAddress/test_operator_parentheses.cpp deleted file mode 100644 index b9ad65c..0000000 --- a/ArduinoCore-API/test/src/IPAddress/test_operator_parentheses.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing IPAddress::operator uint32_t() const", "[IPAddress-Operator-()-01]") -{ - arduino::IPAddress ip(129,168,1,2); - uint32_t const val_expected = ip; - uint32_t const val_actual = (129 | (168 << 8) | (1 << 16) | (2 << 24)); - // NOTE: Only correct on little-endian systems - REQUIRE(val_expected == val_actual); -} diff --git a/ArduinoCore-API/test/src/IPAddress/test_operator_parentheses6.cpp b/ArduinoCore-API/test/src/IPAddress/test_operator_parentheses6.cpp deleted file mode 100644 index d360f12..0000000 --- a/ArduinoCore-API/test/src/IPAddress/test_operator_parentheses6.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -// These comparisons should always return false, as you can't compare an IPv6 to an int32_t - -TEST_CASE ("Testing implicit cast of IPv6 compatible (little endian) to uint32_t always false", "[IPAddress6-Operator-()-01]") -{ - // On little endian systems, considering only last four octets (ignoring the rest) - arduino::IPAddress ip(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 129,168, 1,2); - uint32_t const val_expected = ip; - uint32_t const val_actual = (129 | (168 << 8) | (1 << 16) | (2 << 24)); - REQUIRE((val_expected == val_actual) == false); -} - -TEST_CASE ("Testing implicit cast of IPv6 full little endian to uint32_t always false", "[IPAddress6-Operator-()-01]") -{ - // On little endian systems (full value) - arduino::IPAddress ip(129,168, 1,2, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0); - uint32_t const val_expected = ip; - uint32_t const val_actual = (129 | (168 << 8) | (1 << 16) | (2 << 24)); - REQUIRE((val_expected == val_actual) == false); -} - -TEST_CASE ("Testing implicit cast of IPv6 to uint32_t always false", "[IPAddress6-Operator-()-01]") -{ - // Actual value of the 128-bit IPv6 address, which is network byte order - arduino::IPAddress ip(0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 129,168, 1,2); - uint32_t const val_expected = ip; - uint32_t const val_actual = ((129 << 24) | (168 << 16) | (1 << 8) | 2); - REQUIRE((val_expected == val_actual) == false); -} diff --git a/ArduinoCore-API/test/src/IPAddress/test_printTo.cpp b/ArduinoCore-API/test/src/IPAddress/test_printTo.cpp deleted file mode 100644 index 68e2ea9..0000000 --- a/ArduinoCore-API/test/src/IPAddress/test_printTo.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print IPAddress via print method", "[IPAddress-printTo-01]") -{ - PrintMock mock; - arduino::IPAddress const ip(192,168,1,2); - - mock.print(ip); - - REQUIRE(mock._str == "192.168.1.2"); -} diff --git a/ArduinoCore-API/test/src/IPAddress/test_printTo6.cpp b/ArduinoCore-API/test/src/IPAddress/test_printTo6.cpp deleted file mode 100644 index 71dea49..0000000 --- a/ArduinoCore-API/test/src/IPAddress/test_printTo6.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print IPv6", "[IPAddress-printTo6-01]") -{ - PrintMock mock; - arduino::IPAddress ip(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - - mock.print(ip); - - REQUIRE(mock._str == "2001:db8:102:304:506:708:90a:b0c"); -} - -TEST_CASE ("Print IPv6 any", "[IPAddress-printTo6-02]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); - - mock.print(ip); - - REQUIRE(mock._str == "::"); -} - -TEST_CASE ("Print IPv6 localhost", "[IPAddress-printTo6-03]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1); - - mock.print(ip); - - REQUIRE(mock._str == "::1"); -} - -TEST_CASE ("Print IPv6 different length segments", "[IPAddress-printTo6-04]") -{ - PrintMock mock; - arduino::IPAddress const ip(0xab,0xcd, 0x0e,0xf1, 0x00,0x23, 0,0, 0x00,0x04, 0,0, 0,0, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "abcd:ef1:23:0:4::"); -} - -TEST_CASE ("Print IPv6 zero longest run end", "[IPAddress-printTo6-05]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,1, 0,0, 0,0, 0,2, 0,0, 0,0, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "0:1:0:0:2::"); -} - -TEST_CASE ("Print IPv6 zero longest run mid", "[IPAddress-printTo6-06]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,1, 0,0, 0,0, 0,0, 0,2, 0,0, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "0:1::2:0:0"); -} - -TEST_CASE ("Print IPv6 start zero", "[IPAddress-printTo6-07]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,2, 0,3, 0,4, 0,5, 0,6, 0,7, 0,8); - - mock.print(ip); - - REQUIRE(mock._str == "0:2:3:4:5:6:7:8"); -} - -TEST_CASE ("Print IPv6 ending zero", "[IPAddress-printTo6-08]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,1, 0,2, 0,3, 0,4, 0,5, 0,6, 0,7, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "1:2:3:4:5:6:7:0"); -} - -TEST_CASE ("Print IPv6 start two zero", "[IPAddress-printTo6-09]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,0, 0,3, 0,4, 0,5, 0,6, 0,7, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "::3:4:5:6:7:0"); -} - -TEST_CASE ("Print IPv6 ending two zero", "[IPAddress-printTo6-10]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,0, 0,2, 0,3, 0,4, 0,5, 0,6, 0,0, 0,0); - - mock.print(ip); - - REQUIRE(mock._str == "0:2:3:4:5:6::"); -} - -TEST_CASE ("Print IPv6 first out of same length", "[IPAddress-printTo6-11]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,1, 0,0, 0,0, 0,4, 0,5, 0,0, 0,0, 0,8); - - mock.print(ip); - - REQUIRE(mock._str == "1::4:5:0:0:8"); -} - - -TEST_CASE ("Print IPv6 single zeros not compressed", "[IPAddress-printTo6-12]") -{ - PrintMock mock; - arduino::IPAddress const ip(0,1, 0,0, 0,3, 0,0, 0,5, 0,0, 0,7, 0,8); - - mock.print(ip); - - REQUIRE(mock._str == "1:0:3:0:5:0:7:8"); -} diff --git a/ArduinoCore-API/test/src/IPAddress/test_toString.cpp b/ArduinoCore-API/test/src/IPAddress/test_toString.cpp deleted file mode 100644 index 1bd8d74..0000000 --- a/ArduinoCore-API/test/src/IPAddress/test_toString.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Extract valid string from IPv4address", "[IPAddress-toString-01]") -{ - arduino::IPAddress ip(129,168,1,2); - - REQUIRE(ip.toString().equals("129.168.1.2") == true); -} - -TEST_CASE ("Extract valid ipv6 string from IPv6address", "[IPAddress-toString-02]") -{ - arduino::IPAddress ip(0x20,0x01, 0xd,0xb8, 1,2, 3,4, 5,6, 7,8, 9,0xa, 0xb,0xc); - - REQUIRE(ip.toString().equals("2001:0db8:0102:0304:0506:0708:090a:0b0c") == true); -} - -TEST_CASE ("Extract 0.0.0.0 string from uninitialized IP address", "[IPAddress-toString-03]") -{ - arduino::IPAddress ip; - - REQUIRE(ip.toString().equals("0.0.0.0") == true); -} diff --git a/ArduinoCore-API/test/src/MillisFake.cpp b/ArduinoCore-API/test/src/MillisFake.cpp deleted file mode 100644 index 293af87..0000000 --- a/ArduinoCore-API/test/src/MillisFake.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TYPEDEF - **************************************************************************************/ - -enum class MillisFakeMode -{ - Auto, Manual -}; - -/************************************************************************************** - * GLOBAL VARIABLES - **************************************************************************************/ - -static unsigned long millis_val = 0; -static MillisFakeMode millis_fake_mode = MillisFakeMode::Auto; -static std::chrono::steady_clock::time_point const millis_begin = std::chrono::steady_clock::now(); - -/************************************************************************************** - * FUNCTION DEFINITION - **************************************************************************************/ - -void millis_autoOn() -{ - millis_fake_mode = MillisFakeMode::Auto; -} - -void millis_autoOff() -{ - millis_fake_mode = MillisFakeMode::Manual; -} - -void set_millis(unsigned long const val) -{ - millis_autoOff(); - millis_val = val; -} - -unsigned long millis() -{ - if (millis_fake_mode == MillisFakeMode::Manual) - return millis_val; - - if (millis_fake_mode == MillisFakeMode::Auto) - { - std::chrono::steady_clock::time_point millis_now = std::chrono::steady_clock::now(); - auto millis = std::chrono::duration_cast(millis_now - millis_begin).count(); - return static_cast(millis); - } - - return 0; -} diff --git a/ArduinoCore-API/test/src/Print/test_availableForWrite.cpp b/ArduinoCore-API/test/src/Print/test_availableForWrite.cpp deleted file mode 100644 index ab6647c..0000000 --- a/ArduinoCore-API/test/src/Print/test_availableForWrite.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print::availableForWrite() should return 0 if not overwritten by derived class", "[Print-availableForWrite-01]") -{ - PrintMock mock; - REQUIRE(mock.availableForWrite() == 0); -} diff --git a/ArduinoCore-API/test/src/Print/test_clearWriteError.cpp b/ArduinoCore-API/test/src/Print/test_clearWriteError.cpp deleted file mode 100644 index 5f674cb..0000000 --- a/ArduinoCore-API/test/src/Print/test_clearWriteError.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Clear write error should set the error code back to 0", "[Print-clearWriteError-01]") -{ - PrintMock mock; - mock.mock_setWriteError(5); - mock.clearWriteError(); - REQUIRE(mock.getWriteError() == 0); -} diff --git a/ArduinoCore-API/test/src/Print/test_getWriteError.cpp b/ArduinoCore-API/test/src/Print/test_getWriteError.cpp deleted file mode 100644 index ff9eb0d..0000000 --- a/ArduinoCore-API/test/src/Print/test_getWriteError.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("No write error has been set", "[Print-getWriteError-01]") -{ - PrintMock mock; - REQUIRE(mock.getWriteError() == 0); -} - -TEST_CASE ("A write error has been set", "[Print-getWriteError-02]") -{ - PrintMock mock; - mock.mock_setWriteError(5); - REQUIRE(mock.getWriteError() == 5); -} diff --git a/ArduinoCore-API/test/src/Print/test_print.cpp b/ArduinoCore-API/test/src/Print/test_print.cpp deleted file mode 100644 index 1a41c46..0000000 --- a/ArduinoCore-API/test/src/Print/test_print.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print::print(char)", "[Print-print-01]") -{ - PrintMock mock; - - mock.print('A'); - - REQUIRE(mock._str == "A"); -} - -TEST_CASE ("Print::print(const String &)", "[Print-print-02]") -{ - PrintMock mock; - arduino::String const str("Test String"); - - mock.print(str); - - REQUIRE(mock._str == "Test String"); -} - -TEST_CASE ("Print::print(const char str[])", "[Print-print-03]") -{ - PrintMock mock; - const char str[] = "Test String"; - - mock.print(str); - - REQUIRE(mock._str == "Test String"); -} - -TEST_CASE ("Print::print(int, int = DEC|HEX|OCT|BIN)", "[Print-print-04]") -{ - PrintMock mock; - - int const val = -1; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); } -} - -TEST_CASE ("Print::print(unsigned int, int = DEC|HEX|OCT|BIN)", "[Print-print-05]") -{ - PrintMock mock; - - unsigned int const val = 17; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); } -} - -TEST_CASE ("Print::print(long, int = DEC|HEX|OCT|BIN)", "[Print-print-06]") -{ - PrintMock mock; - - long const val = -1; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); } -} - -TEST_CASE ("Print::print(unsigned long, int = DEC|HEX|OCT|BIN)", "[Print-print-07]") -{ - PrintMock mock; - - unsigned long const val = 17; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); } -} - -TEST_CASE ("Print::print(long long, int = DEC|HEX|OCT|BIN)", "[Print-print-08]") -{ - PrintMock mock; - - long long const val = -1; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "-1"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "FFFFFFFFFFFFFFFF"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "1777777777777777777777"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "1111111111111111111111111111111111111111111111111111111111111111"); } -} - -TEST_CASE ("Print::print(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-print-09]") -{ - PrintMock mock; - - GIVEN("a value of zero ...") - { - unsigned long long const val = 0; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "0"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "0"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "0"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "0"); } - } - GIVEN("a non-zero value ...") - { - unsigned long long const val = 17; - - WHEN("DEC") { mock.print(val, DEC); REQUIRE(mock._str == "17"); } - WHEN("HEX") { mock.print(val, HEX); REQUIRE(mock._str == "11"); } - WHEN("OCT") { mock.print(val, OCT); REQUIRE(mock._str == "21"); } - WHEN("BIN") { mock.print(val, BIN); REQUIRE(mock._str == "10001"); } - } -} - -TEST_CASE ("Print::print(double, int = 2)", "[Print-print-10]") -{ - PrintMock mock; - - WHEN ("val is a positive floating point value") - { - double const val = 3.1459; - WHEN("digits = 0") { mock.print(val, 0); REQUIRE(mock._str == "3"); } - WHEN("digits = 1") { mock.print(val, 1); REQUIRE(mock._str == "3.1"); } - WHEN("digits = 2 (default)") { mock.print(val); REQUIRE(mock._str == "3.15"); } - WHEN("digits = 3") { mock.print(val, 3); REQUIRE(mock._str == "3.146"); } - WHEN("digits = 4") { mock.print(val, 4); REQUIRE(mock._str == "3.1459"); } - WHEN("digits = 5") { mock.print(val, 5); REQUIRE(mock._str == "3.14590"); } - } - - WHEN ("digits are negative") - { - double const val = 3.1459; - WHEN("digits = -1") { mock.print(val, -1); REQUIRE(mock._str == "3.15"); } - } - - WHEN ("val is a negative floating point value") - { - double const val = -3.1459; - WHEN("digits = 2 (default)") { mock.print(val); REQUIRE(mock._str == "-3.15"); } - } - - WHEN ("val is NAN") { mock.print(NAN); REQUIRE(mock._str == "nan"); } - WHEN ("val is INFINITY") { mock.print(INFINITY); REQUIRE(mock._str == "inf"); } -} - -TEST_CASE ("Print::print(Printable)", "[Print-print-11]") -{ - PrintMock mock; - - PrintableMock printable; - printable._i = 1; - - mock.print(printable); - - REQUIRE(mock._str == "PrintableMock i = 1"); -} - -TEST_CASE ("Print::print(unsigned char, int)", "[Print-print-12]") -{ - PrintMock mock; - - WHEN("DEC") { mock.print('A', DEC); REQUIRE(mock._str == "65"); } - WHEN("HEX") { mock.print('A', HEX); REQUIRE(mock._str == "41"); } - WHEN("OCT") { mock.print('A', OCT); REQUIRE(mock._str == "101"); } - WHEN("BIN") { mock.print('A', BIN); REQUIRE(mock._str == "1000001"); } -} - -TEST_CASE ("Testing Print::print(const __FlashStringHelper *)", "[Print-print-13]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - PrintMock mock; - - mock.print(F("Hello flash string")); - - REQUIRE(mock._str == "Hello flash string"); -} diff --git a/ArduinoCore-API/test/src/Print/test_println.cpp b/ArduinoCore-API/test/src/Print/test_println.cpp deleted file mode 100644 index e35814e..0000000 --- a/ArduinoCore-API/test/src/Print/test_println.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Print::println(char)", "[Print-println-01]") -{ - PrintMock mock; - - mock.println('A'); - - REQUIRE(mock._str == "A\r\n"); -} - -TEST_CASE ("Print::println(const String &)", "[Print-println-02]") -{ - PrintMock mock; - arduino::String const str("Test String"); - - mock.println(str); - - REQUIRE(mock._str == "Test String\r\n"); -} - -TEST_CASE ("Print::println(const char str[])", "[Print-println-03]") -{ - PrintMock mock; - const char str[] = "Test String"; - - mock.println(str); - - REQUIRE(mock._str == "Test String\r\n"); -} - -TEST_CASE ("Print::println(int, int = DEC (default))", "[Print-println-04]") -{ - PrintMock mock; - int const val = -1; - - mock.println(val); - - REQUIRE(mock._str == "-1\r\n"); -} - -TEST_CASE ("Print::println(unsigned int, int = DEC (default))", "[Print-println-05]") -{ - PrintMock mock; - unsigned int const val = 17; - - mock.println(val); - - REQUIRE(mock._str == "17\r\n"); -} - -TEST_CASE ("Print::println(long, int = DEC (default))", "[Print-println-06]") -{ - PrintMock mock; - long const val = -1; - - mock.println(val); - - REQUIRE(mock._str == "-1\r\n"); -} - -TEST_CASE ("Print::println(unsigned long, int = DEC (default))", "[Print-println-07]") -{ - PrintMock mock; - unsigned long const val = 17; - - mock.println(val); - - REQUIRE(mock._str == "17\r\n"); -} - -TEST_CASE ("Print::println(long long, int = DEC (default))", "[Print-println-08]") -{ - PrintMock mock; - long long const val = -1; - - mock.println(val); - - REQUIRE(mock._str == "-1\r\n"); -} - -TEST_CASE ("Print::println(unsigned long long, int = DEC|HEX|OCT|BIN)", "[Print-println-09]") -{ - PrintMock mock; - unsigned long long const val = 17; - - mock.println(val); - - REQUIRE(mock._str == "17\r\n"); -} - -TEST_CASE ("Print::println(double, int = 2)", "[Print-println-10]") -{ - PrintMock mock; - double const val = 3.1459; - - mock.println(val); - - REQUIRE(mock._str == "3.15\r\n"); -} - -TEST_CASE ("Print::println(Printable)", "[Print-println-11]") -{ - PrintMock mock; - PrintableMock printable; - printable._i = 1; - - mock.println(printable); - - REQUIRE(mock._str == "PrintableMock i = 1\r\n"); -} - -TEST_CASE ("Print::println(unsigned char, int base = DEC (default))", "[Print-println-12]") -{ - PrintMock mock; - - mock.println('A', DEC); - - REQUIRE(mock._str == "65\r\n"); -} - -TEST_CASE ("Testing Print::println(const __FlashStringHelper *)", "[Print-println-13]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - PrintMock mock; - - mock.println(F("Hello flash string")); - - REQUIRE(mock._str == "Hello flash string\r\n"); -} diff --git a/ArduinoCore-API/test/src/PrintMock.cpp b/ArduinoCore-API/test/src/PrintMock.cpp deleted file mode 100644 index ffa7c58..0000000 --- a/ArduinoCore-API/test/src/PrintMock.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -/************************************************************************************** - * PUBLIC MEMBER FUNCTIONS - **************************************************************************************/ - -size_t PrintMock::write(uint8_t b) -{ - _str.append(1, static_cast(b)); - return 1; -} diff --git a/ArduinoCore-API/test/src/Ringbuffer/test_available.cpp b/ArduinoCore-API/test/src/Ringbuffer/test_available.cpp deleted file mode 100644 index 171dcbf..0000000 --- a/ArduinoCore-API/test/src/Ringbuffer/test_available.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("'available' should return 0 for empty ring buffer", "[Ringbuffer-available-01]") -{ - arduino::RingBufferN<2> ringbuffer; - REQUIRE(ringbuffer.available() == 0); -} - -TEST_CASE ("'available' should return number of elements in ringbuffer", "[Ringbuffer-available-02]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer.available() == 1); - ringbuffer.store_char('B'); - REQUIRE(ringbuffer.available() == 2); -} diff --git a/ArduinoCore-API/test/src/Ringbuffer/test_availableForStore.cpp b/ArduinoCore-API/test/src/Ringbuffer/test_availableForStore.cpp deleted file mode 100644 index 4a06e83..0000000 --- a/ArduinoCore-API/test/src/Ringbuffer/test_availableForStore.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("'availableForStore' should return ring buffer size for empty ring buffer", "[Ringbuffer-availableForStore-01]") -{ - arduino::RingBufferN<2> ringbuffer; - REQUIRE(ringbuffer.availableForStore() == 2); -} - -TEST_CASE ("'availableForStore' should return number of free elements in ringbuffer", "[Ringbuffer-availableForStore-02]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer.availableForStore() == 1); - ringbuffer.store_char('B'); - REQUIRE(ringbuffer.availableForStore() == 0); -} diff --git a/ArduinoCore-API/test/src/Ringbuffer/test_clear.cpp b/ArduinoCore-API/test/src/Ringbuffer/test_clear.cpp deleted file mode 100644 index e2868c1..0000000 --- a/ArduinoCore-API/test/src/Ringbuffer/test_clear.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Calling 'clear' on a empty ring buffer should have no effect", "[Ringbuffer-clear-01]") -{ - arduino::RingBufferN<2> ringbuffer; - REQUIRE(ringbuffer.available() == 0); - ringbuffer.clear(); - REQUIRE(ringbuffer.available() == 0); -} - -TEST_CASE ("Calling 'clear' on a partially filled ring buffer should \"remove\" all elements", "[Ringbuffer-clear-02]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer.available() == 1); - ringbuffer.clear(); - REQUIRE(ringbuffer.available() == 0); -} diff --git a/ArduinoCore-API/test/src/Ringbuffer/test_isFull.cpp b/ArduinoCore-API/test/src/Ringbuffer/test_isFull.cpp deleted file mode 100644 index a7208f8..0000000 --- a/ArduinoCore-API/test/src/Ringbuffer/test_isFull.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("'isFull' should return false for empty ring buffer", "[Ringbuffer-isFull-01]") -{ - arduino::RingBufferN<2> ringbuffer; - REQUIRE(ringbuffer.isFull() == false); -} - -TEST_CASE ("'isFull' should return false for a partial full ring buffer", "[Ringbuffer-isFull-02]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer.isFull() == false); -} - -TEST_CASE ("'isFull' should return true for full ring buffer", "[Ringbuffer-isFull-03]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - ringbuffer.store_char('B'); - REQUIRE(ringbuffer.isFull() == true); -} diff --git a/ArduinoCore-API/test/src/Ringbuffer/test_peek.cpp b/ArduinoCore-API/test/src/Ringbuffer/test_peek.cpp deleted file mode 100644 index 145a7f3..0000000 --- a/ArduinoCore-API/test/src/Ringbuffer/test_peek.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Data is accessed but not removed from the ring buffer via 'peek'", "[Ringbuffer-peek-01]") -{ - arduino::RingBufferN<2> ringbuffer; - - WHEN("The ringbuffer is empty") - THEN("'peek' should return -1") - REQUIRE(ringbuffer.peek() == -1); - - WHEN("The ringbuffer contains data") - { - ringbuffer.store_char('A'); - ringbuffer.store_char('B'); - THEN("'peek' should return first inserted element first (FIFO) and not remove it") - { - REQUIRE(ringbuffer.peek() == 'A'); - REQUIRE(ringbuffer.peek() == 'A'); - } - } -} diff --git a/ArduinoCore-API/test/src/Ringbuffer/test_read_char.cpp b/ArduinoCore-API/test/src/Ringbuffer/test_read_char.cpp deleted file mode 100644 index c6941ad..0000000 --- a/ArduinoCore-API/test/src/Ringbuffer/test_read_char.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Data is removed from the ring buffer via 'read_char'", "[Ringbuffer-read_char-01]") -{ - arduino::RingBufferN<2> ringbuffer; - - WHEN("The ringbuffer is empty") - THEN("'read_char' should return -1") - REQUIRE(ringbuffer.read_char() == -1); - - WHEN("The ringbuffer contains data") - { - ringbuffer.store_char('A'); - ringbuffer.store_char('B'); - THEN("'read_char' should return first inserted element first (FIFO)") - { - REQUIRE(ringbuffer.read_char() == 'A'); - REQUIRE(ringbuffer.read_char() == 'B'); - } - } -} diff --git a/ArduinoCore-API/test/src/Ringbuffer/test_store_char.cpp b/ArduinoCore-API/test/src/Ringbuffer/test_store_char.cpp deleted file mode 100644 index 705d979..0000000 --- a/ArduinoCore-API/test/src/Ringbuffer/test_store_char.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Data is put into the ring buffer via 'store_char'", "[Ringbuffer-store_char-01]") -{ - arduino::RingBufferN<2> ringbuffer; - ringbuffer.store_char('A'); - REQUIRE(ringbuffer._aucBuffer[0] == 'A'); - ringbuffer.store_char('B'); - REQUIRE(ringbuffer._aucBuffer[1] == 'B'); -} diff --git a/ArduinoCore-API/test/src/Stream/test_find.cpp b/ArduinoCore-API/test/src/Stream/test_find.cpp deleted file mode 100644 index c3c69d0..0000000 --- a/ArduinoCore-API/test/src/Stream/test_find.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing find(const char *target)", "[Stream-find-01]") -{ - StreamMock mock; - - WHEN ("'target' is contained in stream") - { - mock << "This is a test string"; - - REQUIRE(mock.find("test") == true); - REQUIRE(mock.readString() == arduino::String(" string")); - } - WHEN ("'target' is not contained in stream") - { - mock << "This is a string"; - - REQUIRE(mock.find("test") == false); - REQUIRE(mock.readString() == arduino::String("")); - } -} - -TEST_CASE ("Testing find(const char *target, size_t length)", "[Stream-find-02]") -{ - StreamMock mock; - - WHEN ("'target' is contained in stream") - { - mock << "This is a test string"; - - /* 'length' should actually be '4' or strlen("test"). I'd rather - * think this API should not be exposed at all. - */ - REQUIRE(mock.find("test", 3) == true); - REQUIRE(mock.readString() == arduino::String("t string")); - } - WHEN ("'target' is not contained in stream") - { - mock << "This is a string"; - - REQUIRE(mock.find("test", 3) == false); - REQUIRE(mock.readString() == arduino::String("")); - } -} - -TEST_CASE ("Testing find(char target)", "[Stream-find-03]") -{ - StreamMock mock; - - WHEN ("'target' is contained in stream") - { - mock << "This is a test string"; - - REQUIRE(mock.find('t') == true); - REQUIRE(mock.readString() == arduino::String("est string")); - } - WHEN ("'target' is not contained in stream") - { - mock << "This is a string"; - - REQUIRE(mock.find('!') == false); - REQUIRE(mock.readString() == arduino::String("")); - } -} diff --git a/ArduinoCore-API/test/src/Stream/test_findUntil.cpp b/ArduinoCore-API/test/src/Stream/test_findUntil.cpp deleted file mode 100644 index acd5ea1..0000000 --- a/ArduinoCore-API/test/src/Stream/test_findUntil.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing findUntil(const char *target, const char *terminator)", "[Stream-findUntil-01]") -{ - StreamMock mock; - - WHEN ("'target' is contained in stream") - { - WHEN ("'terminator' appears before 'target'") - { - mock << "This is a : test string"; - REQUIRE(mock.findUntil("test", ": ") == false); - REQUIRE(mock.readString() == arduino::String("test string")); - } - WHEN ("'terminator' appears after 'target'") - { - mock << "This is a test : string"; - REQUIRE(mock.findUntil("test", ": ") == true); - REQUIRE(mock.readString() == arduino::String(" : string")); - } - WHEN ("'terminator' is not included in the string at all") - { - mock << "This is a test string"; - REQUIRE(mock.findUntil("test", ": ") == true); - REQUIRE(mock.readString() == arduino::String(" string")); - } - } - - WHEN ("'target' is not contained in stream") - { - mock << "This is a test string"; - REQUIRE(mock.findUntil("abc", "def") == false); - REQUIRE(mock.readString() == arduino::String("")); - } -} diff --git a/ArduinoCore-API/test/src/Stream/test_getTimeout.cpp b/ArduinoCore-API/test/src/Stream/test_getTimeout.cpp deleted file mode 100644 index 9a9e6e1..0000000 --- a/ArduinoCore-API/test/src/Stream/test_getTimeout.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Verifying if default timeout is returned correctly", "[Stream-getTimeout-01]") -{ - StreamMock mock; - REQUIRE(mock.getTimeout() == 1000); -} diff --git a/ArduinoCore-API/test/src/Stream/test_parseFloat.cpp b/ArduinoCore-API/test/src/Stream/test_parseFloat.cpp deleted file mode 100644 index 2c27337..0000000 --- a/ArduinoCore-API/test/src/Stream/test_parseFloat.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -using namespace Catch; - -#include - -#include - -using namespace arduino; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR)", "[Stream-parseFloat-01]") -{ - StreamMock mock; - - WHEN ("Only a integer (no comma) is contained in stream") - { - mock << "12"; - REQUIRE(mock.parseFloat() == 12.0f); - } - WHEN ("A positive float is contained in stream") - { - mock << "12.34"; - REQUIRE(mock.parseFloat() == 12.34f); - } - WHEN ("A negative float is contained in stream") - { - mock << "-12.34"; - REQUIRE(mock.parseFloat() == -12.34f); - } - WHEN ("A float is prepended by digits") - { - mock << "abcdef12.34"; - REQUIRE(mock.parseFloat() == 12.34f); - } - WHEN ("The integer is prepended by whitespace chars") - { - mock << "\r\n\t 12.34"; - REQUIRE(mock.parseFloat() == 12.34f); - } - WHEN ("A float is provided with too many digits after the decimal point") - { - mock << "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870064"; - REQUIRE(mock.parseFloat() == Approx(3.141592654f)); - } - WHEN ("A float is larger than LONG_MAX") - { - mock << "602200000000000000000000.00"; - REQUIRE(mock.parseFloat() == Approx(6.022e23f)); - } -} - -TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_NONE, char ignore = NO_IGNORE_CHAR)", "[Stream-parseFloat-02]") -{ - StreamMock mock; - - WHEN ("Only a integer is contained in stream") - { - mock << "12.34"; - REQUIRE(mock.parseFloat(SKIP_NONE) == 12.34f); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("The integer is prepended by digits") - { - mock << "abcdef12.34"; - REQUIRE(mock.parseFloat(SKIP_NONE) == 0); - REQUIRE(mock.readString() == arduino::String("abcdef12.34")); - } - WHEN ("The integer is prepended by whitespace chars") - { - mock << "\r\n\t 12.34"; - REQUIRE(mock.parseFloat(SKIP_NONE) == 0); - REQUIRE(mock.readString() == arduino::String("\r\n\t 12.34")); - } -} - -TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_WHITESPACE, char ignore = NO_IGNORE_CHAR)", "[Stream-parseFloat-03]") -{ - StreamMock mock; - - WHEN ("The integer is prepended by whitespace chars") - { - mock << "\r\n\t 12.34"; - REQUIRE(mock.parseFloat(SKIP_WHITESPACE) == 12.34f); - REQUIRE(mock.readString() == arduino::String("")); - } -} - - -TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = 'a')", "[Stream-parseFloat-04]") -{ - StreamMock mock; - - WHEN ("A float is contained in stream") - { - mock << "12.34"; - REQUIRE(mock.parseFloat(SKIP_ALL, 'a') == 12.34f); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("The float contains only ignore char values") - { - mock << "12a.3a4a"; - REQUIRE(mock.parseFloat(SKIP_ALL, 'a') == 12.34f); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("The integer contains other than ignore chars") - { - mock << "1bed234"; - REQUIRE(mock.parseFloat(SKIP_ALL, 'a') == 1.0f); - REQUIRE(mock.readString() == arduino::String("bed234")); - } -} diff --git a/ArduinoCore-API/test/src/Stream/test_parseInt.cpp b/ArduinoCore-API/test/src/Stream/test_parseInt.cpp deleted file mode 100644 index 69cf580..0000000 --- a/ArduinoCore-API/test/src/Stream/test_parseInt.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -using namespace arduino; - -TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR)", "[Stream-parseInt-01]") -{ - StreamMock mock; - - WHEN ("A positive integer is contained in stream") - { - mock << "1234"; - REQUIRE(mock.parseInt() == 1234); - } - WHEN ("A negative integer is contained in stream") - { - mock << "-1234"; - REQUIRE(mock.parseInt() == -1234); - } - WHEN ("A integer is prepended by digits") - { - mock << "abcdef1234"; - REQUIRE(mock.parseInt() == 1234); - } - WHEN ("A integer is prepended by whitespace chars") - { - mock << "\r\n\t 1234"; - REQUIRE(mock.parseInt() == 1234); - } -} - -TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_NONE, char ignore = NO_IGNORE_CHAR)", "[Stream-parseInt-02]") -{ - StreamMock mock; - - WHEN ("A positive integer is contained in stream") - { - mock << "1234"; - REQUIRE(mock.parseInt(SKIP_NONE) == 1234); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("A integer is prepended by digits") - { - mock << "abcdef1234"; - REQUIRE(mock.parseInt(SKIP_NONE) == 0); - REQUIRE(mock.readString() == arduino::String("abcdef1234")); - } - WHEN ("A integer is prepended by whitespace chars") - { - mock << "\r\n\t 1234"; - REQUIRE(mock.parseInt(SKIP_NONE) == 0); - REQUIRE(mock.readString() == arduino::String("\r\n\t 1234")); - } -} - -TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_WHITESPACE, char ignore = NO_IGNORE_CHAR)", "[Stream-parseInt-03]") -{ - StreamMock mock; - - WHEN ("A integer is prepended by whitespace chars") - { - mock << "\r\n\t 1234"; - REQUIRE(mock.parseInt(SKIP_WHITESPACE) == 1234); - REQUIRE(mock.readString() == arduino::String("")); - } -} - -TEST_CASE ("Testing parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = 'a')", "[Stream-parseInt-04]") -{ - StreamMock mock; - - WHEN ("A positive integer is contained in stream") - { - mock << "1234"; - REQUIRE(mock.parseInt(SKIP_ALL, 'a') == 1234); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("A integer contains only ignore char values") - { - mock << "12a3a4a"; - REQUIRE(mock.parseInt(SKIP_ALL, 'a') == 1234); - REQUIRE(mock.readString() == arduino::String("")); - } - WHEN ("A integer contains other than ignore chars") - { - mock << "1bed234"; - REQUIRE(mock.parseInt(SKIP_ALL, 'a') == 1); - REQUIRE(mock.readString() == arduino::String("bed234")); - } -} diff --git a/ArduinoCore-API/test/src/Stream/test_readBytes.cpp b/ArduinoCore-API/test/src/Stream/test_readBytes.cpp deleted file mode 100644 index 814a602..0000000 --- a/ArduinoCore-API/test/src/Stream/test_readBytes.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing readBytes(char *buffer, size_t length)", "[Stream-readBytes-01]") -{ - StreamMock mock; - - WHEN ("the stream is empty") - { - char buf[32] = {0}; - - REQUIRE(mock.readBytes(buf, sizeof(buf)) == 0); - } - - WHEN ("the stream contains less data than we want to read") - { - char buf[32] = {0}; - char const str[] = "some stream content"; - mock << str; - - REQUIRE(mock.readBytes(buf, sizeof(buf)) == strlen(str)); - REQUIRE(strncmp(buf, str, sizeof(buf)) == 0); - REQUIRE(mock.readString() == arduino::String("")); - } - - WHEN ("the stream contains more data than we want to read") - { - char buf[5] = {0}; - mock << "some stream content"; - char const EXPECTED_STR[] = "some "; - - REQUIRE(mock.readBytes(buf, sizeof(buf)) == 5); - REQUIRE(strncmp(buf, EXPECTED_STR, sizeof(buf)) == 0); - REQUIRE(mock.readString() == arduino::String("stream content")); - } -} diff --git a/ArduinoCore-API/test/src/Stream/test_readBytesUntil.cpp b/ArduinoCore-API/test/src/Stream/test_readBytesUntil.cpp deleted file mode 100644 index fa0cff1..0000000 --- a/ArduinoCore-API/test/src/Stream/test_readBytesUntil.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing readBytesUntil(char terminator, char *buffer, size_t length)", "[Stream-readBytesUntil-01]") -{ - StreamMock mock; - - WHEN ("the stream is empty") - { - char buf[32] = {0}; - - REQUIRE(mock.readBytesUntil(' ', buf, sizeof(buf)) == 0); - } - - WHEN ("the stream contains the termination character") - { - char buf[32] = {0}; - char const str[] = "some stream content"; - char const EXPECTED_STR[] = "some"; - mock << str; - - REQUIRE(mock.readBytesUntil(' ', buf, sizeof(buf)) == strlen("some")); - REQUIRE(strncmp(buf, EXPECTED_STR, sizeof(buf)) == 0); - REQUIRE(mock.readString() == arduino::String("stream content")); - } - - WHEN ("the stream does not contain the termination character") - { - char buf[32] = {0}; - char const STR[] = "some stream content"; - mock << STR; - - REQUIRE(mock.readBytesUntil('!', buf, sizeof(buf)) == strlen(STR)); - REQUIRE(strncmp(buf, STR, sizeof(buf)) == 0); - REQUIRE(mock.readString() == arduino::String("")); - } -} diff --git a/ArduinoCore-API/test/src/Stream/test_readString.cpp b/ArduinoCore-API/test/src/Stream/test_readString.cpp deleted file mode 100644 index 996be6e..0000000 --- a/ArduinoCore-API/test/src/Stream/test_readString.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing 'readString' with data available within the stream", "[Stream-readString-01]") -{ - StreamMock mock; - mock.setTimeout(10); - millis_autoOn(); - mock << "This is test stream content"; - - REQUIRE(mock.readString() == arduino::String("This is test stream content")); -} diff --git a/ArduinoCore-API/test/src/Stream/test_readStringUntil.cpp b/ArduinoCore-API/test/src/Stream/test_readStringUntil.cpp deleted file mode 100644 index c4f52b5..0000000 --- a/ArduinoCore-API/test/src/Stream/test_readStringUntil.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include -#include -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing 'readStringUntil' with separator available within the stream", "[Stream-readStringUntil-01]") -{ - StreamMock mock; - mock.setTimeout(10); - millis_autoOn(); - mock << "This is test! lorem ipsum lalala"; - - REQUIRE(mock.readStringUntil('!') == arduino::String("This is test")); -} - -TEST_CASE ("Testing 'readStringUntil' with separator not available within the stream", "[Stream-readStringUntil-02]") -{ - StreamMock mock; - mock.setTimeout(10); - millis_autoOn(); - mock << "This is test ... lorem ipsum lalala"; - - REQUIRE(mock.readStringUntil('!') == arduino::String("This is test ... lorem ipsum lalala")); -} diff --git a/ArduinoCore-API/test/src/Stream/test_setTimeout.cpp b/ArduinoCore-API/test/src/Stream/test_setTimeout.cpp deleted file mode 100644 index 08840c9..0000000 --- a/ArduinoCore-API/test/src/Stream/test_setTimeout.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Verifying if calling 'setTimeout' is indeed modifying the timeout", "[Stream-setTimeout-01]") -{ - StreamMock mock; - - mock.setTimeout(100); - - REQUIRE(mock.getTimeout() == 100); -} diff --git a/ArduinoCore-API/test/src/StreamMock.cpp b/ArduinoCore-API/test/src/StreamMock.cpp deleted file mode 100644 index c176885..0000000 --- a/ArduinoCore-API/test/src/StreamMock.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -/************************************************************************************** - * PUBLIC MEMBER FUNCTIONS - **************************************************************************************/ - -void StreamMock::operator << (char const * str) -{ - for (size_t c = 0; c < strlen(str); c++) - _stream.push_back(str[c]); -} - -size_t StreamMock::write(uint8_t ch) -{ - _stream.push_back(static_cast(ch)); - return 1; -} - -int StreamMock::available() -{ - return _stream.size(); -} - -int StreamMock::read() -{ - if (available() == 0) - return -1; - - /* Extract first/oldest element. */ - char const c = _stream.at(0); - /* Erase first/oldest element. */ - _stream.pop_front(); - - return c; -} - -int StreamMock::peek() -{ - if (available() == 0) - return -1; - - return _stream.at(0); -} diff --git a/ArduinoCore-API/test/src/String/StringPrinter.h b/ArduinoCore-API/test/src/String/StringPrinter.h deleted file mode 100644 index 1785f98..0000000 --- a/ArduinoCore-API/test/src/String/StringPrinter.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#pragma once - -#include -#include - -namespace Catch { - /** - * Template specialization that makes sure Catch can properly print - * Arduino Strings when used in comparisons directly. - * - * Note that without this, String objects are printed as 0 and 1, - * because they are implicitly convertible to StringIfHelperType, - * which is a dummy pointer. - */ - template<> - struct StringMaker { - static std::string convert(const arduino::String& str) { - if (str) - return ::Catch::Detail::stringify(std::string(str.c_str(), str.length())); - else - return "{invalid String}"; - } - }; -} // namespace Catch diff --git a/ArduinoCore-API/test/src/String/test_String.cpp b/ArduinoCore-API/test/src/String/test_String.cpp deleted file mode 100644 index d6ef725..0000000 --- a/ArduinoCore-API/test/src/String/test_String.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String(const char *) constructor()", "[String-Ctor-01]") -{ - char const CSTR[] = "Hello Arduino String Class"; - arduino::String str(CSTR); - REQUIRE(str == CSTR); -} - -TEST_CASE ("Testing String(const String &) constructor()", "[String-Ctor-02]") -{ - arduino::String str1("Hello Arduino String class"), - str2(str1); - REQUIRE(str1 == str2); -} - -TEST_CASE ("Testing String(const __FlashStringHelper) constructor()", "[String-Ctor-03]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - arduino::String str1(F("Hello")); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing String(char) constructor()", "[String-Ctor-04]") -{ - char const ch = 'A'; - arduino::String str(ch); - REQUIRE(str == "A"); -} - -TEST_CASE ("Testing String(unsigned char, unsigned char base = 10) constructor()", "[String-Ctor-05]") -{ - unsigned char const val = 1; - arduino::String str(val); - REQUIRE(str == "1"); -} - -TEST_CASE ("Testing String(int, unsigned char base = 10) constructor()", "[String-Ctor-06]") -{ - int const val = -1; - arduino::String str(val); - REQUIRE(str == "-1"); -} - -TEST_CASE ("Testing String(unsigned int, unsigned char base = 10) constructor()", "[String-Ctor-07]") -{ - unsigned int const val = 1; - arduino::String str(val); - REQUIRE(str == "1"); -} - -TEST_CASE ("Testing String(long, unsigned char base = 10) constructor()", "[String-Ctor-08]") -{ - long const val = -1; - arduino::String str(val); - REQUIRE(str == "-1"); -} - -TEST_CASE ("Testing String(unsigned long, unsigned char base = 10) constructor()", "[String-Ctor-09]") -{ - unsigned long const val = 1; - arduino::String str(val); - REQUIRE(str == "1"); -} - -TEST_CASE ("Testing String(float, unsigned char decimalPlaces = 2) constructor()", "[String-Ctor-10]") -{ - WHEN ("String::String (some float value)") - { - arduino::String str(1.234f); - REQUIRE(str == "1.23"); - } - WHEN ("String::String (FLT_MAX)") - { - arduino::String str(FLT_MAX); - REQUIRE(str == "340282346638528859811704183484516925440.00"); - } - WHEN ("String::String (-FLT_MAX)") - { - arduino::String str(-FLT_MAX); - REQUIRE(str == "-340282346638528859811704183484516925440.00"); - } -} - -TEST_CASE ("Testing String(double, unsigned char decimalPlaces = 2) constructor()", "[String-Ctor-11]") -{ - WHEN ("String::String (some double value)") - { - arduino::String str(5.678); - REQUIRE(str == "5.68"); - } - WHEN ("String::String (DBL_MAX)") - { - arduino::String str(DBL_MAX); - REQUIRE(str == "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00"); - } - WHEN ("String::String (-DBL_MAX)") - { - arduino::String str(-DBL_MAX); - REQUIRE(str == "-179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00"); - } -} - -TEST_CASE ("Testing String(const __FlashStringHelper) constructor() with invalid buffer", "[String-Ctor-12]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - char *buffer = NULL; - - arduino::String str1(F(buffer)); - REQUIRE_FALSE(str1); -} - -TEST_CASE ("Testing String(StringSumHelper &&) constructor()", "[String-Ctor-13]") -{ - arduino::String str("Hello"); - char const ch = '!'; - arduino::String str1(static_cast(str+ch)); - REQUIRE(str1 == "Hello!"); -} - -TEST_CASE ("Testing String(String &&) constructor()", "[String-Ctor-14]") -{ - arduino::String str("Hello"); - arduino::String str1(static_cast(str)); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing String(String &&) with move(String &rhs) from smaller to larger buffer", "[String-Ctor-15]") -{ - arduino::String str("Hello"); - arduino::String str1("Arduino"); - str1 = static_cast(str); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing String(String &&) with move(String &rhs) from larger to smaller buffer", "[String-Ctor-16]") -{ - arduino::String str("Hello"); - arduino::String str1("Arduino"); - str = static_cast(str1); - REQUIRE(str == "Arduino"); -} diff --git a/ArduinoCore-API/test/src/String/test_characterAccessFunc.cpp b/ArduinoCore-API/test/src/String/test_characterAccessFunc.cpp deleted file mode 100644 index e191f1d..0000000 --- a/ArduinoCore-API/test/src/String/test_characterAccessFunc.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::charAt(unsigned int)", "[String-charAt-01]") -{ - arduino::String str1("Hello"); - REQUIRE(str1.charAt(2) == 'l'); -} - -TEST_CASE ("Testing String::setCharAt(unsigned int, char )", "[String-setCharAt-02]") -{ - arduino::String str1("Hello"); - str1.setCharAt(1, 'a'); - REQUIRE(str1 == "Hallo"); -} - -TEST_CASE ("Testing String::getBytes(unsigned char, unsigned int, unsigned int)", "[String-getBytes-02]") -{ - WHEN("No bufsize") { - arduino::String str("Hello"); - unsigned char buf[2]; - str.getBytes(buf, 0, 0); - } - - WHEN("Index >= len") { - arduino::String str("Hello"); - unsigned char buf[2]; - str.getBytes(buf, 5, 6); - } - - WHEN("Valid operation") { - arduino::String str("Hello"); - unsigned char buf[3]; - str.getBytes(buf, 5, 3); - REQUIRE(buf[0] == 'l'); - REQUIRE(buf[1] == 'o'); - REQUIRE(buf[2] == '\0'); - } -} - -TEST_CASE ("Testing & String::operator[]", "[String-&operator subscript-03]") -{ - arduino::String str("Hello"); - str[0] = 'M'; - REQUIRE(str == "Mello"); -} - -TEST_CASE ("Testing & String::operator[] with invalid buffer", "[String-&operator subscript-04]") -{ - char *buffer = NULL; - arduino::String str(buffer); - str[0] = 'M'; - REQUIRE(str[0] == 0); -} diff --git a/ArduinoCore-API/test/src/String/test_compareTo.cpp b/ArduinoCore-API/test/src/String/test_compareTo.cpp deleted file mode 100644 index b567320..0000000 --- a/ArduinoCore-API/test/src/String/test_compareTo.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::compareTo(const String &)", "[String-compareTo-01]") -{ - WHEN ("Strings are equal") - { - arduino::String str1("Hello"), str2("Hello"); - REQUIRE(str1.compareTo(str2) == 0); - } - - WHEN ("str2 is empty") - { - arduino::String str1("Hello"), str2; - REQUIRE(str1.compareTo(str2) > 0); - } - - WHEN ("str1 is empty") - { - arduino::String str1, str2("Hello"); - REQUIRE(str1.compareTo(str2) < 0); - } -} - -TEST_CASE ("Testing String::compareTo(const char *)", "[String-compareTo-02]") -{ - WHEN ("Strings are equal") - { - arduino::String str("Hello"); - REQUIRE(str.compareTo("Hello") == 0); - } - - WHEN ("Passed string is empty") - { - arduino::String str("Hello"); - REQUIRE(str.compareTo("") > 0); - } - - WHEN ("Passed string is compared with empty string") - { - arduino::String str; - REQUIRE(str.compareTo("") == 0); - } -} - -TEST_CASE ("Testing String::compareTo(const char *) with empty buffer", "[String-compareTo-03]") -{ - WHEN ("First string has a valid buffer") - { - char *buffer = NULL; - - arduino::String str("Hello"); - REQUIRE(str.compareTo(buffer) != 0); - } - - WHEN ("First string does NOT have a valid buffer") - { - char *buffer1 = NULL; - char *buffer2 = NULL; - - arduino::String str(buffer1); - REQUIRE(str.compareTo(buffer2) == 0); - } -} - - -TEST_CASE ("Testing String::compareTo(const String &) with empty buffer", "[String-compareTo-04]") -{ - WHEN ("First string has a valid buffer") - { - char *buffer = NULL; - - arduino::String str1("Hello"); - arduino::String str2(buffer); - REQUIRE(str1.compareTo(str2) != 0); - } - - WHEN ("First string does NOT have a valid buffer") - { - char *buffer1 = NULL; - char *buffer2 = NULL; - - arduino::String str1(buffer1); - arduino::String str2(buffer2); - REQUIRE(str1.compareTo(str2) == 0); - } -} diff --git a/ArduinoCore-API/test/src/String/test_comparisonFunc.cpp b/ArduinoCore-API/test/src/String/test_comparisonFunc.cpp deleted file mode 100644 index 558012d..0000000 --- a/ArduinoCore-API/test/src/String/test_comparisonFunc.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::equals(const String &) with exit status PASS", "[String-equals-01]") -{ - arduino::String str1("Hello"), str2("Hello"); - REQUIRE(str1.equals(str2) == 1); -} - -TEST_CASE ("Testing String::operator==(const String &) with exit status PASS", "[String-equals-01]") -{ - arduino::String str1("Hello"), str2("Hello"); - REQUIRE(str1 == str2); -} - -TEST_CASE ("Testing String::operator!=(const String &) with exit status FAIL", "[String-equals-01]") -{ - arduino::String str1("Hello"), str2("Hello"); - REQUIRE_FALSE(str1 != str2); -} - -TEST_CASE ("Testing String::equals(const String &) with exit status FAIL", "[String-equals-02]") -{ - arduino::String str1("Hello"), str2("World"); - REQUIRE(str1.equals(str2) == 0); -} - -TEST_CASE ("Testing String::operator==(const String &) with exit status FAIL", "[String-equals-02]") -{ - arduino::String str1("Hello"), str2("World"); - REQUIRE_FALSE(str1 == str2); -} - -TEST_CASE ("Testing String::operator !=(const String &) with exit status PASS", "[String-equals-02]") -{ - arduino::String str1("Hello"), str2("World"); - REQUIRE(str1 != str2); -} - -TEST_CASE ("Testing String::equals(const char *) with exit status PASS", "[String-equals-03]") -{ - arduino::String str1("Hello"); - REQUIRE(str1.equals("Hello") == 1); -} - -TEST_CASE ("Testing String::operator ==(const char *) with exit status PASS", "[String-equals-03]") -{ - arduino::String str1("Hello"); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing String::operator !=(const char *) with exit status FAIL", "[String-equals-03]") -{ - arduino::String str1("Hello"); - REQUIRE_FALSE(str1 != "Hello"); -} - -TEST_CASE ("Testing String::equals(const char *) with exit status FAIL", "[String-equals-04]") -{ - arduino::String str1("Hello"); - REQUIRE(str1.equals("World") == 0); -} - -TEST_CASE ("Testing String::operator ==(const char *) with exit status FAIL", "[String-equals-04]") -{ - arduino::String str1("Hello"); - REQUIRE_FALSE(str1 == "World"); -} - -TEST_CASE ("Testing String::operator !=(const char *) with exit status PASS", "[String-equals-04]") -{ - arduino::String str1("Hello"); - REQUIRE(str1 != "World"); -} - -TEST_CASE ("Testing String::equalsIgnoreCase(const String &) PASS with NON-empty string", "[String-equalsIgnoreCase-05]") -{ - arduino::String str1("Hello"), str2("Hello"); - REQUIRE(str1.equalsIgnoreCase(str2) == 1); -} - -TEST_CASE ("Testing String::equalsIgnoreCase(const String &) FAIL with NON-empty string", "[String-equalsIgnoreCase-06]") -{ - arduino::String str1("Hello"), str2("Hel"); - REQUIRE(str1.equalsIgnoreCase(str2) == 0); -} - -TEST_CASE ("Testing String::equalsIgnoreCase(const String &) FAIL with different strings", "[String-equalsIgnoreCase-07]") -{ - arduino::String str1("Hello"), str2("World"); - REQUIRE(str1.equalsIgnoreCase(str2) == 0); -} - -TEST_CASE ("Testing String::equalsIgnoreCase(const String &) PASS with same string", "[String-equalsIgnoreCase-08]") -{ - arduino::String str1("Hello"); - REQUIRE(str1.equalsIgnoreCase(str1) == 1); -} - -TEST_CASE ("Testing String::startsWith(const String &)", "[String-startsWith-09]") -{ - WHEN ("str2 is larger than str1") - { - arduino::String str1("Hello"); - arduino::String str2("Hello World"); - REQUIRE(str1.startsWith(str2) == 0); - } - WHEN ("str1 starts with str2") - { - arduino::String str1("Hello World"); - arduino::String str2("Hello"); - REQUIRE(str1.startsWith(str2) == 1); - } - WHEN ("str1 does NOT start with str2") - { - arduino::String str1("Hello World"); - arduino::String str2("Helo"); - REQUIRE(str1.startsWith(str2) == 0); - } -} - -TEST_CASE ("Testing String::endsWith(const String &)", "[String-endsWith-10]") -{ - WHEN ("str2 is larger than str1") - { - arduino::String str1("Hello"); - arduino::String str2("Hello World"); - REQUIRE(str1.endsWith(str2) == 0); - } - WHEN ("str1 ends with str2") - { - arduino::String str1("Hello World"); - arduino::String str2("World"); - REQUIRE(str1.endsWith(str2) == 1); - } - WHEN ("str1 does NOT end with str2") - { - arduino::String str1("Hello World"); - arduino::String str2("Helo"); - REQUIRE(str1.endsWith(str2) == 0); - } -} diff --git a/ArduinoCore-API/test/src/String/test_concat.cpp b/ArduinoCore-API/test/src/String/test_concat.cpp deleted file mode 100644 index 8113659..0000000 --- a/ArduinoCore-API/test/src/String/test_concat.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::concat(const String &)", "[String-concat-01]") -{ - arduino::String str1("Hello "), str2("Arduino!"); - REQUIRE(str1.concat(str2) == 1); - REQUIRE(str1 == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::concat(const char *)", "[String-concat-02]") -{ - arduino::String str("Hello "); - REQUIRE(str.concat("Arduino!") == 1); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::concat(char)", "[String-concat-03]") -{ - arduino::String str("Hello "); - char const c = 'A'; - REQUIRE(str.concat(c) == 1); - REQUIRE(str == "Hello A"); -} - -TEST_CASE ("Testing String::concat(unsigned char)", "[String-concat-04]") -{ - arduino::String str("Hello "); - unsigned char const c = 'A'; - REQUIRE(str.concat(c) == 1); - REQUIRE(str == "Hello 65"); /* ASCII['A'] = 65 */ -} - -TEST_CASE ("Testing String::concat(int)", "[String-concat-05]") -{ - arduino::String str("Hello "); - int const num = -1; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello -1"); -} - -TEST_CASE ("Testing String::concat(unsigned int)", "[String-concat-06]") -{ - arduino::String str("Hello "); - unsigned int const num = 1; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello 1"); -} - -TEST_CASE ("Testing String::concat(long)", "[String-concat-07]") -{ - arduino::String str("Hello "); - long const num = -1; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello -1"); -} - -TEST_CASE ("Testing String::concat(unsigned long)", "[String-concat-08]") -{ - arduino::String str("Hello "); - unsigned long const num = 1; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello 1"); -} - -TEST_CASE ("Testing String::concat(float)", "[String-concat-09]") -{ - arduino::String str("Hello "); - float const num = 1.234f; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello 1.23"); -} - -TEST_CASE ("Testing String::concat(double)", "[String-concat-10]") -{ - arduino::String str("Hello "); - double const num = 5.678; - REQUIRE(str.concat(num) == 1); - REQUIRE(str == "Hello 5.68"); -} - -TEST_CASE ("Testing String::concat(const __FlashStringHelper *)", "[String-concat-11]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - arduino::String str1("Hello"); - REQUIRE(str1.concat(F(" Arduino")) == 1); - REQUIRE(str1 == "Hello Arduino"); -} diff --git a/ArduinoCore-API/test/src/String/test_indexOf.cpp b/ArduinoCore-API/test/src/String/test_indexOf.cpp deleted file mode 100644 index 12de054..0000000 --- a/ArduinoCore-API/test/src/String/test_indexOf.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::indexOf(char ch)", "[String-indexOf-01]") -{ - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.indexOf('a') == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hello"); - REQUIRE(str.indexOf('a') == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hello"); - REQUIRE(str.indexOf('l') == 2); - } -} - -TEST_CASE ("Testing String::indexOf(char ch, unsigned int fromIndex)", "[String-indexOf-02]") -{ - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.indexOf('a', 5) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.indexOf('a', 3) == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hello"); - REQUIRE(str.indexOf('l', 3) == 3); - } -} - -TEST_CASE ("Testing String::indexOf(const String &)", "[String-indexOf-03]") -{ - arduino::String const search_str("Arduino"); - - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.indexOf(search_str) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.indexOf(search_str) == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hello Arduino!"); - REQUIRE(str.indexOf(search_str) == 6); - } -} - -TEST_CASE ("Testing String::indexOf(const String &, unsigned int fromIndex)", "[String-indexOf-04]") -{ - arduino::String const search_str("Arduino"); - - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.indexOf(search_str, 3) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.indexOf(search_str, 3) == -1); - } - WHEN ("str does contain searched element and fromIndex is < start of searched element") - { - arduino::String str("Hello Arduino!"); - REQUIRE(str.indexOf(search_str, 3) == 6); - } - WHEN ("str does contain searched element and fromIndex is > start of searched element") - { - arduino::String str("Hello Arduino!"); - REQUIRE(str.indexOf(search_str, 8) == -1); - } -} diff --git a/ArduinoCore-API/test/src/String/test_isEmpty.cpp b/ArduinoCore-API/test/src/String/test_isEmpty.cpp deleted file mode 100644 index a6e30f9..0000000 --- a/ArduinoCore-API/test/src/String/test_isEmpty.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2023 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::isEmpty when string is empty", "[String-isEmpty-01]") -{ - arduino::String str; - REQUIRE(str.isEmpty()); -} - -TEST_CASE ("Testing String::isEmpty when string contains characters", "[String-isEmpty-02]") -{ - arduino::String str("Testing String::isEmpty"); - REQUIRE(!str.isEmpty()); -} diff --git a/ArduinoCore-API/test/src/String/test_lastIndexOf.cpp b/ArduinoCore-API/test/src/String/test_lastIndexOf.cpp deleted file mode 100644 index 13e850c..0000000 --- a/ArduinoCore-API/test/src/String/test_lastIndexOf.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::lastIndexOf(char ch)", "[String-lastIndexOf-01]") -{ - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.lastIndexOf('a') == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hello"); - REQUIRE(str.lastIndexOf('a') == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hellolol"); - REQUIRE(str.lastIndexOf('l') == 7); - } -} - -TEST_CASE ("Testing String::lastIndexOf(char ch, unsigned int fromIndex)", "[String-lastIndexOf-02]") -{ - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.lastIndexOf('a', 5) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.lastIndexOf('o', 3) == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hellolol"); - REQUIRE(str.lastIndexOf('l', 3) == 3); - } -} - -TEST_CASE ("Testing String::lastIndexOf(const String &)", "[String-lastIndexOf-03]") -{ - arduino::String const search_str("Arduino"); - - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.lastIndexOf(search_str) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.lastIndexOf(search_str) == -1); - } - WHEN ("str does contain searched element") - { - arduino::String str("Hello Arduino, Arduino!"); - REQUIRE(str.lastIndexOf(search_str) == 15); - } -} - -TEST_CASE ("Testing String::lastIndexOf(const String &, unsigned int fromIndex)", "[String-lastIndexOf-04]") -{ - arduino::String const search_str("Arduino"); - - WHEN ("str is empty") - { - arduino::String str; - REQUIRE(str.lastIndexOf(search_str, 3) == -1); - } - WHEN ("str does not contained searched element") - { - arduino::String str("Hallo"); - REQUIRE(str.lastIndexOf(search_str, 3) == -1); - } - WHEN ("str does contain searched element and fromIndex is > start of searched element") - { - arduino::String str("Hello Arduino, Arduino!"); - REQUIRE(str.lastIndexOf(search_str, 17) == 15); - } - WHEN ("str does contain searched element and fromIndex is < start of searched element") - { - arduino::String str("Hello Arduino, Arduino!"); - REQUIRE(str.lastIndexOf(search_str, 3) == -1); - } -} diff --git a/ArduinoCore-API/test/src/String/test_length.cpp b/ArduinoCore-API/test/src/String/test_length.cpp deleted file mode 100644 index 062ba81..0000000 --- a/ArduinoCore-API/test/src/String/test_length.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::length when string is empty", "[String-length-01]") -{ - arduino::String str; - REQUIRE(str.length() == 0); -} - -TEST_CASE ("Testing String::length when string contains characters", "[String-length-02]") -{ - arduino::String str("Testing String::length"); - REQUIRE(str.length() == strlen("Testing String::length")); -} diff --git a/ArduinoCore-API/test/src/String/test_move.cpp b/ArduinoCore-API/test/src/String/test_move.cpp deleted file mode 100644 index fda0a0d..0000000 --- a/ArduinoCore-API/test/src/String/test_move.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#include - -#include - -#include "StringPrinter.h" - -#include - -TEST_CASE("Testing String move constructor", "[String-move-01]") -{ - arduino::String a("src"); - char const* const a_str = a.c_str(); - arduino::String b(std::move(a)); - REQUIRE(a.length() == 0); - REQUIRE(a.c_str() == nullptr); - REQUIRE(b.c_str() == a_str); - REQUIRE(b.length() == 3); -} - -TEST_CASE("Testing String move assignment", "[String-move-02]") -{ - arduino::String a("src"); - char const* const a_str = a.c_str(); - arduino::String b; - b = std::move(a); - REQUIRE(a.length() == 0); - REQUIRE(a.c_str() == nullptr); - REQUIRE(b == arduino::String("src")); - REQUIRE(b.c_str() == a_str); -} - -TEST_CASE("Testing String move self assignment", "[String-move-03]") -{ -#if (defined(GCC_VERSION) && GCC_VERSION >= 13) || (defined(__clang_major__) && __clang_major__ >= 14) \ - || (defined(__GNUC__) && __GNUC__ >= 13) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wself-move" -#endif - arduino::String a("src"); - a = std::move(a); - REQUIRE(a == "src"); -#if defined(GCC_VERSION) && GCC_VERSION >= 13 || (defined(__clang_major__) && __clang_major__ >= 14) \ - || (defined(__GNUC__) && __GNUC__ >= 13) -#pragma GCC diagnostic pop -#endif -} diff --git a/ArduinoCore-API/test/src/String/test_operators.cpp b/ArduinoCore-API/test/src/String/test_operators.cpp deleted file mode 100644 index 14f826b..0000000 --- a/ArduinoCore-API/test/src/String/test_operators.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::operator + (const StringSumHelper, const String)", "[String-operator+-01]") -{ - arduino::String str1("Hello "); - arduino::String str2("Arduino"); - arduino::String str("Hello Arduino"); - REQUIRE(str == str1+str2); -} - -TEST_CASE ("Testing String::operator + (const StringSumHelper, const char *)", "[String-operator+-02]") -{ - arduino::String str1("Hello "); - arduino::String str("Hello Arduino"); - REQUIRE(str == str1+"Arduino"); -} - -TEST_CASE ("Testing String::operator + (const StringSumHelper, char)", "[String-operator+-03]") -{ - arduino::String str1("Hello"); - char ch='!'; - arduino::String str("Hello!"); - REQUIRE(str == str1+ch); -} - -TEST_CASE ("Testing String::operator + (const StringSumHelper, unsigned char)", "[String-operator+-04]") -{ - arduino::String str1("Hello "); - unsigned char ch='A'; - arduino::String str("Hello 65"); /* ASCII['A'] = 65 */ - REQUIRE(str == str1+ch); -} - -TEST_CASE ("Testing String::operator + (const StringSumHelper, int)", "[String-operator+-05]") -{ - arduino::String str1("Hello "); - arduino::String str("Hello 1"); - REQUIRE(str == str1+1); -} - -TEST_CASE ("Testing String::operator + (unsigned int)", "[String-operator+-06]") -{ - arduino::String str1("Hello "); - unsigned int const num = 1; - arduino::String str("Hello 1"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (long)", "[String-operator+-07]") -{ - arduino::String str1("Hello "); - long const num = -1; - arduino::String str("Hello -1"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (unsigned long)", "[String-operator+-08]") -{ - arduino::String str1("Hello "); - unsigned long const num = 1; - arduino::String str("Hello 1"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (float)", "[String-operator+-09]") -{ - arduino::String str1("Hello "); - float const num = 1.234f; - arduino::String str("Hello 1.23"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (double)", "[String-operator+-10]") -{ - arduino::String str1("Hello "); - double const num = 5.678; - arduino::String str("Hello 5.68"); - REQUIRE(str == str1+num); -} - -TEST_CASE ("Testing String::operator + (const __FlashStringHelper *)", "[String-operator+-11]") -{ -#undef F -#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) - arduino::String str1("Hello "); - arduino::String str("Hello Arduino"); - REQUIRE(str == str1+F("Arduino")); -} - -TEST_CASE ("Testing & String::operator = (StringSumHelper &&rval)", "[String-operator+-12]") -{ - arduino::String str1("Hello "); - arduino::String str = (str1+"Arduino"); - REQUIRE(str == "Hello Arduino"); -} - -TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of second string", "[String-operator+-13]") -{ - arduino::String str1("Hello"); - - char *buffer2 = NULL; - arduino::String str2(buffer2); - - str1 = str2; - REQUIRE(str1 == str2); -} - -TEST_CASE ("Testing & String::operator = (const char *) with NULL does not leave string unchanged", "[String-operator+-14]") -{ - char *buffer = NULL; - arduino::String str("Hello"); - str = buffer; - REQUIRE(str != "Hello"); -} - -TEST_CASE ("Testing & String::operator = (const char *) with NULL produces invalid string", "[String-operator+-14]") -{ - char *buffer = NULL; - arduino::String str("Hello"); - str = buffer; - REQUIRE_FALSE(str); -} - -TEST_CASE ("Testing & String::operator = (const String &) with invalid buffer of first string", "[String-operator+-15]") -{ - char *buffer1 = NULL; - arduino::String str1(buffer1); - - arduino::String str2("Hello"); - - str1 = str2; - REQUIRE(str1 == str2); -} - -TEST_CASE ("Testing & String::operator = (String &&)", "[String-operator+-16]") -{ - arduino::String str("Hello"); - arduino::String str1("Arduino"); - str1 = static_cast(str); - REQUIRE(str1 == "Hello"); -} - -TEST_CASE ("Testing & String::operator = (StringSumHelper &&)", "[String-operator+-17]") -{ - arduino::String str("Hello"); - char const ch = '!'; - arduino::String str1("Arduino"); - str1 = static_cast(str+ch); - REQUIRE(str1 == "Hello!"); -} diff --git a/ArduinoCore-API/test/src/String/test_remove.cpp b/ArduinoCore-API/test/src/String/test_remove.cpp deleted file mode 100644 index 6281d77..0000000 --- a/ArduinoCore-API/test/src/String/test_remove.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::remove(index) when string is empty", "[String-remove-01]") -{ - arduino::String str; - str.remove(0); - REQUIRE(str.length() == 0); -} - -TEST_CASE ("Testing String::remove(index) when index is > string length", "[String-remove-02]") -{ - arduino::String str("Hello Arduino!"); - str.remove(100); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::remove(index) when index is < string length", "[String-remove-03]") -{ - arduino::String str("Hello Arduino!"); - str.remove(5); - REQUIRE(str == "Hello"); -} - -TEST_CASE ("Testing String::remove(index,count) when string is empty", "[String-remove-04]") -{ - arduino::String str; - str.remove(0, 10); - REQUIRE(str.length() == 0); -} - -TEST_CASE ("Testing String::remove(index,count) when index is > string length", "[String-remove-05]") -{ - arduino::String str("Hello Arduino!"); - str.remove(100, 10); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::remove(index,count) when index is < string length && count is > remaining length", "[String-remove-06]") -{ - arduino::String str("Hello Arduino!"); - str.remove(5, 100); - REQUIRE(str == "Hello"); -} - -TEST_CASE ("Testing String::remove(index,count) when index is < string length && count is < remaining length", "[String-remove-07]") -{ - arduino::String str("Hello Arduino!"); - str.remove(5, 1); - REQUIRE(str == "HelloArduino!"); -} diff --git a/ArduinoCore-API/test/src/String/test_replace.cpp b/ArduinoCore-API/test/src/String/test_replace.cpp deleted file mode 100644 index 36b4413..0000000 --- a/ArduinoCore-API/test/src/String/test_replace.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::replace(char, char) when string is empty", "[String-replace-01]") -{ - arduino::String str; - str.replace('a', 'b'); - REQUIRE(str.length() == 0); -} - -TEST_CASE ("Testing String::replace(char, char) when string contains elements != 'find'", "[String-replace-02]") -{ - arduino::String str("Hello Arduino!"); - str.replace('Z', '0'); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::replace(char, char) when string contains elements = 'find'", "[String-replace-03]") -{ - arduino::String str("Hello Arduino!"); - str.replace('o', '0'); - str.replace('e', '3'); - str.replace('i', '1'); - REQUIRE(str == "H3ll0 Ardu1n0!"); -} - -TEST_CASE ("Testing String::replace(String, String) when string does not contain substr 'find'", "[String-replace-04]") -{ - arduino::String str("Hello Arduino!"); - str.replace(arduino::String("Zulu"), arduino::String("11")); - REQUIRE(str == "Hello Arduino!"); -} - -TEST_CASE ("Testing String::replace(String, String) when string contains substr 'find'", "[String-replace-05]") -{ - arduino::String str("Hello Arduino!"); - str.replace(arduino::String("ll"), arduino::String("11")); - REQUIRE(str == "He11o Arduino!"); -} - -TEST_CASE ("Testing String::replace(String, String) substr 'find' larger than 'replace'", "[String-replace-06]") -{ - arduino::String str("Hello Arduino!"); - str.replace(arduino::String("llo"), arduino::String("11")); - REQUIRE(str == "He11 Arduino!"); -} - -TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than 'replace'", "[String-replace-07]") -{ - arduino::String str("Hello Arduino!"); - str.replace(arduino::String("ll"), arduino::String("111")); - REQUIRE(str == "He111o Arduino!"); -} - -TEST_CASE ("Testing String::replace(String, String) substr 'find' smaller than 'replace' multiple occurencies", "[String-replace-08]") -{ - arduino::String str("Hello Arduino! Hello, Hello, Hello"); - str.replace(arduino::String("ll"), arduino::String("lll")); - REQUIRE(str == "Helllo Arduino! Helllo, Helllo, Helllo"); -} - -TEST_CASE ("Testing String::replace(String, String) substr 'find' same length as 'replace' multiple occurencies", "[String-replace-09]") -{ - arduino::String str("Hello Arduino! Hello, Hello, Hello"); - str.replace(arduino::String("ll"), arduino::String("11")); - REQUIRE(str == "He11o Arduino! He11o, He11o, He11o"); -} - -TEST_CASE ("Testing String::replace(String, String) substr 'find' larger than 'replace' multiple occurencies", "[String-replace-10]") -{ - arduino::String str("Helllo Arduino! Helllo, Helllo, Helllo"); - str.replace(arduino::String("lll"), arduino::String("ll")); - REQUIRE(str == "Hello Arduino! Hello, Hello, Hello"); -} diff --git a/ArduinoCore-API/test/src/String/test_substring.cpp b/ArduinoCore-API/test/src/String/test_substring.cpp deleted file mode 100644 index 6397b90..0000000 --- a/ArduinoCore-API/test/src/String/test_substring.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::substring(unsigned int, unsigned int)", "[String-substring-01]") -{ - WHEN ("left higher than len") - { - arduino::String str("Hello"); - str.substring(7,9); - } - - WHEN ("right higher than len") - { - arduino::String str1("Hello"); - arduino::String str2("ello"); - REQUIRE(str2 == str1.substring(1,9)); - } - - WHEN ("left higher than right") - { - arduino::String str1("Hello"); - arduino::String str2("ello"); - REQUIRE(str2 == str1.substring(9,1)); - } -} diff --git a/ArduinoCore-API/test/src/String/test_toDouble.cpp b/ArduinoCore-API/test/src/String/test_toDouble.cpp deleted file mode 100644 index 3bb1ba5..0000000 --- a/ArduinoCore-API/test/src/String/test_toDouble.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toDouble when string is empty", "[String-toDouble-01]") -{ - arduino::String str; - double const val = str.toDouble(); - REQUIRE(val == 0.0); -} - -TEST_CASE ("Testing String::toDouble when string contains no number", "[String-toDouble-02]") -{ - arduino::String str("abc"); - double const val = str.toDouble(); - REQUIRE(val == 0.0); -} - -TEST_CASE ("Testing String::toDouble when string contains a number", "[String-toDouble-03]") -{ - arduino::String str("-1.2345"); - double const val = str.toDouble(); - REQUIRE(val == -1.2345); -} - -TEST_CASE ("Testing String::toDouble when string does not have a buffer", "[String-toDouble-04]") -{ - char *buffer = NULL; - arduino::String str(buffer); - REQUIRE(str.toDouble() == 0); -} diff --git a/ArduinoCore-API/test/src/String/test_toFloat.cpp b/ArduinoCore-API/test/src/String/test_toFloat.cpp deleted file mode 100644 index 28fca21..0000000 --- a/ArduinoCore-API/test/src/String/test_toFloat.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toFloat when string is empty", "[String-toFloat-01]") -{ - arduino::String str; - float const val = str.toFloat(); - REQUIRE(val == 0.0f); -} - -TEST_CASE ("Testing String::toFloat when string contains no number", "[String-toFloat-02]") -{ - arduino::String str("abc"); - float const val = str.toFloat(); - REQUIRE(val == 0.0f); -} - -TEST_CASE ("Testing String::toFloat when string contains a number", "[String-toFloat-03]") -{ - arduino::String str("-1.2345"); - float const val = str.toFloat(); - REQUIRE(val == -1.2345f); -} diff --git a/ArduinoCore-API/test/src/String/test_toInt.cpp b/ArduinoCore-API/test/src/String/test_toInt.cpp deleted file mode 100644 index c93fcc4..0000000 --- a/ArduinoCore-API/test/src/String/test_toInt.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toInt when string is empty", "[String-toInt-01]") -{ - arduino::String str; - int const val = str.toInt(); - REQUIRE(val == 0); -} - -TEST_CASE ("Testing String::toInt when string contains no number", "[String-toInt-02]") -{ - arduino::String str("abc"); - int const val = str.toInt(); - REQUIRE(val == 0); -} - -TEST_CASE ("Testing String::toInt when string contains a number", "[String-toInt-03]") -{ - arduino::String str("-1"); - int const val = str.toInt(); - REQUIRE(val == -1); -} - -TEST_CASE ("Testing String::toInt when string does not have a buffer", "[String-toInt-04]") -{ - char *buffer = NULL; - arduino::String str(buffer); - REQUIRE(str.toInt() == 0); -} diff --git a/ArduinoCore-API/test/src/String/test_toLowerCase.cpp b/ArduinoCore-API/test/src/String/test_toLowerCase.cpp deleted file mode 100644 index ec0f9eb..0000000 --- a/ArduinoCore-API/test/src/String/test_toLowerCase.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toLowerCase", "[String-toLowerCase-01]") -{ - arduino::String str("HELLO ARDUINO"); - str.toLowerCase(); - REQUIRE(str == "hello arduino"); -} diff --git a/ArduinoCore-API/test/src/String/test_toUpperCase.cpp b/ArduinoCore-API/test/src/String/test_toUpperCase.cpp deleted file mode 100644 index 937fa52..0000000 --- a/ArduinoCore-API/test/src/String/test_toUpperCase.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::toUpperCase", "[String-toUpperCase-01]") -{ - arduino::String str("hello arduino"); - str.toUpperCase(); - REQUIRE(str == "HELLO ARDUINO"); -} diff --git a/ArduinoCore-API/test/src/String/test_trim.cpp b/ArduinoCore-API/test/src/String/test_trim.cpp deleted file mode 100644 index eddc9fd..0000000 --- a/ArduinoCore-API/test/src/String/test_trim.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -#include "StringPrinter.h" - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("Testing String::trim with space at the beginning", "[String-trim-01]") -{ - arduino::String str(" hello"); - str.trim(); - REQUIRE(str == "hello"); -} - -TEST_CASE ("Testing String::trim with space at the end", "[String-trim-02]") -{ - arduino::String str("hello "); - str.trim(); - REQUIRE(str == "hello"); -} - -TEST_CASE ("Testing String::trim with space at both beginning and end", "[String-trim-03]") -{ - arduino::String str(" hello "); - str.trim(); - REQUIRE(str == "hello"); -} - -TEST_CASE ("Testing String::trim with space in the middle", "[String-trim-04]") -{ - arduino::String str("Hello Arduino!"); - str.trim(); - REQUIRE(str == "Hello Arduino!"); -} diff --git a/ArduinoCore-API/test/src/WCharacter/test_isAscii.cpp b/ArduinoCore-API/test/src/WCharacter/test_isAscii.cpp deleted file mode 100644 index 4ec92d3..0000000 --- a/ArduinoCore-API/test/src/WCharacter/test_isAscii.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_ASCII_VECT = {' ', 'a', 'b', 'q', '\n', '\r'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isAscii(...) is called with a valid ascii character", "[isAscii-01]") -{ - std::for_each(std::begin(VALID_ASCII_VECT), - std::end (VALID_ASCII_VECT), - [](char const c) - { - REQUIRE(arduino::isAscii(c) == true); - }); -} - -TEST_CASE ("isAscii(...) is called with a invalid ascii character", "[isAscii-02]") -{ - REQUIRE(arduino::isAscii(0xf7) == false); -} - -TEST_CASE ("isAscii(...) is called with a invalid casted ascii character", "[isAscii-03]") -{ - REQUIRE(arduino::isAscii((unsigned char)0xf7) == false); -} - -TEST_CASE ("isAscii(...) is called with a character latger than 1 byte", "[isAscii-04]") -{ - REQUIRE(arduino::isAscii(0x3030) == false); -} - diff --git a/ArduinoCore-API/test/src/WCharacter/test_isControl.cpp b/ArduinoCore-API/test/src/WCharacter/test_isControl.cpp deleted file mode 100644 index c4e985c..0000000 --- a/ArduinoCore-API/test/src/WCharacter/test_isControl.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_CONTROL_VECT = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,'\t','\f','\v','\n','\r',0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x7F}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isControl(...) is called with control char", "[isControl-01]") -{ - std::for_each(std::begin(VALID_CONTROL_VECT), - std::end (VALID_CONTROL_VECT), - [](char const c) - { - REQUIRE(arduino::isControl(c) == true); - }); -} - -TEST_CASE ("isControl(...) is called with non control char", "[isControl-02]") -{ - REQUIRE(arduino::isControl('z') == false); -} diff --git a/ArduinoCore-API/test/src/WCharacter/test_isDigit.cpp b/ArduinoCore-API/test/src/WCharacter/test_isDigit.cpp deleted file mode 100644 index 3303cf4..0000000 --- a/ArduinoCore-API/test/src/WCharacter/test_isDigit.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_DIGIT_VECT = {'0','1','2','3','4','5','6','7','8','9'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isDigit(...) is called with valid digits", "[isDigit-01]") -{ - std::for_each(std::begin(VALID_DIGIT_VECT), - std::end (VALID_DIGIT_VECT), - [](char const c) - { - REQUIRE(arduino::isDigit(c) == true); - }); -} - -TEST_CASE ("isDigit(...) is called with non digit", "[isDigit-02]") -{ - REQUIRE(arduino::isDigit('z') == false); -} diff --git a/ArduinoCore-API/test/src/WCharacter/test_isHexadecimalDigit.cpp b/ArduinoCore-API/test/src/WCharacter/test_isHexadecimalDigit.cpp deleted file mode 100644 index ad5a0f4..0000000 --- a/ArduinoCore-API/test/src/WCharacter/test_isHexadecimalDigit.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_HEXADECIMAL_NUMBER_VECT = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','A','B','C','D','E','F'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isHexadecimalDigit(...) is called with valid hexadecimal numbers", "[isHexadecimalDigit-01]") -{ - std::for_each(std::begin(VALID_HEXADECIMAL_NUMBER_VECT), - std::end (VALID_HEXADECIMAL_NUMBER_VECT), - [](char const c) - { - REQUIRE(arduino::isHexadecimalDigit(c) == true); - }); -} - -TEST_CASE ("isHexadecimalDigit(...) is called with non hexadecimal number", "[isHexadecimalDigit-02]") -{ - REQUIRE(arduino::isHexadecimalDigit('z') == false); -} diff --git a/ArduinoCore-API/test/src/WCharacter/test_isLowerCase.cpp b/ArduinoCore-API/test/src/WCharacter/test_isLowerCase.cpp deleted file mode 100644 index 7a75220..0000000 --- a/ArduinoCore-API/test/src/WCharacter/test_isLowerCase.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isLowerCase(...) is called with a upper case number", "[isLowerCase-01]") -{ - REQUIRE(arduino::isLowerCase('A') == false); -} - -TEST_CASE ("isLowerCase(...) is called with a lower case number", "[isLowerCase-02]") -{ - REQUIRE(arduino::isLowerCase('a') == true); -} - -TEST_CASE ("isLowerCase(...) is called with a non-alphabetic number", "[isLowerCase-03]") -{ - REQUIRE(arduino::isLowerCase('0') == false); -} diff --git a/ArduinoCore-API/test/src/WCharacter/test_isPunct.cpp b/ArduinoCore-API/test/src/WCharacter/test_isPunct.cpp deleted file mode 100644 index 6d1167d..0000000 --- a/ArduinoCore-API/test/src/WCharacter/test_isPunct.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_PUNCT_VECT = {'!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>','?','@','[','\\',']','^','_','`','{','|','}','~'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isPunct('.') is called with a valid punct character", "[isPunct-01]") -{ - std::for_each(std::begin(VALID_PUNCT_VECT), - std::end (VALID_PUNCT_VECT), - [](char const c) - { - REQUIRE(arduino::isPunct(c) == true); - }); -} - -TEST_CASE ("isPunct(...) is called with a invalid punct character", "[isPunct-02]") -{ - REQUIRE(arduino::isPunct('a') == false); -} diff --git a/ArduinoCore-API/test/src/WCharacter/test_isSpace.cpp b/ArduinoCore-API/test/src/WCharacter/test_isSpace.cpp deleted file mode 100644 index 5c0be94..0000000 --- a/ArduinoCore-API/test/src/WCharacter/test_isSpace.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_SPACE_VECT = {' ', '\t', '\n', '\v', '\f', '\r'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isSpace(...) is called with a valid white space character", "[isSpace-01]") -{ - std::for_each(std::begin(VALID_SPACE_VECT), - std::end (VALID_SPACE_VECT), - [](char const c) - { - REQUIRE(arduino::isSpace(c) == true); - }); -} - -TEST_CASE ("isSpace(...) is called with a invalid white space character", "[isSpace-02]") -{ - REQUIRE(arduino::isSpace('{') == false); -} diff --git a/ArduinoCore-API/test/src/WCharacter/test_isUpperCase.cpp b/ArduinoCore-API/test/src/WCharacter/test_isUpperCase.cpp deleted file mode 100644 index 01dbf86..0000000 --- a/ArduinoCore-API/test/src/WCharacter/test_isUpperCase.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isUpperCase(...) is called with a upper case number", "[isUpperCase-01]") -{ - REQUIRE(arduino::isUpperCase('A') == true); -} - -TEST_CASE ("isUpperCase(...) is called with a lower case number", "[isUpperCase-02]") -{ - REQUIRE(arduino::isUpperCase('a') == false); -} - -TEST_CASE ("isUpperCase(...) is called with a non-alphabetic number", "[isUpperCase-03]") -{ - REQUIRE(arduino::isUpperCase('0') == false); -} diff --git a/ArduinoCore-API/test/src/WCharacter/test_isWhitespace.cpp b/ArduinoCore-API/test/src/WCharacter/test_isWhitespace.cpp deleted file mode 100644 index 0eaa96d..0000000 --- a/ArduinoCore-API/test/src/WCharacter/test_isWhitespace.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("isWhitespace(...) is called with ' '", "[isWhitespace-01]") -{ - REQUIRE(arduino::isWhitespace(' ') == true); -} - -TEST_CASE ("isWhitespace(...) is called with '\t'", "[isWhitespace-02]") -{ - REQUIRE(arduino::isWhitespace('\t') == true); -} - -TEST_CASE ("isWhitespace(...) is called with a non whitespace char", "[isWhitespace-03]") -{ - REQUIRE(arduino::isWhitespace('\r') == false); -} diff --git a/ArduinoCore-API/test/src/WCharacter/test_toAscii.cpp b/ArduinoCore-API/test/src/WCharacter/test_toAscii.cpp deleted file mode 100644 index eb085cb..0000000 --- a/ArduinoCore-API/test/src/WCharacter/test_toAscii.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include -#include - -#include - -#include - -/************************************************************************************** - * CONSTANTS - **************************************************************************************/ - -std::vector const VALID_ASCII_VECT = {' ', 'a', 'b', 'q', '\n', '\r'}; - -/************************************************************************************** - * TEST CODE - **************************************************************************************/ - -TEST_CASE ("toAscii(...) is called with a valid ascii character", "[toAscii-01]") -{ - std::for_each(std::begin(VALID_ASCII_VECT), - std::end (VALID_ASCII_VECT), - [](char const c) - { - REQUIRE(arduino::toAscii(c) == c); - }); -} - -TEST_CASE ("toAscii(...) is called with a invalid ascii character", "[toAscii-02]") -{ - REQUIRE(arduino::toAscii(0xf7) == 0x77); -} - -TEST_CASE ("toAscii(...) is called with a invalid casted ascii character", "[toAscii-03]") -{ - REQUIRE(arduino::toAscii((unsigned char)0xf7) == 0x77); -} - -TEST_CASE ("toAscii(...) is called with a character larger than 1 byte", "[toAscii-04]") -{ - REQUIRE(arduino::toAscii(0x3030) == 0x30); -} diff --git a/ArduinoCore-API/test/src/dtostrf.cpp b/ArduinoCore-API/test/src/dtostrf.cpp deleted file mode 100644 index 02ea2fe..0000000 --- a/ArduinoCore-API/test/src/dtostrf.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include - -/************************************************************************************** - * FUNCTION IMPLEMENTATION - **************************************************************************************/ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/ArduinoCore-API/test/src/itoa.cpp b/ArduinoCore-API/test/src/itoa.cpp deleted file mode 100644 index 4070ca6..0000000 --- a/ArduinoCore-API/test/src/itoa.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2020 Arduino. All rights reserved. - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -/************************************************************************************** - * INCLUDE - **************************************************************************************/ - -#include - -#include -#include - -#include - -/************************************************************************************** - * FUNCTION IMPLEMENTATION - **************************************************************************************/ - -std::string radixToFmtString(int const radix) -{ - if (radix == 8) return std::string("%o"); - else if (radix == 10) return std::string("%d"); - else if (radix == 16) return std::string("%X"); - else throw std::runtime_error("Invalid radix."); -} - -char * itoa(int value, char * str, int radix) -{ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - sprintf(str, radixToFmtString(radix).c_str(), value); -#pragma GCC diagnostic pop - return str; -} - -char * ltoa(long value, char * str, int radix) -{ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - sprintf(str, radixToFmtString(radix).c_str(), value); -#pragma GCC diagnostic pop - return str; -} - -char * utoa(unsigned value, char *str, int radix) -{ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - sprintf(str, radixToFmtString(radix).c_str(), value); -#pragma GCC diagnostic pop - return str; -} - -char * ultoa(unsigned long value, char * str, int radix) -{ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - sprintf(str, radixToFmtString(radix).c_str(), value); -#pragma GCC diagnostic pop - return str; -} From 6f1e23c996873835d38b8133571870bc4b91c81d Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Thu, 2 Oct 2025 17:50:59 +0200 Subject: [PATCH 4/4] ArduinoCore-API as submodule --- .gitmodules | 3 +++ ArduinoCore-API | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 ArduinoCore-API diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7922a52 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ArduinoCore-API"] + path = ArduinoCore-API + url = https://github.com/arduino/ArduinoCore-API.git diff --git a/ArduinoCore-API b/ArduinoCore-API new file mode 160000 index 0000000..cd91833 --- /dev/null +++ b/ArduinoCore-API @@ -0,0 +1 @@ +Subproject commit cd91833d90b4fe50e428021ba5051e2b7ceafc84