Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.6 KiB

  1. /*
  2. DEBUG MODULE
  3. Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #include <stdio.h>
  6. #include <stdarg.h>
  7. #ifdef DEBUG_UDP_IP
  8. #include <WiFiUdp.h>
  9. WiFiUDP udpDebug;
  10. #endif
  11. void debugSend(const char * format, ...) {
  12. char buffer[DEBUG_MESSAGE_MAX_LENGTH+1];
  13. va_list args;
  14. va_start(args, format);
  15. int len = ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, format, args);
  16. va_end(args);
  17. #ifdef DEBUG_PORT
  18. DEBUG_PORT.printf(buffer);
  19. if (len > DEBUG_MESSAGE_MAX_LENGTH) {
  20. DEBUG_PORT.printf(" (...)\n");
  21. }
  22. #endif
  23. #ifdef DEBUG_UDP_IP
  24. udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
  25. udpDebug.write(buffer);
  26. if (len > DEBUG_MESSAGE_MAX_LENGTH) {
  27. udpDebug.write(" (...)\n");
  28. }
  29. udpDebug.endPacket();
  30. #endif
  31. }
  32. void debugSend_P(PGM_P format, ...) {
  33. char f[DEBUG_MESSAGE_MAX_LENGTH+1];
  34. memcpy_P(f, format, DEBUG_MESSAGE_MAX_LENGTH);
  35. char buffer[DEBUG_MESSAGE_MAX_LENGTH+1];
  36. va_list args;
  37. va_start(args, format);
  38. int len = ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, f, args);
  39. va_end(args);
  40. #ifdef DEBUG_PORT
  41. DEBUG_PORT.printf(buffer);
  42. if (len > DEBUG_MESSAGE_MAX_LENGTH) {
  43. DEBUG_PORT.printf(" (...)\n");
  44. }
  45. #endif
  46. #ifdef DEBUG_UDP_IP
  47. udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
  48. udpDebug.write(buffer);
  49. if (len > DEBUG_MESSAGE_MAX_LENGTH) {
  50. udpDebug.write(" (...)\n");
  51. }
  52. udpDebug.endPacket();
  53. delay(1);
  54. #endif
  55. }