40 std::unique_ptr<SerialPort> port,
41 std::shared_ptr<ConnectionPool> connection_pool,
42 std::unique_ptr<Connection> connection)
43 : port_(
std::move(port)),
44 connection_pool_(
std::move(connection_pool)),
45 connection_(
std::move(connection))
49 throw std::invalid_argument(
"Given serial port pointer is null.");
52 if (connection_pool_ ==
nullptr)
54 throw std::invalid_argument(
"Given connection pool pointer is null.");
57 if (connection_ ==
nullptr)
59 throw std::invalid_argument(
"Given connection pointer is null.");
62 connection_pool_->add(connection_);
72 auto packet = connection_->next_packet(timeout);
74 if (packet !=
nullptr)
76 port_->write(packet->data());
88 auto buffer = port_->read(timeout);
93 for (
auto byte : buffer)
97 if (packet !=
nullptr)
99 packet->connection(connection_);
100 connection_->add_address(packet->source());
101 connection_pool_->send(std::move(packet));
void receive_packet(const std::chrono::nanoseconds &timeout) final
void send_packet(const std::chrono::nanoseconds &timeout) final
std::ostream & print_(std::ostream &os) const final
SerialInterface(std::unique_ptr< SerialPort > port, std::shared_ptr< ConnectionPool > connection_pool, std::unique_ptr< Connection > connection)
std::unique_ptr< Packet > parse_byte(uint8_t byte)