diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index bfae90ac..5f604321 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -15,13 +15,19 @@ uint32_t colorBalanceFromKelvin(uint16_t kelvin, uint32_t rgb); void colorRGBtoRGBW(byte* rgb); // enable additional debug output +#if defined(WLED_DEBUG_HOST) + #define DEBUGOUT NetDebug +#else + #define DEBUGOUT Serial +#endif + #ifdef WLED_DEBUG #ifndef ESP8266 #include #endif - #define DEBUG_PRINT(x) Serial.print(x) - #define DEBUG_PRINTLN(x) Serial.println(x) - #define DEBUG_PRINTF(x...) Serial.printf(x) + #define DEBUG_PRINT(x) DEBUGOUT.print(x) + #define DEBUG_PRINTLN(x) DEBUGOUT.println(x) + #define DEBUG_PRINTF(x...) DEBUGOUT.printf(x) #else #define DEBUG_PRINT(x) #define DEBUG_PRINTLN(x) diff --git a/wled00/net_debug.cpp b/wled00/net_debug.cpp new file mode 100644 index 00000000..f1242bb1 --- /dev/null +++ b/wled00/net_debug.cpp @@ -0,0 +1,81 @@ +#include "wled.h" + +#ifdef WLED_DEBUG_HOST + +NetworkDebugPrinter NetDebug; + +void NetworkDebugPrinter::printchar(char s) { + debugUdp.write(s); +} + +void NetworkDebugPrinter::print(const char *s) { + if (!WLED_CONNECTED || s == nullptr) { + return; + } + IPAddress debugPrintHostIP; + if (!debugPrintHostIP.fromString(netDebugPrintHost)) { + #ifdef ESP8266 + WiFi.hostByName(netDebugPrintHost, debugPrintHostIP, 750); + #else + #ifdef WLED_USE_ETHERNET + ETH.hostByName(netDebugPrintHost, debugPrintHostIP); + #else + WiFi.hostByName(netDebugPrintHost, debugPrintHostIP); + #endif + #endif + } + debugUdp.beginPacket(debugPrintHostIP, netDebugPrintPort); + //for (size_t i=0; i(s), strlen(s)); + debugUdp.endPacket(); +} + +void NetworkDebugPrinter::print(const __FlashStringHelper* s) { + print(reinterpret_cast(s)); +} + +void NetworkDebugPrinter::print(String s) { + print(s.c_str()); +} + +void NetworkDebugPrinter::print(unsigned int n) { + char s[10]; + snprintf_P(s, sizeof(s), PSTR("%d"), n); + s[9] = '\0'; + print(s); +} + +void NetworkDebugPrinter::println() { + print("\n"); +} + +void NetworkDebugPrinter::println(const char *s) { + print(s); + print("\n"); +} + +void NetworkDebugPrinter::println(const __FlashStringHelper* s) { + print(s); + print("\n"); +} + +void NetworkDebugPrinter::println(String s) { + print(s); + print("\n"); +} + +void NetworkDebugPrinter::println(unsigned int n) { + print(n); + print("\n"); +} + +void NetworkDebugPrinter::printf(const char *fmt...) { + va_list args; + va_start(args, fmt); + char s[1024]; + vsnprintf(s, sizeof(s), fmt, args); + va_end(args); + print(s); +} + +#endif diff --git a/wled00/net_debug.h b/wled00/net_debug.h new file mode 100644 index 00000000..d15a9f76 --- /dev/null +++ b/wled00/net_debug.h @@ -0,0 +1,26 @@ +#ifndef WLED_NET_DEBUG_H +#define WLED_NET_DEBUG_H + +#include +#include + +class NetworkDebugPrinter { +private: + WiFiUDP debugUdp; + void printchar(char c); +public: + void print(const char *s); + void print(const __FlashStringHelper* s); + void print(String s); + void print(unsigned int n); + void println(); + void println(const char *s); + void println(const __FlashStringHelper* s); + void println(String s); + void println(unsigned int n); + void printf(const char *fmt, ...); +}; + +extern NetworkDebugPrinter NetDebug; + +#endif \ No newline at end of file diff --git a/wled00/wled.h b/wled00/wled.h index 44327176..7f7928ca 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -95,6 +95,10 @@ #include "my_config.h" #endif +#ifdef WLED_DEBUG_HOST +#include "net_debug.h" +#endif + #include #ifdef WLED_ADD_EEPROM_SUPPORT #include @@ -669,13 +673,27 @@ WLED_GLOBAL StaticJsonDocument doc; WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0); // enable additional debug output +#if defined(WLED_DEBUG_HOST) + // On the host side, use netcat to receive the log statements: nc -l 7868 -u + // use -D WLED_DEBUG_HOST='"192.168.xxx.xxx"' or FQDN within quotes + #define DEBUGOUT NetDebug + WLED_GLOBAL char netDebugPrintHost[33] _INIT(WLED_DEBUG_HOST); + #if defined(WLED_DEBUG_NET_PORT) + WLED_GLOBAL int netDebugPrintPort _INIT(WLED_DEBUG_PORT); + #else + WLED_GLOBAL int netDebugPrintPort _INIT(7868); + #endif +#else + #define DEBUGOUT Serial +#endif + #ifdef WLED_DEBUG #ifndef ESP8266 #include #endif - #define DEBUG_PRINT(x) Serial.print(x) - #define DEBUG_PRINTLN(x) Serial.println(x) - #define DEBUG_PRINTF(x...) Serial.printf(x) + #define DEBUG_PRINT(x) DEBUGOUT.print(x) + #define DEBUG_PRINTLN(x) DEBUGOUT.println(x) + #define DEBUG_PRINTF(x...) DEBUGOUT.printf(x) #else #define DEBUG_PRINT(x) #define DEBUG_PRINTLN(x) @@ -683,9 +701,9 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0); #endif #ifdef WLED_DEBUG_FS - #define DEBUGFS_PRINT(x) Serial.print(x) - #define DEBUGFS_PRINTLN(x) Serial.println(x) - #define DEBUGFS_PRINTF(x...) Serial.printf(x) + #define DEBUGFS_PRINT(x) DEBUGOUT.print(x) + #define DEBUGFS_PRINTLN(x) DEBUGOUT.println(x) + #define DEBUGFS_PRINTF(x...) DEBUGOUT.printf(x) #else #define DEBUGFS_PRINT(x) #define DEBUGFS_PRINTLN(x) diff --git a/wled00/wled00.vcxproj b/wled00/wled00.vcxproj index 9e30b6f1..638e69b8 100644 --- a/wled00/wled00.vcxproj +++ b/wled00/wled00.vcxproj @@ -227,6 +227,7 @@ + VisualMicroDebugger