Merge branch 'netdebug' of https://github.com/visigoth/WLED into net_debug

This commit is contained in:
Blaz Kristan 2022-11-06 10:58:19 +01:00
commit 7fcc8be73c
5 changed files with 141 additions and 9 deletions

View File

@ -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 <rom/rtc.h>
#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)

81
wled00/net_debug.cpp Normal file
View File

@ -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<strlen(s); i++) printchar(s[i]);
debugUdp.write(reinterpret_cast<const uint8_t *>(s), strlen(s));
debugUdp.endPacket();
}
void NetworkDebugPrinter::print(const __FlashStringHelper* s) {
print(reinterpret_cast<const char *>(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

26
wled00/net_debug.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef WLED_NET_DEBUG_H
#define WLED_NET_DEBUG_H
#include <WString.h>
#include <WiFiUdp.h>
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

View File

@ -95,6 +95,10 @@
#include "my_config.h"
#endif
#ifdef WLED_DEBUG_HOST
#include "net_debug.h"
#endif
#include <ESPAsyncWebServer.h>
#ifdef WLED_ADD_EEPROM_SUPPORT
#include <EEPROM.h>
@ -669,13 +673,27 @@ WLED_GLOBAL StaticJsonDocument<JSON_BUFFER_SIZE> 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 <rom/rtc.h>
#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)

View File

@ -227,6 +227,7 @@
<ClCompile Include="wled_eeprom.cpp" />
<ClCompile Include="wled_server.cpp" />
<ClCompile Include="xml.cpp" />
<ClCompile Include="net_debug.cpp" />
</ItemGroup>
<PropertyGroup>
<DebuggerFlavor>VisualMicroDebugger</DebuggerFlavor>