sdr: stop reading packets if the TX buffer is too full
This commit is contained in:
parent
e807f0617b
commit
3a4be428b5
|
@ -1,5 +1,4 @@
|
|||
#include <liquid/liquid.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
|
|
@ -262,6 +262,18 @@ int main(void)
|
|||
break;
|
||||
} else if(ret > 0) {
|
||||
// there is a packet to be read.
|
||||
|
||||
// check free buffer space (50 ms required corresponding to 5000 baseband symbols)
|
||||
size_t buffer_free_space_samples = sdr_get_tx_buffer_free_space(&sdr);
|
||||
|
||||
fprintf(stderr, "TX buffer free: %zu\n", buffer_free_space_samples);
|
||||
|
||||
if(buffer_free_space_samples < 100000) { // sample count for 50 ms at 2 MHz
|
||||
// try again after a short delay
|
||||
fsleep(10e-3);
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t packetbuf[2048];
|
||||
ret = read(m_tunfd, packetbuf, sizeof(packetbuf));
|
||||
if(ret < 0) {
|
||||
|
|
|
@ -366,6 +366,26 @@ result_t sdr_flush_tx_buffer(sdr_ctx_t *ctx)
|
|||
}
|
||||
|
||||
|
||||
size_t sdr_get_tx_buffer_free_space(sdr_ctx_t *ctx)
|
||||
{
|
||||
size_t free_samples = 0;
|
||||
|
||||
if(sem_wait(&ctx->buf_sem) < 0) {
|
||||
perror("sem_wait");
|
||||
return 0;
|
||||
}
|
||||
|
||||
free_samples = cbuffercf_space_available(ctx->tx_buf);
|
||||
|
||||
if(sem_post(&ctx->buf_sem) < 0) {
|
||||
perror("sem_post");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return free_samples;
|
||||
}
|
||||
|
||||
|
||||
result_t sdr_rf_to_baseband(sdr_ctx_t *ctx,
|
||||
const float complex *rf_samples, size_t nrf,
|
||||
float complex *bb_samples, size_t *nbb)
|
||||
|
|
|
@ -49,6 +49,7 @@ result_t sdr_transmit(sdr_ctx_t *ctx, const float complex *samples, size_t nsamp
|
|||
result_t sdr_receive(sdr_ctx_t *ctx, float complex *samples, size_t *nsamples, long timeout_us);
|
||||
|
||||
result_t sdr_flush_tx_buffer(sdr_ctx_t *ctx);
|
||||
size_t sdr_get_tx_buffer_free_space(sdr_ctx_t *ctx);
|
||||
|
||||
/*!
|
||||
* \brief Convert and resample a received signal to baseband.
|
||||
|
|
Loading…
Reference in a new issue