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.

74 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. delay(1);
  31. #endif
  32. }
  33. void debugSend_P(PGM_P format, ...) {
  34. char f[DEBUG_MESSAGE_MAX_LENGTH+1];
  35. memcpy_P(f, format, DEBUG_MESSAGE_MAX_LENGTH);
  36. char buffer[DEBUG_MESSAGE_MAX_LENGTH+1];
  37. va_list args;
  38. va_start(args, format);
  39. int len = ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, f, args);
  40. va_end(args);
  41. #ifdef DEBUG_PORT
  42. DEBUG_PORT.printf(buffer);
  43. if (len > DEBUG_MESSAGE_MAX_LENGTH) {
  44. DEBUG_PORT.printf(" (...)\n");
  45. }
  46. #endif
  47. #ifdef DEBUG_UDP_IP
  48. udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
  49. udpDebug.write(buffer);
  50. if (len > DEBUG_MESSAGE_MAX_LENGTH) {
  51. udpDebug.write(" (...)\n");
  52. }
  53. udpDebug.endPacket();
  54. delay(1);
  55. #endif
  56. }