skullc-peripherals/Utility/Src/utility_uartlogger.cpp
Erki d945e7a799
Some checks failed
continuous-integration/drone/push Build is failing
Add basic logging framework with a global logger
2021-03-20 23:22:17 +02:00

33 lines
544 B
C++

/*
* 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);
}
}