diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 103 |
1 files changed, 60 insertions, 43 deletions
@@ -84,7 +84,7 @@ size_t do_receive(OutputUHD* output_uhd) void find_peak_correlation() { - FILE* fd = fopen("correlation.debug", "w"); + FILE* fd = nullptr; //fopen("correlation.debug", "w"); while (running) { const size_t correlation_length = 16 * 1024; // 8ms at 2048000 @@ -95,34 +95,34 @@ void find_peak_correlation() auto result = aligner.crosscorrelate(correlation_length); auto& xcs = result.correlation; - fprintf(fd, "Max correlation is %f at %fms, with RX %fdB and TX %fdB, RXtime %f, TXtime %f\n", - std::sqrt(max_norm), - (double)pos_max / (double)samplerate * 1000.0, - 10*std::log(result.rx_power), - 10*std::log(result.tx_power), - result.rx_timestamp, - result.tx_timestamp); // Find correlation peak for (size_t offset = 0; offset < xcs.size(); offset++) { complexf xc = xcs[offset]; - fprintf(fd, "%f ", std::norm(xc)); + if (fd) { + fprintf(fd, "%f ", std::norm(xc)); + } if (std::norm(xc) >= max_norm) { max_norm = std::norm(xc); pos_max = offset; } } - fprintf(fd, "\n"); - MDEBUG("Max correlation is %f at %fms, with RX %fdB and TX %fdB, RXtime %f, TXtime %f\n", - std::sqrt(max_norm), - (double)pos_max / (double)samplerate * 1000.0, - 10*std::log(result.rx_power), - 10*std::log(result.tx_power), - result.rx_timestamp, - result.tx_timestamp); + char msg[512]; + snprintf(msg, 512, "Max correlation is %f at %fms (%zu), with RX %fdB and TX %fdB, RXtime %f, TXtime %f\n", + std::sqrt(max_norm), + (double)pos_max / (double)samplerate * 1000.0, + pos_max, + 10*std::log(result.rx_power), + 10*std::log(result.tx_power), + result.rx_timestamp, + result.tx_timestamp); + if (fd) { + fprintf(fd, "\n%s", msg); + } + std::cerr << msg; std::this_thread::sleep_for(std::chrono::microseconds(1)); // Eat much more than we correlate, because correlation is slow - aligner.consume(2048000); + aligner.consume(204800); } else { MDEBUG("Waiting for correlation\n"); @@ -165,43 +165,60 @@ int main(int argc, char **argv) FILE* fd = nullptr; if (uri == "test") { - FILE* fd_rx = fopen("rx.debug", "r"); - FILE* fd_tx = fopen("tx.debug", "r"); + FILE* fd_rx = fopen("rx.test", "r"); + if (!fd_rx) { + std::cerr << "fx_rx open error" << std::endl; + abort(); + } + FILE* fd_tx = fopen("tx.test", "r"); + if (!fd_tx) { + std::cerr << "fx_tx open error" << std::endl; + abort(); + } - const size_t len = 64; + size_t num_rx_samples; + size_t num_tx_samples; + do { + const size_t len = 64; + std::vector<complexf> rx_samples(len); + std::vector<complexf> tx_samples(len); - std::vector<complexf> rx_samples(len*1024); - std::vector<complexf> tx_samples(len*1024); + num_rx_samples = fread(&rx_samples.front(), sizeof(complexf), len, fd_rx); + num_tx_samples = fread(&tx_samples.front(), sizeof(complexf), len, fd_tx); - size_t num_rx_samples = fread(&rx_samples.front(), sizeof(complexf), len, fd_rx); - size_t num_tx_samples = fread(&tx_samples.front(), sizeof(complexf), len, fd_tx); + aligner.push_rx_samples(&rx_samples.front(), num_rx_samples, 1); + aligner.push_tx_samples(&tx_samples.front(), num_tx_samples, 1); - aligner.push_rx_samples(&rx_samples.front(), num_rx_samples, 1); - aligner.push_tx_samples(&tx_samples.front(), num_tx_samples, 1); + std::cerr << "."; + } while (num_rx_samples and num_tx_samples); + std::cerr << std::endl; aligner.debug(); const size_t correlation_length = 16 * 1024; double max_norm = 0.0; size_t pos_max = 0; - auto result = aligner.crosscorrelate(correlation_length); - auto& xcs = result.correlation; - for (size_t offset = 0; offset < xcs.size(); offset++) { - complexf xc = xcs[offset]; - fprintf(fd, "%f ", std::norm(xc)); - if (std::norm(xc) >= max_norm) { - max_norm = std::norm(xc); - pos_max = offset; + while (aligner.ready(correlation_length)) { + auto result = aligner.crosscorrelate(correlation_length); + auto& xcs = result.correlation; + for (size_t offset = 0; offset < xcs.size(); offset++) { + complexf& xc = xcs[offset]; + if (std::norm(xc) >= max_norm) { + max_norm = std::norm(xc); + pos_max = offset; + } } - } - MDEBUG("Max correlation is %f at %fms, with RX %fdB and TX %fdB, RXtime %f, TXtime %f\n", - std::sqrt(max_norm), - (double)pos_max / (double)samplerate * 1000.0, - 10*std::log(result.rx_power), - 10*std::log(result.tx_power), - result.rx_timestamp, - result.tx_timestamp); + MDEBUG("Max correlation is %f at %fms (%zu), with RX %fdB and TX %fdB, RXtime %f, TXtime %f\n", + std::sqrt(max_norm), + (double)pos_max / (double)samplerate * 1000.0, + pos_max, + 10*std::log(result.rx_power), + 10*std::log(result.tx_power), + result.rx_timestamp, + result.tx_timestamp); + aligner.consume(correlation_length / 2); + } return 0; } else if (uri.find("tcp://") != 0) { |