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.

78 lines
1.7 KiB

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