Skip to content

Commit

Permalink
allow control of enabling debug and debug level from IDE
Browse files Browse the repository at this point in the history
  • Loading branch information
Links2004 committed Jan 2, 2016
1 parent bcfa5c8 commit 2b23b00
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 34 deletions.
26 changes: 26 additions & 0 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ menu.FlashFreq=Flash Frequency
menu.UploadTool=Upload Using
menu.ResetMethod=Reset Method
menu.ESPModule=Module
menu.Debug=Debug port
menu.DebugLevel=Debug Level

##############################################################
generic.name=Generic ESP8266 Module
Expand All @@ -26,6 +28,8 @@ generic.build.core=esp8266
generic.build.variant=generic
generic.build.flash_mode=qio
generic.build.spiffs_pagesize=256
generic.build.debug_port=
generic.build.debug_level=

generic.menu.UploadTool.esptool=Serial
generic.menu.UploadTool.esptool.upload.tool=esptool
Expand Down Expand Up @@ -166,6 +170,28 @@ generic.menu.ResetMethod.ck.upload.resetmethod=ck
generic.menu.ResetMethod.nodemcu=nodemcu
generic.menu.ResetMethod.nodemcu.upload.resetmethod=nodemcu

generic.menu.Debug.Disabled=Disabled
generic.menu.Debug.Disabled.build.debug_port=
generic.menu.Debug.Serial=Serial
generic.menu.Debug.Serial.build.debug_port=-DDEBUG_ESP_PORT=Serial
generic.menu.Debug.Serial1=Serial1
generic.menu.Debug.Serial1.build.debug_port=-DDEBUG_ESP_PORT=Serial1

generic.menu.DebugLevel.None=None
generic.menu.DebugLevel.None.build.debug_level=
generic.menu.DebugLevel.Core=Core
generic.menu.DebugLevel.Core.build.debug_level=-DDEBUG_ESP_CORE
generic.menu.DebugLevel.SSL=Core + SSL
generic.menu.DebugLevel.SSL.build.debug_level=-DDEBUG_ESP_CORE -DDEBUG_ESP_SSL
generic.menu.DebugLevel.HTTPClient=HTTPClient
generic.menu.DebugLevel.HTTPClient.build.debug_level=-DDEBUG_ESP_HTTP_CLIENT
generic.menu.DebugLevel.HTTPUpdate=HTTPUpdate
generic.menu.DebugLevel.HTTPUpdate.build.debug_level=-DDEBUG_ESP_HTTP_UPDATE
generic.menu.DebugLevel.HTTPUpdate2=HTTPClient + HTTPUpdate
generic.menu.DebugLevel.HTTPUpdate2.build.debug_level=-DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_UPDATE
generic.menu.DebugLevel.HTTPServer=HTTPServer
generic.menu.DebugLevel.HTTPServer.build.debug_level=-DDEBUG_ESP_HTTP_SERVER

# disabled because espressif's bootloader refuses to write above 4M
# generic.menu.FlashSize.8M=8M (7M SPIFFS)
# generic.menu.FlashSize.8M.build.flash_size=1M
Expand Down
3 changes: 3 additions & 0 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ static void loop_wrapper() {
preloop_update_frequency();
if(!setup_done) {
setup();
#ifdef DEBUG_ESP_PORT
DEBUG_ESP_PORT.setDebugOutput(true);
#endif
setup_done = true;
}
loop();
Expand Down
4 changes: 3 additions & 1 deletion cores/esp8266/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
#include <stddef.h>
#include <stdint.h>

//#define DEBUGV(...) ets_printf(__VA_ARGS__)
#ifdef DEBUG_ESP_CORE
#define DEBUGV(...) ets_printf(__VA_ARGS__)
#endif

#ifndef DEBUGV
#define DEBUGV(...)
Expand Down
6 changes: 5 additions & 1 deletion libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
#ifndef ESP8266HTTPClient_H_
#define ESP8266HTTPClient_H_

//#define DEBUG_HTTPCLIENT(...) Serial1.printf( __VA_ARGS__ )
#ifdef DEBUG_ESP_HTTP_CLIENT
#ifdef DEBUG_ESP_PORT
#define DEBUG_HTTPCLIENT(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
#endif
#endif

#ifndef DEBUG_HTTPCLIENT
#define DEBUG_HTTPCLIENT(...)
Expand Down
13 changes: 9 additions & 4 deletions libraries/ESP8266WebServer/src/ESP8266WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@
#include "ESP8266WebServer.h"
#include "FS.h"
#include "detail/RequestHandlersImpl.h"
// #define DEBUG

//#define DEBUG_ESP_HTTP_SERVER
#ifdef DEBUG_ESP_PORT
#define DEBUG_OUTPUT DEBUG_ESP_PORT
#else
#define DEBUG_OUTPUT Serial
#endif

const char * AUTHORIZATION_HEADER = "Authorization";

Expand Down Expand Up @@ -155,7 +160,7 @@ void ESP8266WebServer::handleClient() {
return;
}

#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.println("New client");
#endif

Expand Down Expand Up @@ -416,13 +421,13 @@ void ESP8266WebServer::onNotFound(THandlerFunction fn) {
void ESP8266WebServer::_handleRequest() {
bool handled = false;
if (!_currentHandler){
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.println("request handler not found");
#endif
}
else {
handled = _currentHandler->handle(*this, _currentMethod, _currentUri);
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
if (!handled) {
DEBUG_OUTPUT.println("request handler failed to handle request");
}
Expand Down
50 changes: 27 additions & 23 deletions libraries/ESP8266WebServer/src/Parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
#include "WiFiClient.h"
#include "ESP8266WebServer.h"

//#define DEBUG
//#define DEBUG_ESP_HTTP_SERVER
#ifdef DEBUG_ESP_PORT
#define DEBUG_OUTPUT DEBUG_ESP_PORT
#else
#define DEBUG_OUTPUT Serial
#endif

bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
// Read the first line of HTTP request
Expand All @@ -41,7 +45,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
int addr_start = req.indexOf(' ');
int addr_end = req.indexOf(' ', addr_start + 1);
if (addr_start == -1 || addr_end == -1) {
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("Invalid request: ");
DEBUG_OUTPUT.println(req);
#endif
Expand Down Expand Up @@ -72,7 +76,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
}
_currentMethod = method;

#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("method: ");
DEBUG_OUTPUT.print(methodStr);
DEBUG_OUTPUT.print(" url: ");
Expand Down Expand Up @@ -111,7 +115,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
headerValue.trim();
_collectHeader(headerName.c_str(),headerValue.c_str());

#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("headerName: ");
DEBUG_OUTPUT.println(headerName);
DEBUG_OUTPUT.print("headerValue: ");
Expand Down Expand Up @@ -142,7 +146,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
char *plainBuf = (char*)malloc(plainLen+1);
client.readBytes(plainBuf, plainLen);
plainBuf[plainLen] = '\0';
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("Plain: ");
DEBUG_OUTPUT.println(plainBuf);
#endif
Expand Down Expand Up @@ -177,7 +181,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
headerValue = req.substring(headerDiv + 2);
_collectHeader(headerName.c_str(),headerValue.c_str());

#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("headerName: ");
DEBUG_OUTPUT.println(headerName);
DEBUG_OUTPUT.print("headerValue: ");
Expand All @@ -192,7 +196,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
}
client.flush();

#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("Request: ");
DEBUG_OUTPUT.println(url);
DEBUG_OUTPUT.print(" Arguments: ");
Expand All @@ -213,7 +217,7 @@ bool ESP8266WebServer::_collectHeader(const char* headerName, const char* header
}

void ESP8266WebServer::_parseArguments(String data) {
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("args: ");
DEBUG_OUTPUT.println(data);
#endif
Expand All @@ -233,7 +237,7 @@ void ESP8266WebServer::_parseArguments(String data) {
++i;
++_currentArgCount;
}
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("args count: ");
DEBUG_OUTPUT.println(_currentArgCount);
#endif
Expand All @@ -244,7 +248,7 @@ void ESP8266WebServer::_parseArguments(String data) {
for (iarg = 0; iarg < _currentArgCount;) {
int equal_sign_index = data.indexOf('=', pos);
int next_arg_index = data.indexOf('&', pos);
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("pos ");
DEBUG_OUTPUT.print(pos);
DEBUG_OUTPUT.print("=@ ");
Expand All @@ -253,7 +257,7 @@ void ESP8266WebServer::_parseArguments(String data) {
DEBUG_OUTPUT.println(next_arg_index);
#endif
if ((equal_sign_index == -1) || ((equal_sign_index > next_arg_index) && (next_arg_index != -1))) {
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("arg missing value: ");
DEBUG_OUTPUT.println(iarg);
#endif
Expand All @@ -265,7 +269,7 @@ void ESP8266WebServer::_parseArguments(String data) {
RequestArgument& arg = _currentArgs[iarg];
arg.key = data.substring(pos, equal_sign_index);
arg.value = urlDecode(data.substring(equal_sign_index + 1, next_arg_index));
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("arg ");
DEBUG_OUTPUT.print(iarg);
DEBUG_OUTPUT.print(" key: ");
Expand All @@ -279,7 +283,7 @@ void ESP8266WebServer::_parseArguments(String data) {
pos = next_arg_index + 1;
}
_currentArgCount = iarg;
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("args count: ");
DEBUG_OUTPUT.println(_currentArgCount);
#endif
Expand Down Expand Up @@ -308,7 +312,7 @@ uint8_t ESP8266WebServer::_uploadReadByte(WiFiClient& client){

bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){

#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("Parse Form: Boundary: ");
DEBUG_OUTPUT.print(boundary);
DEBUG_OUTPUT.print(" Length: ");
Expand Down Expand Up @@ -346,14 +350,14 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
argFilename = argName.substring(nameStart+2, argName.length() - 1);
argName = argName.substring(0, argName.indexOf('"'));
argIsFile = true;
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("PostArg FileName: ");
DEBUG_OUTPUT.println(argFilename);
#endif
//use GET to set the filename if uploading using blob
if (argFilename == "blob" && hasArg("filename")) argFilename = arg("filename");
}
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("PostArg Name: ");
DEBUG_OUTPUT.println(argName);
#endif
Expand All @@ -366,7 +370,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
client.readStringUntil('\r');
client.readStringUntil('\n');
}
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("PostArg Type: ");
DEBUG_OUTPUT.println(argType);
#endif
Expand All @@ -378,7 +382,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
if (argValue.length() > 0) argValue += "\n";
argValue += line;
}
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("PostArg Value: ");
DEBUG_OUTPUT.println(argValue);
DEBUG_OUTPUT.println();
Expand All @@ -389,7 +393,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
arg.value = argValue;

if (line == ("--"+boundary+"--")){
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.println("Done Parsing POST");
#endif
break;
Expand All @@ -401,7 +405,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
_currentUpload.type = argType;
_currentUpload.totalSize = 0;
_currentUpload.currentSize = 0;
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("Start File: ");
DEBUG_OUTPUT.print(_currentUpload.filename);
DEBUG_OUTPUT.print(" Type: ");
Expand Down Expand Up @@ -450,7 +454,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
_currentUpload.status = UPLOAD_FILE_END;
if(_currentHandler && _currentHandler->canUpload(_currentUri))
_currentHandler->upload(*this, _currentUri, _currentUpload);
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("End File: ");
DEBUG_OUTPUT.print(_currentUpload.filename);
DEBUG_OUTPUT.print(" Type: ");
Expand All @@ -461,7 +465,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
line = client.readStringUntil(0x0D);
client.readStringUntil(0x0A);
if (line == "--"){
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.println("Done Parsing POST");
#endif
break;
Expand Down Expand Up @@ -507,7 +511,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
if (postArgs) delete[] postArgs;
return true;
}
#ifdef DEBUG
#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("Error: line: ");
DEBUG_OUTPUT.println(line);
#endif
Expand Down
4 changes: 3 additions & 1 deletion libraries/ESP8266WiFi/src/WiFiClientSecure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ extern "C"
#include "include/ClientContext.h"
#include "c_types.h"

//#define DEBUG_SSL
#ifdef DEBUG_ESP_SSL
#define DEBUG_SSL
#endif

#ifdef DEBUG_SSL
#define SSL_DEBUG_OPTS SSL_DISPLAY_STATES
Expand Down
6 changes: 5 additions & 1 deletion libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
#include <WiFiUdp.h>
#include <ESP8266HTTPClient.h>

//#define DEBUG_HTTP_UPDATE(...) Serial1.printf( __VA_ARGS__ )
#ifdef DEBUG_ESP_HTTP_UPDATE
#ifdef DEBUG_ESP_PORT
#define DEBUG_HTTP_UPDATE(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ )
#endif
#endif

#ifndef DEBUG_HTTP_UPDATE
#define DEBUG_HTTP_UPDATE(...)
Expand Down
6 changes: 3 additions & 3 deletions platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ compiler.objcopy.eep.extra_flags=
compiler.elf2hex.extra_flags=

## Compile c files
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -DF_CPU={build.f_cpu} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"

## Compile c++ files
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -DF_CPU={build.f_cpu} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"

## Compile S files
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"
recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -DF_CPU={build.f_cpu} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"

## Create archives
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/arduino.ar" "{object_file}"
Expand Down

0 comments on commit 2b23b00

Please sign in to comment.