mirror of
https://github.com/thelsing/knx.git
synced 2025-09-05 17:50:22 +02:00
wip of a new logging approach in the knx stack
This commit is contained in:
parent
7215f470af
commit
485d973034
69
src/knx/logger.h
Normal file
69
src/knx/logger.h
Normal file
@ -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)...);
|
||||||
|
}
|
@ -3,6 +3,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
Memory::Memory(Platform& platform, DeviceObject& deviceObject)
|
Memory::Memory(Platform& platform, DeviceObject& deviceObject)
|
||||||
: _platform(platform), _deviceObject(deviceObject)
|
: _platform(platform), _deviceObject(deviceObject)
|
||||||
@ -13,13 +14,13 @@ Memory::~Memory()
|
|||||||
|
|
||||||
void Memory::readMemory()
|
void Memory::readMemory()
|
||||||
{
|
{
|
||||||
println("readMemory");
|
KNX_LOG_INFO<KNX_LOG_MEM>("readMemory");
|
||||||
|
|
||||||
uint8_t* flashStart = _platform.getNonVolatileMemoryStart();
|
uint8_t* flashStart = _platform.getNonVolatileMemoryStart();
|
||||||
size_t flashSize = _platform.getNonVolatileMemorySize();
|
size_t flashSize = _platform.getNonVolatileMemorySize();
|
||||||
if (flashStart == nullptr)
|
if (flashStart == nullptr)
|
||||||
{
|
{
|
||||||
println("no user flash available;");
|
KNX_LOG_ERROR<KNX_LOG_MEM>("no user flash available;");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ For usage of KNX-IP you have to define either
|
|||||||
|
|
||||||
#ifdef ARDUINO_ARCH_RP2040
|
#ifdef ARDUINO_ARCH_RP2040
|
||||||
#include "knx/bits.h"
|
#include "knx/bits.h"
|
||||||
|
#include "knx/logger.h"
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user