加入 BPSK 封包

上级 26d5c159
......@@ -17,7 +17,10 @@ build/
bld/
[Bb]in/
[Oo]bj/
.kde*
kde*.*
*.del*
build*/
# Roslyn cache directories
*.ide/
......
{
"mod0": {
"control_pannel": {
"instance": {
"additional_args": "nice=2;",
"batchtime": 20,
"exec": "modules/control_pannel",
"instance_value": 1
},
"name": {
"name": "CtrlPannel"
},
"version": {
"version": "1,1,0"
}
}
},
"mod1": {
"network_pcaphub": {
"input_subjects": {
"packin": {
"instance_value": 0,
"tooltip": "packin",
"type": "bytes"
}
},
"instance": {
"additional_args": "IND=1;OUTD=-1;nice=2;",
"batchtime": 20,
"exec": "../../build-pcaphub-dskqt6-Release/pcapHub",
"instance_value": 2
},
"name": {
"name": "pcap_hub"
},
"output_subjects": {
"packout": {
"instance_value": 1,
"tooltip": "packout",
"type": "bytes"
}
},
"parameters": {
"autostart": {
"default": 0,
"instance_value": 0,
"tooltip": "auto start",
"type": "int"
},
"hide": {
"default": 0,
"instance_value": 0,
"tooltip": "hide window when start",
"type": "int"
}
}
}
},
"mod2": {
"a2psk_encap": {
"input_subjects": {
"input": {
"instance_value": 1,
"tooltip": "package",
"type": "byte"
},
"water_mark": {
"instance_value": 7,
"tooltip": "water mark for uhd",
"type": "int"
}
},
"instance": {
"additional_args": "IND=5,2;nice=0;",
"batchtime": 20,
"exec": "../../build-taskbus_course-dskqt5-Release/modules/a2psk_encap",
"instance_value": 3
},
"name": {
"name": "a2psk_encap"
},
"output_subjects": {
"output": {
"instance_value": 10,
"tooltip": "encap signal",
"type": "vector"
}
},
"parameters": {
"min_watermark": {
"default": 10000,
"instance_value": "40000",
"tooltip": "Min Watermark",
"type": "long long"
}
}
}
},
"mod3": {
"uhd_usrp_io": {
"input_subjects": {
"tx_time": {
"instance_value": "",
"tooltip": "tx_time",
"type": "uint64+double"
},
"wav_tx0": {
"instance_value": 11,
"tooltip": "TX0",
"type": "short[2]"
},
"wav_tx1": {
"instance_value": "",
"tooltip": "TX1",
"type": "short[2]"
}
},
"instance": {
"additional_args": "OUTD=1,-2;nice=0;",
"batchtime": 20,
"exec": "modules/uhd_usrp_io",
"instance_value": 4
},
"name": {
"name": "UHD收发"
},
"output_subjects": {
"rx_time": {
"instance_value": "",
"tooltip": "rx_time",
"type": "uint64+double"
},
"tx_mark": {
"instance_value": 7,
"tooltip": "TXWaterMark",
"type": "int64"
},
"wav_rx0": {
"instance_value": "",
"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": "1",
"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": "30",
"range": "0-100",
"tooltip": "接收增益(dB)",
"type": "double"
},
"rx_on": {
"default": "0",
"instance_value": "0",
"tooltip": "接收开关",
"type": "int"
},
"rx_rate": {
"default": 1,
"instance_value": 1,
"tooltip": "RX采样率(MHz)",
"type": "int"
},
"rx_rf": {
"default": "99.0,101.1",
"instance_value": "220",
"range": "0-6000",
"tooltip": "接收频率(MHz)",
"type": "double"
},
"tx_atn": {
"default": "TX/RX,TX/RX",
"instance_value": "TX/RX",
"tooltip": "发射天线名称",
"type": "string"
},
"tx_bw": {
"default": "1.0,1.0",
"instance_value": "1",
"tooltip": "发射滤波器带宽(MHz)",
"type": "double"
},
"tx_channels": {
"default": "0,1",
"instance_value": "0",
"tooltip": "发射各个通道",
"type": "int"
},
"tx_gain": {
"default": "30.0,30.0",
"instance_value": "80",
"range": "0-100",
"tooltip": "发射增益(dB)",
"type": "double"
},
"tx_on": {
"default": 0,
"instance_value": "1",
"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",
"range": "0-6000",
"tooltip": "发射频率(MHz)",
"type": "double"
}
}
}
},
"mod4": {
"a2psk_mod": {
"input_subjects": {
"input": {
"instance_value": 10,
"tooltip": "encap msg",
"type": "byte"
}
},
"instance": {
"additional_args": "nice=0;",
"batchtime": 20,
"exec": "../../build-taskbus_course-dskqt5-Release/modules/a2psk_mod",
"instance_value": 5
},
"name": {
"name": "a2psk_mod"
},
"output_subjects": {
"output": {
"instance_value": 11,
"tooltip": "iq16bits",
"type": "vector"
}
}
}
},
"pos0": {
"x": 1706,
"y": 1545
},
"pos1": {
"x": 2137,
"y": 1292
},
"pos2": {
"x": 1702,
"y": 1384
},
"pos3": {
"x": 2375,
"y": 1514
},
"pos4": {
"x": 2035,
"y": 1590
},
"total_mods": 5
}
......@@ -4,3 +4,5 @@ add_subdirectory(a1frame_encap)
add_subdirectory(a1frame_askmod)
add_subdirectory(a1frame_askdem)
add_subdirectory(a1frame_decap)
add_subdirectory(a2psk_encap)
add_subdirectory(a2psk_mod)
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 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
include_directories(${TCOURSE_INTERFACEDIR})
set(PRJ_SOURCES
main.cpp
resource.qrc
)
#############Target======================
add_executable(a2psk_encap
${PRJ_SOURCES}
)
target_link_libraries(a2psk_encap Qt${QT_VERSION_MAJOR}::Core)
{
"a2psk_encap":{
"name":"a2psk_encap",
"parameters":{
"min_watermark":{
"type":"long long",
"tooltip":"Min Watermark",
"default":10000
}
},
"input_subjects":
{
"input":{
"type":"byte",
"tooltip":"package"
},
"water_mark":{
"type":"int",
"tooltip":"water mark for uhd"
}
},
"output_subjects":{
"output":{
"type":"vector",
"tooltip":"encap signal"
}
}
}
}
#include <QCoreApplication>
#include <QFile>
#include <QVector>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <thread>
#include <iterator>
#include <mutex>
#include <string>
#include <QTextStream>
#include <QThread>
#include "cmdlineparser.h"
#include "tb_interface.h"
using namespace TASKBUS;
const int OFFLINEDEBUG = 0;
//处理逻辑
int do_function(const cmdlineParser & args);
std::vector<unsigned char> alg_encap(const std::vector<unsigned char> & input,bool dummy = false);
//全局的终止标记
static bool bfinished = false;
using namespace std;
//Global queue
std::list<std::vector<unsigned char> > g_vec_sendqueue;
std::mutex g_vec_mutex;
int i_watermark =0;
std::atomic<long long> g_watermark (-1);
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("/debug/pid4213",&old_stdin,&old_stdout);
args.parser(ars);
}
int ret = 0;
//每个模块要响应 --information参数,打印自己的功能定义字符串。或者提供一个json文件。
if (args.contains("information"))
{
QFile file(":/function.json");
if (file.open(QIODevice::ReadOnly))
{
QByteArray arr = file.readAll();
QTextStream st(stdout);
st << QString::fromUtf8(arr);
st.flush();
}
ret = -1;
}
else if (args.contains("function"/*,"do_function"*/))//正常运行模式
{
ret = do_function(args);
}
else
{
fprintf(stderr,"Error:Function does not exits.");
ret = -1;
}
return ret;
}
int do_function(const cmdlineParser & args)
{
using namespace TASKBUS;
int res = 0;
//获得平台告诉自己的实例名
const unsigned int instance = args.toInt("instance",0);
const unsigned int sub_input = args.toInt("input",0);
const unsigned int i_watermark = args.toInt("water_mark",0);
const unsigned int sub_output = args.toInt("output",0);
//Watermark feedback
const long long minmark = args.toInt64("min_watermark",0);
std::thread send_thread(
[&]()->void{
unsigned long long g_packs = 0,g_dummy = 0;
while (false==bfinished)
{
//水位控制
if (minmark > 0 && i_watermark > 0)
{
while(g_watermark > minmark || g_watermark==-1)
{
QThread::msleep(10);
}
}
std::vector<unsigned char> out ;
g_vec_mutex.lock();
if(g_vec_sendqueue.size()>0)
{
out = std::move(*g_vec_sendqueue.begin());
g_vec_sendqueue.pop_front();
}
g_vec_mutex.unlock();
if (sub_output && out.size())
{
TASKBUS::push_subject(sub_output,instance,out.size(),out.data());
++g_packs;
}
else if (sub_output && i_watermark > 0 && minmark > 0)
{
static std::vector<unsigned char> pkdummy{0,0,0,0};
unsigned short * pkp = (unsigned short * ) pkdummy.data();
*pkp = g_packs % 65536;
pkp = (unsigned short * ) (pkdummy.data() + 2);
*pkp = g_dummy % 65536;
out = alg_encap(pkdummy);
TASKBUS::push_subject(sub_output,instance,out.size(),out.data());
++g_dummy;
}
else
QThread::msleep(10);
}
}
);
try{
//判断参数合法性
if (instance==0)
throw "function=quit;{\"error\":\"instance is 0, quit.\"}";
int failed_header = 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 == sub_input && packagedta.size() )
{
std::vector<unsigned char> out = alg_encap(packagedta);
g_vec_mutex.lock();
g_vec_sendqueue.push_back(std::move(out));
g_vec_mutex.unlock();
}
else if (header.subject_id==i_watermark&& packagedta.size())
{
if (header.data_length>=8)
{
long long * ptr = (long long *)packagedta.data();
g_watermark = *ptr;
}
}
}
}
catch (const char * errMessage)
{
//向所有部位广播,偶要退出。
push_subject(control_subect_id(),/*instance,broadcast_destin_id(),*/0,errMessage);
fprintf(stderr,"Error:%s.",errMessage);
fflush (stderr);
res = -1;
}
send_thread.join();
return res;
}
static long long total_packs = 0;
std::vector<unsigned char> alg_encap(const std::vector<unsigned char> & inputData,bool dummy)
{
std::vector<unsigned char> err;
//Checksum
std::vector<unsigned char> input;
input.push_back(dummy?0:0x66);
std::copy(inputData.begin(),inputData.end(),std::back_inserter(input));
unsigned int vsum = 0;
unsigned char * psum = (unsigned char *) &vsum;
for (int i=0;i<input.size();++i)
{
unsigned int vl = (vsum >>24) &0xff;
unsigned int vr = input[i] ^ vl;
vsum <<=8;
vsum ^=vr;
}
input.push_back(psum[0]);
input.push_back(psum[1]);
input.push_back(psum[2]);
input.push_back(psum[3]);
unsigned long long len = input.size();
if (len >=65536)
return err;
//Bit encap
std::vector<unsigned char> bitspan{0,1,1,1,1,1,1,0};
unsigned char scm[15] = {1,0,1,1,0,0,1,1,1,1,0,0,1,1,0};
int cnt = 0;
for (int i=0;i<len;++i)
{
for (int j=0;j<8;++j)
{
const int b = (input[i]>>j)&0x01;
const int ib = i *8 + j;
const int c = b ^ scm[ib % 15];
scm[ib%15] ^= (scm[(ib+13)%15] ^ scm[(ib+14)%15]);
bitspan.push_back(c);
if (c)
{
++cnt;
if (cnt==5)
{
bitspan.push_back(0);
cnt = 0;
}
}
}
}
//1/2 conv code OCT 133,171, continous with static
static unsigned char reg[6] = {0,0,0,0,0,0};
std::vector<unsigned char> vec_bits;
const int bitlen = bitspan.size();
//xor code
for (int i=0;i<bitlen;++i)
{
const int c = bitspan[i];
vec_bits.push_back(c^reg[1]^reg[2]^reg[4]^reg[5]);
vec_bits.push_back(c^reg[0]^reg[1]^reg[2]^reg[5]);
reg[5] = reg[4];
reg[4] = reg[3];
reg[3] = reg[2];
reg[2] = reg[1];
reg[1] = reg[0];
reg[0] = c;
}
if (++total_packs % 100==0)
{
fprintf(stderr,"Encaped %lld caps.curr Watermark = %lld\n",total_packs,(long long)g_watermark);
}
return vec_bits;
}
<RCC>
<qresource prefix="/">
<file>function.json</file>
</qresource>
</RCC>
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 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
include_directories(${TCOURSE_INTERFACEDIR})
set(PRJ_SOURCES
main.cpp
resource.qrc
)
#############Target======================
add_executable(a2psk_mod
${PRJ_SOURCES}
)
target_link_libraries(a2psk_mod Qt${QT_VERSION_MAJOR}::Core)
{
"a2psk_mod":{
"name":"a2psk_mod",
"parameters":{
},
"input_subjects":
{
"input":{
"type":"byte",
"tooltip":"encap msg"
}
},
"output_subjects":{
"output":{
"type":"vector",
"tooltip":"iq16bits"
}
}
}
}
#include <QCoreApplication>
#include <QFile>
#include <QVector>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <string>
#include <QTextStream>
#include "cmdlineparser.h"
#include "tb_interface.h"
using namespace TASKBUS;
const int OFFLINEDEBUG = 0;
//处理逻辑
int do_function(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("/debug/pid4213",&old_stdin,&old_stdout);
args.parser(ars);
}
int ret = 0;
//每个模块要响应 --information参数,打印自己的功能定义字符串。或者提供一个json文件。
if (args.contains("information"))
{
QFile file(":/function.json");
if (file.open(QIODevice::ReadOnly))
{
QByteArray arr = file.readAll();
QTextStream st(stdout);
st << QString::fromUtf8(arr);
st.flush();
}
ret = -1;
}
else if (args.contains("function"/*,"do_function"*/))//正常运行模式
{
ret = do_function(args);
}
else
{
fprintf(stderr,"Error:Function does not exits.");
ret = -1;
}
return ret;
}
int do_function(const cmdlineParser & args)
{
using namespace TASKBUS;
int res = 0;
//获得平台告诉自己的实例名
const unsigned int instance = args.toInt("instance",0);
const unsigned int sub_input = args.toInt("input",0);
const unsigned int sub_output = args.toInt("output",0);
try{
//判断参数合法性
if (instance==0)
throw "function=quit;{\"error\":\"instance is 0, quit.\"}";
int failed_header = 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 == sub_input && packagedta.size())
{
static const double fir_rcos_q25[25] = {-0.018773,0.0030136,0.032677,0.047094,0.02655,-0.027522,-0.085225,-0.099447,-0.032147,0.11904,0.31118,0.472,0.53463,0.472,0.31118,0.11904,-0.032147,-0.099447,-0.085225,-0.027522,0.02655,0.047094,0.032677,0.0030136,-0.018773};
static double fir_cache[25] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
static unsigned long long fir_clock = 0;
std::vector<short> signal;
for (int i=0;i<packagedta.size();++i)
{
//x4
double maxc = 0;
for (int sym = 0; sym< 4;++sym)
{
fir_cache[fir_clock % 25] = sym==0?(packagedta[i]==1?1:-1):0;
double fval = 0;
for (int f=0;f<25;++f)
fval += fir_cache[(fir_clock + 1 + f) % 25] * fir_rcos_q25[f];
++fir_clock;
if (maxc < fval)
maxc= fval;
signal.push_back(fval * 8192);
signal.push_back(0);
}
//fprintf(stderr,"%lf ",maxc);
}
if (sub_output && signal.size())
{
TASKBUS::push_subject(sub_output,instance,signal.size()*2,(unsigned char *)signal.data());
//fprintf(stderr,"%d IQ bits emitted.",signal.size()/2);
}
}
}
}
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;
}
<RCC>
<qresource prefix="/">
<file>function.json</file>
</qresource>
</RCC>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册