ZuluSCSI_log.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * ZuluSCSI™ - Copyright (c) 2022 Rabbit Hole Computing™
  3. *
  4. * ZuluSCSI™ firmware is licensed under the GPL version 3 or any later version. 
  5. *
  6. * https://www.gnu.org/licenses/gpl-3.0.html
  7. * ----
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version. 
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. * GNU General Public License for more details. 
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  20. **/
  21. // Helpers for log messages.
  22. #pragma once
  23. #include <stdint.h>
  24. #include <stddef.h>
  25. // Get total number of bytes that have been written to log
  26. uint32_t log_get_buffer_len();
  27. // Get log as a string.
  28. // If startpos is given, continues log reading from previous position and updates the position.
  29. const char *log_get_buffer(uint32_t *startpos);
  30. // Whether to enable debug messages
  31. extern bool g_log_debug;
  32. // Firmware version string
  33. extern const char *g_log_firmwareversion;
  34. // Log string
  35. void log_raw(const char *str);
  36. // Log byte as hex
  37. void log_raw(uint8_t value);
  38. // Log integer as hex
  39. void log_raw(uint32_t value);
  40. // Log integer as hex
  41. void log_raw(uint64_t value);
  42. // Log integer as decimal
  43. void log_raw(int value);
  44. // Log array of bytes
  45. struct bytearray {
  46. bytearray(const uint8_t *data, size_t len): data(data), len(len) {}
  47. const uint8_t *data;
  48. size_t len;
  49. };
  50. void log_raw(bytearray array);
  51. inline void log_raw()
  52. {
  53. // End of template recursion
  54. }
  55. extern "C" unsigned long millis();
  56. // Variadic template for printing multiple items
  57. template<typename T, typename T2, typename... Rest>
  58. inline void log_raw(T first, T2 second, Rest... rest)
  59. {
  60. log_raw(first);
  61. log_raw(second);
  62. log_raw(rest...);
  63. }
  64. // Format a complete log message
  65. template<typename... Params>
  66. inline void logmsg(Params... params)
  67. {
  68. log_raw("[", (int)millis(), "ms] ");
  69. log_raw(params...);
  70. log_raw("\n");
  71. }
  72. // Format a complete debug message
  73. template<typename... Params>
  74. inline void dbgmsg(Params... params)
  75. {
  76. if (g_log_debug)
  77. {
  78. log_raw("[", (int)millis(), "ms] DBG ");
  79. log_raw(params...);
  80. log_raw("\n");
  81. }
  82. }