Browse Source

add uart_printer

disinfection_machine
zhaohe 2 years ago
parent
commit
f4e805b65f
  1. 27
      src/iflytop/components/uart_printer/uart_printer.cpp
  2. 37
      src/iflytop/components/uart_printer/uart_printer.hpp

27
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<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;
}

37
src/iflytop/components/uart_printer/uart_printer.hpp

@ -0,0 +1,37 @@
#pragma once
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <mutex>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#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<Uart> 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
Loading…
Cancel
Save