提交 65911571 编写于 作者: M manjaro-xfce

Testing SDR

上级 4d66e16a
......@@ -5,6 +5,7 @@
#include <signal.h>
#include <string.h>
#include <thread>
#include <mutex>
#include "../waveform.h"
static bool stop_signal_called = false;
#define UHD_DO(X) \
......@@ -20,7 +21,8 @@ void sigint_handler(int code){
(void)code;
stop_signal_called = true;
}
std::list<char> lst_data;
std::mutex mtx_data;
int runSend()
{
int return_code = EXIT_SUCCESS;
......@@ -115,14 +117,49 @@ int runSend()
fprintf(stderr, "Input :");
// Actual streaming, TX Threading
while (!stop_signal_called) {
char cha = getchar();
for (int i=0;i<16;++i)
bool has_data = false;
char cha = 0;
mtx_data.lock();
has_data = lst_data.size()>0;
if (has_data)
{
cha = *lst_data.begin();
lst_data.pop_front();
}
mtx_data.unlock();
if (has_data)
{
char c = 0;
if (i<3 || i>11)
c = 1;
else if (i>=4)
c = (cha >> (11 - i)) & 0x01;
for (int i=0;i<10;++i)
{
char c = 0;
if (i==0)
c = 0;
else if (i<9)
c = (cha >> (8 - i)) & 0x01;
else
c = 1;
size_t total_sent = 0;
int wfm = c==0?0:1;
while (total_sent < WAVSIZE && !stop_signal_called )
{
size_t num_samps_sent = 0;
SPTYPE * tx_buff = wav_spread[wfm][total_sent];
const void ** tx_buff_ptr = (const void **) &tx_buff;
int start_of_burst = total_sent==0?1:0;
int end_of_burst = (total_sent + tx_sps_buff) >=WAVSIZE ?1:0;
int metai = start_of_burst * 2 + end_of_burst;
int send_sz = end_of_burst?(WAVSIZE - total_sent ):(tx_sps_buff);
UHD_DO(uhd_tx_streamer_send(tx_streamer, tx_buff_ptr,
send_sz, tx_meta + metai,
1, &num_samps_sent));
total_sent += num_samps_sent;
}
}
}
else
{
char c = 1;
size_t total_sent = 0;
int wfm = c==0?0:1;
while (total_sent < WAVSIZE && !stop_signal_called )
......@@ -165,7 +202,18 @@ int main()
// Ctrl+C will exit loop
init_wavform();
signal(SIGINT, &sigint_handler);
runSend();
std::thread th(runSend);
while (!stop_signal_called)
{
char c = getchar();
mtx_data.lock();
lst_data.push_back(c);
mtx_data.unlock();
}
th.join();
return 0;
}
......
......@@ -27,8 +27,6 @@ static const size_t rxbuf_points = 1000*1000*16;
static std::shared_ptr<short [][2]> rx_buf_ptr(new short[rxbuf_points+1024*1024][2]{{0,0}});
static std::atomic< unsigned long long> deal_count (0);
static std::atomic< unsigned long long> rx_count (0);
//Sample rate in Hz
double sprate = 240000 ;
//消费者线程,for rx
void dealer();
int runRecieve()
......@@ -36,7 +34,7 @@ int runRecieve()
int return_code = EXIT_SUCCESS;
//Need soapyuhd soapysdr soapyplutosdr soapyosmo soapy_power
//要用libuhd操作RTLSDR,需要soapyuhd 来代理
char dev_args[] = "";//"available=Yes,driver=rtlsdr,label=Generic RTL2832U :: 77771111153705700,manufacturer=Generic,product=RTL2832U,rtl=0,serial=77771111153705700,tuner=Rafael Micro R820T,type=soapy";
char dev_args[] = "available=Yes,driver=rtlsdr,label=Generic RTL2832U :: 77771111153705700,manufacturer=Generic,product=RTL2832U,rtl=0,serial=77771111153705700,tuner=Rafael Micro R820T,type=soapy";
char error_string[4096];
//GainName
......@@ -45,7 +43,7 @@ int runRecieve()
//接收频率
double rx_freq = 200e6;
double rx_sprate = SIGRATE;
double rx_gain = 0.0;
double rx_gain = 10.0;
bool rx_agc = true;
double rx_bw = SIGRATE;
//接收信号。MIMO时,可以指定0,1
......@@ -200,6 +198,11 @@ void runDeal()
char c = 0;
while (!stop_signal_called)
{
//快速捕获
if (next_test + WAVSIZE * 2 < deal_count)
{
next_test = rx_count;
}
if (deal_count + WAVSIZE >= rx_count || rx_count < WAVSIZE )
{
std::this_thread::sleep_for(std::chrono::milliseconds(1));
......@@ -311,6 +314,7 @@ void runDeal()
}
++deal_count;
}
delete [] ampwin;
fftw_destroy_plan(p[0]);
......
#include <stdio.h>
#include <memory.h>
#include "waveform.h"
//4倍符号速率
//0,1对应的波形
SPTYPE wav_spread[2][WAVSIZE][2];
//0,1单个符号的表达。
static SPTYPE wav[2][MODRATE_N][2];
//用于相关的共轭
float wav_xorr[2][WAVSIZE][2];
void init_wavform(void)
{
......
......@@ -2,10 +2,10 @@
#define WAVEFORM_H
typedef short SPTYPE;
#define MODRATE_N 1
#define C_AMP 8192
#define SPREAD_RAT 256
#define C_AMP 32767
#define SPREAD_RAT 800
#define WAVSIZE SPREAD_RAT*MODRATE_N
#define SIGRATE 240000
#define SIGRATE 250000
extern SPTYPE wav_spread[2][WAVSIZE][2];
extern float wav_xorr[2][WAVSIZE][2];
void init_wavform();
......
......@@ -6,7 +6,9 @@
#include <QHostAddress>
#include <QTextStream>
#include <QNetworkDatagram>
#ifdef _MSC_VER
#include <windows.h>
#endif
static const int tests = 10000;
static const int port = 23456;
static const int period = 20;
......@@ -105,7 +107,7 @@ private:
QUdpSocket * m_sock = nullptr;
};
#ifdef _MSC_VER
/*!
* \brief local_test test udp recv using local socket API
* \return total send
......@@ -162,7 +164,7 @@ inline int local_test()
WSACleanup();
return endID - startID + 1;
}
#endif
/*!
* \brief The sendingThread class send testing packages.
......@@ -241,4 +243,4 @@ protected:
private:
bool term = false;
};
#endif // ALLINONE_H
\ No newline at end of file
#endif // ALLINONE_H
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册