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.

82 lines
1.8 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. if (systemCheck()) {
  26. udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
  27. udpDebug.write(buffer);
  28. if (len > DEBUG_MESSAGE_MAX_LENGTH) {
  29. udpDebug.write(" (...)\n");
  30. }
  31. udpDebug.endPacket();
  32. delay(1);
  33. }
  34. #endif
  35. }
  36. void debugSend_P(PGM_P format, ...) {
  37. char f[DEBUG_MESSAGE_MAX_LENGTH+1];
  38. memcpy_P(f, format, DEBUG_MESSAGE_MAX_LENGTH);
  39. char buffer[DEBUG_MESSAGE_MAX_LENGTH+1];
  40. va_list args;
  41. va_start(args, format);
  42. int len = ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, f, args);
  43. va_end(args);
  44. #if DEBUG_SERIAL_SUPPORT
  45. DEBUG_PORT.printf(buffer);
  46. if (len > DEBUG_MESSAGE_MAX_LENGTH) {
  47. DEBUG_PORT.printf(" (...)\n");
  48. }
  49. #endif
  50. #if DEBUG_UDP_SUPPORT
  51. if (systemCheck()) {
  52. udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
  53. udpDebug.write(buffer);
  54. if (len > DEBUG_MESSAGE_MAX_LENGTH) {
  55. udpDebug.write(" (...)\n");
  56. }
  57. udpDebug.endPacket();
  58. delay(1);
  59. }
  60. #endif
  61. }
  62. #endif // DEBUG_SERIAL_SUPPORT || DEBUG_UDP_SUPPORT