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

FM 广播接收例子成功

上级 75d5536f
......@@ -5,6 +5,7 @@ SUBDIRS += \
sources/source_plutosdr \
transforms/transform_fft \
transforms/mod_fm \
transforms/mod_fm_dem \
transforms/filter_fir \
transforms/resample_pqfraction \
sources/source_files \
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>306</width>
<height>154</height>
<height>182</height>
</rect>
</property>
<property name="windowTitle">
......@@ -43,10 +43,10 @@
<number>4000</number>
</property>
<property name="maximum">
<number>192000</number>
<number>500000</number>
</property>
<property name="value">
<number>48000</number>
<number>44100</number>
</property>
</widget>
</item>
......@@ -66,7 +66,7 @@
<number>5</number>
</property>
<property name="value">
<number>2</number>
<number>1</number>
</property>
</widget>
</item>
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>306</width>
<height>154</height>
<height>182</height>
</rect>
</property>
<property name="windowTitle">
......@@ -43,10 +43,10 @@
<number>4000</number>
</property>
<property name="maximum">
<number>192000</number>
<number>500000</number>
</property>
<property name="value">
<number>48000</number>
<number>44100</number>
</property>
</widget>
</item>
......@@ -66,7 +66,7 @@
<number>5</number>
</property>
<property name="value">
<number>2</number>
<number>1</number>
</property>
</widget>
</item>
......
cmake_minimum_required(VERSION 3.5)
add_subdirectory(mod_fm)
add_subdirectory(mod_fm_dem)
add_subdirectory(transform_fft)
add_subdirectory(filter_fir)
add_subdirectory(resample_pqfraction)
cmake_minimum_required(VERSION 3.5)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
include_directories(${TASKBUS_INTERFACEDIR})
set(PRJ_SOURCES
main.cpp
info.qrc
)
#############Target======================
add_executable(mod_fm_dem
${PRJ_SOURCES}
)
target_link_libraries(mod_fm_dem Qt${QT_VERSION_MAJOR}::Core)
<RCC>
<qresource prefix="/">
<file>mod_fm_dem.json</file>
</qresource>
</RCC>
#include <QCoreApplication>
#include <QVector>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <string>
#include <QFile>
#include "cmdlineparser.h"
#include "tb_interface.h"
using namespace TASKBUS;
const int OFFLINEDEBUG = 0;
//数据源方法
int do_mod_fm_dem(const cmdlineParser & args);
//全局的终止标记
static bool bfinished = false;
using namespace std;
int main(int argc , char * argv[])
{
QCoreApplication a(argc, argv);
//重要!设置输入输出为二进制!
init_client();
//解释命令行
cmdlineParser args;
if (OFFLINEDEBUG==0)
args.parser(argc,argv);
else
{
FILE * old_stdin, *old_stdout;
auto ars = debug("/home/goldenhawking/projects/taskbus/bin_linux_64/bin/debug/pid4113",&old_stdin,&old_stdout);
args.parser(ars);
}
int ret = 0;
//每个模块要响应 --information参数,打印自己的功能定义字符串。或者提供一个json文件。
if (args.contains("information"))
{
QFile fp(":/mod_fm_dem.json");
fp.open(QIODevice::ReadOnly);
if (fp.isOpen())
{
QByteArray arr = fp.readAll();
arr.push_back('\0');
puts(arr.constData());
fflush(stdout);
}
return 0;
}
else if (args.contains("function"/*,"mod_fm"*/))//正常运行模式
{
ret = do_mod_fm_dem(args);
}
else
{
fprintf(stderr,"Error:Function does not exits.");
ret = -1;
}
return ret;
}
#define Pi 3.14159265354
int do_mod_fm_dem(const cmdlineParser & args)
{
using namespace TASKBUS;
int res = 0;
//获得平台告诉自己的实例名
const unsigned int instance = args.toInt("instance",0);
const unsigned int itmstamp_in = args.toUInt("tmstamp_in",0);
const unsigned int itmstamp_out = args.toUInt("tmstamp_out",0);
const unsigned int isig = args.toInt("signal",0);
const unsigned int osound = args.toInt("sound",0);
//工作模式
try{
//判断参数合法性
if (instance==0)
throw "function=quit;{\"error\":\"instance is 0, quit.\"}";
int failed_header = 0;
int last_i = 0, last_q = 0;
while (false==bfinished)
{
subject_package_header header;
vector<unsigned char> packagedta = pull_subject(&header);
if (is_valid_header(header)==false)
{
if (++failed_header>16)
bfinished = true;
continue;
}
if ( is_control_subject(header))
{
//收到命令进程退出的广播消息,退出
if (strstr(control_subject(header,packagedta).c_str(),"function=quit;")!=nullptr)
bfinished = true;
}
else if (header.subject_id==itmstamp_in)
{
const unsigned char * pdta = (unsigned char *) packagedta.data();
if (itmstamp_out)
{
push_subject(itmstamp_out,instance,packagedta.size(),
pdta
);
}
}
else if (header.subject_id == isig)
{
std::vector<short> vec_output;
const unsigned char * pdta = packagedta.data();
const int nPts = header.data_length / sizeof(short)/2;
const short (* pdata)[2] = (const short (*)[2])pdta;
for (int j=0;j<nPts;++j)
{
//前后差分
int curr_i = pdata[j][0];
int curr_q = pdata[j][1];
//Diff for e(ja(t)) * e(-ja(t+1)), diff phase = freq
// (lastI + j*lastQ) * (currI - j * currQ)
int diff_i = last_i * curr_i + last_q * curr_q;
int diff_q = last_q * curr_i - last_i * curr_q;
double angle = 0;
//计算角度
if (diff_i==0)
angle = (diff_q>0)? Pi/2:-Pi/2;
else if (diff_i >0 )
angle = atan(diff_q*1.0/diff_i);
else if (diff_q >=0)
angle = atan(diff_q*1.0/diff_i)+Pi;
else
angle = atan(diff_q*1.0/diff_i)-Pi;
last_i = curr_i;
last_q = curr_q;
vec_output.push_back(angle/Pi*4096);
}
//播发
if (osound)
{
push_subject(osound,instance,vec_output.size()*2,
(unsigned char *)vec_output.data()
);
}
}
}
}
catch (const char * errMessage)
{
//向所有部位广播,偶要退出。
push_subject(control_subect_id(),/*instance,broadcast_destin_id(),*/0,errMessage);
fprintf(stderr,"Error:%s.",errMessage);
fflush (stderr);
res = -1;
}
return res;
}
{
"mod_fm_dem":{
"name":"fm_dem",
"parameters":{
},
"input_subjects":
{
"signal":{
"type":"vector",
"tooltip":"fm signal"
},
"tmstamp_in":{
"type":"unsigned long long",
"tooltip":"tmstamp_in"
}
},
"output_subjects":{
"sound":{
"type":"byte",
"tooltip":"sound"
},
"tmstamp_out":{
"type":"unsigned long long",
"tooltip":"tmstamp_out"
}
}
}
}
TEMPLATE = app
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
INCLUDEPATH += ../../../tb_interface
DESTDIR = $$OUT_PWD/../../../bin/modules
SOURCES += \
main.cpp
RESOURCES += \
info.qrc
\ No newline at end of file
{
"mod0": {
"uhd_usrp_io": {
"input_subjects": {
"tx_time": {
"instance_value": "",
"tooltip": "tx_time",
"type": "uint64+double"
},
"wav_tx0": {
"instance_value": "",
"tooltip": "TX0",
"type": "short[2]"
},
"wav_tx1": {
"instance_value": "",
"tooltip": "TX1",
"type": "short[2]"
}
},
"instance": {
"additional_args": "nice=0;",
"exec": "modules/uhd_usrp_io",
"instance_value": 1
},
"name": {
"name": "UHD收发"
},
"output_subjects": {
"rx_time": {
"instance_value": 0,
"tooltip": "rx_time",
"type": "uint64+double"
},
"wav_rx0": {
"instance_value": 3,
"tooltip": "RX0",
"type": "short[2]"
},
"wav_rx1": {
"instance_value": "",
"tooltip": "RX1",
"type": "short[2]"
}
},
"parameters": {
"dev_args": {
"default": "",
"instance_value": "",
"tooltip": "设备初始化参数.",
"type": "string"
},
"rx_agc": {
"default": "0,0",
"instance_value": "0,0",
"range": "0=off,1=on",
"tooltip": "接收AGC开关",
"type": "int"
},
"rx_atn": {
"default": "RX2,RX2",
"instance_value": "RX2",
"range": "TX/RX,RX2",
"tooltip": "接收天线名称",
"type": "string"
},
"rx_bw": {
"default": "1.0,1.0",
"instance_value": "0.2,0.2",
"tooltip": "接收滤波器带宽(MHz)",
"type": "double"
},
"rx_channels": {
"default": "0,1",
"instance_value": "0",
"range": "0,1",
"tooltip": "接收各个通道号",
"type": "int"
},
"rx_gain": {
"default": "30.0,30.0",
"instance_value": "50",
"range": "0-100",
"tooltip": "接收增益(dB)",
"type": "double"
},
"rx_on": {
"default": "0",
"instance_value": "1",
"tooltip": "接收开关",
"type": "int"
},
"rx_rate": {
"default": 1,
"instance_value": "0.5",
"tooltip": "RX采样率(MHz)",
"type": "int"
},
"rx_rf": {
"default": "99.0,101.1",
"instance_value": "99.0",
"range": "0-6000",
"tooltip": "接收频率(MHz)",
"type": "double"
},
"tx_atn": {
"default": "TX/RX,TX/RX",
"instance_value": "TX/RX,TX/RX",
"tooltip": "发射天线名称",
"type": "string"
},
"tx_bw": {
"default": "1.0,1.0",
"instance_value": "1.0,1.0",
"tooltip": "发射滤波器带宽(MHz)",
"type": "double"
},
"tx_channels": {
"default": "0,1",
"instance_value": "0,1",
"tooltip": "发射各个通道",
"type": "int"
},
"tx_gain": {
"default": "30.0,30.0",
"instance_value": "30.0,30.0",
"range": "0-100",
"tooltip": "发射增益(dB)",
"type": "double"
},
"tx_on": {
"default": 0,
"instance_value": 0,
"tooltip": "发射开关",
"type": "int"
},
"tx_rate": {
"default": 1,
"instance_value": 1,
"tooltip": "TX采样率(MHz)",
"type": "int"
},
"tx_rf": {
"default": "200.0,203.0",
"instance_value": "200.0,203.0",
"range": "0-6000",
"tooltip": "发射频率(MHz)",
"type": "double"
}
}
}
},
"mod1": {
"transform_fft": {
"input_subjects": {
"signal": {
"instance_value": 8,
"tooltip": "signal",
"type": "byte"
},
"tmstamp_in": {
"instance_value": 0,
"tooltip": "tmstamp_in",
"type": "uint64"
}
},
"instance": {
"additional_args": "nice=0;",
"exec": "modules/transform_fft",
"instance_value": 2
},
"name": {
"name": "libfftw"
},
"output_subjects": {
"FFT": {
"instance_value": 4,
"tooltip": "FFT in dB",
"type": "vector"
},
"Spec": {
"instance_value": "",
"tooltip": "Spec in Complex",
"type": "vector"
},
"tmstamp_out": {
"instance_value": 0,
"tooltip": "tmstamp_out",
"type": "uint64"
}
},
"parameters": {
"channels": {
"default": 1,
"instance_value": 1,
"tooltip": "Channels",
"type": "int"
},
"fftsize": {
"default": 1024,
"instance_value": 1024,
"tooltip": "fft size",
"type": "int"
},
"input_type": {
"default": 0,
"instance_value": "1",
"tooltip": "0=Real,1=Complex",
"type": "int"
},
"sptype": {
"default": 0,
"instance_value": 0,
"range": {
"0": "16 bit Intel",
"1": "16 bit Moto",
"2": "int8",
"3": "uint8"
},
"tooltip": "sample point format",
"type": "enum"
}
}
}
},
"mod2": {
"sink_plots": {
"input_subjects": {
"plot0": {
"instance_value": 9,
"tooltip": "input0",
"type": "byte"
},
"plot1": {
"instance_value": 4,
"tooltip": "input1",
"type": "byte"
},
"plot2": {
"instance_value": "",
"tooltip": "input2",
"type": "byte"
},
"plot3": {
"instance_value": "",
"tooltip": "input3",
"type": "byte"
},
"plot4": {
"instance_value": "",
"tooltip": "input4",
"type": "byte"
}
},
"instance": {
"additional_args": "nice=0;",
"exec": "modules/sink_plots",
"instance_value": 3
},
"name": {
"name": "plots"
},
"parameters": {
"channels": {
"default": "1,1,1,1,1,1",
"instance_value": "0,0",
"range": {
"tip": "0:1d spectrogram 1: 1d wav or 2:2d xy"
},
"tooltip": "各路通道数",
"type": "string"
},
"datatypes": {
"default": "9,9,9,9,9",
"instance_value": "9,9,9,9,9",
"range": {
"value": "0:uint8 1:int8 2:uint16 3:int16 4:uint32 5:int32 6:uint64 7:int64 8:float 9:double"
},
"tooltip": "各路数据类型",
"type": "string"
}
},
"version": {
"version": "1,1,0"
}
}
},
"mod3": {
"resample_pqfraction": {
"input_subjects": {
"in": {
"instance_value": 3,
"tooltip": "Input",
"type": "byte"
},
"in_time": {
"instance_value": 1,
"tooltip": "Input timestamp",
"type": "timestamp"
}
},
"instance": {
"additional_args": "nice=0;",
"exec": "modules/resample_pqfraction",
"instance_value": 4
},
"name": {
"name": "resamplepq"
},
"output_subjects": {
"out": {
"instance_value": 8,
"tooltip": "Output",
"type": "vector"
},
"out_time": {
"instance_value": 0,
"tooltip": "Out timestamp",
"type": "timestamp"
}
},
"parameters": {
"np": {
"default": "1",
"instance_value": "200",
"range": "N",
"tooltip": "new rate",
"type": "int"
},
"nq": {
"default": "1",
"instance_value": "500",
"range": "N",
"tooltip": "old rate",
"type": "int"
},
"sptype": {
"default": 0,
"instance_value": 0,
"range": {
"0": "16 bit Intel",
"1": "16 bit Moto",
"2": "int8",
"3": "uint8"
},
"tooltip": "sample point format",
"type": "enum"
},
"type": {
"default": "1",
"instance_value": "1",
"range": "0:real,1:complex",
"tooltip": "type",
"type": "int"
}
}
}
},
"mod4": {
"sink_soundcard": {
"input_subjects": {
"timestamp_in": {
"instance_value": 0,
"tooltip": "timestamp ref",
"type": "uint64"
},
"wav": {
"instance_value": 5,
"tooltip": "Sample Points",
"type": "bytes"
}
},
"instance": {
"additional_args": "nice=0;",
"exec": "modules/sink_soundcard",
"instance_value": 5
},
"name": {
"name": "soundcard"
},
"parameters": {
"autostart": {
"default": 0,
"instance_value": "1",
"tooltip": "auto start",
"type": "int"
},
"channel": {
"default": 2,
"instance_value": "1",
"tooltip": "channels",
"type": "int"
},
"device": {
"default": "default",
"instance_value": "default",
"tooltip": "device name",
"type": "string"
},
"hide": {
"default": 0,
"instance_value": 0,
"tooltip": "hide window when start",
"type": "int"
},
"sample_rate": {
"default": 44100,
"instance_value": "32000",
"range": {
"desc": "8000~192000"
},
"tooltip": "sample rate (Hz)",
"type": "int"
}
}
}
},
"mod5": {
"mod_fm_dem": {
"input_subjects": {
"signal": {
"instance_value": 8,
"tooltip": "fm signal",
"type": "vector"
},
"tmstamp_in": {
"instance_value": 0,
"tooltip": "tmstamp_in",
"type": "unsigned long long"
}
},
"instance": {
"additional_args": "nice=0;",
"exec": "modules/mod_fm_dem",
"instance_value": 6
},
"name": {
"name": "fm_dem"
},
"output_subjects": {
"sound": {
"instance_value": 2,
"tooltip": "sound",
"type": "byte"
},
"tmstamp_out": {
"instance_value": 0,
"tooltip": "tmstamp_out",
"type": "unsigned long long"
}
}
}
},
"mod6": {
"resample_pqfraction": {
"input_subjects": {
"in": {
"instance_value": 2,
"tooltip": "Input",
"type": "byte"
},
"in_time": {
"instance_value": "",
"tooltip": "Input timestamp",
"type": "timestamp"
}
},
"instance": {
"additional_args": "nice=0;",
"exec": "modules/resample_pqfraction",
"instance_value": 7
},
"name": {
"name": "resamplepq"
},
"output_subjects": {
"out": {
"instance_value": 5,
"tooltip": "Output",
"type": "vector"
},
"out_time": {
"instance_value": "",
"tooltip": "Out timestamp",
"type": "timestamp"
}
},
"parameters": {
"np": {
"default": "1",
"instance_value": "32000",
"range": "N",
"tooltip": "new rate",
"type": "int"
},
"nq": {
"default": "1",
"instance_value": "200000",
"range": "N",
"tooltip": "old rate",
"type": "int"
},
"sptype": {
"default": 0,
"instance_value": 0,
"range": {
"0": "16 bit Intel",
"1": "16 bit Moto",
"2": "int8",
"3": "uint8"
},
"tooltip": "sample point format",
"type": "enum"
},
"type": {
"default": "1",
"instance_value": "1",
"range": "0:real,1:complex",
"tooltip": "type",
"type": "int"
}
}
}
},
"pos0": {
"x": 1519,
"y": 1375
},
"pos1": {
"x": 2078,
"y": 1340
},
"pos2": {
"x": 2383,
"y": 1327
},
"pos3": {
"x": 1805,
"y": 1467
},
"pos4": {
"x": 2649,
"y": 1414
},
"pos5": {
"x": 2085,
"y": 1511
},
"pos6": {
"x": 2378,
"y": 1518
},
"total_mods": 7
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册