103 lines
2.4 KiB
C
103 lines
2.4 KiB
C
|
#ifndef LAYER1_RX_H
|
||
|
#define LAYER1_RX_H
|
||
|
|
||
|
#include <liquid/liquid.h>
|
||
|
|
||
|
#include "correlator.h"
|
||
|
|
||
|
#include "results.h"
|
||
|
|
||
|
typedef enum {
|
||
|
RX_STATE_ACQUISITION,
|
||
|
RX_STATE_HEADER,
|
||
|
RX_STATE_DATA,
|
||
|
} rx_state_t;
|
||
|
|
||
|
|
||
|
typedef enum {
|
||
|
RX_EVT_PACKET_RECEIVED,
|
||
|
RX_EVT_PREAMBLE_FOUND,
|
||
|
RX_EVT_CHECKSUM_ERROR,
|
||
|
} rx_evt_t;
|
||
|
|
||
|
|
||
|
typedef void (*rx_callback_t)(rx_evt_t evt, uint8_t *packet_data, size_t packet_len);
|
||
|
|
||
|
|
||
|
typedef struct
|
||
|
{
|
||
|
// NCOs for carrier frequency offset correction
|
||
|
nco_crcf carrier_coarse_nco;
|
||
|
nco_crcf carrier_fine_nco;
|
||
|
|
||
|
// Forward error correction objects
|
||
|
fec hdr_fec;
|
||
|
fec payload_fec;
|
||
|
|
||
|
// Demodulators
|
||
|
modem hdr_demod;
|
||
|
modem payload_demod;
|
||
|
|
||
|
// symbol timing synchronizer
|
||
|
symsync_crcf symsync;
|
||
|
|
||
|
// preamble correlator
|
||
|
correlator_ctx_t preamble_correlator;
|
||
|
|
||
|
// Receiver state
|
||
|
rx_state_t state;
|
||
|
|
||
|
// Callback function to notify user of certain events
|
||
|
rx_callback_t callback;
|
||
|
|
||
|
// Precalcuated header lengths
|
||
|
unsigned int hdr_len_symbols;
|
||
|
unsigned int hdr_len_enc_bytes;
|
||
|
|
||
|
// Information from the decoded header
|
||
|
uint16_t payload_len_symbols;
|
||
|
uint16_t payload_len_bytes;
|
||
|
uint16_t payload_crc;
|
||
|
uint16_t payload_len_enc_bytes;
|
||
|
} layer1_rx_t;
|
||
|
|
||
|
|
||
|
/*!
|
||
|
* \brief Initialize the receiver.
|
||
|
*
|
||
|
* \param tx Pointer to the receiver context.
|
||
|
* \param callback Function to be called on receiver events.
|
||
|
* \returns The result of the initialization.
|
||
|
*/
|
||
|
result_t layer1_rx_init(layer1_rx_t *rx, rx_callback_t callback);
|
||
|
|
||
|
|
||
|
/*!
|
||
|
* \brief Shut the receiver down. Frees all memory.
|
||
|
*
|
||
|
* \param tx Pointer to the receiver context.
|
||
|
* \returns The result of the shutdown.
|
||
|
*/
|
||
|
result_t layer1_rx_shutdown(layer1_rx_t *rx);
|
||
|
|
||
|
|
||
|
/*!
|
||
|
* \brief Process the given block of samples.
|
||
|
*
|
||
|
* Runs the whole receiver chain for the given samples. This includes timing-
|
||
|
* and frequency synchronization, preamble search, header demodulation and
|
||
|
* decoding and payload demodulation and decoding.
|
||
|
*
|
||
|
* On specific events, most notably when a packet is successfully decoded, the
|
||
|
* callback function passed to \ref layer1_rx_init() will be called. See \ref
|
||
|
* rx_evt_t for possible events.
|
||
|
*
|
||
|
* \param tx Pointer to the receiver context.
|
||
|
* \param samples Pointer to the samples to process.
|
||
|
* \param sample_count Number of samples to process.
|
||
|
* \returns The result of the shutdown.
|
||
|
*/
|
||
|
result_t layer1_rx_process(layer1_rx_t *rx, const float complex *samples, size_t sample_count);
|
||
|
|
||
|
#endif // LAYER1_RX_H
|