diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-19 21:39:28 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-19 21:49:03 +0200 |
commit | ae2d05eee4ffcec4c0611d907779ce8ef61d3a6e (patch) | |
tree | 6b86d64d03dfda4efc4a41e5814a229507289cb9 /apps/sm-serial-read.h | |
parent | 0374af511d7efdb856af372f126e66e5a78841d7 (diff) | |
download | ble-toys-ae2d05eee4ffcec4c0611d907779ce8ef61d3a6e.tar.gz ble-toys-ae2d05eee4ffcec4c0611d907779ce8ef61d3a6e.tar.bz2 ble-toys-ae2d05eee4ffcec4c0611d907779ce8ef61d3a6e.tar.xz ble-toys-ae2d05eee4ffcec4c0611d907779ce8ef61d3a6e.zip |
o Going back to a bunch of cpp files instead of launcher+bunch of header files. This ends up with an easier build file and faster builds with CMake's "OBJECT" library type.
Diffstat (limited to 'apps/sm-serial-read.h')
-rw-r--r-- | apps/sm-serial-read.h | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/apps/sm-serial-read.h b/apps/sm-serial-read.h deleted file mode 100644 index dcfcc73..0000000 --- a/apps/sm-serial-read.h +++ /dev/null @@ -1,107 +0,0 @@ -#include "trygvis/sensor.h" -#include "trygvis/sensor/io.h" -#include "json.hpp" -#include "apps.h" -#include <chrono> -#include <thread> -#include <boost/asio/serial_port.hpp> - -namespace trygvis { -namespace apps { - -using namespace boost::asio; -using namespace std; -using namespace std::chrono; -using namespace trygvis::apps; -using namespace trygvis::sensor; -using namespace trygvis::sensor::io; -namespace po = boost::program_options; -using json = nlohmann::json; - -namespace sm_serial_read_utils { - -class port_handler { -public: - port_handler(string port_name, serial_port &serial_port, shared_ptr<KeyValueSampleStreamParser> input) - : port_name(port_name), port(serial_port), input(input) { - } - - void run() { - auto packet = make_shared<vector<uint8_t>>(1024); - - while (port.is_open()) { - std::size_t some = port.read_some(buffer); - - mutable_buffers_1 chunk = boost::asio::buffer(data, some); - input->process(chunk); - } - - cerr << "port closed" << endl; - } - - -private: - static const size_t size = 1024; - string port_name; - serial_port &port; - uint8_t data[size]; - mutable_buffers_1 buffer = boost::asio::buffer(data, size); - - shared_ptr<KeyValueSampleStreamParser> input; -}; -} - -class sm_serial_read : public app { - typedef trygvis::apps::sm_serial_read_utils::port_handler port_handler; - -public: - sm_serial_read() : app("sm-serial-read") { - } - - ~sm_serial_read() = default; - - sample_format_type format; - - void add_options(po::options_description_easy_init &options) override { - options("port", po::value<string>()->required(), "The serial port to read"); - options("format", po::value<sample_format_type>(&format)->default_value(sample_format_type::KEY_VALUE), - "Output format"); - } - - int main(app_execution &execution) override { - auto desc = execution.desc; - auto vm = execution.vm; - - KeyDictionary dict; - - uint32_t baud_rate = 115200; - auto port_name = vm["port"].as<string>(); - - io_service io_service; - - serial_port port(io_service); - port.open(port_name); - port.set_option(serial_port_base::baud_rate(baud_rate)); - port.set_option(serial_port_base::character_size(8)); - port.set_option(serial_port_base::parity(serial_port_base::parity::none)); - port.set_option(serial_port_base::stop_bits(serial_port_base::stop_bits::one)); - port.set_option(serial_port_base::flow_control(serial_port_base::flow_control::none)); - - if (port.is_open()) { - cerr << "port is open" << endl; - } else { - cerr << "port is not open" << endl; - } - - shared_ptr<ostream> outputStream = shared_ptr<ostream>(&cout, noop_deleter); - shared_ptr<SampleOutputStream> output = open_sample_output_stream(outputStream, dict, format); - - shared_ptr<KeyValueSampleStreamParser> input = make_shared<KeyValueSampleStreamParser>(output, dict); - - port_handler(port_name, port, input).run(); - - return EXIT_SUCCESS; - } -}; -} -} |