BCNP 3.2.1
Batched Command Network Protocol
Loading...
Searching...
No Matches
spi_adapter.h
Go to the documentation of this file.
1#pragma once
2
11#include "bcnp/packet.h"
12#include "bcnp/stream_parser.h"
13
14#include <cstddef>
15#include <cstdint>
16#include <functional>
17#include <vector>
18
19namespace bcnp {
20
34class [[deprecated("Use TcpPosixAdapter instead")]] SpiStreamAdapter {
35public:
42 using ReceiveChunkFn = std::function<std::size_t(uint8_t* dst, std::size_t maxLen)>;
43
50 using SendBytesFn = std::function<bool(const uint8_t* data, std::size_t length)>;
51
60
67 void Poll();
68
77 void PushChunk(const uint8_t* data, std::size_t length);
78
88 template<typename MsgType>
89 bool SendPacket(const TypedPacket<MsgType>& packet) {
90 std::vector<uint8_t> buffer;
91 if (!EncodeTypedPacket(packet, buffer)) {
92 return false;
93 }
94 return m_send(buffer.data(), buffer.size());
95 }
96
97private:
98 ReceiveChunkFn m_receive;
99 SendBytesFn m_send;
100 StreamParser& m_parser;
101};
102
103} // namespace bcnp
SPI transport adapter for legacy SPI-based communication.
Definition spi_adapter.h:34
std::function< std::size_t(uint8_t *dst, std::size_t maxLen)> ReceiveChunkFn
Callback type for receiving SPI data chunks.
Definition spi_adapter.h:42
bool SendPacket(const TypedPacket< MsgType > &packet)
Send a typed packet over SPI.
Definition spi_adapter.h:89
std::function< bool(const uint8_t *data, std::size_t length)> SendBytesFn
Callback type for sending raw bytes over SPI.
Definition spi_adapter.h:50
Parses a byte stream into BCNP packets.
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
BCNP packet structures, encoding, and decoding utilities.
Generic packet containing messages of a specific type.
Definition packet.h:242