Reorganize Soapy stream management; flush tx buffer
This commit is contained in:
parent
152d2f02f6
commit
47fc177e87
|
@ -6,6 +6,8 @@
|
|||
#include <math.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <SoapySDR/Logger.h>
|
||||
|
||||
#include <liquid/liquid.h>
|
||||
|
||||
#include <sys/poll.h>
|
||||
|
@ -26,7 +28,7 @@
|
|||
#define RESULT_CHECK(stmt) { \
|
||||
result_t res = stmt; \
|
||||
if(res != OK) { \
|
||||
fprintf(stderr, "Error %d in %s:%d!", res, __FILE__, __LINE__); \
|
||||
fprintf(stderr, "Error %d in %s:%d!\n", res, __FILE__, __LINE__); \
|
||||
exit(1); \
|
||||
} \
|
||||
}
|
||||
|
@ -171,6 +173,8 @@ int main(void)
|
|||
|
||||
sdr_ctx_t sdr;
|
||||
|
||||
SoapySDR_setLogLevel(SOAPY_SDR_DEBUG);
|
||||
|
||||
bool on_air = false;
|
||||
|
||||
debug_fd = open("/tmp/dump.cf32", O_CREAT | O_WRONLY | O_TRUNC);
|
||||
|
@ -201,9 +205,6 @@ int main(void)
|
|||
|
||||
unsigned rx_retries = 0;
|
||||
|
||||
float complex zeros[1024];
|
||||
memset(zeros, 0, sizeof(zeros));
|
||||
|
||||
while(m_running) {
|
||||
if(on_air || !layer1_rx_is_busy(&rx)) {
|
||||
int ret = poll(&pfd, 1, 0);
|
||||
|
@ -237,17 +238,19 @@ int main(void)
|
|||
dump_array_cf(whole_burst, burst_len, 1.0f, "/tmp/tx.cpx");
|
||||
|
||||
if(!on_air) {
|
||||
RESULT_CHECK(sdr_start_tx(&sdr));
|
||||
RESULT_CHECK(sdr_start_tx(&sdr, burst_len * SDR_OVERSAMPLING));
|
||||
|
||||
RESULT_CHECK(sdr_flush_tx_buffer(&sdr));
|
||||
}
|
||||
|
||||
RESULT_CHECK(transmit_in_chunks(&sdr, whole_burst, burst_len));
|
||||
|
||||
on_air = true;
|
||||
} else if(on_air) { // ret == 0
|
||||
//RESULT_CHECK(sdr_start_rx(&sdr));
|
||||
//on_air = false;
|
||||
fprintf(stderr, "z");
|
||||
sdr_transmit(&sdr, zeros, sizeof(zeros)/sizeof(zeros[0]), 100000);
|
||||
RESULT_CHECK(sdr_flush_tx_buffer(&sdr));
|
||||
|
||||
RESULT_CHECK(sdr_start_rx(&sdr));
|
||||
on_air = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#include "sdr.h"
|
||||
|
||||
static void shutdown_streams(sdr_ctx_t *ctx)
|
||||
static void close_streams(sdr_ctx_t *ctx)
|
||||
{
|
||||
if(ctx->rx_stream) {
|
||||
SoapySDRDevice_deactivateStream(ctx->sdr, ctx->rx_stream, 0, 0);
|
||||
|
@ -107,13 +107,29 @@ result_t sdr_init(sdr_ctx_t *ctx)
|
|||
return ERR_SOAPY;
|
||||
}
|
||||
|
||||
//setup streams
|
||||
ctx->rx_stream = SoapySDRDevice_setupStream(ctx->sdr, SOAPY_SDR_RX, SOAPY_SDR_CF32, NULL, 0, NULL);
|
||||
|
||||
if(ctx->rx_stream == NULL) {
|
||||
fprintf(stderr, "sdr: setupStream fail: %s\n", SoapySDRDevice_lastError());
|
||||
return ERR_SOAPY;
|
||||
}
|
||||
|
||||
ctx->tx_stream = SoapySDRDevice_setupStream(ctx->sdr, SOAPY_SDR_TX, SOAPY_SDR_CF32, NULL, 0, NULL);
|
||||
|
||||
if(ctx->tx_stream == NULL) {
|
||||
fprintf(stderr, "sdr: setupStream fail: %s\n", SoapySDRDevice_lastError());
|
||||
return ERR_SOAPY;
|
||||
}
|
||||
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
result_t sdr_destroy(sdr_ctx_t *ctx)
|
||||
{
|
||||
shutdown_streams(ctx);
|
||||
close_streams(ctx);
|
||||
|
||||
nco_crcf_destroy(ctx->rx_nco);
|
||||
nco_crcf_destroy(ctx->tx_nco);
|
||||
|
@ -131,36 +147,20 @@ result_t sdr_destroy(sdr_ctx_t *ctx)
|
|||
|
||||
result_t sdr_start_rx(sdr_ctx_t *ctx)
|
||||
{
|
||||
shutdown_streams(ctx);
|
||||
|
||||
//setup a stream (complex floats)
|
||||
ctx->rx_stream = SoapySDRDevice_setupStream(ctx->sdr, SOAPY_SDR_RX, SOAPY_SDR_CF32, NULL, 0, NULL);
|
||||
|
||||
if(ctx->rx_stream == NULL) {
|
||||
fprintf(stderr, "sdr: setupStream fail: %s\n", SoapySDRDevice_lastError());
|
||||
return ERR_SOAPY;
|
||||
if(SoapySDRDevice_activateStream(ctx->sdr, ctx->rx_stream, 0, 0, 0) != 0) {
|
||||
fprintf(stderr, "sdr: activateStream fail: %s\n", SoapySDRDevice_lastError());
|
||||
}
|
||||
|
||||
SoapySDRDevice_activateStream(ctx->sdr, ctx->rx_stream, 0, 0, 0); //start streaming
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
result_t sdr_start_tx(sdr_ctx_t *ctx)
|
||||
result_t sdr_start_tx(sdr_ctx_t *ctx, size_t burst_size)
|
||||
{
|
||||
shutdown_streams(ctx);
|
||||
|
||||
//setup a stream (complex floats)
|
||||
ctx->tx_stream = SoapySDRDevice_setupStream(ctx->sdr, SOAPY_SDR_TX, SOAPY_SDR_CF32, NULL, 0, NULL);
|
||||
|
||||
if(ctx->tx_stream == NULL) {
|
||||
fprintf(stderr, "sdr: setupStream fail: %s\n", SoapySDRDevice_lastError());
|
||||
return ERR_SOAPY;
|
||||
if(SoapySDRDevice_activateStream(ctx->sdr, ctx->tx_stream, 0, 0, burst_size) != 0) {
|
||||
fprintf(stderr, "sdr: activateStream fail: %s\n", SoapySDRDevice_lastError());
|
||||
}
|
||||
|
||||
SoapySDRDevice_activateStream(ctx->sdr, ctx->tx_stream, 0, 0, 0); //start streaming
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -205,6 +205,22 @@ result_t sdr_receive(sdr_ctx_t *ctx, float complex *samples, size_t *nsamples, l
|
|||
}
|
||||
|
||||
|
||||
result_t sdr_flush_tx_buffer(sdr_ctx_t *ctx)
|
||||
{
|
||||
size_t mtu = SoapySDRDevice_getStreamMTU(ctx->sdr, ctx->tx_stream);
|
||||
|
||||
float complex zeros[mtu];
|
||||
memset(zeros, 0, sizeof(zeros));
|
||||
|
||||
for(int i = 0; i < 4; i++) {
|
||||
fprintf(stderr, "z");
|
||||
sdr_transmit(ctx, zeros, sizeof(zeros)/sizeof(zeros[0]), 100000);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
|
|
|
@ -26,11 +26,13 @@ result_t sdr_init(sdr_ctx_t *ctx);
|
|||
result_t sdr_destroy(sdr_ctx_t *ctx);
|
||||
|
||||
result_t sdr_start_rx(sdr_ctx_t *ctx);
|
||||
result_t sdr_start_tx(sdr_ctx_t *ctx);
|
||||
result_t sdr_start_tx(sdr_ctx_t *ctx, size_t burst_size);
|
||||
|
||||
result_t sdr_transmit(sdr_ctx_t *ctx, const float complex *samples, size_t nsamples, long timeout_us);
|
||||
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);
|
||||
|
||||
/*!
|
||||
* \brief Convert and resample a received signal to baseband.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue