BCNP 3.2.1
Batched Command Network Protocol
Loading...
Searching...
No Matches
bcnp::TelemetryAccumulator< MsgType, Storage > Class Template Reference

Accumulates high-frequency telemetry data and batches into packets. More...

#include <telemetry_accumulator.h>

Classes

struct  Metrics
 Metrics for diagnostics. More...
 

Public Types

using Clock = std::chrono::steady_clock
 

Public Member Functions

 TelemetryAccumulator (TelemetryAccumulatorConfig config={})
 
bool Record (const MsgType &msg)
 Record a telemetry reading.
 
template<typename InputIt >
void RecordBatch (InputIt first, InputIt last)
 Record multiple telemetry readings at once.
 
template<typename Adapter >
bool MaybeFlush (Adapter &adapter)
 Flush if interval has elapsed.
 
template<typename Adapter >
bool ForceFlush (Adapter &adapter)
 Force an immediate flush regardless of interval.
 
std::size_t BufferedCount () const
 Get the number of buffered messages waiting to be sent.
 
void Clear ()
 Clear all buffered messages without sending.
 
Metrics GetMetrics () const
 
void ResetMetrics ()
 
void SetConfig (const TelemetryAccumulatorConfig &config)
 Update configuration.
 

Detailed Description

template<typename MsgType, typename Storage = StaticVector<MsgType, 64>>
class bcnp::TelemetryAccumulator< MsgType, Storage >

Accumulates high-frequency telemetry data and batches into packets.

The accumulator collects sensor/state readings during the control loop and sends them as batched BCNP packets at a configurable rate. This avoids the overhead of a send() syscall per reading.

Template Parameters
MsgTypeThe message struct type (e.g., DrivetrainState, EncoderData)
StorageContainer type (default: StaticVector<MsgType, 64>)

Usage (robot side):

// In TeleopPeriodic (50Hz):
drivetrainTelem.Record(DrivetrainState{
.vxActual = drivetrain.GetVelocity(),
.omegaActual = drivetrain.GetAngularVelocity(),
.leftPos = drivetrain.GetLeftEncoder(),
.rightPos = drivetrain.GetRightEncoder(),
.timestampMs = static_cast<uint32_t>(Timer::GetFPGATimestamp() * 1000)
});
// At end of Periodic:
drivetrainTelem.MaybeFlush(tcpAdapter); // Sends every N ticks
Accumulates high-frequency telemetry data and batches into packets.
bool Record(const MsgType &msg)
Record a telemetry reading.
bool MaybeFlush(Adapter &adapter)
Flush if interval has elapsed.

Definition at line 55 of file telemetry_accumulator.h.

Member Typedef Documentation

◆ Clock

template<typename MsgType , typename Storage = StaticVector<MsgType, 64>>
using bcnp::TelemetryAccumulator< MsgType, Storage >::Clock = std::chrono::steady_clock

Definition at line 57 of file telemetry_accumulator.h.

Constructor & Destructor Documentation

◆ TelemetryAccumulator()

template<typename MsgType , typename Storage = StaticVector<MsgType, 64>>
bcnp::TelemetryAccumulator< MsgType, Storage >::TelemetryAccumulator ( TelemetryAccumulatorConfig config = {})
inlineexplicit

Definition at line 59 of file telemetry_accumulator.h.

Member Function Documentation

◆ BufferedCount()

template<typename MsgType , typename Storage = StaticVector<MsgType, 64>>
std::size_t bcnp::TelemetryAccumulator< MsgType, Storage >::BufferedCount ( ) const
inline

Get the number of buffered messages waiting to be sent.

Definition at line 172 of file telemetry_accumulator.h.

◆ Clear()

template<typename MsgType , typename Storage = StaticVector<MsgType, 64>>
void bcnp::TelemetryAccumulator< MsgType, Storage >::Clear ( )
inline

Clear all buffered messages without sending.

Definition at line 180 of file telemetry_accumulator.h.

◆ ForceFlush()

template<typename MsgType , typename Storage = StaticVector<MsgType, 64>>
template<typename Adapter >
bool bcnp::TelemetryAccumulator< MsgType, Storage >::ForceFlush ( Adapter & adapter)
inline

Force an immediate flush regardless of interval.

Parameters
adapterThe transport adapter to send through
Returns
true if a packet was sent, false if buffer was empty

Definition at line 147 of file telemetry_accumulator.h.

◆ GetMetrics()

template<typename MsgType , typename Storage = StaticVector<MsgType, 64>>
Metrics bcnp::TelemetryAccumulator< MsgType, Storage >::GetMetrics ( ) const
inline

Definition at line 197 of file telemetry_accumulator.h.

◆ MaybeFlush()

template<typename MsgType , typename Storage = StaticVector<MsgType, 64>>
template<typename Adapter >
bool bcnp::TelemetryAccumulator< MsgType, Storage >::MaybeFlush ( Adapter & adapter)
inline

Flush if interval has elapsed.

Call this at the end of each control loop iteration.

Parameters
adapterThe transport adapter to send through (must have SendBytes)
Returns
true if a packet was sent, false if interval not yet elapsed or buffer empty

Definition at line 112 of file telemetry_accumulator.h.

◆ Record()

template<typename MsgType , typename Storage = StaticVector<MsgType, 64>>
bool bcnp::TelemetryAccumulator< MsgType, Storage >::Record ( const MsgType & msg)
inline

Record a telemetry reading.

Call this for each sensor/state update during the control loop. If the buffer is full, the oldest reading is discarded (ring behavior via clear+re-add).

Parameters
msgThe telemetry message to record
Returns
true if recorded successfully, false if buffer was full (still recorded, but overwrote)

Definition at line 71 of file telemetry_accumulator.h.

◆ RecordBatch()

template<typename MsgType , typename Storage = StaticVector<MsgType, 64>>
template<typename InputIt >
void bcnp::TelemetryAccumulator< MsgType, Storage >::RecordBatch ( InputIt first,
InputIt last )
inline

Record multiple telemetry readings at once.

Useful for batching multiple encoder readings in a single call.

Definition at line 91 of file telemetry_accumulator.h.

◆ ResetMetrics()

template<typename MsgType , typename Storage = StaticVector<MsgType, 64>>
void bcnp::TelemetryAccumulator< MsgType, Storage >::ResetMetrics ( )
inline

Definition at line 202 of file telemetry_accumulator.h.

◆ SetConfig()

template<typename MsgType , typename Storage = StaticVector<MsgType, 64>>
void bcnp::TelemetryAccumulator< MsgType, Storage >::SetConfig ( const TelemetryAccumulatorConfig & config)
inline

Update configuration.

Definition at line 210 of file telemetry_accumulator.h.


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