|
BCNP 3.2.1
Batched Command Network Protocol
|
Namespaces | |
| namespace | detail |
| Type traits to detect container capabilities for packet storage. | |
Classes | |
| class | ByteStream |
| Interface for receiving raw bytes from a transport. More... | |
| class | ByteWriter |
| Interface for sending raw bytes over a transport. More... | |
| class | CommandQueue |
| Legacy CommandQueue - use MessageQueue<DriveCmd> for new code. More... | |
| struct | DecodeViewResult |
| Result of decoding a packet from raw bytes. More... | |
| struct | DispatcherConfig |
| Configuration for the packet dispatcher. More... | |
| class | DispatcherDriver |
| Drives a PacketDispatcher from a transport adapter. More... | |
| class | DuplexAdapter |
| Combined send/receive interface for bidirectional transports. More... | |
| struct | HasDurationMs |
| Type trait to detect messages with a durationMs field. More... | |
| struct | IsValidPacketStorage |
| Concept-like check for valid packet storage containers. More... | |
| struct | MessageInfo |
| class | MessageIterator |
| Forward iterator for zero-copy message access from packet payload. More... | |
| class | MessageQueue |
| Generic timed message queue for any message type with durationMs field. More... | |
| struct | MessageQueueConfig |
| Configuration parameters for a message queue. More... | |
| struct | MessageQueueMetrics |
| Runtime metrics for queue diagnostics. More... | |
| class | PacketDispatcher |
| Parses BCNP stream and dispatches packets to registered handlers. More... | |
| struct | PacketHeader |
| Parsed packet header structure. More... | |
| struct | PacketView |
| Zero-copy view into a decoded packet buffer. More... | |
| class | SpiStreamAdapter |
| SPI transport adapter for legacy SPI-based communication. More... | |
| class | StaticVector |
| Fixed-capacity vector with no heap allocation. More... | |
| class | StreamParser |
| Parses a byte stream into BCNP packets. More... | |
| class | TcpPosixAdapter |
| TCP transport adapter for BCNP over POSIX sockets. More... | |
| class | TelemetryAccumulator |
| Accumulates high-frequency telemetry data and batches into packets. More... | |
| struct | TelemetryAccumulatorConfig |
| Configuration for telemetry accumulator. More... | |
| struct | TypedPacket |
| Generic packet containing messages of a specific type. More... | |
| class | UdpPosixAdapter |
| UDP transport adapter for BCNP over POSIX sockets. More... | |
Typedefs | |
| using | QueueConfig = MessageQueueConfig |
| using | QueueMetrics = MessageQueueMetrics |
| using | Command = DriveCmd |
| using | PacketHandler = std::function<void(const PacketView&)> |
| Callback for handling message packets. | |
| using | ErrorHandler = std::function<void(const StreamParser::ErrorInfo&)> |
| Error callback for parse errors. | |
| using | MessageHandler = PacketHandler |
| template<typename MsgType > | |
| using | TimedQueue = MessageQueue<MsgType> |
| Convenience alias for MessageQueue (backward compatibility). | |
| template<typename MsgType , std::size_t Capacity = 64> | |
| using | StaticTypedPacket = TypedPacket<MsgType, StaticVector<MsgType, Capacity>> |
| Convenience alias for stack-allocated real-time packets (default 64 messages) | |
| template<typename MsgType > | |
| using | DynamicTypedPacket = TypedPacket<MsgType, std::vector<MsgType>> |
| Convenience alias for heap-allocated packets (backward compatible). | |
| template<typename T > | |
| using | DynamicPacketStorage = std::vector<T> |
| Default packet storage using heap allocation. | |
| template<typename T , std::size_t Capacity = 64> | |
| using | StaticPacketStorage = StaticVector<T, Capacity> |
| Real-time packet storage using stack allocation. | |
| template<typename T > | |
| using | DefaultRealtimeStorage = StaticPacketStorage<T, 64> |
| Alias for the recommended real-time default (64 messages). | |
| template<typename MsgType > | |
| using | DynamicTelemetryAccumulator = TelemetryAccumulator<MsgType, std::vector<MsgType>> |
| Convenience alias for heap-allocated accumulator (large batches). | |
| template<typename MsgType , std::size_t Capacity = 64> | |
| using | StaticTelemetryAccumulator = TelemetryAccumulator<MsgType, StaticVector<MsgType, Capacity>> |
| Convenience alias for stack-allocated accumulator (real-time, default). | |
| using | ControllerDriver = DispatcherDriver |
| Backward-compatible alias (prefer DispatcherDriver for new code). | |
Enumerations | |
| enum class | PacketError { None , TooSmall , UnsupportedVersion , TooManyMessages , TooManyCommands = TooManyMessages , Truncated , InvalidFloat , ChecksumMismatch , UnknownMessageType , HandshakeRequired , SchemaMismatch } |
| Error codes returned by packet decoding operations. More... | |
| enum class | MessageTypeId : uint16_t { Unknown = 0 } |
Functions | |
| uint32_t | ComputeCrc32 (const uint8_t *data, std::size_t length) |
| Compute CRC32 checksum for data integrity verification. | |
| DecodeViewResult | DecodePacketViewWithSize (const uint8_t *data, std::size_t length, std::size_t wireSize) |
| Decode a packet with explicitly provided message wire size. | |
| DecodeViewResult | DecodePacketView (const uint8_t *data, std::size_t length) |
| Decode a packet using the global message type registry. | |
| template<typename MsgType , typename Storage > | |
| 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. | |
| template<typename MsgType , typename Storage > | |
| bool | EncodeTypedPacket (const TypedPacket< MsgType, Storage > &packet, std::vector< uint8_t > &output) |
| Encode a typed packet to a dynamically-sized vector. | |
| template<typename MsgType > | |
| std::optional< TypedPacket< MsgType > > | DecodeTypedPacket (const PacketView &view) |
| Decode messages from a PacketView into a typed packet. | |
| template<typename MsgType , typename Storage > | |
| std::optional< TypedPacket< MsgType, Storage > > | DecodeTypedPacketAs (const PacketView &view) |
| Decode messages from a PacketView with custom storage type. | |
| template<typename MsgType > | |
| DecodeViewResult | DecodePacketViewAs (const uint8_t *data, std::size_t length) |
| Type-safe packet view decode using compile-time message type. | |
| template<typename Container > | |
| void | ReserveIfPossible (Container &container, std::size_t capacity) |
| Helper to reserve capacity (no-op for static storage). | |
| std::optional< MessageInfo > | GetMessageInfo (MessageTypeId typeId) |
| std::optional< MessageInfo > | GetMessageInfo (uint16_t typeId) |
| bool | EncodeHandshake (uint8_t *out, std::size_t capacity) |
| Encode handshake with default schema hash. | |
| bool | EncodeHandshakeWithHash (uint8_t *out, std::size_t capacity, uint32_t schemaHash) |
| Encode handshake with custom schema hash (for testing) | |
| bool | ValidateHandshake (const uint8_t *data, std::size_t length) |
| bool | ValidateHandshakeWithHash (const uint8_t *data, std::size_t length, uint32_t expectedHash) |
| Validate handshake against custom expected hash (for testing) | |
| uint32_t | ExtractSchemaHash (const uint8_t *data, std::size_t length) |
Variables | |
| constexpr std::size_t | kChecksumSize = 4 |
| Size of CRC32 checksum in bytes. | |
| constexpr std::size_t | kMaxMessagesPerPacket = 65535 |
| Maximum number of messages allowed in a single packet. | |
| constexpr uint8_t | kFlagClearQueue = 0x01 |
| Packet flag: Clear command queue before processing this packet. | |
| constexpr uint8_t | kProtocolMajor = kProtocolMajorV3 |
| Current protocol major version. | |
| constexpr uint8_t | kProtocolMinor = kProtocolMinorV3 |
| Current protocol minor version. | |
| constexpr std::size_t | kHeaderSize = kHeaderSizeV3 |
| Size of packet header in bytes. | |
| constexpr std::size_t | kHeaderMajorIndex = 0 |
| Byte offset of major version in header. | |
| constexpr std::size_t | kHeaderMinorIndex = 1 |
| Byte offset of minor version in header. | |
| constexpr std::size_t | kHeaderFlagsIndex = 2 |
| Byte offset of flags byte in header. | |
| template<typename Container > | |
| constexpr bool | IsValidPacketStorage_v = IsValidPacketStorage<Container>::value |
| constexpr uint8_t | kProtocolMajorV3 = 3 |
| constexpr uint8_t | kProtocolMinorV3 = 2 |
| constexpr uint32_t | kSchemaHash = 0x5667F881U |
| constexpr std::size_t | kHandshakeSize = 8 |
| constexpr std::array< uint8_t, 4 > | kHandshakeMagic = {{'B', 'C', 'N', 'P'}} |
| constexpr std::size_t | kHeaderSizeV3 = 7 |
| constexpr std::size_t | kHeaderMsgTypeIndex = 3 |
| constexpr std::size_t | kHeaderMsgCountIndex = 5 |
| constexpr std::array< MessageInfo, 0 > | kMessageRegistry = {{}} |
| using bcnp::Command = DriveCmd |
Definition at line 13 of file command_queue.h.
Backward-compatible alias (prefer DispatcherDriver for new code).
Definition at line 52 of file controller_driver.h.
| using bcnp::DefaultRealtimeStorage = StaticPacketStorage<T, 64> |
Alias for the recommended real-time default (64 messages).
Definition at line 114 of file packet_storage.h.
| using bcnp::DynamicPacketStorage = std::vector<T> |
Default packet storage using heap allocation.
Use for Large batches, trajectory uploads or config dumps.
Definition at line 96 of file packet_storage.h.
| using bcnp::DynamicTelemetryAccumulator = TelemetryAccumulator<MsgType, std::vector<MsgType>> |
Convenience alias for heap-allocated accumulator (large batches).
Definition at line 276 of file telemetry_accumulator.h.
| using bcnp::DynamicTypedPacket = TypedPacket<MsgType, std::vector<MsgType>> |
| using bcnp::ErrorHandler = std::function<void(const StreamParser::ErrorInfo&)> |
Error callback for parse errors.
Definition at line 24 of file dispatcher.h.
| using bcnp::MessageHandler = PacketHandler |
Definition at line 124 of file dispatcher.h.
| using bcnp::PacketHandler = std::function<void(const PacketView&)> |
Callback for handling message packets.
Definition at line 21 of file dispatcher.h.
| using bcnp::QueueConfig = MessageQueueConfig |
Definition at line 11 of file command_queue.h.
Definition at line 12 of file command_queue.h.
| using bcnp::StaticPacketStorage = StaticVector<T, Capacity> |
Real-time packet storage using stack allocation.
Use for Control loop telemetry or command batches.
Default capacity of 64 covers most FRC use cases: 64 × 12 bytes (EncoderData) = 768 bytes (safe for stack) 64 × 32 bytes (TrajectoryPoint) = 2 KB (safe for stack)
Definition at line 108 of file packet_storage.h.
| using bcnp::StaticTelemetryAccumulator = TelemetryAccumulator<MsgType, StaticVector<MsgType, Capacity>> |
Convenience alias for stack-allocated accumulator (real-time, default).
Definition at line 282 of file telemetry_accumulator.h.
| using bcnp::StaticTypedPacket = TypedPacket<MsgType, StaticVector<MsgType, Capacity>> |
| using bcnp::TimedQueue = MessageQueue<MsgType> |
Convenience alias for MessageQueue (backward compatibility).
| MsgType | Message type with durationMs field |
Definition at line 408 of file message_queue.h.
|
strong |
| Enumerator | |
|---|---|
| Unknown | |
Definition at line 39 of file message_types.h.
|
strong |
Error codes returned by packet decoding operations.
These errors indicate various failure modes during packet parsing, from simple size issues to protocol mismatches and data corruption.
| Enumerator | |
|---|---|
| None | No error - packet decoded successfully. |
| TooSmall | Buffer too small to contain header. |
| UnsupportedVersion | Protocol version mismatch. |
| TooManyMessages | Message count exceeds kMaxMessagesPerPacket. |
| TooManyCommands |
|
| Truncated | Buffer ends before expected packet length. |
| InvalidFloat | NaN or Inf detected in float field. |
| ChecksumMismatch | CRC32 validation failed. |
| UnknownMessageType | Message type ID not in registry. |
| HandshakeRequired | Connection requires handshake first. |
| SchemaMismatch | Client/server schema hash mismatch. |
| uint32_t bcnp::ComputeCrc32 | ( | const uint8_t * | data, |
| std::size_t | length ) |
Compute CRC32 checksum for data integrity verification.
Uses the standard CRC32 polynomial (0xEDB88320) with initial value of 0xFFFFFFFF and final XOR. Compatible with common CRC32 implementations.
| data | Pointer to data buffer |
| length | Number of bytes to checksum |
Definition at line 49 of file packet.cpp.
| DecodeViewResult bcnp::DecodePacketView | ( | const uint8_t * | data, |
| std::size_t | length ) |
Decode a packet using the global message type registry.
Decode packet view using the global message type registry.
Extracts the message type ID from the header and looks up the wire size from GetMessageInfo(). Returns UnknownMessageType error if the type is not registered.
| data | Pointer to raw packet bytes |
| length | Available bytes in buffer |
Looks up the wire size from GetMessageInfo() based on the message type ID in the packet header. Use this for general-purpose packet handling.
| data | Raw packet bytes |
| length | Number of bytes available |
Definition at line 143 of file packet.cpp.
| DecodeViewResult bcnp::DecodePacketViewAs | ( | const uint8_t * | data, |
| std::size_t | length ) |
Type-safe packet view decode using compile-time message type.
Template version that uses MsgType::kWireSize directly, avoiding runtime registry lookup. Preferred when the expected type is known.
| MsgType | Expected message type with kWireSize constant |
| data | Raw packet bytes |
| length | Number of bytes available |
Definition at line 490 of file packet.h.
| DecodeViewResult bcnp::DecodePacketViewWithSize | ( | const uint8_t * | data, |
| std::size_t | length, | ||
| std::size_t | wireSize ) |
Decode a packet with explicitly provided message wire size.
Decode packet view with explicit wire size.
This is the core decoding function used by all other decode variants. Validates the header, checks CRC, and constructs a PacketView on success.
| data | Pointer to raw packet bytes |
| length | Available bytes in buffer |
| wireSize | Size of each message in bytes (from schema or lookup) |
Low-level decode function used when the message wire size is known (e.g., from a custom lookup table or test fixture).
| data | Raw packet bytes |
| length | Number of bytes available |
| wireSize | Size of each message in bytes |
Definition at line 76 of file packet.cpp.
| std::optional< TypedPacket< MsgType > > bcnp::DecodeTypedPacket | ( | const PacketView & | view | ) |
Decode messages from a PacketView into a typed packet.
Converts a validated PacketView into a TypedPacket with heap-allocated storage. Returns nullopt if the view's message type doesn't match MsgType.
| MsgType | Expected message type |
| view | Validated packet view to decode from |
| std::optional< TypedPacket< MsgType, Storage > > bcnp::DecodeTypedPacketAs | ( | const PacketView & | view | ) |
Decode messages from a PacketView with custom storage type.
Allows decoding into stack-allocated or custom storage for real-time applications. Use StaticVector<MsgType, N> for deterministic memory usage.
| MsgType | Expected message type |
| Storage | Container type (e.g., StaticVector<MsgType, 64>) |
| view | Validated packet view to decode from |
Definition at line 431 of file packet.h.
|
inline |
Encode handshake with default schema hash.
Definition at line 135 of file message_types.h.
|
inline |
Encode handshake with custom schema hash (for testing)
Definition at line 143 of file message_types.h.
| bool bcnp::EncodeTypedPacket | ( | const TypedPacket< MsgType, Storage > & | packet, |
| std::vector< uint8_t > & | output ) |
Encode a typed packet to a dynamically-sized vector.
Convenience overload that allocates the required buffer automatically. Suitable for non-real-time code paths where allocation is acceptable.
| MsgType | Message struct type with Encode() and kWireSize |
| Storage | Container type holding the messages |
| packet | The packet to encode | |
| [out] | output | Vector to receive encoded bytes (resized automatically) |
Definition at line 372 of file packet.h.
| bool bcnp::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.
Serializes the packet header and all messages to wire format, appending a CRC32 checksum. Works with any storage type (vector, StaticVector, etc.).
| MsgType | Message struct type with Encode() and kWireSize |
| Storage | Container type holding the messages |
| packet | The packet to encode | |
| output | Destination buffer (must have sufficient capacity) | |
| capacity | Size of output buffer in bytes | |
| [out] | bytesWritten | Number of bytes written on success |
Definition at line 322 of file packet.h.
|
inline |
|
inline |
|
inline |
| void bcnp::ReserveIfPossible | ( | Container & | container, |
| std::size_t | capacity ) |
Helper to reserve capacity (no-op for static storage).
This allows generic code to call reserve() without knowing storage type.
Definition at line 122 of file packet_storage.h.
|
inline |
|
inline |
Validate handshake against custom expected hash (for testing)
Definition at line 158 of file message_types.h.
|
inlineconstexpr |
Definition at line 87 of file packet_storage.h.
|
constexpr |
Definition at line 28 of file message_types.h.
|
constexpr |
Definition at line 27 of file message_types.h.
|
constexpr |
Definition at line 33 of file message_types.h.
|
constexpr |
Definition at line 32 of file message_types.h.
|
constexpr |
Definition at line 31 of file message_types.h.
|
inlineconstexpr |
Definition at line 117 of file message_types.h.
|
constexpr |
Definition at line 22 of file message_types.h.
|
constexpr |
Definition at line 23 of file message_types.h.
|
constexpr |
Definition at line 24 of file message_types.h.