Commit c56e2c7e authored by Pierre NARVOR's avatar Pierre NARVOR
Browse files

[tests] Added serial dump test with boost

parent 3ca8f36f
list(APPEND test_names
hello_test.cpp
dump_test.cpp
)
list(APPEND test_deps
......
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
#define BOOST_BIND_GLOBAL_PLACEHOLDERS
#include <boost/asio.hpp>
#include <boost/bind.hpp>
using IoService = boost::asio::io_service;
using SerialPort = boost::asio::serial_port;
void read_callback(SerialPort* serial,
boost::asio::streambuf* buffer,
const boost::system::error_code& err, size_t byteCount)
{
std::istream is(buffer);
std::ostringstream oss;
for(int i = 0; i < byteCount; i++) {
oss << (char)is.get();
}
cout << oss.str();
buffer->consume(byteCount);
boost::asio::async_read_until(*serial, *buffer, "\r\n",
boost::bind(read_callback, serial, buffer, _1, _2));
}
int main()
{
SerialPort::baud_rate baudRate(115200);
SerialPort::character_size cSize(8);
SerialPort::parity parity(SerialPort::parity::none);
SerialPort::flow_control flowControl(SerialPort::flow_control::none);
SerialPort::stop_bits stopBits(SerialPort::stop_bits::two);
IoService service;
SerialPort serial(service, "/dev/narval_usbl");
serial.set_option(baudRate);
serial.set_option(cSize);
serial.set_option(parity);
serial.set_option(flowControl);
serial.set_option(stopBits);
boost::asio::streambuf buffer;
boost::asio::async_read_until(serial, buffer, "\r\n",
boost::bind(read_callback, &serial, &buffer, _1, _2));
service.run();
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment