Skip to content

Commit

Permalink
add printf via DEBUG_PORT define see #909
Browse files Browse the repository at this point in the history
  • Loading branch information
Links2004 committed Sep 28, 2024
1 parent 7a4c416 commit 83a87f7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/WebSockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
DEBUG_ESP_PORT.flush(); \
}
#else
// #define DEBUG_WEBSOCKETS(...) os_printf( __VA_ARGS__ )
#ifdef DEBUG_PORT
#define DEBUG_WEBSOCKETS(...) websocket_debug_printf(__VA_ARGS__)
void websocket_debug_printf(const char * format, ...);
#endif
#endif
#endif

Expand Down
32 changes: 32 additions & 0 deletions src/debug.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

#include "WebSockets.h"

#include <stdarg.h>

#ifdef DEBUG_PORT

void websocket_debug_printf(const char * format, ...) {
va_list arg;
va_start(arg, format);
char temp[64];
char * buffer = temp;
size_t len = vsnprintf(temp, sizeof(temp), format, arg);
va_end(arg);
if(len > sizeof(temp) - 1) {
buffer = new(std::nothrow) char[len + 1];
if(!buffer) {
return 0;
}
va_start(arg, format);
vsnprintf(buffer, len + 1, format, arg);
va_end(arg);
}
len = DEBUG_PORT.write((const uint8_t *)buffer, len);
if(buffer != temp) {
delete[] buffer;
}
DEBUG_PORT.flush();
return len;
}

#endif
2 changes: 1 addition & 1 deletion travis/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_library_json_version():

def get_header_versions():
data = {}
define = re.compile('^#define WEBSOCKETS_VERSION_?(.*) "?([0-9\.]*)"?$')
define = re.compile('^#define WEBSOCKETS_VERSION_?(.*) "?([0-9\\.]*)"?$')
with open(f'{base_dir}/src/WebSocketsVersion.h', 'r') as f:
for line in f:
m = define.match(line)
Expand Down

0 comments on commit 83a87f7

Please sign in to comment.