// // Copyright (c) 2024 Klemens Morgenstern (klemens.morgenstern@gmx.net) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_COBALT_IO_SERIAL_PORT_HPP #define BOOST_COBALT_IO_SERIAL_PORT_HPP #include #include #include #include #include #include #include #include namespace boost::cobalt::io { struct BOOST_SYMBOL_VISIBLE serial_port final : stream { BOOST_COBALT_IO_DECL system::result close(); BOOST_COBALT_IO_DECL system::result cancel(); BOOST_COBALT_IO_DECL bool is_open() const; [[nodiscard]] BOOST_COBALT_IO_DECL system::result send_break(); [[nodiscard]] BOOST_COBALT_IO_DECL system::result set_baud_rate(unsigned rate); [[nodiscard]] BOOST_COBALT_IO_DECL system::result get_baud_rate(); [[nodiscard]] BOOST_COBALT_IO_DECL system::result set_character_size(unsigned rate); [[nodiscard]] BOOST_COBALT_IO_DECL system::result get_character_size(); using flow_control = asio::serial_port_base::flow_control::type; [[nodiscard]] BOOST_COBALT_IO_DECL system::result set_flow_control(flow_control rate); [[nodiscard]] BOOST_COBALT_IO_DECL system::result get_flow_control(); using parity = asio::serial_port_base::parity::type; [[nodiscard]] BOOST_COBALT_IO_DECL system::result set_parity(parity rate); [[nodiscard]] BOOST_COBALT_IO_DECL system::result get_parity(); using native_handle_type = typename asio::basic_serial_port::native_handle_type; native_handle_type native_handle() {return serial_port_.native_handle();} BOOST_COBALT_IO_DECL serial_port(const cobalt::executor & executor = this_thread::get_executor()); BOOST_COBALT_IO_DECL serial_port(serial_port && lhs) = default; BOOST_COBALT_IO_DECL serial_port(std::string_view device, const cobalt::executor & executor = this_thread::get_executor()); BOOST_COBALT_IO_DECL serial_port(native_handle_type native_handle, const cobalt::executor & executor = this_thread::get_executor()); [[nodiscard]] BOOST_COBALT_IO_DECL system::result assign(native_handle_type native_handle); [[nodiscard]] BOOST_COBALT_IO_DECL system::result open(std::string_view device); [[nodiscard]] write_op write_some(const_buffer_sequence buffer) { return {buffer, this, initiate_write_some_}; } [[nodiscard]] read_op read_some(mutable_buffer_sequence buffer) { return {buffer, this, initiate_read_some_}; } private: BOOST_COBALT_IO_DECL static void initiate_read_some_(void *, mutable_buffer_sequence, boost::cobalt::completion_handler); BOOST_COBALT_IO_DECL static void initiate_write_some_(void *, const_buffer_sequence, boost::cobalt::completion_handler); asio::basic_serial_port serial_port_; }; } #endif //BOOST_COBALT_IO_SERIAL_PORT_HPP