CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
receive_buffer.c File Reference

This file contains the implementation of the receive payload delay buffer. More...

#include "receive_buffer.h"
#include "cdi_os_api.h"
#include "configuration.h"
#include "internal.h"
#include <stdint.h>
#include <stdlib.h>

Data Structures

struct  ReceiveBufferState
 

Functions

static uint64_t TaiNowMicroseconds ()
 
CDI_THREAD ReceiveBufferThread (void *ptr)
 
CdiReturnStatus RxBufferInit (CdiLogHandle log_handle, CdiPoolHandle error_message_pool, int buffer_delay_ms, int max_rx_payloads, CdiQueueHandle output_queue_handle, ReceiveBufferHandle *receive_buffer_handle_ptr, CdiQueueHandle *input_queue_handle_ptr)
 
void RxBufferDestroy (ReceiveBufferHandle receive_buffer_handle)
 

Variables

static const int kMaxMissed = 100
 The number of consecutive payloads with time stamps out of the buffering window before offset is reset.
 

Detailed Description

This file contains the implementation of the receive payload delay buffer.

Function Documentation

◆ ReceiveBufferThread()

CDI_THREAD ReceiveBufferThread ( void * ptr)

The main function for the receive delay buffer thread. It takes application callback structures from its input queue and sends them to the configured queue after a configurable delay based on the timestamps associated with each payload.

Parameters
ptrPointer to thread specific data. In this case, a pointer to ReceiveBufferState.
Returns
The return value is not used.

◆ RxBufferDestroy()

void RxBufferDestroy ( ReceiveBufferHandle receive_buffer_handle)

Destroys the receive delay buffer specified by the handle. Payloads currently in the delay line are pushed to the output queue then the associate thread is shut down and joined and all resources allocated are freed.

Parameters
receive_buffer_handleHandle for the receive delay buffer to destroy.

◆ RxBufferInit()

CdiReturnStatus RxBufferInit ( CdiLogHandle log_handle,
CdiPoolHandle error_message_pool,
int buffer_delay_ms,
int max_rx_payloads,
CdiQueueHandle output_queue_handle,
ReceiveBufferHandle * receive_buffer_handle_ptr,
CdiQueueHandle * input_queue_handle_ptr )

Creates a receive delay buffer of the specified length, allocating all of the associated resources.

Parameters
log_handleHandle to the logger to be used for any messages from this module.
error_message_poolHandle to the pool to which error messages are to be freed in the event that an internal error prevents an input payload from being sent to the next stage.
buffer_delay_msThe number of milliseconds to delay each payload, more or less, depending on each payload's timestamp value.
max_rx_payloadsThe number of objects to allocate for holding payloads in the delay buffer.
output_queue_handleHandle to which the receive delay buffer is to send payloads after they've been delayed.
receive_buffer_handle_ptrAddress of where to write the receive delay buffer's handle if successfully created.
input_queue_handle_ptrAddress to write the handle for the receive delay buffer's input queue if creation was successful.
Returns
CdiReturnStatus kCdiStatusOk if the recieve delay buffer was successfully created or kCdiStatusNotEnoughMemory if memory was insufficient to allocate all of the required resources.

◆ TaiNowMicroseconds()

static uint64_t TaiNowMicroseconds ( )
inlinestatic

Convenience function to get the TAI based PTP timestamp and convert it to a single integer value representing the number of microseconds from the epoch.

Returns
uint64_t The number of microseconds since the epoch according to the hosts real time clock.