kopia lustrzana https://github.com/Aircoookie/WLED
				
				
				
			NetworkDebugPrinter packet optimization.
							rodzic
							
								
									c0a783198e
								
							
						
					
					
						commit
						77f04d913a
					
				| 
						 | 
				
			
			@ -28,10 +28,12 @@ void colorRGBtoRGBW(byte* rgb);
 | 
			
		|||
  #define DEBUG_PRINT(x) DEBUGOUT.print(x)
 | 
			
		||||
  #define DEBUG_PRINTLN(x) DEBUGOUT.println(x)
 | 
			
		||||
  #define DEBUG_PRINTF(x...) DEBUGOUT.printf(x)
 | 
			
		||||
  #define DEBUG_FLUSH() DEBUGOUT.flush()
 | 
			
		||||
#else
 | 
			
		||||
  #define DEBUG_PRINT(x)
 | 
			
		||||
  #define DEBUG_PRINTLN(x)
 | 
			
		||||
  #define DEBUG_PRINTF(x...)
 | 
			
		||||
  #define DEBUG_FLUSH()
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define GET_BIT(var,bit)    (((var)>>(bit))&0x01)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,28 +3,26 @@
 | 
			
		|||
#ifdef WLED_DEBUG_HOST
 | 
			
		||||
 | 
			
		||||
size_t NetworkDebugPrinter::write(uint8_t c) {
 | 
			
		||||
  if (!WLED_CONNECTED || !udpConnected) return 0;
 | 
			
		||||
 | 
			
		||||
  if (!debugPrintHostIP && !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);
 | 
			
		||||
  debugUdp.write(c);
 | 
			
		||||
  debugUdp.endPacket();
 | 
			
		||||
  return 1;
 | 
			
		||||
  begin();
 | 
			
		||||
  if (!udpConnected) return 0;
 | 
			
		||||
  return debugUdp.write(c);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
size_t NetworkDebugPrinter::write(const uint8_t *buf, size_t size) {
 | 
			
		||||
  if (!WLED_CONNECTED || !udpConnected || buf == nullptr) return 0;
 | 
			
		||||
  if (buf == nullptr) return 0;
 | 
			
		||||
  begin();
 | 
			
		||||
  if (!udpConnected) return 0;
 | 
			
		||||
  return debugUdp.write(buf, size);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void NetworkDebugPrinter::begin() {
 | 
			
		||||
  if (udpConnected) return;
 | 
			
		||||
  if (!WLED_CONNECTED) {
 | 
			
		||||
    debugUdp.stop();
 | 
			
		||||
    debugPrintHostIP = INADDR_NONE;
 | 
			
		||||
    udpConnected = false;
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (!debugPrintHostIP && !debugPrintHostIP.fromString(netDebugPrintHost)) {
 | 
			
		||||
    #ifdef ESP8266
 | 
			
		||||
| 
						 | 
				
			
			@ -38,10 +36,13 @@ size_t NetworkDebugPrinter::write(const uint8_t *buf, size_t size) {
 | 
			
		|||
    #endif
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  debugUdp.beginPacket(debugPrintHostIP, netDebugPrintPort);
 | 
			
		||||
  debugUdp.write(buf, size);
 | 
			
		||||
  debugUdp.endPacket();
 | 
			
		||||
  return size;
 | 
			
		||||
  udpConnected = debugUdp.beginPacket(debugPrintHostIP, netDebugPrintPort);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void NetworkDebugPrinter::flush() {
 | 
			
		||||
  if (udpConnected) {
 | 
			
		||||
    if (!debugUdp.endPacket()) udpConnected = false;  // we were not able to send packet
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
NetworkDebugPrinter NetDebug;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,10 +7,14 @@
 | 
			
		|||
class NetworkDebugPrinter : public Print {
 | 
			
		||||
  private:
 | 
			
		||||
    WiFiUDP debugUdp; // needs to be here otherwise UDP messages get truncated upon destruction
 | 
			
		||||
    IPAddress debugPrintHostIP;
 | 
			
		||||
    IPAddress debugPrintHostIP = INADDR_NONE;
 | 
			
		||||
    bool udpConnected = false;
 | 
			
		||||
  public:
 | 
			
		||||
    virtual ~NetworkDebugPrinter() { flush(); }
 | 
			
		||||
    virtual size_t write(uint8_t c);
 | 
			
		||||
    virtual size_t write(const uint8_t *buf, size_t s);
 | 
			
		||||
    void begin();
 | 
			
		||||
    void flush();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern NetworkDebugPrinter NetDebug;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -218,6 +218,7 @@ void WLED::loop()
 | 
			
		|||
    debugTime = millis();
 | 
			
		||||
  }
 | 
			
		||||
  loops++;
 | 
			
		||||
  DEBUG_FLUSH();
 | 
			
		||||
#endif        // WLED_DEBUG
 | 
			
		||||
  toki.resetTick();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -446,6 +447,8 @@ void WLED::setup()
 | 
			
		|||
  #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_DISABLE_BROWNOUT_DET)
 | 
			
		||||
  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 1); //enable brownout detector
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  DEBUG_FLUSH();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void WLED::beginStrip()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -695,20 +695,24 @@ WLED_GLOBAL volatile uint8_t jsonBufferLock _INIT(0);
 | 
			
		|||
  #define DEBUG_PRINT(x) DEBUGOUT.print(x)
 | 
			
		||||
  #define DEBUG_PRINTLN(x) DEBUGOUT.println(x)
 | 
			
		||||
  #define DEBUG_PRINTF(x...) DEBUGOUT.printf(x)
 | 
			
		||||
  #define DEBUG_FLUSH() DEBUGOUT.flush()
 | 
			
		||||
#else
 | 
			
		||||
  #define DEBUG_PRINT(x)
 | 
			
		||||
  #define DEBUG_PRINTLN(x)
 | 
			
		||||
  #define DEBUG_PRINTF(x...)
 | 
			
		||||
  #define DEBUG_FLUSH()
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef WLED_DEBUG_FS
 | 
			
		||||
  #define DEBUGFS_PRINT(x) DEBUGOUT.print(x)
 | 
			
		||||
  #define DEBUGFS_PRINTLN(x) DEBUGOUT.println(x)
 | 
			
		||||
  #define DEBUGFS_PRINTF(x...) DEBUGOUT.printf(x)
 | 
			
		||||
  #define DEBUGFS_FLUSH() DEBUGOUT.flush()
 | 
			
		||||
#else
 | 
			
		||||
  #define DEBUGFS_PRINT(x)
 | 
			
		||||
  #define DEBUGFS_PRINTLN(x)
 | 
			
		||||
  #define DEBUGFS_PRINTF(x...)
 | 
			
		||||
  #define DEBUGFS_FLUSH()
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// debug macro variable definitions
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue