From 59b4863ea767703f4ca0facd89bc4fc5c73c40ec Mon Sep 17 00:00:00 2001 From: manjaro Date: Sun, 4 Apr 2021 21:58:52 +0100 Subject: [PATCH] Add Linux Demo for XCORR info trans --- uhd_cpp/uhd_the_ark.cpp | 103 +++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 44 deletions(-) diff --git a/uhd_cpp/uhd_the_ark.cpp b/uhd_cpp/uhd_the_ark.cpp index a2aaad5..ae34adf 100644 --- a/uhd_cpp/uhd_the_ark.cpp +++ b/uhd_cpp/uhd_the_ark.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include using uhd::tune_request_t; using uhd::tx_streamer; @@ -46,9 +47,9 @@ struct tag_channelOptions{ string wirefmt; //内部类型 (sc8 or sc16),是片上处理的类型 vector channels {0};//通道号,可以设置0,1之类的。默认subdev时,0=A:A,1=A:B,subdev被修改,则采取修改后的编号 size_t spb = 10000; //缓冲大小,太小会丢包,太大会超时 - double rate = 500000; //采样率,单位Hz + double rate = 1e6; //采样率,单位Hz double freq = 1.0e9; //射频频率,单位Hz - double gain = 55; //射频增益,单位dB + double gain = 20; //射频增益,单位dB double bw = rate; //滤波带宽,默认为采样窗口 double lo_offset = 0; //LO偏移,单位 Hz (缺省) bool int_n_mod = false; //int-n 模式(本例不配置) @@ -77,7 +78,7 @@ int UHD_SAFE_MAIN(int /*argc*/, char* /*argv*/[]) //3.配置发射 tag_channelOptions tx_op; - tx_op.freq = 230e6; + tx_op.freq = 200e6; tx_op.bw = tx_op.rate; tx_op.gain=70; tx_op.channels[0] = 0; @@ -111,14 +112,15 @@ int UHD_SAFE_MAIN(int /*argc*/, char* /*argv*/[]) //4.配置接收 tag_channelOptions rx_op; - rx_op.ant = "RX2"; rx_op.bw = rx_op.rate; - rx_op.freq = 230e6; - rx_op.gain = 30; - rx_op.channels[0] = 1; + rx_op.freq = 200e6; + rx_op.gain = 50; + rx_op.channels[0] = 0; + rx_op.ant = "RX2"; //4.1 子设备 if (rx_op.subdev.size()) usrp->set_rx_subdev_spec(rx_op.subdev,multi_usrp::ALL_MBOARDS); + usrp->set_rx_agc(true,rx_op.channels[0]); cerr << "RX Using Device: " << usrp->get_pp_string() << endl; //4.2 采样率 cerr << "Setting RX Rate: " << (rx_op.rate / 1e6) << "Msps..." << endl; @@ -169,9 +171,9 @@ int UHD_SAFE_MAIN(int /*argc*/, char* /*argv*/[]) //收发计数 -static unsigned long long rx_count (0), tx_count (0); +static std::atomic< unsigned long long> rx_count (0), tx_count (0); //消费生产计数 -static unsigned long long deal_count (0), gene_count (0); +static std::atomic< unsigned long long> deal_count (0), gene_count (0); //缓存点数(IQ) static const size_t rxbuf_points = 1000*1000*16; static const size_t txbuf_points = 1000*1000*16; @@ -263,7 +265,7 @@ void do_io( //主线程不断打印状态 while (!stop_signal_called) { - cerr<<"P " << gene_count<<" TX "<< tx_count<< " RX "<< rx_count << "D "<< deal_count<< " \r"; + //cerr<<"P " << gene_count<<" TX "<< tx_count<< " RX "<< rx_count << "D "<< deal_count<< " \r"; std::this_thread::sleep_for(std::chrono::milliseconds(100)); if (rx_count >= 4*1024*1024) @@ -276,12 +278,12 @@ void do_io( deal_thread.join(); } -static const int modraten = 32; -static const int amp = 1000; -static const int spread_ratio = 16; +static const int modraten = 4; +static const int amp = 1024; +static const int spread_ratio = 128; static const size_t wav_size = spread_ratio*modraten; static short wav_spread[2][wav_size][2]; -static short wav_xorr[2][wav_size][2]; +static float wav_xorr[2][wav_size][2]; void init_wavform() { const double pi = 3.14159265358979323846; @@ -289,12 +291,12 @@ void init_wavform() short wav[2][modraten][2]; for (int i=0;i tx_count + txbuf_points/2) + if (gene_count > tx_count + txbuf_points-16) { std::this_thread::sleep_for(std::chrono::milliseconds(10)); continue; @@ -378,12 +380,14 @@ void producer() void dealer() { unsigned long long next_test = wav_size; + const unsigned int half_sz = wav_size/2; short (*pBufRx)[2] = rx_buf_ptr.get(); + float (* ampwin)[2] = new float[wav_size][2]; while (!stop_signal_called) { if (deal_count + wav_size >= rx_count || rx_count < wav_size ) { - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); continue; } @@ -392,38 +396,49 @@ void dealer() ++deal_count; continue; } - long long cross[2][3] = {{0,0,0},{0,0,0}}; + float cross[2][2] = {{0,0},{0,0}}; unsigned long long start_x = deal_count - wav_size; //xorr #pragma omp simd for (size_t i=0;i cross[1][2] ) + bool best0 = true, best1=true; + + for (size_t i=0;i 0=%lld,1=%lld, %lf\n",deal_count,deal_count / wav_size, cross[0][2],cross[1][2] - ,log((cross[0][2]+1.0)/(cross[1][2]+1.0))/log(10)*10 - ); - next_test = deal_count + wav_size - modraten*2; + if (i!=half_sz) + { + if (ampwin[(deal_count +i - wav_size )% wav_size][0] >= ampwin[(deal_count +half_sz - wav_size )% wav_size][0]) + best0 = false; + if (ampwin[(deal_count +i - wav_size )% wav_size][1] >= ampwin[(deal_count +half_sz - wav_size )% wav_size][1]) + best1 = false; + } + if (ampwin[(deal_count +i - wav_size )% wav_size][1] >= ampwin[(deal_count +half_sz - wav_size )% wav_size][0]) + best0 = false; + if (ampwin[(deal_count +i - wav_size )% wav_size][0] >= ampwin[(deal_count +half_sz - wav_size )% wav_size][1]) + best1 = false; } - if (cross[1][2]/5 > cross[0][2] ) + + if (best0 ) + { + putchar('0'); + } + else if (best1 ) { - printf ("Clock %lld(%lld) > 1=%lld,0=%lld, %lf\n",deal_count,deal_count / wav_size, cross[1][2],cross[0][2] - ,log((cross[1][2]+1.0)/(cross[0 ][2]+1.0))/log(10)*10 - ); - next_test = deal_count + wav_size - modraten*2; + putchar('1'); } ++deal_count; } - + delete [] ampwin; } //-----------------------维护代码------------------------ bool check_tx_status(const string & ref, multi_usrp::sptr usrp,const tag_channelOptions & op) -- GitLab