16#define DEBUG_ENABLED true
18#define DEBUG_ENABLED false
27#define DEBUG_PRINT(x) Serial.print(x)
28#define DEBUG_PRINTLN(x) Serial.println(x)
29#define DEBUG_PRINTF(fmt, ...) Serial.printf(fmt, ##__VA_ARGS__)
31#define DEBUG_PRINT(x) \
35#define DEBUG_PRINTLN(x) \
39#define DEBUG_PRINTF(fmt, ...) \
46#if DEBUG_ENABLED && DEBUG_MODBUS_ENABLED
47#define DEBUG_MODBUS_PRINT(x) \
48 Serial.print("[MODBUS] "); \
50#define DEBUG_MODBUS_PRINTLN(x) \
51 Serial.print("[MODBUS] "); \
53#define DEBUG_MODBUS_PRINTF(fmt, ...) Serial.printf("[MODBUS] " fmt, ##__VA_ARGS__)
55#define DEBUG_MODBUS_PRINT(x) \
59#define DEBUG_MODBUS_PRINTLN(x) \
63#define DEBUG_MODBUS_PRINTF(fmt, ...) \
69#if DEBUG_ENABLED && DEBUG_MQTT_ENABLED
70#define DEBUG_MQTT_PRINT(x) \
71 Serial.print("[MQTT] "); \
73#define DEBUG_MQTT_PRINTLN(x) \
74 Serial.print("[MQTT] "); \
76#define DEBUG_MQTT_PRINTF(fmt, ...) Serial.printf("[MQTT] " fmt, ##__VA_ARGS__)
78#define DEBUG_MQTT_PRINT(x) \
82#define DEBUG_MQTT_PRINTLN(x) \
86#define DEBUG_MQTT_PRINTF(fmt, ...) \
92#if DEBUG_ENABLED && DEBUG_WIFI_ENABLED
93#define DEBUG_WIFI_PRINT(x) \
94 Serial.print("[WIFI] "); \
96#define DEBUG_WIFI_PRINTLN(x) \
97 Serial.print("[WIFI] "); \
99#define DEBUG_WIFI_PRINTF(fmt, ...) Serial.printf("[WIFI] " fmt, ##__VA_ARGS__)
101#define DEBUG_WIFI_PRINT(x) \
105#define DEBUG_WIFI_PRINTLN(x) \
109#define DEBUG_WIFI_PRINTF(fmt, ...) \
132 va_start(args, format);
133 Serial.printf(format, args);
147#if DEBUG_ENABLED && DEBUG_MODBUS_ENABLED
151 Serial.print(prefix);
152 for (
size_t i = 0; i < length; i++)
154 if (buffer[i] < 0x10) Serial.print(
"0");
155 Serial.print(buffer[i], HEX);
169inline void debugPrintStatus(
const char* module,
bool status,
const char* details =
nullptr)
172 Serial.printf(
"[%s] %s", module, status ?
"✅" :
"❌");
175 Serial.printf(
" - %s", details);
186#define DEBUG_MQTT_DELTA(fmt, ...) DEBUG_MQTT_PRINTF("[DELTA] " fmt "\n", ##__VA_ARGS__)
187#define DEBUG_MQTT_DNS(fmt, ...) DEBUG_MQTT_PRINTF("[DNS] " fmt "\n", ##__VA_ARGS__)
188#define DEBUG_MQTT_HA(fmt, ...) DEBUG_MQTT_PRINTF("[HA] " fmt "\n", ##__VA_ARGS__)
191#define DEBUG_MODBUS_TX() DEBUG_MODBUS_PRINTLN("TX режим")
192#define DEBUG_MODBUS_RX() DEBUG_MODBUS_PRINTLN("RX режим")
193#define DEBUG_MODBUS_MOVING_AVG(fmt, ...) DEBUG_MODBUS_PRINTF("[MOVING_AVG] " fmt "\n", ##__VA_ARGS__)
196#define DEBUG_MAIN_BATCH(msg) DEBUG_PRINTLN("[BATCH] " msg)
197#define DEBUG_MAIN_BUTTON(msg) DEBUG_PRINTLN("[BUTTON] " msg)
206 unsigned long total_messages;
207 unsigned long modbus_messages;
208 unsigned long mqtt_messages;
209 unsigned long wifi_messages;
210 unsigned long start_time;
213extern DebugStats debug_stats;
217 debug_stats = {0, 0, 0, 0, millis()};
222 debug_stats.total_messages++;
223 if (strstr(category,
"MODBUS"))
224 debug_stats.modbus_messages++;
225 else if (strstr(category,
"MQTT"))
226 debug_stats.mqtt_messages++;
227 else if (strstr(category,
"WIFI"))
228 debug_stats.wifi_messages++;
233 unsigned long uptime = millis() - debug_stats.start_time;
234 Serial.printf(
"\n=== DEBUG СТАТИСТИКА ===\n");
235 Serial.printf(
"Время работы: %lu мс\n", uptime);
236 Serial.printf(
"Всего сообщений: %lu\n", debug_stats.total_messages);
237 Serial.printf(
"MODBUS: %lu, MQTT: %lu, WIFI: %lu\n", debug_stats.modbus_messages, debug_stats.mqtt_messages,
238 debug_stats.wifi_messages);
239 Serial.printf(
"Частота: %.2f сообщений/сек\n", debug_stats.total_messages * 1000.0 / uptime);
240 Serial.printf(
"========================\n\n");
253#define MIGRATE_DEBUG_PRINTF(fmt, ...) DEBUG_PRINTF(fmt, ##__VA_ARGS__)
254#define MIGRATE_DEBUG_PRINTLN(msg) DEBUG_PRINTLN(msg)
257#define CRITICAL_DEBUG_PRINT(x) \
258 Serial.print("[CRITICAL] "); \
260#define CRITICAL_DEBUG_PRINTLN(x) \
261 Serial.print("[CRITICAL] "); \
263#define CRITICAL_DEBUG_PRINTF(fmt, ...) Serial.printf("[CRITICAL] " fmt, ##__VA_ARGS__)
void debugPrintHexBuffer(const char *prefix, const uint8_t *buffer, size_t length)
Отладочная печать буфера в HEX формате (оптимизированная)
void debugConditionalPrint(int level, const char *format,...)
Условная отладочная печать с проверкой уровня логирования
void debugPrintStatus(const char *module, bool status, const char *details=nullptr)
Отладочная печать состояния системы (компактная)
void debugStatsIncrement(const char *category)
Централизованные константы системы JXCT.
constexpr int LOG_LEVEL_DEBUG