diff options
-rw-r--r-- | AlignSample.cpp | 14 | ||||
-rw-r--r-- | OutputUHD.cpp | 18 | ||||
-rw-r--r-- | OutputUHD.hpp | 3 | ||||
-rw-r--r-- | main.cpp | 33 | ||||
-rw-r--r-- | pointcloud.cpp | 15 | ||||
-rw-r--r-- | pointcloud.hpp | 4 |
6 files changed, 67 insertions, 20 deletions
diff --git a/AlignSample.cpp b/AlignSample.cpp index 50b818e..4f5a8eb 100644 --- a/AlignSample.cpp +++ b/AlignSample.cpp @@ -186,7 +186,7 @@ CorrelationResult AlignSample::crosscorrelate(size_t len) tx_fft_plan.execute(); for (size_t i = 0; i < len; i++) { - ifft_in[i] = rx_fft_out[i] * std::conj(tx_fft_out[i]); + ifft_in[i] = tx_fft_out[i] * std::conj(rx_fft_out[i]); } ifft_plan.execute(); @@ -195,18 +195,6 @@ CorrelationResult AlignSample::crosscorrelate(size_t len) result.correlation[i] = ifft_out[i]; } -#if 0 - // Calculate correlation - for (size_t offset = 0; offset < max_offset; offset++) { - complexf xcorr(0, 0); - - for (size_t i = 0; i < len; i++) { - xcorr += rxsamps[i]/rx_power_f * std::conj(txsamps[i+offset])/tx_power_f; - } - result.correlation[offset] = xcorr; - } -#endif - return result; } diff --git a/OutputUHD.cpp b/OutputUHD.cpp index 9536ebd..255f63f 100644 --- a/OutputUHD.cpp +++ b/OutputUHD.cpp @@ -136,3 +136,21 @@ ssize_t OutputUHD::Receive(complexf *samples, size_t sizeIn, double *first_sampl return num_rx_samps; } +void OutputUHD::SetTxGain(double gain) +{ + m_txgain = gain; + + MDEBUG("OutputUHD:Setting TX Gain: %f ...\n", m_txgain); + m_usrp->set_tx_gain(m_txgain); + MDEBUG("OutputUHD:Actual TX Gain: %f ...\n", m_usrp->get_tx_gain()); +} + +void OutputUHD::SetRxGain(double gain) +{ + m_rxgain = gain; + + MDEBUG("OutputUHD:Setting RX Gain: %f ...\n", m_rxgain); + m_usrp->set_rx_gain(m_rxgain); + MDEBUG("OutputUHD:Actual RX Gain: %f ...\n", m_usrp->get_rx_gain()); +} + diff --git a/OutputUHD.hpp b/OutputUHD.hpp index b3169c6..b0288b8 100644 --- a/OutputUHD.hpp +++ b/OutputUHD.hpp @@ -36,6 +36,9 @@ class OutputUHD { size_t Transmit(const complexf *samples, size_t sizeIn, double transmit_time); ssize_t Receive(complexf *samples, size_t sizeIn, double *first_sample_time); + void SetTxGain(double gain); + void SetRxGain(double gain); + private: double m_txgain; double m_rxgain; @@ -94,9 +94,11 @@ size_t do_receive(OutputUHD* output_uhd) const size_t correlation_length = 16 * 1024; // 8ms at 2048000 +long user_delay = 0; + void push_to_point_cloud(size_t rx_delay) { - auto points = aligner.get_samples(correlation_length, rx_delay); + auto points = aligner.get_samples(correlation_length, rx_delay + user_delay); if (points.first.size() > 0) { cloud.push_samples(points); @@ -332,7 +334,34 @@ int main(int argc, char **argv) total_samps_read += samps_read; try { - cloud.handle_event(); + std::string keyname = cloud.handle_event(); + if (keyname == "l") { + user_delay += 1; + std::cerr << "User delay: " << user_delay << std::endl; + } + else if (keyname == "e") { + user_delay -= 1; + std::cerr << "User delay: " << user_delay << std::endl; + } + else if (keyname == "z") { + rxgain -= 1; + output_uhd.SetRxGain(rxgain); + } + else if (keyname == "a") { + rxgain += 1; + output_uhd.SetRxGain(rxgain); + } + else if (keyname == "x") { + txgain -= 1; + output_uhd.SetTxGain(txgain); + } + else if (keyname == "s") { + txgain += 1; + output_uhd.SetTxGain(txgain); + } + else if (not keyname.empty()) { + std::cerr << "Press L for later, E for earlier, Z/A to decrease/increase RX gain, X/S for TX gain" << std::endl; + } } catch (sdl_quit &e) { running = false; diff --git a/pointcloud.cpp b/pointcloud.cpp index 417c31c..7c92d16 100644 --- a/pointcloud.cpp +++ b/pointcloud.cpp @@ -96,9 +96,10 @@ void PointCloud::push_samples(std::pair<std::vector<complexf>, std::vector<compl double arg_tx = std::arg(tx[i]); // Phase is colour - p.r = p.g = p.b = 255; + p.r = p.b = 255; + p.g = 64; if (arg_rx > arg_tx) { - int corr = 255 - 10 * (arg_rx - arg_tx); + int corr = 255 - 20 * (arg_rx - arg_tx); if (corr < 0) { corr = 0; @@ -107,7 +108,7 @@ void PointCloud::push_samples(std::pair<std::vector<complexf>, std::vector<compl p.r = corr; } else { - int corr = 255 - 10 * (arg_tx - arg_rx); + int corr = 255 - 20 * (arg_tx - arg_rx); if (corr < 0) { corr = 0; @@ -124,7 +125,7 @@ void PointCloud::push_samples(std::pair<std::vector<complexf>, std::vector<compl } } -void PointCloud::handle_event() +std::string PointCloud::handle_event() { SDL_Event event; while (SDL_PollEvent(&event)) @@ -133,8 +134,14 @@ void PointCloud::handle_event() case SDL_QUIT: throw sdl_quit(); break; + case SDL_KEYDOWN: + std::string key(SDL_GetKeyName(event.key.keysym.sym)); + return key; + break; } } + + return std::string(); } void PointCloud::draw() diff --git a/pointcloud.hpp b/pointcloud.hpp index a2dc7c3..b7df253 100644 --- a/pointcloud.hpp +++ b/pointcloud.hpp @@ -43,7 +43,9 @@ class PointCloud PointCloud(size_t num_points); // Must call this regularly - void handle_event(void); + // returns name of key pressed, or an empty string if nothing + // happened + std::string handle_event(void); // The caller must guarantee that the two vectors have the same size void push_samples(std::pair<std::vector<complexf>, std::vector<complexf> > &data); |