Compare commits
2 Commits
b4949a6f07
...
d945e7a799
| Author | SHA1 | Date | |
|---|---|---|---|
| d945e7a799 | |||
| 3af6a8d42a |
@ -1,7 +1,7 @@
|
|||||||
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||||
|
|
||||||
add_library(utility STATIC
|
add_library(utility STATIC
|
||||||
Src/utility_logger.cpp
|
Src/utility_itmlogger.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(skullc::utility ALIAS utility)
|
add_library(skullc::utility ALIAS utility)
|
||||||
|
|||||||
49
Utility/Inc/utility_ilogger.hpp
Normal file
49
Utility/Inc/utility_ilogger.hpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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_
|
||||||
30
Utility/Inc/utility_itmlogger.hpp
Normal file
30
Utility/Inc/utility_itmlogger.hpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// 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_
|
||||||
28
Utility/Inc/utility_logging.hpp
Normal file
28
Utility/Inc/utility_logging.hpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// 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;
|
return;
|
||||||
|
|
||||||
new (&*_tail)T(std::forward<Args>(args)...);
|
new (&*_tail)T(std::forward<Args>(args)...);
|
||||||
return *(_tail++);
|
++_tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pop_front()
|
void pop_front()
|
||||||
|
|||||||
39
Utility/Inc/utility_uartlogger.hpp
Normal file
39
Utility/Inc/utility_uartlogger.hpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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_ */
|
||||||
33
Utility/Src/utility_itmlogger.cpp
Normal file
33
Utility/Src/utility_itmlogger.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,10 +0,0 @@
|
|||||||
/*
|
|
||||||
* utility_logger.cpp
|
|
||||||
*
|
|
||||||
* Created on: Mar 13, 2021
|
|
||||||
* Author: erki
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
25
Utility/Src/utility_logging.cpp
Normal file
25
Utility/Src/utility_logging.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
32
Utility/Src/utility_uartlogger.cpp
Normal file
32
Utility/Src/utility_uartlogger.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* 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