Net debug optimizations
Fix ESP8266 (unaligned progmem flash string reads) Do not send an extra package for \n in println Only resolve IP/hostname once
This commit is contained in:
parent
7fcc8be73c
commit
1d8c9ac020
@ -4,16 +4,10 @@
|
|||||||
|
|
||||||
NetworkDebugPrinter NetDebug;
|
NetworkDebugPrinter NetDebug;
|
||||||
|
|
||||||
void NetworkDebugPrinter::printchar(char s) {
|
void NetworkDebugPrinter::print(const char *s, bool newline) {
|
||||||
debugUdp.write(s);
|
if (!WLED_CONNECTED || !udpConnected || s == nullptr) return;
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkDebugPrinter::print(const char *s) {
|
if (!debugPrintHostIP && !debugPrintHostIP.fromString(netDebugPrintHost)) {
|
||||||
if (!WLED_CONNECTED || s == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
IPAddress debugPrintHostIP;
|
|
||||||
if (!debugPrintHostIP.fromString(netDebugPrintHost)) {
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
WiFi.hostByName(netDebugPrintHost, debugPrintHostIP, 750);
|
WiFi.hostByName(netDebugPrintHost, debugPrintHostIP, 750);
|
||||||
#else
|
#else
|
||||||
@ -24,49 +18,49 @@ void NetworkDebugPrinter::print(const char *s) {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WiFiUDP debugUdp;
|
||||||
debugUdp.beginPacket(debugPrintHostIP, netDebugPrintPort);
|
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.write(reinterpret_cast<const uint8_t *>(s), strlen(s));
|
||||||
|
if (newline) debugUdp.write('\n');
|
||||||
debugUdp.endPacket();
|
debugUdp.endPacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkDebugPrinter::print(const __FlashStringHelper* s) {
|
void NetworkDebugPrinter::print(const __FlashStringHelper* s, bool newline) {
|
||||||
print(reinterpret_cast<const char *>(s));
|
char buf[512];
|
||||||
|
strncpy_P(buf, (PGM_P)s, 512);
|
||||||
|
print(buf, newline);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkDebugPrinter::print(String s) {
|
void NetworkDebugPrinter::print(String s) {
|
||||||
print(s.c_str());
|
print(s.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkDebugPrinter::print(unsigned int n) {
|
void NetworkDebugPrinter::print(unsigned int n, bool newline) {
|
||||||
char s[10];
|
char s[10];
|
||||||
snprintf_P(s, sizeof(s), PSTR("%d"), n);
|
snprintf_P(s, sizeof(s), PSTR("%d"), n);
|
||||||
s[9] = '\0';
|
s[9] = '\0';
|
||||||
print(s);
|
print(s, newline);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkDebugPrinter::println() {
|
void NetworkDebugPrinter::println() {
|
||||||
print("\n");
|
print("", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkDebugPrinter::println(const char *s) {
|
void NetworkDebugPrinter::println(const char *s) {
|
||||||
print(s);
|
print(s, true);
|
||||||
print("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkDebugPrinter::println(const __FlashStringHelper* s) {
|
void NetworkDebugPrinter::println(const __FlashStringHelper* s) {
|
||||||
print(s);
|
print(s, true);
|
||||||
print("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkDebugPrinter::println(String s) {
|
void NetworkDebugPrinter::println(String s) {
|
||||||
print(s);
|
print(s.c_str(), true);
|
||||||
print("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkDebugPrinter::println(unsigned int n) {
|
void NetworkDebugPrinter::println(unsigned int n) {
|
||||||
print(n);
|
print(n, true);
|
||||||
print("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkDebugPrinter::printf(const char *fmt...) {
|
void NetworkDebugPrinter::printf(const char *fmt...) {
|
||||||
|
@ -6,13 +6,12 @@
|
|||||||
|
|
||||||
class NetworkDebugPrinter {
|
class NetworkDebugPrinter {
|
||||||
private:
|
private:
|
||||||
WiFiUDP debugUdp;
|
IPAddress debugPrintHostIP;
|
||||||
void printchar(char c);
|
|
||||||
public:
|
public:
|
||||||
void print(const char *s);
|
void print(const char *s, bool newline = false);
|
||||||
void print(const __FlashStringHelper* s);
|
void print(const __FlashStringHelper* s, bool newline = false);
|
||||||
void print(String s);
|
void print(String s);
|
||||||
void print(unsigned int n);
|
void print(unsigned int n, bool newline = false);
|
||||||
void println();
|
void println();
|
||||||
void println(const char *s);
|
void println(const char *s);
|
||||||
void println(const __FlashStringHelper* s);
|
void println(const __FlashStringHelper* s);
|
||||||
|
Loading…
Reference in New Issue
Block a user