Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
221 changes: 221 additions & 0 deletions include/amis_debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
#pragma once

#include "proj.h"

#include <stdarg.h>
#include <stdio.h>

#ifndef DEBUG_ENABLE
#define DEBUG_ENABLE 0
#endif
#ifndef DEBUG_ENABLE_SERIAL
#define DEBUG_ENABLE_SERIAL 0
#endif
#ifndef DEBUG_ENABLE_SERIAL1
#define DEBUG_ENABLE_SERIAL1 0
#endif
#ifndef DEBUG_ENABLE_REMOTEDEBUG
#define DEBUG_ENABLE_REMOTEDEBUG 1 //RemoteDebug is enabled by default (if DEBUG_ENABLE is enabled)
#endif
#ifndef DEBUG_ENABLE_WITH_CONTEXT
#define DEBUG_ENABLE_WITH_CONTEXT 0
#endif
#ifndef DEBUG_FLUSH_ALWAYS
#define DEBUG_FLUSH_ALWAYS 0
#endif
#ifndef DEBUG_BUFFER_SIZE
#define DEBUG_BUFFER_SIZE 256
#endif
#ifndef DEBUG_ENABLE_SW_SERIAL
// Set to a GPIO number to enable SoftwareSerial debug TX on that pin.
// Default: GPIO4 (ESP-12F D2), avoids UART0/UART1 pins.
#define DEBUG_ENABLE_SW_SERIAL 0
#endif
#ifndef DEBUG_SW_SERIAL_TX_PIN
#define DEBUG_SW_SERIAL_TX_PIN 4
#endif
#ifndef DEBUG_UART0_TX_PIN
#if defined(ARDUINO_ARCH_ESP8266)
#define DEBUG_UART0_TX_PIN 1
#define DEBUG_UART0_RX_PIN 3
#define DEBUG_UART0_TX_PIN_SWAP 15
#define DEBUG_UART0_RX_PIN_SWAP 13
#define DEBUG_UART1_TX_PIN 2
#else
// Unknown MCU: set to -1 to disable pin conflict checks by default.
#define DEBUG_UART0_TX_PIN -1
#define DEBUG_UART0_RX_PIN -1
#define DEBUG_UART0_TX_PIN_SWAP -1
#define DEBUG_UART0_RX_PIN_SWAP -1
#define DEBUG_UART1_TX_PIN -1
#endif
#endif

#if DEBUG_ENABLE
#if DEBUG_ENABLE_REMOTEDEBUG
#include <RemoteDebug.h>
#endif
#endif

class DebugNoOp {
public:
static void Init() {}
static void Handle() {}
static bool ShouldFlush(bool force_flush) {
(void)force_flush;
return false;
}
static void Flush(bool force_flush) {
(void)force_flush;
}
static void WriteRaw(const char *msg, bool force_flush) {
(void)msg;
(void)force_flush;
}
static void WriteRaw(const String &msg, bool force_flush) {
(void)msg;
(void)force_flush;
}
static void WriteRaw(const __FlashStringHelper *msg, bool force_flush) {
(void)msg;
(void)force_flush;
}
static void VPrintf(bool force_flush, const char *fmt, va_list args) {
(void)force_flush;
(void)fmt;
(void)args;
}
static void Printf(bool force_flush, const char *fmt, ...) __attribute__((format(printf, 2, 3))) {
(void)force_flush;
(void)fmt;
}
static void WritePrefix(bool force_flush, const char *file, int line, const char *func) {
(void)force_flush;
(void)file;
(void)line;
(void)func;
}
static void Out(const char *msg) {
(void)msg;
}
static void Out(const String &msg) {
(void)msg;
}
static void Out(const __FlashStringHelper *msg) {
(void)msg;
}

template <typename... Args>
static void Out(const char *fmt, Args... args) {
(void)fmt;
(void)sizeof...(args);
}

template <typename... Args>
static void OutSource(const char *file, int line, const char *func, Args... args) {
(void)file;
(void)line;
(void)func;
(void)sizeof...(args);
}

static void OutFlush(const char *msg) {
(void)msg;
}
static void OutFlush(const String &msg) {
(void)msg;
}
static void OutFlush(const __FlashStringHelper *msg) {
(void)msg;
}

template <typename... Args>
static void OutFlush(const char *fmt, Args... args) {
(void)fmt;
(void)sizeof...(args);
}

template <typename... Args>
static void OutSourceFlush(const char *file, int line, const char *func, Args... args) {
(void)file;
(void)line;
(void)func;
(void)sizeof...(args);
}
};

#if DEBUG_ENABLE
class Debug : public DebugNoOp {
public:
static void Init();
static void Handle();
static bool ShouldFlush(bool force_flush);
static void Flush(bool force_flush);
static void WriteRaw(const char *msg, bool force_flush);
static void WriteRaw(const String &msg, bool force_flush);
static void WriteRaw(const __FlashStringHelper *msg, bool force_flush);
static void VPrintf(bool force_flush, const char *fmt, va_list args);
static void Printf(bool force_flush, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
static void WritePrefix(bool force_flush, const char *file, int line, const char *func);
static void Out(const char *msg);
static void Out(const String &msg);
static void Out(const __FlashStringHelper *msg);

template <typename... Args>
static void Out(const char *fmt, Args... args) {
Printf(false, fmt, args...);
}

template <typename... Args>
static void OutSource(const char *file, int line, const char *func, Args... args) {
WritePrefix(false, file, line, func);
Out(args...);
}

static void OutFlush(const char *msg);
static void OutFlush(const String &msg);
static void OutFlush(const __FlashStringHelper *msg);

template <typename... Args>
static void OutFlush(const char *fmt, Args... args) {
Printf(true, fmt, args...);
}

template <typename... Args>
static void OutSourceFlush(const char *file, int line, const char *func, Args... args) {
WritePrefix(true, file, line, func);
OutFlush(args...);
}

private:
#if DEBUG_ENABLE_REMOTEDEBUG
static void RemoteDebugBegin();
static void RemoteDebugEnd();
static RemoteDebug _remote_debug;
static bool _remote_debug_started;
#endif
};
#else
class Debug : public DebugNoOp {};
#endif

#if DEBUG_ENABLE
#if DEBUG_ENABLE_WITH_CONTEXT
#define DBG(...) Debug::OutSource(__FILE__, __LINE__, __func__, __VA_ARGS__)
#define DBG_FLUSH(...) Debug::OutSourceFlush(__FILE__, __LINE__, __func__, __VA_ARGS__)
#define DBG_NOCTX(...) Debug::Out(__VA_ARGS__)
#define DBG_FLUSH_NOCTX(...) Debug::OutFlush(__VA_ARGS__)
#else
#define DBG(...) Debug::Out(__VA_ARGS__)
#define DBG_FLUSH(...) Debug::OutFlush(__VA_ARGS__)
#define DBG_NOCTX(...) Debug::Out(__VA_ARGS__)
#define DBG_FLUSH_NOCTX(...) Debug::OutFlush(__VA_ARGS__)
#endif
#else
#define DBG(...) do { } while (0)
#define DBG_FLUSH(...) do { } while (0)
#define DBG_NOCTX(...) do { } while (0)
#define DBG_FLUSH_NOCTX(...) do { } while (0)
#endif

/* vim:set ts=4 et: */
23 changes: 0 additions & 23 deletions include/debug.h

This file was deleted.

21 changes: 3 additions & 18 deletions include/proj.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,12 @@
#include <ESP8266mDNS.h>
#include <EEPROM.h>
#include <ESP8266HTTPClient.h>

#include "amis_debug.h"
#include "config.h"

/// Debug Einstellungen:
/// DEBUGHW 0 keine Ausgaben
/// DEBUGHW 1 TCP Port 10000
/// DEBUGHW 2 DEBUG_OUTPUT 0 | 1 : Serial(Pin Txd) | Serial1(Pin GPIO2)
/// DEBUGHW 3 Websock
#define DEBUGHW 0
#define DEBUG_OUTPUT 0
//#define STROMPREIS
extern String dbg_string;
extern char dbg[128];
#if DEBUG_OUTPUT==0
#define S Serial
#else
#define S Serial1
#endif
#define VERSION "1.5.4"
#define APP_NAME "Amis"
struct kwhstruct {
unsigned kwh_in;
unsigned kwh_out;
Expand All @@ -38,9 +26,6 @@ extern int logPage;
//extern AsyncWebServer server;
//extern AsyncWebSocket ws;
extern AsyncWebSocket *ws;
extern WiFiClient dbg_client;
extern WiFiServer dbg_server;

extern unsigned first_frame;
extern uint8_t dow;
extern uint8_t mon,myyear;
Expand Down
34 changes: 34 additions & 0 deletions patches/esp12e/RemoteDebug.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--- a/.pio/libdeps/$$$env$$$/RemoteDebug/src/RemoteDebugCfg.h
+++ b/.pio/libdeps/$$$env$$$/RemoteDebug/src/RemoteDebugCfg.h
@@ -42,7 +42,7 @@
///// Debug disable for compile to production/release
///// as nothing of RemotedDebug is compiled, zero overhead :-)
// #define DEBUG_DISABLED true
-#define VERSION "4.0.0"
+#define REMOTEDEBUG_VERSION "4.0.0"

// Debug enabled ?
#ifndef DEBUG_DISABLED

--- a/.pio/libdeps/$$$env$$$/RemoteDebug/src/RemoteDebug.cpp
+++ b/.pio/libdeps/$$$env$$$/RemoteDebug/src/RemoteDebug.cpp
@@ -952,9 +952,9 @@ void RemoteDebug::showHelp() {
#if defined(ESP8266)
help.concat("*** Remote debug - over telnet - for ESP8266 (NodeMCU) - version ");
#elif defined(ESP32)
help.concat("*** Remote debug - over telnet - for ESP32 - version ");
#endif
- help.concat(VERSION);
+ help.concat(REMOTEDEBUG_VERSION);
help.concat("\r\n");
help.concat("* Host name: ");
help.concat(_hostName);
@@ -1508,7 +1508,7 @@ void RemoteDebug::wsSendInfo() {
#endif

// Send info
- String version = String(VERSION);
+ String version = String(REMOTEDEBUG_VERSION);
String board;

#ifdef ESP32
28 changes: 24 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
; eeprom @0x405FB000 (4KB) */
; rfcal @0x405FC000 (4KB) */
; wifi @0x405FD000 (12KB) */
; das esptool addressiert den Sketch mit 0, das spiffs mit 0x200000 etc.
; esptool addresses the sketch at 0, SPIFFS at 0x200000, etc.

; Infos ESP12E: https://docs.platformio.org/en/latest/boards/espressif8266/esp12e.html
; ESP12E info: https://docs.platformio.org/en/latest/boards/espressif8266/esp12e.html

[platformio]
default_envs = esp12e
Expand All @@ -37,6 +37,7 @@ lib_deps =
ESP32Async/ESPAsyncTCP@2.0.0
ESP32Async/ESPAsyncWebServer@3.6.0
bblanchon/ArduinoJson@5.13.4
karol-brejna-i/RemoteDebug@4.0.1
marvinroger/AsyncMqttClient@0.9.0
https://github.com/akajes/AsyncPing#95ac7e4ce1d4b41087acc0f7d8109cfd1f553881

Expand Down Expand Up @@ -89,14 +90,33 @@ build_flags =
${env.build_flags}
-DAMIS_DEVELOPER_MODE=0


[env:esp12e_debug]
board = esp12e
build_type = debug
build_flags =
${env.build_flags}
-DAMIS_DEVELOPER_MODE=0

-DDEBUG_ENABLE=1
-DDEBUG_ENABLE_REMOTEDEBUG=1
-DDEBUG_ENABLE_WITH_CONTEXT=1
monitor_speed = 115200

; SWSerial needs a lot of IRAM so the sketch fits into flash.
; Only release build_type may be possible, because debug build_types can be too large.
[env:esp12e_debug_sw_serial]
board = esp12e
build_type = release
build_flags =
${env.build_flags}
-DAMIS_DEVELOPER_MODE=0
-DDEBUG_ENABLE=1
-DDEBUG_ENABLE_REMOTEDEBUG=1
-DDEBUG_ENABLE_WITH_CONTEXT=1
-DDEBUG_ENABLE_SERIAL=0 ; Serial|Serial1 cannot be used easily on hardware V1/V2 because the pins are assigned to the IR LEDs.
-DDEBUG_ENABLE_SERIAL1=0 ; see previous line
-DDEBUG_ENABLE_SW_SERIAL=1 ; WARNING: very large overhead and IRAM memory usage (possibly only feasible with release build_type)
-DDEBUG_SW_SERIAL_TX_PIN=14
monitor_speed = 9600 ; for SWSerial, baud rate is set to 9600 (for stability)

[env:esp12e_developer_mode]
board = esp12e
Expand Down
6 changes: 5 additions & 1 deletion src/Logfile.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Log.h"
#include "amis_debug.h"
#include "unused.h"
#include "Utils.h"

Expand Down Expand Up @@ -304,10 +305,13 @@ void LogfileClass::log(uint32_t type, uint32_t module, bool use_progmem, const c
}
va_end(args);
}

DBG_NOCTX("[LOG][%s][%s] %s", t, modulName, buffer);

// R"({"type":"%s","src":"%s","time":"","desc":"%s","data":""})"
_size += f.printf(R"({"ms":%u,"type":"%s","src":"%s","time":"%s","data":"","desc":"%s"})",
(unsigned int) millis(), t, modulName, timecode, buffer);
va_end(args);

_size += f.write('\n');

if (buffer != temp) {
Expand Down
Loading