From c56840f03cf139d60c6d90b55cf16e70f6ae2bc2 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 21 Jun 2015 00:15:04 +0200 Subject: o Going all header file based and single-executable to launch all apps. o Ading CMake magic to generate the launcher --- apps/sm-serial-read.cpp | 114 ------------------------------------------------ 1 file changed, 114 deletions(-) delete mode 100644 apps/sm-serial-read.cpp (limited to 'apps/sm-serial-read.cpp') diff --git a/apps/sm-serial-read.cpp b/apps/sm-serial-read.cpp deleted file mode 100644 index 8c4c299..0000000 --- a/apps/sm-serial-read.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include "trygvis/sensor.h" -#include "trygvis/sensor/io.h" -#include "json.hpp" -#include "apps.h" -#include -#include -#include - -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; - -sample_format_type format; -string hostname = get_hostname(); - -class port_handler { -public: - port_handler(string port_name, serial_port &serial_port, shared_ptr input) : - port_name(port_name), port(serial_port), input(input) { - } - - void run() { - auto packet = make_shared>(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 input; -}; - -class sm_serial_read : public app { - -public: - sm_serial_read() : app("sm-serial-read") { - } - - ~sm_serial_read() = default; - - void add_options(po::options_description_easy_init &options) override { - options - ("help", "produce help message") - ("port", po::value()->required(), "The serial port to read") - ("format", po::value(&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(); - - 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 outputStream = shared_ptr(&cout, noop_deleter); - shared_ptr output = open_sample_output_stream(outputStream, dict, format); - - shared_ptr input = make_shared(output, dict); - - port_handler(port_name, port, input).run(); - - return EXIT_SUCCESS; - } - -}; - -} -} - -using namespace trygvis::apps; - -int main(int argc, char *argv[]) { - sm_serial_read app; - return launch_app(argc, argv, app); -} -- cgit v1.2.3