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.

90 lines
2.0 KiB

7 years ago
7 years ago
7 years ago
7 years ago
  1. /*
  2. DEBUG MODULE
  3. Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #if DEBUG_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. #if DEBUG_TELNET_SUPPORT
  36. _telnetWrite(buffer, strlen(buffer));
  37. #endif
  38. }
  39. void debugSend_P(PGM_P format, ...) {
  40. char f[DEBUG_MESSAGE_MAX_LENGTH+1];
  41. memcpy_P(f, format, DEBUG_MESSAGE_MAX_LENGTH);
  42. char buffer[DEBUG_MESSAGE_MAX_LENGTH+1];
  43. va_list args;
  44. va_start(args, format);
  45. int len = ets_vsnprintf(buffer, DEBUG_MESSAGE_MAX_LENGTH, f, args);
  46. va_end(args);
  47. #if DEBUG_SERIAL_SUPPORT
  48. DEBUG_PORT.printf(buffer);
  49. if (len > DEBUG_MESSAGE_MAX_LENGTH) {
  50. DEBUG_PORT.printf(" (...)\n");
  51. }
  52. #endif
  53. #if DEBUG_UDP_SUPPORT
  54. if (systemCheck()) {
  55. udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
  56. udpDebug.write(buffer);
  57. if (len > DEBUG_MESSAGE_MAX_LENGTH) {
  58. udpDebug.write(" (...)\n");
  59. }
  60. udpDebug.endPacket();
  61. delay(1);
  62. }
  63. #endif
  64. #if DEBUG_TELNET_SUPPORT
  65. _telnetWrite(buffer, strlen(buffer));
  66. #endif
  67. }
  68. #endif // DEBUG_SUPPORT