BCNP 3.2.1
Batched Command Network Protocol
Loading...
Searching...
No Matches
bcnp::SpiStreamAdapter Class Reference

SPI transport adapter for legacy SPI-based communication. More...

#include <spi_adapter.h>

Public Types

using ReceiveChunkFn = std::function<std::size_t(uint8_t* dst, std::size_t maxLen)>
 Callback type for receiving SPI data chunks.
 
using SendBytesFn = std::function<bool(const uint8_t* data, std::size_t length)>
 Callback type for sending raw bytes over SPI.
 

Public Member Functions

 SpiStreamAdapter (ReceiveChunkFn receive, SendBytesFn send, StreamParser &parser)
 Construct an SPI adapter with receive/send callbacks.
 
void Poll ()
 Poll for incoming SPI data.
 
void PushChunk (const uint8_t *data, std::size_t length)
 Push a data chunk directly to the parser.
 
template<typename MsgType >
bool SendPacket (const TypedPacket< MsgType > &packet)
 Send a typed packet over SPI.
 

Detailed Description

SPI transport adapter for legacy SPI-based communication.

Deprecated
Use TcpPosixAdapter or UdpPosixAdapter instead. This class will be removed in a future version.

Provides a polling-based interface for SPI communication with the BCNP stream parser. Handles both receiving data chunks and sending typed packets over an SPI bus.

Note
This adapter does not manage SPI hardware directly; it requires user-provided receive and send function callbacks.

Definition at line 34 of file spi_adapter.h.

Member Typedef Documentation

◆ ReceiveChunkFn

using bcnp::SpiStreamAdapter::ReceiveChunkFn = std::function<std::size_t(uint8_t* dst, std::size_t maxLen)>

Callback type for receiving SPI data chunks.

Parameters
dstDestination buffer to fill
maxLenMaximum bytes to read
Returns
Number of bytes actually read (0 if none available)

Definition at line 42 of file spi_adapter.h.

◆ SendBytesFn

using bcnp::SpiStreamAdapter::SendBytesFn = std::function<bool(const uint8_t* data, std::size_t length)>

Callback type for sending raw bytes over SPI.

Parameters
dataData to transmit
lengthNumber of bytes to send
Returns
true if send succeeded, false on error

Definition at line 50 of file spi_adapter.h.

Constructor & Destructor Documentation

◆ SpiStreamAdapter()

bcnp::SpiStreamAdapter::SpiStreamAdapter ( ReceiveChunkFn receive,
SendBytesFn send,
StreamParser & parser )

Construct an SPI adapter with receive/send callbacks.

Parameters
receiveFunction to call to receive data chunks
sendFunction to call to transmit data
parserReference to StreamParser for received data

Definition at line 10 of file spi_adapter.cpp.

Member Function Documentation

◆ Poll()

void bcnp::SpiStreamAdapter::Poll ( )

Poll for incoming SPI data.

Calls the receive callback repeatedly until no more data is available, feeding each chunk to the parser. Call this periodically in your main loop.

Definition at line 14 of file spi_adapter.cpp.

Here is the call graph for this function:

◆ PushChunk()

void bcnp::SpiStreamAdapter::PushChunk ( const uint8_t * data,
std::size_t length )

Push a data chunk directly to the parser.

Bypasses the receive callback for manual data injection.

Parameters
dataPointer to received data
lengthNumber of bytes received

Definition at line 28 of file spi_adapter.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SendPacket()

template<typename MsgType >
bool bcnp::SpiStreamAdapter::SendPacket ( const TypedPacket< MsgType > & packet)
inline

Send a typed packet over SPI.

Encodes the packet to wire format and transmits using the send callback.

Template Parameters
MsgTypeMessage type in the packet
Parameters
packetThe packet to send
Returns
true if send succeeded, false on encoding or transmission error

Definition at line 89 of file spi_adapter.h.

Here is the call graph for this function:

The documentation for this class was generated from the following files: