Subversion Repositories ESP8266_P1_Meter

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 raymond 1
#ifndef _DEBUG_PRINT_MACROS_H
2
#define _DEBUG_PRINT_MACROS_H
3
// Some customizable print macros to suite the debug needs de jour.
4
 
5
// Debug macros
6
// #include <pgmspace.h>
7
// https://stackoverflow.com/questions/8487986/file-macro-shows-full-path
8
// This value is resolved at compile time.
9
#define _FILENAME_ strrchr("/" __FILE__, '/')
10
 
11
// #define DEBUG_ESP_ASYNC_TCP 1
12
// #define DEBUG_ESP_TCP_SSL 1
13
// #define DEBUG_ESP_PORT Serial
14
 
15
#if defined(DEBUG_ESP_PORT) && !defined(DEBUG_TIME_STAMP_FMT)
16
#define DEBUG_TIME_STAMP_FMT "%06u.%03u "
17
struct _DEBUG_TIME_STAMP {
18
  unsigned dec;
19
  unsigned whole;
20
};
21
inline struct _DEBUG_TIME_STAMP debugTimeStamp(void) {
22
  struct _DEBUG_TIME_STAMP st;
23
  unsigned now = millis() % 1000000000;
24
  st.dec = now % 1000;
25
  st.whole = now / 1000;
26
  return st;
27
}
28
#endif
29
 
30
#if defined(DEBUG_ESP_PORT) && !defined(DEBUG_ESP_PORT_PRINTF)
31
 
32
#ifdef __cplusplus
33
#define DEBUG_ESP_PORT_PRINTF(format, ...)   DEBUG_ESP_PORT.printf((format), ##__VA_ARGS__)
34
#define DEBUG_ESP_PORT_PRINTF_F(format, ...) DEBUG_ESP_PORT.printf_P(PSTR(format), ##__VA_ARGS__)
35
#define DEBUG_ESP_PORT_FLUSH DEBUG_ESP_PORT.flush
36
#else
37
// Handle debug printing from .c without CPP Stream, Print, ... classes
38
// Cannot handle flash strings in this setting
39
#define DEBUG_ESP_PORT_PRINTF ets_uart_printf
40
#define DEBUG_ESP_PORT_PRINTF_F ets_uart_printf
41
#define DEBUG_ESP_PORT_FLUSH (void)0
42
#endif
43
 
44
#endif
45
 
46
#if defined(DEBUG_ESP_PORT) && !defined(DEBUG_GENERIC)
47
  #define DEBUG_GENERIC( module, format, ... ) \
48
    do { \
49
      struct _DEBUG_TIME_STAMP st = debugTimeStamp(); \
50
      DEBUG_ESP_PORT_PRINTF( (DEBUG_TIME_STAMP_FMT module " " format), st.whole, st.dec, ##__VA_ARGS__ ); \
51
    } while(false)
52
#endif
53
#if defined(DEBUG_ESP_PORT) && !defined(DEBUG_GENERIC_F)
54
  #define DEBUG_GENERIC_F( module, format, ... ) \
55
    do { \
56
      struct _DEBUG_TIME_STAMP st = debugTimeStamp(); \
57
      DEBUG_ESP_PORT_PRINTF_F( (DEBUG_TIME_STAMP_FMT module " " format), st.whole, st.dec, ##__VA_ARGS__ ); \
58
    } while(false)
59
#endif
60
 
61
#if defined(DEBUG_GENERIC) && !defined(ASSERT_GENERIC)
62
#define ASSERT_GENERIC( a, module ) \
63
  do { \
64
    if ( !(a) ) { \
65
      DEBUG_GENERIC( module, "%s:%s:%u: ASSERT("#a") failed!\n", __FILE__, __func__, __LINE__); \
66
      DEBUG_ESP_PORT_FLUSH(); \
67
    } \
68
  } while(false)
69
#endif
70
#if defined(DEBUG_GENERIC_F) && !defined(ASSERT_GENERIC_F)
71
#define ASSERT_GENERIC_F( a, module ) \
72
  do { \
73
    if ( !(a) ) { \
74
      DEBUG_GENERIC_F( module, "%s:%s:%u: ASSERT("#a") failed!\n", __FILE__, __func__, __LINE__); \
75
      DEBUG_ESP_PORT_FLUSH(); \
76
    } \
77
  } while(false)
78
#endif
79
 
80
#ifndef DEBUG_GENERIC
81
#define DEBUG_GENERIC(...) do { (void)0;} while(false)
82
#endif
83
 
84
#ifndef DEBUG_GENERIC_F
85
#define DEBUG_GENERIC_F(...) do { (void)0;} while(false)
86
#endif
87
 
88
#ifndef ASSERT_GENERIC
89
#define ASSERT_GENERIC(...) do { (void)0;} while(false)
90
#endif
91
 
92
#ifndef ASSERT_GENERIC_F
93
#define ASSERT_GENERIC_F(...) do { (void)0;} while(false)
94
#endif
95
 
96
#ifndef DEBUG_ESP_PRINTF
97
#define DEBUG_ESP_PRINTF( format, ...) DEBUG_GENERIC_F("[%s]", format, &_FILENAME_[1], ##__VA_ARGS__)
98
#endif
99
 
100
#if defined(DEBUG_ESP_ASYNC_TCP) && !defined(ASYNC_TCP_DEBUG)
101
#define ASYNC_TCP_DEBUG( format, ...) DEBUG_GENERIC_F("[ASYNC_TCP]", format, ##__VA_ARGS__)
102
#endif
103
 
104
#ifndef ASYNC_TCP_ASSERT
105
#define ASYNC_TCP_ASSERT( a ) ASSERT_GENERIC_F( (a), "[ASYNC_TCP]")
106
#endif
107
 
108
#if defined(DEBUG_ESP_TCP_SSL) && !defined(TCP_SSL_DEBUG)
109
#define TCP_SSL_DEBUG( format, ...) DEBUG_GENERIC_F("[TCP_SSL]", format, ##__VA_ARGS__)
110
#endif
111
 
112
#endif //_DEBUG_PRINT_MACROS_H