23
23
#include < inttypes.h>
24
24
#endif
25
25
26
+ #if defined(ARDUINO_ARCH_ARC32)
27
+ typedef uint64_t millis_time_t ;
28
+ #else
29
+ typedef uint32_t millis_time_t ;
30
+ #endif
31
+
26
32
#if defined(SPARK) || defined(PARTICLE)
27
33
#include " application.h"
28
34
#endif
@@ -77,21 +83,17 @@ void BlynkFatal() BLYNK_NORETURN;
77
83
#define BLYNK_LOG_FN () BLYNK_LOG3(BLYNK_F(__FUNCTION__), ' @' , __LINE__);
78
84
#define BLYNK_LOG_TROUBLE (t ) BLYNK_LOG2(BLYNK_F(" Trouble detected: http://docs.blynk.cc/#troubleshooting-" ), t)
79
85
80
- #if defined(BLYNK_DEBUG) && !defined( BLYNK_PRINT)
86
+ #ifndef BLYNK_PRINT
81
87
#undef BLYNK_DEBUG
82
88
#endif
83
89
84
90
#ifdef BLYNK_PRINT
85
91
86
92
#if defined(ARDUINO) || defined(SPARK) || defined(PARTICLE)
87
93
88
- #define BLYNK_DBG_BREAK () { for (;;); }
89
- #define BLYNK_ASSERT (expr ) { if (!(expr)) { BLYNK_LOG2 (BLYNK_F (" Assertion failed: " ), BLYNK_F (#expr)); BLYNK_DBG_BREAK () } }
90
-
91
- #if defined(__SAM3X8E__)
92
- #define BLYNK_LOG (msg, ...) blynk_dbg_print(msg, ##__VA_ARGS__)
93
- #elif defined(ARDUINO_ARCH_ARC32)
94
- #undef BLYNK_LOG
94
+ #if defined(ARDUINO_ARCH_ARC32)
95
+ // This will cause error - on purpose
96
+ #define BLYNK_LOG (msg, ...) BLYNK_LOG_UNAVAILABLE(msg, ##__VA_ARGS__)
95
97
#else
96
98
#define BLYNK_LOG (msg, ...) blynk_dbg_print(BLYNK_PSTR(msg), ##__VA_ARGS__)
97
99
#endif
@@ -102,17 +104,15 @@ void BlynkFatal() BLYNK_NORETURN;
102
104
#define BLYNK_LOG4 (p1,p2,p3,p4 ) { BLYNK_LOG_TIME (); BLYNK_PRINT.print (p1); BLYNK_PRINT.print (p2); BLYNK_PRINT.print (p3); BLYNK_PRINT.println (p4); }
103
105
#define BLYNK_LOG6 (p1,p2,p3,p4,p5,p6 ) { BLYNK_LOG_TIME (); BLYNK_PRINT.print (p1); BLYNK_PRINT.print (p2); BLYNK_PRINT.print (p3); BLYNK_PRINT.print (p4); BLYNK_PRINT.print (p5); BLYNK_PRINT.println (p6); }
104
106
#define BLYNK_LOG_IP (msg, ip ) { BLYNK_LOG_TIME (); BLYNK_PRINT.print (BLYNK_F (msg)); \
105
- BLYNK_PRINT.print (ip[0 ]); BLYNK_PRINT.print (' .' ); \
106
- BLYNK_PRINT.print (ip[1 ]); BLYNK_PRINT.print (' .' ); \
107
- BLYNK_PRINT.print (ip[2 ]); BLYNK_PRINT.print (' .' ); \
108
- BLYNK_PRINT.println (ip[3 ]); }
107
+ BLYNK_PRINT.print (ip[0 ]); BLYNK_PRINT.print (' .' ); \
108
+ BLYNK_PRINT.print (ip[1 ]); BLYNK_PRINT.print (' .' ); \
109
+ BLYNK_PRINT.print (ip[2 ]); BLYNK_PRINT.print (' .' ); \
110
+ BLYNK_PRINT.println (ip[3 ]); }
109
111
#define BLYNK_LOG_IP_REV (msg, ip ) { BLYNK_LOG_TIME (); BLYNK_PRINT.print (BLYNK_F (msg)); \
110
- BLYNK_PRINT.print (ip[3 ]); BLYNK_PRINT.print (' .' ); \
111
- BLYNK_PRINT.print (ip[2 ]); BLYNK_PRINT.print (' .' ); \
112
- BLYNK_PRINT.print (ip[1 ]); BLYNK_PRINT.print (' .' ); \
113
- BLYNK_PRINT.println (ip[0 ]); }
114
-
115
- #include < ctype.h>
112
+ BLYNK_PRINT.print (ip[3 ]); BLYNK_PRINT.print (' .' ); \
113
+ BLYNK_PRINT.print (ip[2 ]); BLYNK_PRINT.print (' .' ); \
114
+ BLYNK_PRINT.print (ip[1 ]); BLYNK_PRINT.print (' .' ); \
115
+ BLYNK_PRINT.println (ip[0 ]); }
116
116
117
117
static
118
118
void BLYNK_LOG_TIME () {
@@ -121,23 +121,38 @@ void BlynkFatal() BLYNK_NORETURN;
121
121
BLYNK_PRINT.print (BLYNK_F (" ] " ));
122
122
}
123
123
124
+ #ifdef BLYNK_DEBUG
125
+ #include < ctype.h>
126
+ #define BLYNK_DBG_BREAK () { for (;;); }
127
+ #define BLYNK_ASSERT (expr ) { if (!(expr)) { BLYNK_LOG2 (BLYNK_F (" Assertion failed: " ), BLYNK_F (#expr)); BLYNK_DBG_BREAK () } }
128
+
124
129
static
125
130
void BLYNK_DBG_DUMP (const char * msg, const void * addr, size_t len) {
126
131
if (len) {
132
+ BLYNK_LOG_TIME ();
127
133
BLYNK_PRINT.print (msg);
128
- int l2 = len; char * octets = (char *)(addr);
134
+ int l2 = len;
135
+ const uint8_t * octets = (const uint8_t *)addr;
136
+ bool prev_print = true ;
129
137
while (l2--) {
130
- if (isprint (*octets)) {
131
- BLYNK_PRINT.print (*octets);
138
+ const uint8_t c = *octets++ & 0xFF ;
139
+ if (isprint (c)) {
140
+ if (!prev_print) { BLYNK_PRINT.print (' ]' ); }
141
+ BLYNK_PRINT.print ((char )c);
142
+ prev_print = true ;
132
143
} else {
133
- BLYNK_PRINT.print (' |' );
134
- BLYNK_PRINT.print (*octets, HEX);
144
+ BLYNK_PRINT.print (prev_print?' [' :' |' );
145
+ if (c < 0x10 ) { BLYNK_PRINT.print (' 0' ); }
146
+ BLYNK_PRINT.print (c, HEX);
147
+ prev_print = false ;
135
148
}
136
- octets++;
137
149
}
150
+ if (!prev_print)
151
+ BLYNK_PRINT.print (' ]' );
138
152
BLYNK_PRINT.println ();
139
153
}
140
154
}
155
+ #endif
141
156
142
157
#if !defined(ARDUINO_ARCH_ARC32)
143
158
#include < stdio.h>
@@ -170,13 +185,9 @@ void BlynkFatal() BLYNK_NORETURN;
170
185
#include < errno.h>
171
186
#include < signal.h>
172
187
173
- #define BLYNK_DBG_DUMP (msg, addr, len ) if (len) { fprintf (BLYNK_PRINT, msg); fwrite (addr, len, 1 , BLYNK_PRINT); fputc (' \n ' , BLYNK_PRINT); }
174
- #define BLYNK_DBG_BREAK () raise(SIGTRAP);
175
- #define BLYNK_LOG (msg, ...) { fprintf (BLYNK_PRINT, " [%ld] " msg " \n " , millis (), ##__VA_ARGS__); }
176
- #define BLYNK_ASSERT (expr ) assert(expr)
177
-
178
188
#include < iostream>
179
189
using namespace std ;
190
+ #define BLYNK_LOG (msg, ...) { fprintf (BLYNK_PRINT, " [%ld] " msg " \n " , millis (), ##__VA_ARGS__); }
180
191
#define BLYNK_LOG1 (p1 ) { BLYNK_LOG_TIME (); cout << p1 << endl; }
181
192
#define BLYNK_LOG2 (p1,p2 ) { BLYNK_LOG_TIME (); cout << p1 << p2 << endl; }
182
193
#define BLYNK_LOG3 (p1,p2,p3 ) { BLYNK_LOG_TIME (); cout << p1 << p2 << p3 << endl; }
@@ -185,40 +196,21 @@ void BlynkFatal() BLYNK_NORETURN;
185
196
186
197
#define BLYNK_LOG_TIME () cout << ' [' << millis() << " ] " ;
187
198
188
- #elif defined(WINDOWS)
189
-
190
- #include < windows.h>
191
- #include < stdio.h>
192
-
193
- #define BLYNK_DBG_DUMP (msg, addr, len )
194
- #define BLYNK_DBG_BREAK () DebugBreak();
195
- #define BLYNK_LOG (...) { char buff[1024 ]; snprintf (buff, sizeof (buff), __VA_ARGS__); OutputDebugString (buff); }
196
- #define BLYNK_ASSERT (expr ) { if (!(expr)) { BLYNK_DBG_BREAK () } }
199
+ #ifdef BLYNK_DEBUG
200
+ #define BLYNK_DBG_BREAK () raise(SIGTRAP);
201
+ #define BLYNK_ASSERT (expr ) assert(expr)
202
+ #define BLYNK_DBG_DUMP (msg, addr, len ) if (len) { fprintf (BLYNK_PRINT, msg); fwrite (addr, len, 1 , BLYNK_PRINT); fputc (' \n ' , BLYNK_PRINT); }
203
+ #endif
197
204
198
205
#else
199
206
200
207
#warning Could not detect platform
201
- #define BLYNK_DBG_DUMP (msg, addr, len )
202
- #define BLYNK_DBG_BREAK () { *(char *)(NULL ) = 0xFF ; } // SEGV!!!
203
- #define BLYNK_ASSERT (expr ) { if (!(expr)) { BLYNK_DBG_BREAK () } }
204
-
205
- #define BLYNK_LOG (...)
206
- #define BLYNK_LOG1 (p1 )
207
- #define BLYNK_LOG2 (p1,p2 )
208
- #define BLYNK_LOG3 (p1,p2,p3 )
209
- #define BLYNK_LOG4 (p1,p2,p3,p4 )
210
- #define BLYNK_LOG6 (p1,p2,p3,p4,p5,p6 )
211
- #define BLYNK_LOG_IP (msg, ip )
212
- #define BLYNK_LOG_IP_REV (msg, ip )
213
208
214
209
#endif
215
210
216
- #else
217
-
218
- #define BLYNK_DBG_DUMP (msg, addr, len )
219
- #define BLYNK_DBG_BREAK ()
220
- #define BLYNK_ASSERT (expr )
211
+ #endif
221
212
213
+ #ifndef BLYNK_LOG
222
214
#define BLYNK_LOG (...)
223
215
#define BLYNK_LOG1 (p1 )
224
216
#define BLYNK_LOG2 (p1,p2 )
@@ -227,7 +219,12 @@ void BlynkFatal() BLYNK_NORETURN;
227
219
#define BLYNK_LOG6 (p1,p2,p3,p4,p5,p6 )
228
220
#define BLYNK_LOG_IP (msg, ip )
229
221
#define BLYNK_LOG_IP_REV (msg, ip )
222
+ #endif
230
223
224
+ #ifndef BLYNK_DBG_BREAK
225
+ #define BLYNK_DBG_BREAK ()
226
+ #define BLYNK_ASSERT (expr )
227
+ #define BLYNK_DBG_DUMP (msg, addr, len )
231
228
#endif
232
229
233
230
#endif
0 commit comments