From 7b6fd24c8ec2fc60aea31094d1a5f9fd94ce8d39 Mon Sep 17 00:00:00 2001 From: Mestery Date: Sat, 8 Apr 2023 19:56:41 +0000 Subject: [PATCH 1/6] fix non arduino build --- src/protocols/AX25/AX25.cpp | 2 ++ src/protocols/AX25/AX25.h | 2 ++ src/protocols/Hellschreiber/Hellschreiber.cpp | 4 +++ src/protocols/Hellschreiber/Hellschreiber.h | 4 +++ src/protocols/Morse/Morse.cpp | 4 +++ src/protocols/Morse/Morse.h | 4 +++ src/protocols/Pager/Pager.cpp | 4 +++ src/protocols/Pager/Pager.h | 4 +++ src/protocols/PhysicalLayer/PhysicalLayer.cpp | 8 ++++++ src/protocols/PhysicalLayer/PhysicalLayer.h | 8 ++++++ src/protocols/RTTY/RTTY.cpp | 26 +++++++++++-------- src/protocols/RTTY/RTTY.h | 8 ++++-- 12 files changed, 65 insertions(+), 13 deletions(-) diff --git a/src/protocols/AX25/AX25.cpp b/src/protocols/AX25/AX25.cpp index 8bc8de4b..5b657c41 100644 --- a/src/protocols/AX25/AX25.cpp +++ b/src/protocols/AX25/AX25.cpp @@ -194,9 +194,11 @@ int16_t AX25Client::begin(const char* srcCallsign, uint8_t srcSSID, uint8_t prea return(_phy->startDirect()); } +#if defined(RADIOLIB_BUILD_ARDUINO) int16_t AX25Client::transmit(String& str, const char* destCallsign, uint8_t destSSID) { return(transmit(str.c_str(), destCallsign, destSSID)); } +#endif int16_t AX25Client::transmit(const char* str, const char* destCallsign, uint8_t destSSID) { // create control field diff --git a/src/protocols/AX25/AX25.h b/src/protocols/AX25/AX25.h index dcf03334..608f09a7 100644 --- a/src/protocols/AX25/AX25.h +++ b/src/protocols/AX25/AX25.h @@ -322,6 +322,7 @@ class AX25Client { */ int16_t begin(const char* srcCallsign, uint8_t srcSSID = 0x00, uint8_t preambleLen = 8); + #if defined(RADIOLIB_BUILD_ARDUINO) /*! \brief Transmit unnumbered information (UI) frame. @@ -334,6 +335,7 @@ class AX25Client { \returns \ref status_codes */ int16_t transmit(String& str, const char* destCallsign, uint8_t destSSID = 0x00); + #endif /*! \brief Transmit unnumbered information (UI) frame. diff --git a/src/protocols/Hellschreiber/Hellschreiber.cpp b/src/protocols/Hellschreiber/Hellschreiber.cpp index 78eb3bdb..2607142b 100644 --- a/src/protocols/Hellschreiber/Hellschreiber.cpp +++ b/src/protocols/Hellschreiber/Hellschreiber.cpp @@ -94,6 +94,7 @@ size_t HellClient::write(uint8_t b) { return(printGlyph(buff)); } +#if defined(RADIOLIB_BUILD_ARDUINO) size_t HellClient::print(__FlashStringHelper* fstr) { PGM_P p = reinterpret_cast(fstr); size_t n = 0; @@ -110,6 +111,7 @@ size_t HellClient::print(__FlashStringHelper* fstr) { size_t HellClient::print(const String& str) { return(HellClient::write((uint8_t*)str.c_str(), str.length())); } +#endif size_t HellClient::print(const char* str) { return(HellClient::write((uint8_t*)str, strlen(str))); @@ -163,6 +165,7 @@ size_t HellClient::println(void) { return(HellClient::print(' ')); } +#if defined(RADIOLIB_BUILD_ARDUINO) size_t HellClient::println(__FlashStringHelper* fstr) { size_t n = HellClient::print(fstr); n += HellClient::println(); @@ -174,6 +177,7 @@ size_t HellClient::println(const String& str) { n += HellClient::println(); return(n); } +#endif size_t HellClient::println(const char* str) { size_t n = HellClient::print(str); diff --git a/src/protocols/Hellschreiber/Hellschreiber.h b/src/protocols/Hellschreiber/Hellschreiber.h index 59e11409..1609168a 100644 --- a/src/protocols/Hellschreiber/Hellschreiber.h +++ b/src/protocols/Hellschreiber/Hellschreiber.h @@ -135,8 +135,10 @@ class HellClient { size_t write(uint8_t* buff, size_t len); size_t write(uint8_t b); + #if defined(RADIOLIB_BUILD_ARDUINO) size_t print(__FlashStringHelper*); size_t print(const String &); + #endif size_t print(const char[]); size_t print(char); size_t print(unsigned char, int = DEC); @@ -147,8 +149,10 @@ class HellClient { size_t print(double, int = 2); size_t println(void); + #if defined(RADIOLIB_BUILD_ARDUINO) size_t println(__FlashStringHelper*); size_t println(const String &); + #endif size_t println(const char[]); size_t println(char); size_t println(unsigned char, int = DEC); diff --git a/src/protocols/Morse/Morse.cpp b/src/protocols/Morse/Morse.cpp index 84972590..3fbe3dd4 100644 --- a/src/protocols/Morse/Morse.cpp +++ b/src/protocols/Morse/Morse.cpp @@ -179,6 +179,7 @@ size_t MorseClient::write(uint8_t b) { return(1); } +#if defined(RADIOLIB_BUILD_ARDUINO) size_t MorseClient::print(__FlashStringHelper* fstr) { PGM_P p = reinterpret_cast(fstr); size_t n = 0; @@ -195,6 +196,7 @@ size_t MorseClient::print(__FlashStringHelper* fstr) { size_t MorseClient::print(const String& str) { return(MorseClient::write((uint8_t*)str.c_str(), str.length())); } +#endif size_t MorseClient::print(const char* str) { return(MorseClient::write((uint8_t*)str, strlen(str))); @@ -247,6 +249,7 @@ size_t MorseClient::println(void) { return(MorseClient::write('^')); } +#if defined(RADIOLIB_BUILD_ARDUINO) size_t MorseClient::println(__FlashStringHelper* fstr) { size_t n = MorseClient::print(fstr); n += MorseClient::println(); @@ -258,6 +261,7 @@ size_t MorseClient::println(const String& str) { n += MorseClient::println(); return(n); } +#endif size_t MorseClient::println(const char* str) { size_t n = MorseClient::print(str); diff --git a/src/protocols/Morse/Morse.h b/src/protocols/Morse/Morse.h index 0ae567e7..fe60cc7c 100644 --- a/src/protocols/Morse/Morse.h +++ b/src/protocols/Morse/Morse.h @@ -160,8 +160,10 @@ class MorseClient { size_t write(uint8_t* buff, size_t len); size_t write(uint8_t b); + #if defined(RADIOLIB_BUILD_ARDUINO) size_t print(__FlashStringHelper*); size_t print(const String &); + #endif size_t print(const char[]); size_t print(char); size_t print(unsigned char, int = DEC); @@ -172,8 +174,10 @@ class MorseClient { size_t print(double, int = 2); size_t println(void); + #if defined(RADIOLIB_BUILD_ARDUINO) size_t println(__FlashStringHelper*); size_t println(const String &); + #endif size_t println(const char[]); size_t println(char); size_t println(unsigned char, int = DEC); diff --git a/src/protocols/Pager/Pager.cpp b/src/protocols/Pager/Pager.cpp index 32f401f6..f6aae335 100644 --- a/src/protocols/Pager/Pager.cpp +++ b/src/protocols/Pager/Pager.cpp @@ -52,9 +52,11 @@ int16_t PagerClient::sendTone(uint32_t addr) { return(PagerClient::transmit(NULL, 0, addr)); } +#if defined(RADIOLIB_BUILD_ARDUINO) int16_t PagerClient::transmit(String& str, uint32_t addr, uint8_t encoding) { return(PagerClient::transmit(str.c_str(), addr, encoding)); } +#endif int16_t PagerClient::transmit(const char* str, uint32_t addr, uint8_t encoding) { return(PagerClient::transmit((uint8_t*)str, strlen(str), addr, encoding)); @@ -260,6 +262,7 @@ size_t PagerClient::available() { return(_phy->available() + sizeof(uint32_t))/(sizeof(uint32_t) * (RADIOLIB_PAGER_BATCH_LEN + 1)); } +#if defined(RADIOLIB_BUILD_ARDUINO) int16_t PagerClient::readData(String& str, size_t len, uint32_t* addr) { int16_t state = RADIOLIB_ERR_NONE; @@ -304,6 +307,7 @@ int16_t PagerClient::readData(String& str, size_t len, uint32_t* addr) { return(state); } +#endif int16_t PagerClient::readData(uint8_t* data, size_t* len, uint32_t* addr) { // find the correct address diff --git a/src/protocols/Pager/Pager.h b/src/protocols/Pager/Pager.h index 844150bc..966033fb 100644 --- a/src/protocols/Pager/Pager.h +++ b/src/protocols/Pager/Pager.h @@ -101,6 +101,7 @@ class PagerClient { */ int16_t sendTone(uint32_t addr); + #if defined(RADIOLIB_BUILD_ARDUINO) /*! \brief Arduino String transmit method. @@ -113,6 +114,7 @@ class PagerClient { \returns \ref status_codes */ int16_t transmit(String& str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD); + #endif /*! \brief C-string transmit method. @@ -164,6 +166,7 @@ class PagerClient { */ size_t available(); + #if defined(RADIOLIB_BUILD_ARDUINO) /*! \brief Reads data that was received after calling startReceive method. @@ -177,6 +180,7 @@ class PagerClient { \returns \ref status_codes */ int16_t readData(String& str, size_t len = 0, uint32_t* addr = NULL); + #endif /*! \brief Reads data that was received after calling startReceive method. diff --git a/src/protocols/PhysicalLayer/PhysicalLayer.cpp b/src/protocols/PhysicalLayer/PhysicalLayer.cpp index 78acfebb..46093ba9 100644 --- a/src/protocols/PhysicalLayer/PhysicalLayer.cpp +++ b/src/protocols/PhysicalLayer/PhysicalLayer.cpp @@ -9,6 +9,7 @@ PhysicalLayer::PhysicalLayer(float freqStep, size_t maxPacketLength) { #endif } +#if defined(RADIOLIB_BUILD_ARDUINO) int16_t PhysicalLayer::transmit(__FlashStringHelper* fstr, uint8_t addr) { // read flash string length size_t len = 0; @@ -45,6 +46,7 @@ int16_t PhysicalLayer::transmit(__FlashStringHelper* fstr, uint8_t addr) { int16_t PhysicalLayer::transmit(String& str, uint8_t addr) { return(transmit(str.c_str(), addr)); } +#endif int16_t PhysicalLayer::transmit(const char* str, uint8_t addr) { return(transmit((uint8_t*)str, strlen(str), addr)); @@ -57,6 +59,7 @@ int16_t PhysicalLayer::transmit(uint8_t* data, size_t len, uint8_t addr) { return(RADIOLIB_ERR_UNSUPPORTED); } +#if defined(RADIOLIB_BUILD_ARDUINO) int16_t PhysicalLayer::receive(String& str, size_t len) { int16_t state = RADIOLIB_ERR_NONE; @@ -103,6 +106,7 @@ int16_t PhysicalLayer::receive(String& str, size_t len) { return(state); } +#endif int16_t PhysicalLayer::receive(uint8_t* data, size_t len) { (void)data; @@ -131,9 +135,11 @@ int16_t PhysicalLayer::startReceive(uint32_t timeout, uint16_t irqFlags, uint16_ return(RADIOLIB_ERR_UNSUPPORTED); } +#if defined(RADIOLIB_BUILD_ARDUINO) int16_t PhysicalLayer::startTransmit(String& str, uint8_t addr) { return(startTransmit(str.c_str(), addr)); } +#endif int16_t PhysicalLayer::startTransmit(const char* str, uint8_t addr) { return(startTransmit((uint8_t*)str, strlen(str), addr)); @@ -150,6 +156,7 @@ int16_t PhysicalLayer::finishTransmit() { return(RADIOLIB_ERR_UNSUPPORTED); } +#if defined(RADIOLIB_BUILD_ARDUINO) int16_t PhysicalLayer::readData(String& str, size_t len) { int16_t state = RADIOLIB_ERR_NONE; @@ -192,6 +199,7 @@ int16_t PhysicalLayer::readData(String& str, size_t len) { return(state); } +#endif int16_t PhysicalLayer::readData(uint8_t* data, size_t len) { (void)data; diff --git a/src/protocols/PhysicalLayer/PhysicalLayer.h b/src/protocols/PhysicalLayer/PhysicalLayer.h index 915faf45..ddf742b7 100644 --- a/src/protocols/PhysicalLayer/PhysicalLayer.h +++ b/src/protocols/PhysicalLayer/PhysicalLayer.h @@ -27,6 +27,7 @@ class PhysicalLayer { // basic methods + #if defined(RADIOLIB_BUILD_ARDUINO) /*! \brief Arduino Flash String transmit method. @@ -48,6 +49,7 @@ class PhysicalLayer { \returns \ref status_codes */ int16_t transmit(String& str, uint8_t addr = 0); + #endif /*! \brief C-string transmit method. @@ -73,6 +75,7 @@ class PhysicalLayer { */ virtual int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0); + #if defined(RADIOLIB_BUILD_ARDUINO) /*! \brief Arduino String receive method. @@ -83,6 +86,7 @@ class PhysicalLayer { \returns \ref status_codes */ int16_t receive(String& str, size_t len = 0); + #endif /*! \brief Sets module to sleep. @@ -131,6 +135,7 @@ class PhysicalLayer { */ virtual int16_t receive(uint8_t* data, size_t len); + #if defined(RADIOLIB_BUILD_ARDUINO) /*! \brief Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes. @@ -142,6 +147,7 @@ class PhysicalLayer { \returns \ref status_codes */ int16_t startTransmit(String& str, uint8_t addr = 0); + #endif /*! \brief Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. @@ -175,6 +181,7 @@ class PhysicalLayer { */ virtual int16_t finishTransmit(); + #if defined(RADIOLIB_BUILD_ARDUINO) /*! \brief Reads data that was received after calling startReceive method. @@ -186,6 +193,7 @@ class PhysicalLayer { \returns \ref status_codes */ int16_t readData(String& str, size_t len = 0); + #endif /*! \brief Reads data that was received after calling startReceive method. diff --git a/src/protocols/RTTY/RTTY.cpp b/src/protocols/RTTY/RTTY.cpp index e1994978..abd4c6cb 100644 --- a/src/protocols/RTTY/RTTY.cpp +++ b/src/protocols/RTTY/RTTY.cpp @@ -209,6 +209,7 @@ size_t RTTYClient::write(uint8_t b) { return(1); } +#if defined(RADIOLIB_BUILD_ARDUINO) size_t RTTYClient::print(__FlashStringHelper* fstr) { // read flash string length size_t len = 0; @@ -247,13 +248,6 @@ size_t RTTYClient::print(__FlashStringHelper* fstr) { return(n); } -size_t RTTYClient::print(ITA2String& ita2) { - uint8_t* arr = ita2.byteArr(); - size_t n = RTTYClient::write(arr, ita2.length()); - delete[] arr; - return(n); -} - size_t RTTYClient::print(const String& str) { size_t n = 0; if(_encoding == RADIOLIB_ITA2) { @@ -264,6 +258,14 @@ size_t RTTYClient::print(const String& str) { } return(n); } +#endif + +size_t RTTYClient::print(ITA2String& ita2) { + uint8_t* arr = ita2.byteArr(); + size_t n = RTTYClient::write(arr, ita2.length()); + delete[] arr; + return(n); +} size_t RTTYClient::print(const char str[]) { size_t n = 0; @@ -337,20 +339,22 @@ size_t RTTYClient::println(void) { return(n); } +#if defined(RADIOLIB_BUILD_ARDUINO) size_t RTTYClient::println(__FlashStringHelper* fstr) { size_t n = RTTYClient::print(fstr); n += RTTYClient::println(); return(n); } -size_t RTTYClient::println(ITA2String& ita2) { - size_t n = RTTYClient::print(ita2); +size_t RTTYClient::println(const String& str) { + size_t n = RTTYClient::print(str); n += RTTYClient::println(); return(n); } +#endif -size_t RTTYClient::println(const String& str) { - size_t n = RTTYClient::print(str); +size_t RTTYClient::println(ITA2String& ita2) { + size_t n = RTTYClient::print(ita2); n += RTTYClient::println(); return(n); } diff --git a/src/protocols/RTTY/RTTY.h b/src/protocols/RTTY/RTTY.h index a26b144b..e663d92c 100644 --- a/src/protocols/RTTY/RTTY.h +++ b/src/protocols/RTTY/RTTY.h @@ -138,9 +138,11 @@ class RTTYClient { size_t write(uint8_t* buff, size_t len); size_t write(uint8_t b); + #if defined(RADIOLIB_BUILD_ARDUINO) size_t print(__FlashStringHelper*); - size_t print(ITA2String &); size_t print(const String &); + #endif + size_t print(ITA2String &); size_t print(const char[]); size_t print(char); size_t print(unsigned char, int = DEC); @@ -151,9 +153,11 @@ class RTTYClient { size_t print(double, int = 2); size_t println(void); + #if defined(RADIOLIB_BUILD_ARDUINO) size_t println(__FlashStringHelper*); - size_t println(ITA2String &); size_t println(const String &); + #endif + size_t println(ITA2String &); size_t println(const char[]); size_t println(char); size_t println(unsigned char, int = DEC); From 2a45f713840a170eebcec63fad50b4361226ce9d Mon Sep 17 00:00:00 2001 From: Mestery Date: Sun, 9 Apr 2023 16:58:56 +0200 Subject: [PATCH 2/6] fix undef digitalread --- src/modules/CC1101/CC1101.cpp | 2 +- src/modules/RF69/RF69.cpp | 2 +- src/modules/SX126x/SX126x.cpp | 2 +- src/modules/SX127x/SX127x.cpp | 2 +- src/modules/Si443x/Si443x.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index ffad818a..dfa57aea 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -946,7 +946,7 @@ void CC1101::setDirectAction(void (*func)(void)) { } void CC1101::readBit(RADIOLIB_PIN_TYPE pin) { - updateDirectBuffer((uint8_t)digitalRead(pin)); + updateDirectBuffer((uint8_t)_mod->digitalRead(pin)); } #endif diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 87b5715d..45f53203 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -959,7 +959,7 @@ void RF69::setDirectAction(void (*func)(void)) { } void RF69::readBit(RADIOLIB_PIN_TYPE pin) { - updateDirectBuffer((uint8_t)digitalRead(pin)); + updateDirectBuffer((uint8_t)_mod->digitalRead(pin)); } #endif diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index ab308961..5288153a 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -1438,7 +1438,7 @@ void SX126x::setDirectAction(void (*func)(void)) { } void SX126x::readBit(RADIOLIB_PIN_TYPE pin) { - updateDirectBuffer((uint8_t)digitalRead(pin)); + updateDirectBuffer((uint8_t)_mod->digitalRead(pin)); } #endif diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 0dc1cbb4..b7c4d8f5 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -1521,7 +1521,7 @@ void SX127x::setDirectAction(void (*func)(void)) { } void SX127x::readBit(RADIOLIB_PIN_TYPE pin) { - updateDirectBuffer((uint8_t)digitalRead(pin)); + updateDirectBuffer((uint8_t)_mod->digitalRead(pin)); } #endif diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index a2ef6399..cabf6789 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -612,7 +612,7 @@ void Si443x::setDirectAction(void (*func)(void)) { } void Si443x::readBit(RADIOLIB_PIN_TYPE pin) { - updateDirectBuffer((uint8_t)digitalRead(pin)); + updateDirectBuffer((uint8_t)_mod->digitalRead(pin)); } #endif From 67e4dd481530bdfb55088cd754c21aeb0aa753c2 Mon Sep 17 00:00:00 2001 From: Mestery Date: Sun, 9 Apr 2023 20:34:42 +0200 Subject: [PATCH 3/6] fix delayMicroseconds --- src/modules/CC1101/CC1101.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index dfa57aea..3ab475de 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -319,7 +319,7 @@ int16_t CC1101::startTransmit(uint8_t* data, size_t len, uint8_t addr) { * * TODO: test this on real hardware */ - delayMicroseconds(250); + _mod->delayMicroseconds(250); } } From 6456da188de8e0cb8014bd88504e42938ecbb387 Mon Sep 17 00:00:00 2001 From: Mestery Date: Sun, 9 Apr 2023 21:34:13 +0200 Subject: [PATCH 4/6] fix debug print --- src/BuildOpt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 76770580..c6b0583d 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -1044,10 +1044,10 @@ #define RADIOLIB_DEBUG_PRINTLN(...) { RADIOLIB_DEBUG_PORT.println(__VA_ARGS__); } #else #if !defined(RADIOLIB_DEBUG_PRINT) - #define RADIOLIB_DEBUG_PRINT(...) { frintf(RADIOLIB_DEBUG_PORT, __VA_ARGS__); } + #define RADIOLIB_DEBUG_PRINT(...) { fprintf(RADIOLIB_DEBUG_PORT, __VA_ARGS__); } #endif #if !defined(RADIOLIB_DEBUG_PRINTLN) - #define RADIOLIB_DEBUG_PRINTLN(...) { printf(RADIOLIB_DEBUG_PORT, __VA_ARGS__ "\n"); } + #define RADIOLIB_DEBUG_PRINTLN(...) { fprintf(RADIOLIB_DEBUG_PORT, __VA_ARGS__ "\n"); } #endif #endif #else From 220b4dad7fa4ae7520f93e74df49bb4c6f050b46 Mon Sep 17 00:00:00 2001 From: Mestery Date: Sun, 9 Apr 2023 23:47:44 +0200 Subject: [PATCH 5/6] use printf in both build --- src/BuildOpt.h | 31 ++++++-- src/Module.cpp | 71 ++++++++----------- src/modules/CC1101/CC1101.cpp | 20 ++---- src/modules/RF69/RF69.cpp | 16 +---- src/modules/RFM9x/RFM95.cpp | 8 +-- src/modules/RFM9x/RFM96.cpp | 8 +-- src/modules/SX1231/SX1231.cpp | 18 ++--- src/modules/SX126x/SX126x.cpp | 47 +++++------- src/modules/SX127x/SX1272.cpp | 8 +-- src/modules/SX127x/SX1278.cpp | 8 +-- src/modules/SX127x/SX127x.cpp | 20 ++---- src/modules/SX128x/SX128x.cpp | 16 ++--- src/modules/Si443x/Si4430.cpp | 2 +- src/modules/Si443x/Si4431.cpp | 2 +- src/modules/Si443x/Si4432.cpp | 2 +- src/modules/Si443x/Si443x.cpp | 32 ++------- src/modules/nRF24/nRF24.cpp | 4 +- src/protocols/Morse/Morse.cpp | 14 ++-- src/protocols/Pager/Pager.cpp | 4 +- src/protocols/PhysicalLayer/PhysicalLayer.cpp | 8 +-- 20 files changed, 127 insertions(+), 212 deletions(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index c6b0583d..0c02b351 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -1040,14 +1040,37 @@ #if defined(RADIOLIB_DEBUG) #if defined(RADIOLIB_BUILD_ARDUINO) - #define RADIOLIB_DEBUG_PRINT(...) { RADIOLIB_DEBUG_PORT.print(__VA_ARGS__); } - #define RADIOLIB_DEBUG_PRINTLN(...) { RADIOLIB_DEBUG_PORT.println(__VA_ARGS__); } +// https://github.com/esp8266/Arduino/blob/65579d29081cb8501e4d7f786747bf12e7b37da2/cores/esp8266/Print.cpp#L50 +size_t serialPrintf(const char *format, ...) { + va_list arg; + va_start(arg, format); + char temp[64]; + char* buffer = temp; + size_t len = vsnprintf(temp, sizeof(temp), format, arg); + va_end(arg); + if (len > sizeof(temp) - 1) { + buffer = new char[len + 1]; + if (!buffer) { + return 0; + } + va_start(arg, format); + vsnprintf(buffer, len + 1, format, arg); + va_end(arg); + } + len = RADIOLIB_DEBUG_PORT.write((const uint8_t*) buffer, len); + if (buffer != temp) { + delete[] buffer; + } + return len; +} + #define RADIOLIB_DEBUG_PRINT(...) serialPrintf(__VA_ARGS__) + #define RADIOLIB_DEBUG_PRINTLN(M, ...) serialPrintf(M "\n", ##__VA_ARGS__) #else #if !defined(RADIOLIB_DEBUG_PRINT) - #define RADIOLIB_DEBUG_PRINT(...) { fprintf(RADIOLIB_DEBUG_PORT, __VA_ARGS__); } + #define RADIOLIB_DEBUG_PRINT(...) fprintf(RADIOLIB_DEBUG_PORT, __VA_ARGS__) #endif #if !defined(RADIOLIB_DEBUG_PRINTLN) - #define RADIOLIB_DEBUG_PRINTLN(...) { fprintf(RADIOLIB_DEBUG_PORT, __VA_ARGS__ "\n"); } + #define RADIOLIB_DEBUG_PRINTLN(M, ...) fprintf(RADIOLIB_DEBUG_PORT, M "\n", ##__VA_ARGS__) #endif #endif #else diff --git a/src/Module.cpp b/src/Module.cpp index df60214f..77e4906d 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -160,24 +160,26 @@ int16_t Module::SPIsetRegValue(uint16_t reg, uint8_t value, uint8_t msb, uint8_t } } + #if defined(RADIOLIB_DEBUG) && defined(RADIOLIB_BUILD_ARDUINO) + #define DEBUG_BIN(x) RADIOLIB_DEBUG_PORT.println(x, BIN) + #else // no bin representation, fallback to hex + #define DEBUG_BIN(x) RADIOLIB_DEBUG_PRINTLN("%X", x) + #endif + // check failed, print debug info RADIOLIB_DEBUG_PRINTLN(); - RADIOLIB_DEBUG_PRINT(F("address:\t0x")); - RADIOLIB_DEBUG_PRINTLN(reg, HEX); - RADIOLIB_DEBUG_PRINT(F("bits:\t\t")); - RADIOLIB_DEBUG_PRINT(msb); - RADIOLIB_DEBUG_PRINT(' '); - RADIOLIB_DEBUG_PRINTLN(lsb); - RADIOLIB_DEBUG_PRINT(F("value:\t\t0b")); - RADIOLIB_DEBUG_PRINTLN(value, BIN); - RADIOLIB_DEBUG_PRINT(F("current:\t0b")); - RADIOLIB_DEBUG_PRINTLN(currentValue, BIN); - RADIOLIB_DEBUG_PRINT(F("mask:\t\t0b")); - RADIOLIB_DEBUG_PRINTLN(mask, BIN); - RADIOLIB_DEBUG_PRINT(F("new:\t\t0b")); - RADIOLIB_DEBUG_PRINTLN(newValue, BIN); - RADIOLIB_DEBUG_PRINT(F("read:\t\t0b")); - RADIOLIB_DEBUG_PRINTLN(readValue, BIN); + RADIOLIB_DEBUG_PRINTLN("address:\t0x%X", reg); + RADIOLIB_DEBUG_PRINTLN("bits:\t\t%d %d", msb, lsb); + RADIOLIB_DEBUG_PRINT("value:\t\t0b"); + DEBUG_BIN(value); + RADIOLIB_DEBUG_PRINT("current:\t0b"); + DEBUG_BIN(currentValue); + RADIOLIB_DEBUG_PRINT("mask:\t\t0b"); + DEBUG_BIN(mask); + RADIOLIB_DEBUG_PRINT("new:\t\t0b"); + DEBUG_BIN(newValue); + RADIOLIB_DEBUG_PRINT("read:\t\t0b"); + DEBUG_BIN(readValue); RADIOLIB_DEBUG_PRINTLN(); return(RADIOLIB_ERR_SPI_WRITE_FAILED); @@ -241,13 +243,11 @@ void Module::SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* d #if defined(RADIOLIB_VERBOSE) if(cmd == SPIwriteCommand) { - RADIOLIB_VERBOSE_PRINT('W'); + RADIOLIB_VERBOSE_PRINT("W"); } else if(cmd == SPIreadCommand) { - RADIOLIB_VERBOSE_PRINT('R'); + RADIOLIB_VERBOSE_PRINT("R"); } - RADIOLIB_VERBOSE_PRINT('\t') - RADIOLIB_VERBOSE_PRINT(reg, HEX); - RADIOLIB_VERBOSE_PRINT('\t'); + RADIOLIB_VERBOSE_PRINT("\t%X\t", reg); #endif // send data or get response @@ -255,16 +255,14 @@ void Module::SPItransfer(uint8_t cmd, uint16_t reg, uint8_t* dataOut, uint8_t* d if(dataOut != NULL) { for(size_t n = 0; n < numBytes; n++) { this->transfer(dataOut[n]); - RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX); - RADIOLIB_VERBOSE_PRINT('\t'); + RADIOLIB_VERBOSE_PRINT("%X\t", dataOut[n]); } } } else if (cmd == SPIreadCommand) { if(dataIn != NULL) { for(size_t n = 0; n < numBytes; n++) { dataIn[n] = this->transfer(0x00); - RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX); - RADIOLIB_VERBOSE_PRINT('\t'); + RADIOLIB_VERBOSE_PRINT("%X\t", dataIn[n]); } } } @@ -419,8 +417,7 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint // print command byte(s) RADIOLIB_VERBOSE_PRINT("CMD\t"); for(uint8_t n = 0; n < cmdLen; n++) { - RADIOLIB_VERBOSE_PRINT(cmd[n], HEX); - RADIOLIB_VERBOSE_PRINT('\t'); + RADIOLIB_VERBOSE_PRINT("%X\t", cmd[n]); } RADIOLIB_VERBOSE_PRINTLN(); @@ -429,25 +426,14 @@ int16_t Module::SPItransferStream(uint8_t* cmd, uint8_t cmdLen, bool write, uint if(write) { RADIOLIB_VERBOSE_PRINT("W\t"); for(size_t n = 0; n < numBytes; n++) { - RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX); - RADIOLIB_VERBOSE_PRINT('\t'); - RADIOLIB_VERBOSE_PRINT(debugBuff[n], HEX); - RADIOLIB_VERBOSE_PRINT('\t'); + RADIOLIB_VERBOSE_PRINT("%X\t%X\t", dataOut[n], debugBuff[n]); } RADIOLIB_VERBOSE_PRINTLN(); } else { - RADIOLIB_VERBOSE_PRINT("R\t"); - // skip the first byte for read-type commands (status-only) - RADIOLIB_VERBOSE_PRINT(this->SPInopCommand, HEX); - RADIOLIB_VERBOSE_PRINT('\t'); - RADIOLIB_VERBOSE_PRINT(debugBuff[0], HEX); - RADIOLIB_VERBOSE_PRINT('\t') + RADIOLIB_VERBOSE_PRINT("R\t%X\t%X\t", this->SPInopCommand, debugBuff[0]); for(size_t n = 0; n < numBytes; n++) { - RADIOLIB_VERBOSE_PRINT(this->SPInopCommand, HEX); - RADIOLIB_VERBOSE_PRINT('\t'); - RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX); - RADIOLIB_VERBOSE_PRINT('\t'); + RADIOLIB_VERBOSE_PRINT("%X\t%X\t", this->SPInopCommand, dataIn[n]); } RADIOLIB_VERBOSE_PRINTLN(); } @@ -752,7 +738,8 @@ void Module::hexdump(uint8_t* data, size_t len, uint32_t offset, uint8_t width, for(size_t j = line_len; j < 16; j++) { sprintf(&str[58 + j], " "); } - RADIOLIB_DEBUG_PRINTLN(str); + RADIOLIB_DEBUG_PRINT(str); + RADIOLIB_DEBUG_PRINTLN(); rem_len -= 16; } } diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 3ab475de..252ca8a2 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -24,28 +24,18 @@ int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t po if((version == RADIOLIB_CC1101_VERSION_CURRENT) || (version == RADIOLIB_CC1101_VERSION_LEGACY) || (version == RADIOLIB_CC1101_VERSION_CLONE)) { flagFound = true; } else { - #if defined(RADIOLIB_DEBUG) - RADIOLIB_DEBUG_PRINT(F("CC1101 not found! (")); - RADIOLIB_DEBUG_PRINT(i + 1); - RADIOLIB_DEBUG_PRINT(F(" of 10 tries) RADIOLIB_CC1101_REG_VERSION == ")); - - char buffHex[7]; - sprintf(buffHex, "0x%04X", version); - RADIOLIB_DEBUG_PRINT(buffHex); - RADIOLIB_DEBUG_PRINT(F(", expected 0x0004/0x0014")); - RADIOLIB_DEBUG_PRINTLN(); - #endif + RADIOLIB_DEBUG_PRINTLN("CC1101 not found! (%d of 10 tries) RADIOLIB_CC1101_REG_VERSION == 0x%04X, expected 0x0004/0x0014", i + 1, version); _mod->delay(10); i++; } } if(!flagFound) { - RADIOLIB_DEBUG_PRINTLN(F("No CC1101 found!")); + RADIOLIB_DEBUG_PRINTLN("No CC1101 found!"); _mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } else { - RADIOLIB_DEBUG_PRINTLN(F("M\tCC1101")); + RADIOLIB_DEBUG_PRINTLN("M\tCC1101"); } // configure settings not accessible by API @@ -388,7 +378,7 @@ int16_t CC1101::readData(uint8_t* data, size_t len) { if (bytesInFIFO == 0) { if (millis() - lastPop > 5) { // readData was required to read a packet longer than the one received. - RADIOLIB_DEBUG_PRINTLN(F("No data for more than 5mS. Stop here.")); + RADIOLIB_DEBUG_PRINTLN("No data for more than 5mS. Stop here."); break; } else { delay(1); @@ -919,7 +909,7 @@ void CC1101::setRfSwitchTable(const RADIOLIB_PIN_TYPE (&pins)[Module::RFSWITCH_M uint8_t CC1101::randomByte() { // set mode to Rx SPIsendCommand(RADIOLIB_CC1101_CMD_RX); - RADIOLIB_DEBUG_PRINTLN("random"); + RADIOLIB_DEBUG_PRINTLN("CC1101::randomByte"); // wait a bit for the RSSI reading to stabilise _mod->delay(10); diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp index 45f53203..a33e245f 100644 --- a/src/modules/RF69/RF69.cpp +++ b/src/modules/RF69/RF69.cpp @@ -26,28 +26,18 @@ int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t powe if(version == RADIOLIB_RF69_CHIP_VERSION) { flagFound = true; } else { - #if defined(RADIOLIB_DEBUG) - RADIOLIB_DEBUG_PRINT(F("RF69 not found! (")); - RADIOLIB_DEBUG_PRINT(i + 1); - RADIOLIB_DEBUG_PRINT(F(" of 10 tries) RADIOLIB_RF69_REG_VERSION == ")); - - char buffHex[7]; - sprintf(buffHex, "0x%04X", version); - RADIOLIB_DEBUG_PRINT(buffHex); - RADIOLIB_DEBUG_PRINT(F(", expected 0x0024")); - RADIOLIB_DEBUG_PRINTLN(); - #endif + RADIOLIB_DEBUG_PRINTLN("RF69 not found! (%d of 10 tries) RADIOLIB_RF69_REG_VERSION == 0x%04X, expected 0x0024", i + 1, version); _mod->delay(10); i++; } } if(!flagFound) { - RADIOLIB_DEBUG_PRINTLN(F("No RF69 found!")); + RADIOLIB_DEBUG_PRINTLN("No RF69 found!"); _mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } else { - RADIOLIB_DEBUG_PRINTLN(F("M\tRF69")); + RADIOLIB_DEBUG_PRINTLN("M\tRF69"); } // configure settings not accessible by API diff --git a/src/modules/RFM9x/RFM95.cpp b/src/modules/RFM9x/RFM95.cpp index 640645da..892fc53c 100644 --- a/src/modules/RFM9x/RFM95.cpp +++ b/src/modules/RFM9x/RFM95.cpp @@ -16,8 +16,8 @@ int16_t RFM95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncW // some other error return(state); } - RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278")); - RADIOLIB_DEBUG_PRINTLN(F("M\tRFM95")); + RADIOLIB_DEBUG_PRINTLN("M\tSX1278"); + RADIOLIB_DEBUG_PRINTLN("M\tRFM95"); // configure publicly accessible settings state = setBandwidth(bw); @@ -51,8 +51,8 @@ int16_t RFM95::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t // some other error return(state); } - RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278")); - RADIOLIB_DEBUG_PRINTLN(F("M\tRFM95")); + RADIOLIB_DEBUG_PRINTLN("M\tSX1278"); + RADIOLIB_DEBUG_PRINTLN("M\tRFM95"); // configure settings not accessible by API state = configFSK(); diff --git a/src/modules/RFM9x/RFM96.cpp b/src/modules/RFM9x/RFM96.cpp index 78427b71..2f7f451a 100644 --- a/src/modules/RFM9x/RFM96.cpp +++ b/src/modules/RFM9x/RFM96.cpp @@ -16,8 +16,8 @@ int16_t RFM96::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncW // some other error return(state); } - RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278")); - RADIOLIB_DEBUG_PRINTLN(F("M\tRFM96")); + RADIOLIB_DEBUG_PRINTLN("M\tSX1278"); + RADIOLIB_DEBUG_PRINTLN("M\tRFM96"); // configure publicly accessible settings state = setBandwidth(bw); @@ -52,8 +52,8 @@ int16_t RFM96::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t // some other error return(state); } - RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278")); - RADIOLIB_DEBUG_PRINTLN(F("M\tRFM96")); + RADIOLIB_DEBUG_PRINTLN("M\tSX1278"); + RADIOLIB_DEBUG_PRINTLN("M\tRFM96"); // configure settings not accessible by API state = configFSK(); diff --git a/src/modules/SX1231/SX1231.cpp b/src/modules/SX1231/SX1231.cpp index c3e750c9..8e81d892 100644 --- a/src/modules/SX1231/SX1231.cpp +++ b/src/modules/SX1231/SX1231.cpp @@ -20,33 +20,23 @@ int16_t SX1231::begin(float freq, float br, float freqDev, float rxBw, int8_t po flagFound = true; _chipRevision = version; } else { - #if defined(RADIOLIB_DEBUG) - RADIOLIB_DEBUG_PRINT(F("SX1231 not found! (")); - RADIOLIB_DEBUG_PRINT(i + 1); - RADIOLIB_DEBUG_PRINT(F(" of 10 tries) RF69_REG_VERSION == ")); - - char buffHex[12]; - sprintf(buffHex, "0x%04X", version); - RADIOLIB_DEBUG_PRINT(buffHex); - RADIOLIB_DEBUG_PRINT(F(", expected 0x0021 / 0x0022 / 0x0023")); - RADIOLIB_DEBUG_PRINTLN(); - #endif + RADIOLIB_DEBUG_PRINTLN("SX1231 not found! (%d of 10 tries) RF69_REG_VERSION == 0x%04X, expected 0x0021 / 0x0022 / 0x0023", i + 1, version); _mod->delay(10); i++; } } if(!flagFound) { - RADIOLIB_DEBUG_PRINTLN(F("No SX1231 found!")); + RADIOLIB_DEBUG_PRINTLN("No SX1231 found!"); _mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } - RADIOLIB_DEBUG_PRINTLN(F("M\tSX1231")); + RADIOLIB_DEBUG_PRINTLN("M\tSX1231"); // configure settings not accessible by API int16_t state = config(); RADIOLIB_ASSERT(state); - RADIOLIB_DEBUG_PRINTLN(F("M\tRF69")); + RADIOLIB_DEBUG_PRINTLN("M\tRF69"); // configure publicly accessible settings state = setFrequency(freq); diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 5288153a..b5ed7188 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -24,11 +24,11 @@ int16_t SX126x::begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, flo // try to find the SX126x chip if(!SX126x::findChip(_chipType)) { - RADIOLIB_DEBUG_PRINTLN(F("No SX126x found!")); + RADIOLIB_DEBUG_PRINTLN("No SX126x found!"); _mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } - RADIOLIB_DEBUG_PRINTLN(F("M\tSX126x")); + RADIOLIB_DEBUG_PRINTLN("M\tSX126x"); // BW in kHz and SF are required in order to calculate LDRO for setModulationParams // set the defaults, this will get overwritten later anyway @@ -106,11 +106,11 @@ int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, uint16_t preambleL // try to find the SX126x chip if(!SX126x::findChip(_chipType)) { - RADIOLIB_DEBUG_PRINTLN(F("No SX126x found!")); + RADIOLIB_DEBUG_PRINTLN("No SX126x found!"); _mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } - RADIOLIB_DEBUG_PRINTLN(F("M\tSX126x")); + RADIOLIB_DEBUG_PRINTLN("M\tSX126x"); // initialize configuration variables (will be overwritten during public settings configuration) _br = 21333; // 48.0 kbps @@ -245,9 +245,7 @@ int16_t SX126x::transmit(uint8_t* data, size_t len, uint8_t addr) { return(RADIOLIB_ERR_UNKNOWN); } - RADIOLIB_DEBUG_PRINT(F("Timeout in ")); - RADIOLIB_DEBUG_PRINT(timeout); - RADIOLIB_DEBUG_PRINTLN(F(" us")); + RADIOLIB_DEBUG_PRINTLN("Timeout in %d us", timeout); // start transmission state = startTransmit(data, len, addr); @@ -296,9 +294,7 @@ int16_t SX126x::receive(uint8_t* data, size_t len) { return(RADIOLIB_ERR_UNKNOWN); } - RADIOLIB_DEBUG_PRINT(F("Timeout in ")); - RADIOLIB_DEBUG_PRINT(timeout); - RADIOLIB_DEBUG_PRINTLN(F(" us")); + RADIOLIB_DEBUG_PRINTLN("Timeout in %d us", timeout); // start reception uint32_t timeoutValue = (uint32_t)((float)timeout / 15.625); @@ -594,8 +590,7 @@ int16_t SX126x::startReceiveDutyCycleAuto(uint16_t senderPreambleLength, uint16_ uint32_t symbolLength = ((uint32_t)(10 * 1000) << _sf) / (10 * _bwKhz); uint32_t sleepPeriod = symbolLength * sleepSymbols; - RADIOLIB_DEBUG_PRINT(F("Auto sleep period: ")); - RADIOLIB_DEBUG_PRINTLN(sleepPeriod); + RADIOLIB_DEBUG_PRINTLN("Auto sleep period: %d", sleepPeriod); // when the unit detects a preamble, it starts a timer that will timeout if it doesn't receive a header in time. // the duration is sleepPeriod + 2 * wakePeriod. @@ -606,8 +601,7 @@ int16_t SX126x::startReceiveDutyCycleAuto(uint16_t senderPreambleLength, uint16_ uint32_t wakePeriod = max( (symbolLength * (senderPreambleLength + 1) - (sleepPeriod - 1000)) / 2, // (A) symbolLength * (minSymbols + 1)); //(B) - RADIOLIB_DEBUG_PRINT(F("Auto wake period: ")); - RADIOLIB_DEBUG_PRINTLN(wakePeriod); + RADIOLIB_DEBUG_PRINTLN("Auto wake period: ", wakePeriod); // If our sleep period is shorter than our transition time, just use the standard startReceive if(sleepPeriod < _tcxoDelay + 1016) { @@ -1451,8 +1445,7 @@ int16_t SX126x::uploadPatch(const uint32_t* patch, size_t len, bool nonvolatile) #if defined(RADIOLIB_DEBUG) char ver_pre[16]; _mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)ver_pre); - RADIOLIB_DEBUG_PRINT(F("Pre-update version string: ")); - RADIOLIB_DEBUG_PRINTLN(ver_pre); + RADIOLIB_DEBUG_PRINTLN("Pre-update version string: %d", ver_pre); #endif // enable patch update @@ -1484,8 +1477,7 @@ int16_t SX126x::uploadPatch(const uint32_t* patch, size_t len, bool nonvolatile) #if defined(RADIOLIB_DEBUG) char ver_post[16]; _mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)ver_post); - RADIOLIB_DEBUG_PRINT(F("Post-update version string: ")); - RADIOLIB_DEBUG_PRINTLN(ver_post); + RADIOLIB_DEBUG_PRINTLN("Post-update version string: %d", ver_post); #endif return(state); @@ -1712,8 +1704,7 @@ int16_t SX126x::calibrateImage(uint8_t* data) { // unless mode is forced to standby, device errors will be 0 standby(); uint16_t errors = getDeviceErrors(); - RADIOLIB_DEBUG_PRINT("Calibration failed, device errors: 0x"); - RADIOLIB_DEBUG_PRINTLN(errors, HEX); + RADIOLIB_DEBUG_PRINTLN("Calibration failed, device errors: 0x%X", errors); } #endif return(state); @@ -1766,9 +1757,7 @@ int16_t SX126x::setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr, uint8_t // calculate symbol length and enable low data rate optimization, if auto-configuration is enabled if(_ldroAuto) { float symbolLength = (float)(uint32_t(1) << _sf) / (float)_bwKhz; - RADIOLIB_DEBUG_PRINT("Symbol length: "); - RADIOLIB_DEBUG_PRINT(symbolLength); - RADIOLIB_DEBUG_PRINTLN(" ms"); + RADIOLIB_DEBUG_PRINTLN("Symbol length: %d ms", symbolLength); if(symbolLength >= 16.0) { _ldro = RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_ON; } else { @@ -1976,8 +1965,7 @@ int16_t SX126x::config(uint8_t modem) { // unless mode is forced to standby, device errors will be 0 standby(); uint16_t errors = getDeviceErrors(); - RADIOLIB_DEBUG_PRINT("Calibration failed, device errors: 0x"); - RADIOLIB_DEBUG_PRINTLN(errors, HEX); + RADIOLIB_DEBUG_PRINTLN("Calibration failed, device errors: 0x%X", errors); } #endif @@ -2010,18 +1998,15 @@ bool SX126x::findChip(const char* verStr) { // check version register if(strncmp(verStr, version, 6) == 0) { - RADIOLIB_DEBUG_PRINTLN(F("Found SX126x: RADIOLIB_SX126X_REG_VERSION_STRING:")); + RADIOLIB_DEBUG_PRINTLN("Found SX126x: RADIOLIB_SX126X_REG_VERSION_STRING:"); _mod->hexdump((uint8_t*)version, 16, RADIOLIB_SX126X_REG_VERSION_STRING); RADIOLIB_DEBUG_PRINTLN(); flagFound = true; } else { #if defined(RADIOLIB_DEBUG) - RADIOLIB_DEBUG_PRINT(F("SX126x not found! (")); - RADIOLIB_DEBUG_PRINT(i + 1); - RADIOLIB_DEBUG_PRINTLN(F(" of 10 tries) RADIOLIB_SX126X_REG_VERSION_STRING:")); + RADIOLIB_DEBUG_PRINTLN("SX126x not found! (%d of 10 tries) RADIOLIB_SX126X_REG_VERSION_STRING:", i + 1); _mod->hexdump((uint8_t*)version, 16, RADIOLIB_SX126X_REG_VERSION_STRING); - RADIOLIB_DEBUG_PRINT(F("Expected string: ")); - RADIOLIB_DEBUG_PRINTLN(verStr); + RADIOLIB_DEBUG_PRINTLN("Expected string: %s", verStr); #endif _mod->delay(10); i++; diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index 27a01722..64b75ba7 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -116,9 +116,7 @@ int16_t SX1272::setBandwidth(float bw) { // calculate symbol length and set low data rate optimization, if auto-configuration is enabled if(_ldroAuto) { float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; - RADIOLIB_DEBUG_PRINT("Symbol length: "); - RADIOLIB_DEBUG_PRINT(symbolLength); - RADIOLIB_DEBUG_PRINTLN(" ms"); + RADIOLIB_DEBUG_PRINTLN("Symbol length: %f ms", symbolLength); if(symbolLength >= 16.0) { state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0); } else { @@ -172,9 +170,7 @@ int16_t SX1272::setSpreadingFactor(uint8_t sf) { // calculate symbol length and set low data rate optimization, if auto-configuration is enabled if(_ldroAuto) { float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; - RADIOLIB_DEBUG_PRINT("Symbol length: "); - RADIOLIB_DEBUG_PRINT(symbolLength); - RADIOLIB_DEBUG_PRINTLN(" ms"); + RADIOLIB_DEBUG_PRINTLN("Symbol length: %f ms", symbolLength); if(symbolLength >= 16.0) { state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0); } else { diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index c8e5832a..aeb947f0 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -130,9 +130,7 @@ int16_t SX1278::setBandwidth(float bw) { // calculate symbol length and set low data rate optimization, if auto-configuration is enabled if(_ldroAuto) { float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; - RADIOLIB_DEBUG_PRINT("Symbol length: "); - RADIOLIB_DEBUG_PRINT(symbolLength); - RADIOLIB_DEBUG_PRINTLN(" ms"); + RADIOLIB_DEBUG_PRINTLN("Symbol length: %f ms", symbolLength); if(symbolLength >= 16.0) { state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3); } else { @@ -186,9 +184,7 @@ int16_t SX1278::setSpreadingFactor(uint8_t sf) { // calculate symbol length and set low data rate optimization, if auto-configuration is enabled if(_ldroAuto) { float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw; - RADIOLIB_DEBUG_PRINT("Symbol length: "); - RADIOLIB_DEBUG_PRINT(symbolLength); - RADIOLIB_DEBUG_PRINTLN(" ms"); + RADIOLIB_DEBUG_PRINT("Symbol length: %f ms", symbolLength); if(symbolLength >= 16.0) { state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3); } else { diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index b7c4d8f5..e8742858 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -17,11 +17,11 @@ int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint16_t preambleLe // try to find the SX127x chip if(!SX127x::findChip(chipVersion)) { - RADIOLIB_DEBUG_PRINTLN(F("No SX127x found!")); + RADIOLIB_DEBUG_PRINTLN("No SX127x found!"); _mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } - RADIOLIB_DEBUG_PRINTLN(F("M\tSX127x")); + RADIOLIB_DEBUG_PRINTLN("M\tSX127x"); // set mode to standby int16_t state = standby(); @@ -64,11 +64,11 @@ int16_t SX127x::beginFSK(uint8_t chipVersion, float freqDev, float rxBw, uint16_ // try to find the SX127x chip if(!SX127x::findChip(chipVersion)) { - RADIOLIB_DEBUG_PRINTLN(F("No SX127x found!")); + RADIOLIB_DEBUG_PRINTLN("No SX127x found!"); _mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } - RADIOLIB_DEBUG_PRINTLN(F("M\tSX127x")); + RADIOLIB_DEBUG_PRINTLN("M\tSX127x"); // set mode to standby int16_t state = standby(); @@ -1434,17 +1434,7 @@ bool SX127x::findChip(uint8_t ver) { if(version == ver) { flagFound = true; } else { - #if defined(RADIOLIB_DEBUG) - RADIOLIB_DEBUG_PRINT(F("SX127x not found! (")); - RADIOLIB_DEBUG_PRINT(i + 1); - RADIOLIB_DEBUG_PRINT(F(" of 10 tries) RADIOLIB_SX127X_REG_VERSION == ")); - - char buffHex[12]; - sprintf(buffHex, "0x%04X", version); - RADIOLIB_DEBUG_PRINT(buffHex); - RADIOLIB_DEBUG_PRINT(F(", expected 0x00")); - RADIOLIB_DEBUG_PRINTLN(ver, HEX); - #endif + RADIOLIB_DEBUG_PRINTLN("SX127x not found! (%d of 10 tries) RADIOLIB_SX127X_REG_VERSION == 0x%04X, expected 0x00%X", i + 1, version, ver); _mod->delay(10); i++; } diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 5a2619c8..8c6ec31a 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -20,7 +20,7 @@ int16_t SX128x::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync _mod->SPIstatusCommand = RADIOLIB_SX128X_CMD_GET_STATUS; _mod->SPIstreamType = true; _mod->SPIparseStatusCb = SPIparseStatus; - RADIOLIB_DEBUG_PRINTLN(F("M\tSX128x")); + RADIOLIB_DEBUG_PRINTLN("M\tSX128x"); // initialize LoRa modulation variables _bwKhz = bw; @@ -81,7 +81,7 @@ int16_t SX128x::beginGFSK(float freq, uint16_t br, float freqDev, int8_t power, _mod->SPIstatusCommand = RADIOLIB_SX128X_CMD_GET_STATUS; _mod->SPIstreamType = true; _mod->SPIparseStatusCb = SPIparseStatus; - RADIOLIB_DEBUG_PRINTLN(F("M\tSX128x")); + RADIOLIB_DEBUG_PRINTLN("M\tSX128x"); // initialize GFSK modulation variables _brKbps = br; @@ -150,7 +150,7 @@ int16_t SX128x::beginBLE(float freq, uint16_t br, float freqDev, int8_t power, u _mod->SPIstatusCommand = RADIOLIB_SX128X_CMD_GET_STATUS; _mod->SPIstreamType = true; _mod->SPIparseStatusCb = SPIparseStatus; - RADIOLIB_DEBUG_PRINTLN(F("M\tSX128x")); + RADIOLIB_DEBUG_PRINTLN("M\tSX128x"); // initialize BLE modulation variables _brKbps = br; @@ -205,7 +205,7 @@ int16_t SX128x::beginFLRC(float freq, uint16_t br, uint8_t cr, int8_t power, uin _mod->SPIstatusCommand = RADIOLIB_SX128X_CMD_GET_STATUS; _mod->SPIstreamType = true; _mod->SPIparseStatusCb = SPIparseStatus; - RADIOLIB_DEBUG_PRINTLN(F("M\tSX128x")); + RADIOLIB_DEBUG_PRINTLN("M\tSX128x"); // initialize FLRC modulation variables _brKbps = br; @@ -311,9 +311,7 @@ int16_t SX128x::transmit(uint8_t* data, size_t len, uint8_t addr) { // calculate timeout (500% of expected time-on-air) uint32_t timeout = getTimeOnAir(len) * 5; - RADIOLIB_DEBUG_PRINT(F("Timeout in ")); - RADIOLIB_DEBUG_PRINT(timeout); - RADIOLIB_DEBUG_PRINTLN(F(" us")); + RADIOLIB_DEBUG_PRINTLN("Timeout in %d us", timeout); // start transmission state = startTransmit(data, len, addr); @@ -346,9 +344,7 @@ int16_t SX128x::receive(uint8_t* data, size_t len) { // calculate timeout (1000% of expected time-on-air) uint32_t timeout = getTimeOnAir(len) * 10; - RADIOLIB_DEBUG_PRINT(F("Timeout in ")); - RADIOLIB_DEBUG_PRINT(timeout); - RADIOLIB_DEBUG_PRINTLN(F(" us")); + RADIOLIB_DEBUG_PRINTLN("Timeout in %d us", timeout); // start reception uint32_t timeoutValue = (uint32_t)((float)timeout / 15.625); diff --git a/src/modules/Si443x/Si4430.cpp b/src/modules/Si443x/Si4430.cpp index d6f40326..ecc8d8c6 100644 --- a/src/modules/Si443x/Si4430.cpp +++ b/src/modules/Si443x/Si4430.cpp @@ -9,7 +9,7 @@ int16_t Si4430::begin(float freq, float br, float freqDev, float rxBw, int8_t po // execute common part int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen); RADIOLIB_ASSERT(state); - RADIOLIB_DEBUG_PRINTLN(F("M\tSi4430")); + RADIOLIB_DEBUG_PRINTLN("M\tSi4430"); // configure publicly accessible settings state = setFrequency(freq); diff --git a/src/modules/Si443x/Si4431.cpp b/src/modules/Si443x/Si4431.cpp index 832ed432..98b07a8f 100644 --- a/src/modules/Si443x/Si4431.cpp +++ b/src/modules/Si443x/Si4431.cpp @@ -9,7 +9,7 @@ int16_t Si4431::begin(float freq, float br, float freqDev, float rxBw, int8_t po // execute common part int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen); RADIOLIB_ASSERT(state); - RADIOLIB_DEBUG_PRINTLN(F("M\tSi4431")); + RADIOLIB_DEBUG_PRINTLN("M\tSi4431"); // configure publicly accessible settings state = setFrequency(freq); diff --git a/src/modules/Si443x/Si4432.cpp b/src/modules/Si443x/Si4432.cpp index 06921add..76147df4 100644 --- a/src/modules/Si443x/Si4432.cpp +++ b/src/modules/Si443x/Si4432.cpp @@ -9,7 +9,7 @@ int16_t Si4432::begin(float freq, float br, float freqDev, float rxBw, int8_t po // execute common part int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen); RADIOLIB_ASSERT(state); - RADIOLIB_DEBUG_PRINTLN(F("M\tSi4432")); + RADIOLIB_DEBUG_PRINTLN("M\tSi4432"); // configure publicly accessible settings state = setFrequency(freq); diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index cabf6789..85719004 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -18,11 +18,11 @@ int16_t Si443x::begin(float br, float freqDev, float rxBw, uint8_t preambleLen) // try to find the Si443x chip if(!Si443x::findChip()) { - RADIOLIB_DEBUG_PRINTLN(F("No Si443x found!")); + RADIOLIB_DEBUG_PRINTLN("No Si443x found!"); _mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } else { - RADIOLIB_DEBUG_PRINTLN(F("M\tSi443x")); + RADIOLIB_DEBUG_PRINTLN("M\tSi443x"); } // reset the device @@ -683,17 +683,7 @@ bool Si443x::findChip() { if(version == RADIOLIB_SI443X_DEVICE_VERSION) { flagFound = true; } else { - #if defined(RADIOLIB_DEBUG) - RADIOLIB_DEBUG_PRINT(F("Si443x not found! (")); - RADIOLIB_DEBUG_PRINT(i + 1); - RADIOLIB_DEBUG_PRINT(F(" of 10 tries) RADIOLIB_SI443X_REG_DEVICE_VERSION == ")); - - char buffHex[5]; - sprintf(buffHex, "0x%02X", version); - RADIOLIB_DEBUG_PRINT(buffHex); - RADIOLIB_DEBUG_PRINT(F(", expected 0x00")); - RADIOLIB_DEBUG_PRINTLN(RADIOLIB_SI443X_DEVICE_VERSION, HEX); - #endif + RADIOLIB_DEBUG_PRINTLN("Si443x not found! (%d of 10 tries) RADIOLIB_SI443X_REG_DEVICE_VERSION == 0x%02X, expected 0x0%X", i + 1, version, RADIOLIB_SI443X_DEVICE_VERSION); _mod->delay(10); i++; } @@ -762,20 +752,8 @@ int16_t Si443x::updateClockRecovery() { uint16_t rxOsr_fixed = (uint16_t)rxOsr; // print that whole mess - RADIOLIB_DEBUG_PRINTLN(bypass, HEX); - RADIOLIB_DEBUG_PRINTLN(decRate, HEX); - RADIOLIB_DEBUG_PRINTLN(manch, HEX); - RADIOLIB_DEBUG_PRINT(rxOsr, 3); - RADIOLIB_DEBUG_PRINT('\t'); - RADIOLIB_DEBUG_PRINT(rxOsr_fixed); - RADIOLIB_DEBUG_PRINT('\t'); - RADIOLIB_DEBUG_PRINTLN(rxOsr_fixed, HEX); - RADIOLIB_DEBUG_PRINT(ncoOff); - RADIOLIB_DEBUG_PRINT('\t'); - RADIOLIB_DEBUG_PRINTLN(ncoOff, HEX); - RADIOLIB_DEBUG_PRINT(crGain); - RADIOLIB_DEBUG_PRINT('\t'); - RADIOLIB_DEBUG_PRINTLN(crGain, HEX); + RADIOLIB_DEBUG_PRINTLN("%X\n%X\n%X", bypass, decRate, manch); + RADIOLIB_DEBUG_PRINTLN("%f\t%d\t%X\n%d\t%X\n%d\t%X", rxOsr, rxOsr_fixed, rxOsr_fixed, ncoOff, ncoOff, crGain, crGain); // update oversampling ratio int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_2, (uint8_t)((rxOsr_fixed & 0x0700) >> 3), 7, 5); diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index e158a043..d8194d21 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -26,11 +26,11 @@ int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrW // check SPI connection int16_t val = _mod->SPIgetRegValue(RADIOLIB_NRF24_REG_SETUP_AW); if(!((val >= 0) && (val <= 3))) { - RADIOLIB_DEBUG_PRINTLN(F("No nRF24 found!")); + RADIOLIB_DEBUG_PRINTLN("No nRF24 found!"); _mod->term(); return(RADIOLIB_ERR_CHIP_NOT_FOUND); } - RADIOLIB_DEBUG_PRINTLN(F("M\tnRF24")); + RADIOLIB_DEBUG_PRINTLN("M\tnRF24"); // configure settings inaccessible by public API int16_t state = config(); diff --git a/src/protocols/Morse/Morse.cpp b/src/protocols/Morse/Morse.cpp index 3fbe3dd4..7810032f 100644 --- a/src/protocols/Morse/Morse.cpp +++ b/src/protocols/Morse/Morse.cpp @@ -91,17 +91,15 @@ int MorseClient::read(byte* symbol, byte* len, float low, float high) { uint32_t signalLen = mod->millis() - signalStart; if((signalLen >= low*(float)_dotLength) && (signalLen <= high*(float)_dotLength)) { - RADIOLIB_DEBUG_PRINT('.'); + RADIOLIB_DEBUG_PRINT("."); (*symbol) |= (RADIOLIB_MORSE_DOT << (*len)); (*len)++; } else if((signalLen >= low*(float)_dashLength) && (signalLen <= high*(float)_dashLength)) { - RADIOLIB_DEBUG_PRINT('-'); + RADIOLIB_DEBUG_PRINT("-"); (*symbol) |= (RADIOLIB_MORSE_DASH << (*len)); (*len)++; } else { - RADIOLIB_DEBUG_PRINT(""); + RADIOLIB_DEBUG_PRINTLN("", signalLen); } } @@ -135,7 +133,7 @@ size_t MorseClient::write(uint8_t b) { // inter-word pause (space) if(b == ' ') { - RADIOLIB_DEBUG_PRINTLN(F("space")); + RADIOLIB_DEBUG_PRINTLN("space"); standby(); mod->waitForMicroseconds(mod->micros(), _wordSpace*1000); return(1); @@ -154,11 +152,11 @@ size_t MorseClient::write(uint8_t b) { // send dot or dash if (code & RADIOLIB_MORSE_DASH) { - RADIOLIB_DEBUG_PRINT('-'); + RADIOLIB_DEBUG_PRINT("-"); transmitDirect(_base, _baseHz); mod->waitForMicroseconds(mod->micros(), _dashLength*1000); } else { - RADIOLIB_DEBUG_PRINT('.'); + RADIOLIB_DEBUG_PRINT("."); transmitDirect(_base, _baseHz); mod->waitForMicroseconds(mod->micros(), _dotLength*1000); } diff --git a/src/protocols/Pager/Pager.cpp b/src/protocols/Pager/Pager.cpp index f6aae335..5a510308 100644 --- a/src/protocols/Pager/Pager.cpp +++ b/src/protocols/Pager/Pager.cpp @@ -496,9 +496,7 @@ uint32_t PagerClient::read() { codeWord = ~codeWord; } - RADIOLIB_VERBOSE_PRINT("R\t"); - RADIOLIB_VERBOSE_PRINTLN(codeWord, HEX); - + RADIOLIB_VERBOSE_PRINTLN("R\t%X", codeWord); // TODO BCH error correction here return(codeWord); } diff --git a/src/protocols/PhysicalLayer/PhysicalLayer.cpp b/src/protocols/PhysicalLayer/PhysicalLayer.cpp index 46093ba9..48eeda61 100644 --- a/src/protocols/PhysicalLayer/PhysicalLayer.cpp +++ b/src/protocols/PhysicalLayer/PhysicalLayer.cpp @@ -274,7 +274,7 @@ int32_t PhysicalLayer::random(int32_t max) { if(randNum < 0) { randNum *= -1; } - RADIOLIB_DEBUG_PRINTLN(randNum); + RADIOLIB_DEBUG_PRINTLN("%d", randNum); return(randNum % max); } @@ -346,8 +346,7 @@ void PhysicalLayer::updateDirectBuffer(uint8_t bit) { _syncBuffer <<= 1; _syncBuffer |= bit; - RADIOLIB_VERBOSE_PRINT("S\t"); - RADIOLIB_VERBOSE_PRINTLN(_syncBuffer, HEX); + RADIOLIB_VERBOSE_PRINTLN("S\t%X", _syncBuffer); if((_syncBuffer & _directSyncWordMask) == _directSyncWord) { _gotSync = true; @@ -368,8 +367,7 @@ void PhysicalLayer::updateDirectBuffer(uint8_t bit) { // check complete byte if(_bufferBitPos == 8) { _buffer[_bufferWritePos] = Module::flipBits(_buffer[_bufferWritePos]); - RADIOLIB_VERBOSE_PRINT("R\t"); - RADIOLIB_VERBOSE_PRINTLN(_buffer[_bufferWritePos], HEX); + RADIOLIB_VERBOSE_PRINTLN("R\t%X", _buffer[_bufferWritePos]); _bufferWritePos++; _bufferBitPos = 0; From 17ae017f89fd771bdf535f634a571cf359975363 Mon Sep 17 00:00:00 2001 From: Mestery Date: Mon, 10 Apr 2023 14:51:07 +0200 Subject: [PATCH 6/6] address changes --- src/BuildOpt.h | 27 ++------------------------- src/Module.cpp | 40 +++++++++++++++++++++++++++++++++------- src/Module.h | 4 ++++ 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/BuildOpt.h b/src/BuildOpt.h index 0c02b351..995f8719 100644 --- a/src/BuildOpt.h +++ b/src/BuildOpt.h @@ -1040,31 +1040,8 @@ #if defined(RADIOLIB_DEBUG) #if defined(RADIOLIB_BUILD_ARDUINO) -// https://github.com/esp8266/Arduino/blob/65579d29081cb8501e4d7f786747bf12e7b37da2/cores/esp8266/Print.cpp#L50 -size_t serialPrintf(const char *format, ...) { - va_list arg; - va_start(arg, format); - char temp[64]; - char* buffer = temp; - size_t len = vsnprintf(temp, sizeof(temp), format, arg); - va_end(arg); - if (len > sizeof(temp) - 1) { - buffer = new char[len + 1]; - if (!buffer) { - return 0; - } - va_start(arg, format); - vsnprintf(buffer, len + 1, format, arg); - va_end(arg); - } - len = RADIOLIB_DEBUG_PORT.write((const uint8_t*) buffer, len); - if (buffer != temp) { - delete[] buffer; - } - return len; -} - #define RADIOLIB_DEBUG_PRINT(...) serialPrintf(__VA_ARGS__) - #define RADIOLIB_DEBUG_PRINTLN(M, ...) serialPrintf(M "\n", ##__VA_ARGS__) + #define RADIOLIB_DEBUG_PRINT(...) Module::serialPrintf(__VA_ARGS__) + #define RADIOLIB_DEBUG_PRINTLN(M, ...) Module::serialPrintf(M "\n", ##__VA_ARGS__) #else #if !defined(RADIOLIB_DEBUG_PRINT) #define RADIOLIB_DEBUG_PRINT(...) fprintf(RADIOLIB_DEBUG_PORT, __VA_ARGS__) diff --git a/src/Module.cpp b/src/Module.cpp index 77e4906d..d7197ab7 100644 --- a/src/Module.cpp +++ b/src/Module.cpp @@ -161,9 +161,9 @@ int16_t Module::SPIsetRegValue(uint16_t reg, uint8_t value, uint8_t msb, uint8_t } #if defined(RADIOLIB_DEBUG) && defined(RADIOLIB_BUILD_ARDUINO) - #define DEBUG_BIN(x) RADIOLIB_DEBUG_PORT.println(x, BIN) + #define RADIOLIB_DEBUG_PRINT_BIN(x) RADIOLIB_DEBUG_PORT.println(x, BIN) #else // no bin representation, fallback to hex - #define DEBUG_BIN(x) RADIOLIB_DEBUG_PRINTLN("%X", x) + #define RADIOLIB_DEBUG_PRINT_BIN(x) RADIOLIB_DEBUG_PRINTLN("%X", x) #endif // check failed, print debug info @@ -171,15 +171,15 @@ int16_t Module::SPIsetRegValue(uint16_t reg, uint8_t value, uint8_t msb, uint8_t RADIOLIB_DEBUG_PRINTLN("address:\t0x%X", reg); RADIOLIB_DEBUG_PRINTLN("bits:\t\t%d %d", msb, lsb); RADIOLIB_DEBUG_PRINT("value:\t\t0b"); - DEBUG_BIN(value); + RADIOLIB_DEBUG_PRINT_BIN(value); RADIOLIB_DEBUG_PRINT("current:\t0b"); - DEBUG_BIN(currentValue); + RADIOLIB_DEBUG_PRINT_BIN(currentValue); RADIOLIB_DEBUG_PRINT("mask:\t\t0b"); - DEBUG_BIN(mask); + RADIOLIB_DEBUG_PRINT_BIN(mask); RADIOLIB_DEBUG_PRINT("new:\t\t0b"); - DEBUG_BIN(newValue); + RADIOLIB_DEBUG_PRINT_BIN(newValue); RADIOLIB_DEBUG_PRINT("read:\t\t0b"); - DEBUG_BIN(readValue); + RADIOLIB_DEBUG_PRINT_BIN(readValue); RADIOLIB_DEBUG_PRINTLN(); return(RADIOLIB_ERR_SPI_WRITE_FAILED); @@ -757,6 +757,32 @@ void Module::regdump(uint16_t start, size_t len) { #endif } +#if defined(RADIOLIB_DEBUG) and defined(RADIOLIB_BUILD_ARDUINO) +// https://github.com/esp8266/Arduino/blob/65579d29081cb8501e4d7f786747bf12e7b37da2/cores/esp8266/Print.cpp#L50 +size_t Module::serialPrintf(const char* format, ...) { + va_list arg; + va_start(arg, format); + char temp[64]; + char* buffer = temp; + size_t len = vsnprintf(temp, sizeof(temp), format, arg); + va_end(arg); + if (len > sizeof(temp) - 1) { + buffer = new char[len + 1]; + if (!buffer) { + return 0; + } + va_start(arg, format); + vsnprintf(buffer, len + 1, format, arg); + va_end(arg); + } + len = RADIOLIB_DEBUG_PORT.write((const uint8_t*)buffer, len); + if (buffer != temp) { + delete[] buffer; + } + return len; +} +#endif + void Module::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) { // This can be on the stack, setRfSwitchTable copies the contents const RADIOLIB_PIN_TYPE pins[] = { diff --git a/src/Module.h b/src/Module.h index 9cb55db9..71ad40f9 100644 --- a/src/Module.h +++ b/src/Module.h @@ -704,6 +704,10 @@ class Module { */ void regdump(uint16_t start, size_t len); + #if defined(RADIOLIB_DEBUG) and defined(RADIOLIB_BUILD_ARDUINO) + static size_t serialPrintf(const char* format, ...); + #endif + #if !defined(RADIOLIB_GODMODE) private: #endif