2022-02-16 20:52:46 +01:00
|
|
|
#ifndef LAYER1_RX_H
|
|
|
|
#define LAYER1_RX_H
|
|
|
|
|
|
|
|
#include <liquid/liquid.h>
|
|
|
|
|
2022-02-17 21:39:18 +01:00
|
|
|
#include "modcod.h"
|
2022-02-16 20:52:46 +01:00
|
|
|
#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
|
|
|
|
{
|
2022-02-27 16:59:14 +01:00
|
|
|
// AGC
|
|
|
|
agc_crcf agc;
|
|
|
|
|
2022-02-16 20:52:46 +01:00
|
|
|
// NCOs for carrier frequency offset correction
|
|
|
|
nco_crcf carrier_coarse_nco;
|
|
|
|
nco_crcf carrier_fine_nco;
|
|
|
|
|
|
|
|
// Forward error correction objects
|
|
|
|
fec hdr_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;
|
2022-02-17 21:39:18 +01:00
|
|
|
modcod_t modcod;
|
2022-02-16 20:52:46 +01:00
|
|
|
} layer1_rx_t;
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Initialize the receiver.
|
|
|
|
*
|
2022-03-01 21:51:41 +01:00
|
|
|
* \param rx Pointer to the receiver context.
|
2022-02-16 20:52:46 +01:00
|
|
|
* \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.
|
|
|
|
*
|
2022-03-01 21:51:41 +01:00
|
|
|
* \param rx Pointer to the receiver context.
|
2022-02-16 20:52:46 +01:00
|
|
|
* \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.
|
|
|
|
*
|
2022-03-01 21:51:41 +01:00
|
|
|
* \param rx Pointer to the receiver context.
|
2022-02-16 20:52:46 +01:00
|
|
|
* \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);
|
|
|
|
|
2022-03-01 21:51:41 +01:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Determine whether the receiver is currently receiving a packet.
|
|
|
|
*
|
|
|
|
* This function can be used to identify idle periods where packet transmission
|
|
|
|
* is possible. Switching to TX while this function returns true will very
|
|
|
|
* probably result in a collision with packet corruption.
|
|
|
|
*
|
|
|
|
* \param rx Pointer to the receiver context.
|
|
|
|
* \returns Whether the receiver is currently receiving a packet.
|
|
|
|
*/
|
|
|
|
bool layer1_rx_is_busy(const layer1_rx_t *rx);
|
|
|
|
|
2022-02-16 20:52:46 +01:00
|
|
|
#endif // LAYER1_RX_H
|