|
@ -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<Uart>(); |
|
|
|
|
|
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; |
|
|
|
|
|
} |