Skip to content

Commit

Permalink
wip of a new logging approach in the knx stack
Browse files Browse the repository at this point in the history
  • Loading branch information
Ing-Dom committed Dec 28, 2023
1 parent 7215f47 commit 485d973
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
69 changes: 69 additions & 0 deletions src/knx/logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* this is just a draft for the logging API, it is not complete and mssing all the backend
ToDo:
- define all areas
- complete the logging functions for all levels
- define the backend logging class that can be inherited and overriden
- define an interface to redirect the logging stream
Usage:
- define KNX_LOG_LVL and KNX_LOG_AREAS globally to your desired value
- KNX_LOG_TRACE<KNX_LOG_LL | KNX_LOG_IP>("Unhandled service identifier: %02x", code);
*/


constexpr auto KNX_LOG_LVL_ERROR = 1;
constexpr auto KNX_LOG_LVL_INFO = 2;
constexpr auto KNX_LOG_LVL_DEBUG = 3;
constexpr auto KNX_LOG_LVL_TRACE = 4;


constexpr auto KNX_LOG_LL = 0x0001;
constexpr auto KNX_LOG_NL = 0x0002;
constexpr auto KNX_LOG_TL = 0x0004;
constexpr auto KNX_LOG_AL = 0x0008;
constexpr auto KNX_LOG_TPUART = 0x0010;
constexpr auto KNX_LOG_IP = 0x0011;
constexpr auto KNX_LOG_MEM = 0x0012;


#ifndef KNX_LOG_AREAS
#define KNX_LOG_AREAS 0
#endif

#ifndef KNX_LOG_LVL
#define KNX_LOG_LVL 0
#endif

constexpr auto LOGLEVEL = KNX_LOG_LVL;
constexpr auto LOGAREAS = KNX_LOG_AREAS;

template<auto x, typename... Args>
__attribute__((always_inline)) constexpr void KNX_LOG_TRACE(Args&&... args)
{
if constexpr((LOGLEVEL >= KNX_LOG_LVL_TRACE) && (x & LOGAREAS))
Serial.printf(std::forward<Args>(args)...);
}

template<auto x, typename... Args>
__attribute__((always_inline)) constexpr void KNX_LOG_DEBUG(Args&&... args)
{
if constexpr((LOGLEVEL >= KNX_LOG_LVL_DEBUG) && (x & LOGAREAS))
Serial.printf(std::forward<Args>(args)...);
}

template<auto x, typename... Args>
__attribute__((always_inline)) constexpr void KNX_LOG_INFO(Args&&... args)
{
if constexpr((LOGLEVEL >= KNX_LOG_LVL_INFO) && (x & LOGAREAS))
Serial.printf(std::forward<Args>(args)...);
}

template<auto x, typename... Args>
__attribute__((always_inline)) constexpr void KNX_LOG_ERROR(Args&&... args)
{
if constexpr((LOGLEVEL >= KNX_LOG_LVL_ERROR) && (x & LOGAREAS))
Serial.printf(std::forward<Args>(args)...);
}
5 changes: 3 additions & 2 deletions src/knx/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string.h>

#include "bits.h"
#include "logger.h"

Memory::Memory(Platform& platform, DeviceObject& deviceObject)
: _platform(platform), _deviceObject(deviceObject)
Expand All @@ -13,13 +14,13 @@ Memory::~Memory()

void Memory::readMemory()
{
println("readMemory");
KNX_LOG_INFO<KNX_LOG_MEM>("readMemory");

uint8_t* flashStart = _platform.getNonVolatileMemoryStart();
size_t flashSize = _platform.getNonVolatileMemorySize();
if (flashStart == nullptr)
{
println("no user flash available;");
KNX_LOG_ERROR<KNX_LOG_MEM>("no user flash available;");
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/rp2040_arduino_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ For usage of KNX-IP you have to define either

#ifdef ARDUINO_ARCH_RP2040
#include "knx/bits.h"
#include "knx/logger.h"

#include <Arduino.h>

Expand Down

0 comments on commit 485d973

Please sign in to comment.