BCNP 3.2.1
Batched Command Network Protocol
Loading...
Searching...
No Matches
controller_driver.h
Go to the documentation of this file.
1#pragma once
2
3#include "bcnp/dispatcher.h"
5
6#include <vector>
7
8namespace bcnp {
9
26public:
27 DispatcherDriver(PacketDispatcher& dispatcher, DuplexAdapter& adapter);
28
30 void PollOnce();
31
33 bool SendBytes(const uint8_t* data, std::size_t length);
34
36 template<typename MsgType>
37 bool SendPacket(const TypedPacket<MsgType>& packet) {
38 std::vector<uint8_t> buffer;
39 if (!EncodeTypedPacket(packet, buffer)) {
40 return false;
41 }
42 return m_adapter.SendBytes(buffer.data(), buffer.size());
43 }
44
45private:
46 PacketDispatcher& m_dispatcher;
47 DuplexAdapter& m_adapter;
48 std::vector<uint8_t> m_rxScratch;
49};
50
53
54} // namespace bcnp
virtual bool SendBytes(const uint8_t *data, std::size_t length)=0
Send bytes over the transport.
Drives a PacketDispatcher from a transport adapter.
DispatcherDriver(PacketDispatcher &dispatcher, DuplexAdapter &adapter)
bool SendBytes(const uint8_t *data, std::size_t length)
Send raw bytes through the adapter.
void PollOnce()
Poll transport and feed data to dispatcher.
bool SendPacket(const TypedPacket< MsgType > &packet)
Send a typed packet.
Combined send/receive interface for bidirectional transports.
Definition adapter.h:43
Parses BCNP stream and dispatches packets to registered handlers.
Definition dispatcher.h:49
bool EncodeTypedPacket(const TypedPacket< MsgType, Storage > &packet, uint8_t *output, std::size_t capacity, std::size_t &bytesWritten)
Encode a typed packet to a pre-allocated buffer.
Definition packet.h:322
Generic packet containing messages of a specific type.
Definition packet.h:242