Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Ing-Dom committed Dec 29, 2023
1 parent 2d40692 commit e147e0e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/knx/application_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "string.h"
#include "bits.h"
#include <stdio.h>
#include "logger.h"

const SecurityControl ApplicationLayer::noSecurity {.toolAccess=false, .dataSecurity=DataSecurity::None};

Expand Down Expand Up @@ -97,8 +98,9 @@ void ApplicationLayer::dataGroupConfirm(AckType ack, HopCountType hopType, Prior
_savedAsapWriteRequest = 0;
break;
default:
print("datagroup-confirm: unhandled APDU-Type: ");
println(apdu.type());
KNX_LOG_INFO<KNX_LOG_AL>("datagroup-confirm: unhandled APDU-Type: 0x%04x", apdu.type());
//print("datagroup-confirm: unhandled APDU-Type: 0x%04x", apdu.type());
//println(apdu.type());
}
}

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

#include "logger.h"

void KnxLogger::log(const char* message, va_list& values)
{
printf(message, values);
}

KnxLogger knxLogger;
21 changes: 17 additions & 4 deletions src/knx/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,21 @@
*/
#pragma once

#include <utility>
#include <string>

#include "platform.h"


class KnxLogger
{
public:
void log(const char* message, va_list& values);
};

extern KnxLogger knxLogger;


constexpr uint64_t KNX_LOG_LVL_ERROR = 1;
Expand Down Expand Up @@ -46,26 +59,26 @@ template<uint64_t x, typename... Args>
__attribute__((always_inline)) constexpr void KNX_LOG_TRACE(Args&&... args)
{
if constexpr((LOGLEVEL >= KNX_LOG_LVL_TRACE) && (x & LOGAREAS))
printf(std::forward<Args>(args)...);
knxLogger.log(std::forward<Args>(args)...);
}

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

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

template<uint64_t x, typename... Args>
__attribute__((always_inline)) constexpr void KNX_LOG_ERROR(Args&&... args)
{
if constexpr((LOGLEVEL >= KNX_LOG_LVL_ERROR) && (x & LOGAREAS))
printf(std::forward<Args>(args)...);
knxLogger.log(std::forward<Args>(args)...);
}

0 comments on commit e147e0e

Please sign in to comment.