BCNP 3.2.1
Batched Command Network Protocol
Loading...
Searching...
No Matches
spi_adapter.cpp
Go to the documentation of this file.
1
6#include "bcnp/spi_adapter.h"
7
8namespace bcnp {
9
11 : m_receive(std::move(receive)), m_send(std::move(send)), m_parser(parser) {
12}
13
15 if (!m_receive) {
16 return;
17 }
18
19 // Read chunks until no more data available
20 uint8_t buffer[256];
21 std::size_t received = m_receive(buffer, sizeof(buffer));
22 while (received > 0) {
23 PushChunk(buffer, received);
24 received = m_receive(buffer, sizeof(buffer));
25 }
26}
27
28void SpiStreamAdapter::PushChunk(const uint8_t* data, std::size_t length) {
29 m_parser.Push(data, length);
30}
31
32// SendPacket<T> is implemented as a template in the header
33
34} // namespace bcnp
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
SpiStreamAdapter(ReceiveChunkFn receive, SendBytesFn send, StreamParser &parser)
Construct an SPI adapter with receive/send callbacks.
void Poll()
Poll for incoming SPI data.
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
void PushChunk(const uint8_t *data, std::size_t length)
Push a data chunk directly to the parser.
Parses a byte stream into BCNP packets.
void Push(const uint8_t *data, std::size_t length)
Push raw bytes into the parser for processing.
SPI transport adapter for BCNP (deprecated).