Compare commits
No commits in common. "d945e7a79992bf0734907917c965cea5a27df63e" and "b4949a6f0789f02184c851ddf10b25c7f9c8fb43" have entirely different histories.
d945e7a799
...
b4949a6f07
@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||
|
||||
add_library(utility STATIC
|
||||
Src/utility_itmlogger.cpp
|
||||
Src/utility_logger.cpp
|
||||
)
|
||||
|
||||
add_library(skullc::utility ALIAS utility)
|
||||
|
||||
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* utility_ringbuffer.hpp
|
||||
*
|
||||
* Created on: Mar 12, 2021
|
||||
* Author: erki
|
||||
*/
|
||||
|
||||
#ifndef SKULLC_UTILITY_ILOGGER_HPP_
|
||||
#define SKULLC_UTILITY_ILOGGER_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace Utility
|
||||
{
|
||||
|
||||
class ILogger
|
||||
{
|
||||
public:
|
||||
enum class LogLevel : std::uint8_t
|
||||
{
|
||||
LOG_DEBUG = 0,
|
||||
LOG_INFO,
|
||||
LOG_NOTICE,
|
||||
LOG_WARNING,
|
||||
LOG_ERROR,
|
||||
LOG_FATAL
|
||||
};
|
||||
|
||||
constexpr static const char* level_strs[] = {
|
||||
"DEBUG",
|
||||
"INFO",
|
||||
"NOTICE",
|
||||
"WARNING",
|
||||
"ERROR",
|
||||
"FATAL"
|
||||
};
|
||||
|
||||
ILogger() = default;
|
||||
ILogger(const ILogger&) = delete;
|
||||
ILogger(ILogger&&) = delete;
|
||||
|
||||
virtual ~ILogger() = default;
|
||||
|
||||
virtual void log(const char* format, ...) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //SKULLC_UTILITY_ILOGGER_HPP_
|
||||
@ -1,30 +0,0 @@
|
||||
//
|
||||
// Created by erki on 14.03.21.
|
||||
//
|
||||
|
||||
#ifndef SKULLC_UTILITY_ITMLOGGER_HPP_
|
||||
#define SKULLC_UTILITY_ITMLOGGER_HPP_
|
||||
|
||||
#include "utility_logging.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace Utility
|
||||
{
|
||||
|
||||
class ITMLogger : public ILogger
|
||||
{
|
||||
public:
|
||||
ITMLogger() = default;
|
||||
ITMLogger(const ITMLogger&) = delete;
|
||||
ITMLogger(ITMLogger&&) = delete;
|
||||
|
||||
void log(const char* format, ...) override;
|
||||
|
||||
private:
|
||||
std::array<char, 255> _buffer;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //SKULLC_UTILITY_ITMLOGGER_HPP_
|
||||
@ -1,28 +0,0 @@
|
||||
//
|
||||
// Created by erki on 14.03.21.
|
||||
//
|
||||
|
||||
#ifndef UTILITY_LOGGING_HPP_
|
||||
#define UTILITY_LOGGING_HPP_
|
||||
|
||||
#include "utility_ilogger.hpp"
|
||||
|
||||
#define SKULLC_LOG(sev, msg, ...) Utility::skullc_logger->log("%s: " msg "\n\r", Utility::ILogger::level_strs[std::uint8_t(sev)], ## __VA_ARGS__)
|
||||
#define SKULLC_LOG_DEBUG(msg, ...) SKULLC_LOG(Utility::ILogger::LogLevel::LOG_DEBUG, msg, ## __VA_ARGS__)
|
||||
#define SKULLC_LOG_INFO(msg, ...) SKULLC_LOG(Utility::ILogger::LogLevel::LOG_INFO, msg, ## __VA_ARGS__)
|
||||
#define SKULLC_LOG_NOTICE(msg, ...) SKULLC_LOG(Utility::ILogger::LogLevel::LOG_NOTICE, msg, ## __VA_ARGS__)
|
||||
#define SKULLC_LOG_WARNING(msg, ...) SKULLC_LOG(Utility::ILogger::LogLevel::LOG_WARNING, msg, ## __VA_ARGS__)
|
||||
#define SKULLC_LOG_ERROR(msg, ...) SKULLC_LOG(Utility::ILogger::LogLevel::LOG_ERROR, msg, ## __VA_ARGS__)
|
||||
#define SKULLC_LOG_FATAL(msg, ...) SKULLC_LOG(Utility::ILogger::LogLevel::LOG_FATAL, msg, ## __VA_ARGS__)
|
||||
|
||||
namespace Utility
|
||||
{
|
||||
|
||||
extern ILogger* skullc_logger;
|
||||
|
||||
void setLogger(ILogger* log);
|
||||
void setLogger(ILogger& log);
|
||||
|
||||
}
|
||||
|
||||
#endif //UTILITY_LOGGING_HPP_
|
||||
@ -164,7 +164,7 @@ public:
|
||||
return;
|
||||
|
||||
new (&*_tail)T(std::forward<Args>(args)...);
|
||||
++_tail;
|
||||
return *(_tail++);
|
||||
}
|
||||
|
||||
void pop_front()
|
||||
|
||||
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* utility_uartlogger.hpp
|
||||
*
|
||||
* Created on: Mar 20, 2021
|
||||
* Author: erki
|
||||
*/
|
||||
|
||||
#ifndef SKULLC_UTILITY_UARTLOGGER_HPP_
|
||||
#define SKULLC_UTILITY_UARTLOGGER_HPP_
|
||||
|
||||
#include "utility_logging.hpp"
|
||||
|
||||
#include "usart.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace Utility
|
||||
{
|
||||
|
||||
class UARTLogger : public ILogger
|
||||
{
|
||||
public:
|
||||
explicit UARTLogger(UART_HandleTypeDef* huart);
|
||||
|
||||
UARTLogger() = delete;
|
||||
UARTLogger(const UARTLogger&) = delete;
|
||||
UARTLogger(UARTLogger&&) = delete;
|
||||
|
||||
void log(const char* format, ...) override;
|
||||
|
||||
private:
|
||||
UART_HandleTypeDef* _huart;
|
||||
std::array<char, 255> _buffer;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif /* SKULLC_UTILITY_UARTLOGGER_HPP_ */
|
||||
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* utility_logger.cpp
|
||||
*
|
||||
* Created on: Mar 13, 2021
|
||||
* Author: erki
|
||||
*/
|
||||
|
||||
#include "utility_itmlogger.hpp"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
|
||||
#include "main.h"
|
||||
|
||||
namespace Utility
|
||||
{
|
||||
|
||||
void ITMLogger::log(const char* format, ...)
|
||||
{
|
||||
std::va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
const std::int32_t len = vsnprintf(_buffer.data(), _buffer.size(), format, args);
|
||||
|
||||
for (std::int32_t i = 0; i < len; i++)
|
||||
{
|
||||
ITM_SendChar(_buffer[i]);
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
}
|
||||
10
Utility/Src/utility_logger.cpp
Normal file
10
Utility/Src/utility_logger.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
/*
|
||||
* utility_logger.cpp
|
||||
*
|
||||
* Created on: Mar 13, 2021
|
||||
* Author: erki
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
/*
|
||||
* utility_logging.cpp
|
||||
*
|
||||
* Created on: Mar 20, 2021
|
||||
* Author: erki
|
||||
*/
|
||||
|
||||
#include "utility_logging.hpp"
|
||||
|
||||
namespace Utility
|
||||
{
|
||||
|
||||
ILogger* skullc_logger = nullptr;
|
||||
|
||||
void setLogger(ILogger* log)
|
||||
{
|
||||
skullc_logger = log;
|
||||
}
|
||||
|
||||
void setLogger(ILogger& log)
|
||||
{
|
||||
skullc_logger = &log;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* utility_uartlogger.cpp
|
||||
*
|
||||
* Created on: Mar 20, 2021
|
||||
* Author: erki
|
||||
*/
|
||||
|
||||
#include "utility_uartlogger.hpp"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
|
||||
namespace Utility
|
||||
{
|
||||
|
||||
UARTLogger::UARTLogger(UART_HandleTypeDef* huart)
|
||||
: _huart(huart)
|
||||
{ }
|
||||
|
||||
void UARTLogger::log(const char* format, ...)
|
||||
{
|
||||
std::va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
const std::int32_t len = vsnprintf(_buffer.data(), _buffer.size(), format, args);
|
||||
|
||||
HAL_UART_Transmit(_huart, reinterpret_cast<std::uint8_t*>(_buffer.data()), len, 10);
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user