diff --git a/src/iflytop/components/uart_printer/uart_printer.cpp b/src/iflytop/components/uart_printer/uart_printer.cpp new file mode 100644 index 0000000..c74ef53 --- /dev/null +++ b/src/iflytop/components/uart_printer/uart_printer.cpp @@ -0,0 +1,27 @@ +#include "uart_printer.hpp" +using namespace iflytop; +using namespace core; + +UartPrinter::UartPrinter() {} +UartPrinter::~UartPrinter() {} +void UartPrinter::initialize(string path, string rate) { + m_path = path; + m_rate = rate; + m_uart = make_shared(); + int ret = m_uart->open(path, rate); + if (ret != 0) { + logger->error("open uart {} failed", path); + m_isopen = false; + return; + } + m_isopen = true; + return; +} +void UartPrinter::print(string str) { + if (!m_isopen) { + logger->error("uart {} is not open", m_path); + return; + } + m_uart->send((char *)str.c_str(), str.size()); + return; +} \ No newline at end of file diff --git a/src/iflytop/components/uart_printer/uart_printer.hpp b/src/iflytop/components/uart_printer/uart_printer.hpp new file mode 100644 index 0000000..1520e3c --- /dev/null +++ b/src/iflytop/components/uart_printer/uart_printer.hpp @@ -0,0 +1,37 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "iflytop/core/components/uart/uart.hpp" +#include "iflytop/core/spdlogfactory/logger.hpp" +namespace iflytop { +namespace core { +using namespace std; +class UartPrinter { + ENABLE_LOGGER(UartPrinter); + + private: + shared_ptr m_uart; + + string m_path; + string m_rate; + + bool m_isopen = false; + + public: + UartPrinter(); + ~UartPrinter(); + void initialize(string path, string rate); + void print(string str); +}; +} // namespace core +} // namespace iflytop \ No newline at end of file