首次提交
This commit is contained in:
@@ -0,0 +1,266 @@
|
||||
#include "Dll_Global.h"
|
||||
|
||||
#include "../../../../core_library/Core/Core/Base/JSON.h"
|
||||
#include "Core/Base/SM_RingBuffer.h"
|
||||
|
||||
Dll_Global *dg = new Dll_Global();
|
||||
|
||||
std::string Dll_Global::get_config_path() { return get_exe_dir() + "/" + "data_progress_config.json"; }
|
||||
|
||||
void Dll_Global::init_when_exe() {
|
||||
rb = new SM_RingBuffer;
|
||||
rb->init("rb", 2112 * 1000);
|
||||
json_func_call = new SM_RingBuffer;
|
||||
json_func_call->init("json_func_call2", 1000);
|
||||
mode_acs = new SM_RingBuffer;
|
||||
mode_acs->init("mode_acs", 2112 * 1000);
|
||||
|
||||
|
||||
void* lib;
|
||||
{
|
||||
auto r = try_load_library(Psc::get_abs_path(library_path));
|
||||
if (!r) {
|
||||
Psc::fail_fast();
|
||||
}
|
||||
lib = r.value();
|
||||
}
|
||||
|
||||
{
|
||||
auto r = Psc::try_load_function(lib, "adsb_set_iq_cbk");
|
||||
if (!r) {
|
||||
Psc::fail_fast();
|
||||
}
|
||||
set_iq_cbk = (adsb_set_iq_cbk_t)r.value();
|
||||
}
|
||||
{
|
||||
auto r = Psc::try_load_function(lib, "adsb_set_less_30Mhz_ddc_param");
|
||||
if (!r) {
|
||||
Psc::fail_fast();
|
||||
}
|
||||
set_less_30Mhz_ddc_param = (adsb_set_less_30Mhz_ddc_param_t)r.value();
|
||||
}
|
||||
{
|
||||
auto r = Psc::try_load_function(lib, "adsb_set_less_30Mhz_fft_param");
|
||||
if (!r) {
|
||||
Psc::fail_fast();
|
||||
}
|
||||
set_less_30Mhz_fft_param = (adsb_set_less_30Mhz_fft_param_t)r.value();
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::cout << "set_less_30Mhz_ddc_param " << VAR_STR_3(center_freq, sample_rate, band_width) << std::endl;
|
||||
set_less_30Mhz_ddc_param(center_freq, sample_rate, band_width, 1);
|
||||
std::cout << "set_less_30Mhz_fft_param " << VAR_STR_3(center_freq, sample_rate, band_width) << std::endl;
|
||||
set_less_30Mhz_fft_param(fft_win_type, fft_point_number, fft_period_ms, 1);
|
||||
std::cout << "set_iq_cbk " << std::endl;
|
||||
set_iq_cbk(
|
||||
[](void *phandle, void *pdata, uint64_t length) {
|
||||
if (length != 2112) {
|
||||
std::cout << LOG_POS << " IQ回调传入的长度不对!" << std::endl;
|
||||
return;
|
||||
}
|
||||
auto dg = (Dll_Global *) phandle;
|
||||
//
|
||||
dg->handle_2112(pdata);
|
||||
|
||||
// auto sk = (UHD_Struct_KFFT *) pdata;
|
||||
// std::cout << (int)sk->DataType << std::endl;
|
||||
|
||||
//dg->iq_memory_buffer.push(pdata, length); // length 永远等于2112
|
||||
},
|
||||
this);
|
||||
}
|
||||
void Dll_Global::init_when_dll() {
|
||||
|
||||
Detach_Thread_Manager &manager = dtm;
|
||||
|
||||
manager.test_and_start_thread("Dll_Global", [&](std::atomic<bool>& run) {
|
||||
std::mt19937 rng(std::random_device{}()); // 随机数引擎
|
||||
std::uniform_int_distribution<uint16_t> dist(0 * 256, 70 * 256);
|
||||
constexpr int size = 64 + 1024 * sizeof(uint16_t);
|
||||
uint8_t buf[size];
|
||||
|
||||
while (run) {
|
||||
int fn = fft_point_number / 1024;
|
||||
auto sk = (UHD_Struct_KFFT *) buf;
|
||||
|
||||
|
||||
uint16_t *fft = (uint16_t *) (buf + 64);
|
||||
for (int fi = 0; fi < fn; fi++) {
|
||||
sk->DataType = kd_fft;
|
||||
sk->Param.FFT.SubFrame = fi;
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
fft[i] = dist(rng);
|
||||
}
|
||||
give_call_back(buf, size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint64_t sleep_ms = fft_period_ms;
|
||||
uint64_t num = sample_rate / sleep_ms;
|
||||
uint64_t times = num / 2048;
|
||||
if (times < 1) {
|
||||
times = 1;
|
||||
}
|
||||
|
||||
sk->DataType = zd_ddc;
|
||||
uint16_t *iq = (uint16_t *) (buf + 64);
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
auto random = dist(rng);
|
||||
iq[i] = random;
|
||||
}
|
||||
|
||||
sk->UsefullLen = 2048;
|
||||
for (int i = 0; i < times; ++i) {
|
||||
give_call_back(buf, size);
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(fft_period_ms));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Dll_Global::Dll_Global() {
|
||||
auto config = try_parse_json_file(get_config_path());
|
||||
if (!config.has_value()) {
|
||||
std::cout << "Dll_Global 配置文件加载失败!" << std::endl;
|
||||
Psc::fail_fast();
|
||||
}
|
||||
load(&config.value());
|
||||
psm = new std::uint8_t[65536 * 2];
|
||||
}
|
||||
|
||||
Dll_Global::~Dll_Global() {
|
||||
|
||||
|
||||
delete psm;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void adsb_close() {
|
||||
std::cout << " adsb_close()" << std::endl;
|
||||
Dll_Global::instance()->dtm.stop_all_thread();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Dll_Global::save() {
|
||||
std::ofstream config_file;
|
||||
config_file.open(get_config_path());
|
||||
std::string json = to_json().to_json_string();
|
||||
config_file.write(json.c_str(), static_cast<long long>(json.size()));
|
||||
config_file.close();
|
||||
}
|
||||
|
||||
void Dll_Global::give_call_back(std::uint8_t *data, size_t len) {
|
||||
recv_cbk(puser, data, len);
|
||||
auto sk = (UHD_Struct_KFFT *) data;
|
||||
if (sk->DataType == kd_fft) {
|
||||
auto idx_max = fft_point_number/1024;
|
||||
auto idx = sk->Param.FFT.SubFrame;
|
||||
if (idx >= idx_max) {
|
||||
std::cout << "give_call_back idx 越界" << idx << " >= " << idx_max << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Dll_Global::handle_2112_test(void *data) {
|
||||
// 记录开始时间
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
// 调用目标函数
|
||||
handle_2112_pure(data);
|
||||
|
||||
// 记录结束时间
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
|
||||
// 计算持续时间(微秒)
|
||||
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
|
||||
|
||||
// 输出每次调用的时间
|
||||
std::cout << "Average time per call: "
|
||||
<< duration.count() << " microseconds" << std::endl;
|
||||
}
|
||||
|
||||
void Dll_Global::handle_2112(void *data) {
|
||||
handle_2112_pure(data);
|
||||
// static Frequency_Limit fl(freq);
|
||||
// if (fl.test()) {
|
||||
// handle_2112_test(data);
|
||||
// } else {
|
||||
// handle_2112_pure(data);
|
||||
// }
|
||||
}
|
||||
|
||||
void Dll_Global::handle_2112_pure(void *data) {
|
||||
auto d = (UHD_Struct_KFFT *) (data);
|
||||
auto pdata = (std::uint8_t*)data + 64;
|
||||
auto idx_max = fft_point_number/1024;
|
||||
auto type = d->DataType;
|
||||
if (type == kd_fft) {
|
||||
auto idx = d->Param.FFT.SubFrame;
|
||||
if (idx >= idx_max) {
|
||||
std::cout << "idx 越界" << idx << " >= " << idx_max << std::endl;
|
||||
} else {
|
||||
memcpy( psm + idx * 2048, pdata, 2048);
|
||||
}
|
||||
}
|
||||
#if WIN32
|
||||
else if (type == kd_ddc || type == zd_ddc) {
|
||||
dg->rb->write((uint8_t *) data, 2112);
|
||||
} else {
|
||||
Psc::fail_fast();
|
||||
}
|
||||
#else
|
||||
else {
|
||||
dg->rb->write((uint8_t *) data, 2112);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Dll_Global::handle_json_call() {
|
||||
size_t length = 0;
|
||||
uint8_t json_func_data[1000];
|
||||
json_func_call->read(json_func_data, length);
|
||||
|
||||
|
||||
std::string json((const char *) json_func_data, length);
|
||||
if (!json.empty()) {
|
||||
auto func_call = Psc::parse_json(json);
|
||||
auto method = func_call.get_string("method");
|
||||
std::cout << func_call.to_json_string() << std::endl;
|
||||
|
||||
if (method == "adsb_set_less_30Mhz_ddc_param") {
|
||||
center_freq = func_call.get_number<double>("center_freq");
|
||||
sample_rate = func_call.get_number<double>("sample_rate");
|
||||
band_width = func_call.get_number<double>("band_width");
|
||||
auto sw = func_call.get_number<int>("sw");
|
||||
save();
|
||||
set_less_30Mhz_ddc_param(center_freq, sample_rate, band_width, sw);
|
||||
}
|
||||
|
||||
if (method == "adsb_set_less_30Mhz_fft_param") {
|
||||
fft_win_type = (UHD_FFTWin) func_call.get_number<int>("fft_win_type");
|
||||
fft_point_number = func_call.get_number<int>("fft_point_number");
|
||||
fft_period_ms = func_call.get_number<int>("fft_period_ms");
|
||||
auto sw = func_call.get_number<int>("sw");
|
||||
save();
|
||||
set_less_30Mhz_fft_param(fft_win_type, fft_point_number, fft_period_ms, sw);
|
||||
}
|
||||
|
||||
if (method == "restart_device") {
|
||||
std::cout << "关闭进程, 然后会被守护进程拉起来" << std::endl;
|
||||
stop_program = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
void set_error_cbk(error_cbk_t cbk) {}
|
||||
@@ -0,0 +1,94 @@
|
||||
#ifndef PLANTSUNCAT_DLL_GLOBAL_H
|
||||
#define PLANTSUNCAT_DLL_GLOBAL_H
|
||||
#include "main.h"
|
||||
#include <chrono>
|
||||
#include <csignal>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "Core/Base/global_include.h"
|
||||
#include "Core/Shared_Memory/Shared_Memory.h"
|
||||
#include "Core/system/export.h"
|
||||
#include "../Local_Server/DSP/global.h"
|
||||
#include "Core/Base/JSON.h"
|
||||
#include "Core/Base/ThreadManager.h"
|
||||
#include "Core/spdlog/export.h"
|
||||
|
||||
namespace Psc {
|
||||
class SM_RingBuffer;
|
||||
}
|
||||
using namespace Psc;
|
||||
|
||||
|
||||
struct Memory_Buffer {
|
||||
std::vector<std::string*> get_all() {
|
||||
std::lock_guard lock(m);
|
||||
std::swap(cache, data_list);
|
||||
return data_list;
|
||||
}
|
||||
void push(void *pdata, uint64_t length) {
|
||||
auto buf = pool.get();
|
||||
buf->resize(length);
|
||||
std::memcpy(buf->data(), pdata, length);
|
||||
{
|
||||
std::lock_guard lock(m);
|
||||
cache.push_back(buf);
|
||||
}
|
||||
}
|
||||
String_Pool pool = String_Pool(2112, 8 * 1024);
|
||||
protected:
|
||||
std::vector<std::string*> data;
|
||||
std::vector<std::string*> cache;
|
||||
std::vector<std::string*> data_list;
|
||||
Psc::Spin_Lock m;
|
||||
};
|
||||
|
||||
struct BB : Base_DSP {
|
||||
BB() {
|
||||
|
||||
}
|
||||
};
|
||||
#define freq 0.1
|
||||
|
||||
struct Dll_Global : BB, public Singleton<Dll_Global>{
|
||||
SM_RingBuffer *rb{};
|
||||
SM_RingBuffer *json_func_call{};
|
||||
SM_RingBuffer *mode_acs{};
|
||||
// Pure_Share_Memory psm = Pure_Share_Memory("fft_data", 65536);
|
||||
std::uint8_t* psm;
|
||||
|
||||
Memory_Buffer iq_memory_buffer;
|
||||
Detach_Thread_Manager dtm;
|
||||
adsb_set_iq_cbk_t set_iq_cbk;
|
||||
adsb_set_less_30Mhz_ddc_param_t set_less_30Mhz_ddc_param;
|
||||
adsb_set_less_30Mhz_fft_param_t set_less_30Mhz_fft_param;
|
||||
static std::string get_config_path();
|
||||
void init_when_exe();
|
||||
void init_when_dll();
|
||||
Dll_Global();
|
||||
~Dll_Global();
|
||||
|
||||
void save();
|
||||
void handle_json_call();
|
||||
iq_cbk_t recv_cbk{};
|
||||
void *puser{};
|
||||
void give_call_back(std::uint8_t* data, size_t len);
|
||||
|
||||
void handle_2112(void* data);
|
||||
void handle_2112_pure(void* data);
|
||||
|
||||
void handle_2112_test(void* data);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,98 @@
|
||||
#ifndef _DEVICE_UHD_C_H_
|
||||
#define _DEVICE_UHD_C_H_
|
||||
|
||||
|
||||
#include "device_uhd_struct.h"
|
||||
// #include "device_uhd_cpp.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef void (*rx_data_cbk_t)(int channel, void *pdata, int length);
|
||||
|
||||
extern "C"
|
||||
{
|
||||
int32_t ex_declare init9002(void **phandle);
|
||||
int32_t ex_declare free9002(void **phandle);
|
||||
int32_t ex_declare isDevOpened(void *phandle, int32_t *result);
|
||||
// int32_t ex_declare findDevices(void *phandle, uhd::device_addrs_t *addrs);
|
||||
// int32_t ex_declare openDevice(void *phandle,uhd::device_addr_t addr);
|
||||
int32_t ex_declare closeDevice(void *phandle);
|
||||
int32_t ex_declare findDevInfos(void *phandle, char infos[1000]);
|
||||
int32_t ex_declare findDevInfos2(void *phandle, char infos[1000]);
|
||||
int32_t ex_declare getDevTree(void *phandle, char tree_infos[1000]);
|
||||
int32_t ex_declare setDevClockSource(void *phandle, char sourceStr[1000]);
|
||||
int32_t ex_declare getDevClockSource(void *phandle, char sourceStr[1000]);
|
||||
int32_t ex_declare setDevInClock(void *phandle, double clockFreq);
|
||||
int32_t ex_declare getDevInClockRange(void *phandle, double *min, double *max);
|
||||
int32_t ex_declare getDevInClock(void *phandle, double *val);
|
||||
int32_t ex_declare getDevRXChCount(void *phandle, size_t *val);
|
||||
int32_t ex_declare getDevTXChCount(void *phandle, size_t *val);
|
||||
int32_t ex_declare setDevParam(void *phandle, char chStr[50], UHD_ParamType paramType, double paramValue);
|
||||
int32_t ex_declare getDevParam(void *phandle, char chStr[50], UHD_ParamType paramType,double *paramValue);
|
||||
int32_t ex_declare getDevParamMin(void *phandle, double *val);
|
||||
int32_t ex_declare getDevParamMax(void *phandle, double *val);
|
||||
int32_t ex_declare setAllAntenna(void *phandle, int32_t *result);
|
||||
int32_t ex_declare setDevDDCParam_Any(void *phandle, char chStr[50], unsigned int jcqOffset, unsigned int jcqData);
|
||||
int32_t ex_declare getDevDDCParam_Any(void *phandle, char chStr[50], unsigned int jcqOffset, unsigned int *jcqData);
|
||||
int32_t ex_declare setDevDataSwitch(void *phandle, char chStr[50], UHD_ParamType dataType, unsigned char ZDCh, int bSwitch);
|
||||
int32_t ex_declare getDevDataSwitch(void *phandle, char chStr[50], UHD_ParamType dataType, unsigned char ZDCh, int *bSwitch);
|
||||
int32_t ex_declare setDevZDParam(void *phandle, char chStr[50], unsigned char ZDCh, long long centerfreq, int bw, int sample);
|
||||
int32_t ex_declare getDevZDParam(void *phandle, char chStr[50], unsigned char ZDCh, long long *centerfreq, int *bw, int *sample);
|
||||
int32_t ex_declare getDevZDCenterRange(void *phandle, char chStr[50], long long &min, long long &max);
|
||||
int32_t ex_declare getDevZDBandWidthRange(void *phandle, char chStr[50], int &min, int &max);
|
||||
int32_t ex_declare getDevZDSampleFreqRange(void *phandle, char chStr[50], int arr[13], int *valid_len);
|
||||
int32_t ex_declare setDevFFTParam(void *phandle, UHD_FFTWin fftWin, UHD_FFTLen fftLen, int fftPeriod_ms);
|
||||
int32_t ex_declare getDevFFTParam(void *phandle, UHD_FFTWin *fftWin, UHD_FFTLen *fftLen, int *fftPeriod_ms);
|
||||
int32_t ex_declare getDevRecvSpeed(void *phandle, int channel, double *val);
|
||||
int32_t ex_declare isDevRecving(void *phandle,int channel, int32_t *result);
|
||||
int32_t ex_declare startDevRecv(void *phandle, int channel, rx_data_cbk_t rx_cbk);
|
||||
int32_t ex_declare stopDevRecv(void *phandle, int channel);
|
||||
int32_t ex_declare getDevSendSpeed(void *phandle, int channel, double *val);
|
||||
int32_t ex_declare isDevSending(void *phandle, int channel, int32_t *rusult);
|
||||
int32_t ex_declare startDevSend(void *phandle, int channel, unsigned long long send_cf, unsigned long long data_sf, char *filename, int bwhile);
|
||||
int32_t ex_declare stopDevSend(void *phandle, int channel);
|
||||
int32_t ex_declare getGPSInfo(void *phandle, char gps_info[50]);
|
||||
int32_t ex_declare setLedEnable(void *phandle, int led_num, int bEnable);
|
||||
int32_t ex_declare getLedEnable(void *phandle,int led_num, int *bEnable);
|
||||
|
||||
|
||||
|
||||
|
||||
typedef void(*adsb_msg_cbk_t)(void *pusr,char *pmsg,int msglen);
|
||||
|
||||
int32_t ex_declare init_adsb9002(void **phandle,adsb_msg_cbk_t cbk,void *pusr);
|
||||
int32_t ex_declare free_adsb9002(void **phandle);
|
||||
|
||||
|
||||
|
||||
// 新接口 :时间 20251107 ,
|
||||
//TODO: 1 增加 dma 回调函数 iq 的(ddc,ffc)
|
||||
}
|
||||
|
||||
#include <string>
|
||||
#include "device_uhd_c.h"
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
|
||||
ex_declare void adsb_close();
|
||||
|
||||
typedef void (*iq_cbk_t)(void* phandle, void* pdata, uint64_t length);
|
||||
|
||||
typedef int (*adsb_set_less_30Mhz_ddc_param_t)(uint64_t cf_hz, uint64_t sf_hz, uint64_t bw_hz, int8_t sw);
|
||||
typedef int (*adsb_set_less_30Mhz_fft_param_t)(uint64_t fftWin, uint64_t fftLen, int fftPeriod_ms, int8_t sw);
|
||||
ex_declare int adsb_set_iq_cbk(iq_cbk_t recv_cbk, void* pusr);
|
||||
ex_declare int adsb_set_less_30Mhz_ddc_param(uint64_t cf_hz, uint64_t sf_hz, uint64_t bw_hz, int8_t sw);
|
||||
ex_declare int adsb_set_less_30Mhz_fft_param(uint64_t fftWin, uint64_t fftLen, int fftPeriod_ms, int8_t sw);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif //_DEVICE_UHD_C_H_
|
||||
@@ -0,0 +1,259 @@
|
||||
#ifndef device_uhd_struct_h
|
||||
#define device_uhd_struct_h
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#define ZDSamSum 200000000//8路窄带采样率之和
|
||||
#define ZDChMax 8 //每路大通道下窄带通道总数
|
||||
enum UHD_ParamType : int
|
||||
{
|
||||
CenterFreq = 0,
|
||||
BandWidth = 1,
|
||||
SampleFreq = 2,
|
||||
Gain = 3,
|
||||
PowerRef = 4,
|
||||
KDDCSwitch = 5,
|
||||
KFFTSwitch = 6,
|
||||
ZDDCSwitch = 7,
|
||||
ZDDCParam = 8,
|
||||
KFFTParam = 9,
|
||||
ClockSource = 10,
|
||||
SnapshotSwitch = 11,
|
||||
Snapshot_tm_s = 12,
|
||||
};
|
||||
enum UHD_FFTWin : unsigned char
|
||||
{
|
||||
jxc =0,// 矩形窗 = 0,
|
||||
hnc = 1,// 汉宁窗 = 1,
|
||||
hmc = 2, // 海明窗 = 2,
|
||||
blkmc = 3,// 布莱克曼窗 = 3,
|
||||
};
|
||||
enum UHD_FFTLen : unsigned int
|
||||
{
|
||||
_1024 = 1024,
|
||||
_2048 = 2048,
|
||||
_4096 = 4096,
|
||||
_8192 = 8192,
|
||||
_16384 = 16384,
|
||||
_32768 = 32768,
|
||||
};
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
struct UHD_ZDParam
|
||||
{
|
||||
unsigned char KCH = 0;//宽带通道号
|
||||
unsigned short ZCH = 0;//窄带通道号
|
||||
long long CenterFreq = 0; // 中频
|
||||
int BandWidth = 0; //带宽
|
||||
int SampleFreq = 0; // 采样率
|
||||
int ExtraPer = 1024;//抽取率 4-4096,2的指数
|
||||
bool bSwitch_ZDDC = false;
|
||||
|
||||
};
|
||||
struct UHD_KDParam
|
||||
{
|
||||
unsigned char KCH = 0;//宽带通道号
|
||||
long long CenterFreq = 10000000;
|
||||
|
||||
int BandWidth = 160000000;
|
||||
int SampleFreq = 200000000;
|
||||
|
||||
bool bSwitch_6GCH = false;
|
||||
|
||||
bool bSwitch_KDDC = false;
|
||||
bool bSwitch_KFFT = false;
|
||||
double gain = 0;
|
||||
UHD_ZDParam ZDParam[ZDChMax];
|
||||
int ExtraPer;
|
||||
bool Snapshot_Switch=false;
|
||||
int Snapshot_tm_s = 0;
|
||||
|
||||
unsigned long long old_sf;
|
||||
unsigned long long old_cf;
|
||||
unsigned long long old_bw;
|
||||
|
||||
};
|
||||
#pragma region 枚举/结构体
|
||||
|
||||
/** @brief TODO: 时码类型枚举
|
||||
* @enum LibWZ57_Enum_TimeType
|
||||
*/
|
||||
enum Enum_TimeType : uint8_t
|
||||
{
|
||||
Enum_TimeType_Invlid = 0, /**< 无效的*/
|
||||
Enum_TimeType_IRIG_B = 1, /**< IRIG-B*/
|
||||
Enum_TimeType_RMC = 2, /**< RMC*/
|
||||
Enum_TimeType_ABSCNTTM = 3, /**< 绝对计数时间*/
|
||||
Enum_TimeType_REFCNTTM = 4, /**< 相对计数时间*/
|
||||
};
|
||||
typedef struct struct_DateTime
|
||||
{
|
||||
|
||||
Enum_TimeType TimeType; /**< 10 时码类型*/
|
||||
|
||||
/** @brief 10个字节的时码信息
|
||||
* @details
|
||||
* 根据 @ref LibWZ57_Enum_TimeType TimeType,对应不同的 联合体
|
||||
*/
|
||||
union TimeInfo
|
||||
{
|
||||
///@brief IRIG-B
|
||||
///@struct IRIGB_Head
|
||||
struct IRIGB_Head
|
||||
{
|
||||
uint8_t Year; /**< 年 字节1*/
|
||||
uint16_t Day; /**< 日 字节2*/
|
||||
uint8_t Hour; /**< 时 字节1*/
|
||||
uint8_t Minute; /**< 分 字节1*/
|
||||
uint8_t Second; /**< 秒 字节1*/
|
||||
uint32_t NanoSec; /**< 纳 字节4*/
|
||||
} IRIGB_Head;
|
||||
|
||||
///@brief RMC
|
||||
///@struct RMC_Head
|
||||
struct RMC_Head
|
||||
{
|
||||
uint8_t Year; /**< 年 字节1*/
|
||||
uint8_t Month; /**< 月 字节1*/
|
||||
uint8_t Day; /**< 日 字节1*/
|
||||
uint8_t Hour; /**< 时 字节1*/
|
||||
uint8_t Minute; /**< 分 字节1*/
|
||||
uint8_t Second; /**< 秒 字节1*/
|
||||
uint32_t NanoSec; /**< 纳 字节4*/
|
||||
} RMC_Head;
|
||||
|
||||
///@brief 绝对计数时间
|
||||
///@struct ABSCNTTM_Head
|
||||
struct ABSCNTTM_Head
|
||||
{
|
||||
///@brief 秒 字节6; 基准秒计数时间+相对秒计数时间 单位:秒
|
||||
uint8_t Second[6];
|
||||
///@brief 纳秒 字节4;
|
||||
uint32_t NanoSec;
|
||||
} ABSCNTTM_Head;
|
||||
|
||||
///@brief 相对计数时间
|
||||
///@struct REFCNTTM_Head
|
||||
struct REFCNTTM_Head
|
||||
{
|
||||
///@brief 秒 字节6; 相对秒计数时间单位:秒
|
||||
uint8_t Second[6];
|
||||
///@brief 纳秒 字节4;
|
||||
uint32_t NanoSec;
|
||||
} REFCNTTM_Head;
|
||||
} TimeInfo;
|
||||
|
||||
} struct_DataTime;
|
||||
|
||||
|
||||
|
||||
#pragma region 枚举
|
||||
/*****************************
|
||||
*数据类型
|
||||
*****************************/
|
||||
enum UHD_Enum_DataType : unsigned char
|
||||
{
|
||||
zd_ddc = 1,
|
||||
kd_ddc = 2,
|
||||
kd_fft = 3,
|
||||
GPS_Info = 16,
|
||||
// 窄带DDC = 0x01,
|
||||
// 宽带DDC = 0x02,
|
||||
// 宽带FFT = 0x03,
|
||||
};
|
||||
#pragma endregion
|
||||
#pragma region 结构体
|
||||
#pragma region UHD_Struct_KFFT UHD_Struct_KDDC UHD_Struct_ZDDC
|
||||
/// <summary>
|
||||
/// 宽带FFT头
|
||||
/// </summary>
|
||||
typedef struct
|
||||
{
|
||||
/// <summary>
|
||||
/// 帧标识 6 0x2828F628F6F6 固定值
|
||||
/// </summary>
|
||||
unsigned int Head;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
unsigned short Head2;
|
||||
/// <summary>
|
||||
/// 协议版本 1 0x80
|
||||
/// </summary>
|
||||
unsigned char DealVersion;
|
||||
/// <summary>
|
||||
/// 帧头长度 1 64
|
||||
/// </summary>
|
||||
unsigned char FrameHeadLen;
|
||||
/// <summary>
|
||||
/// 数据长度 2 2048
|
||||
/// </summary>
|
||||
unsigned short DataLen;
|
||||
/// <summary>
|
||||
/// 有效数据长度 2 2048
|
||||
/// </summary>
|
||||
unsigned short UsefullLen;
|
||||
/// <summary>
|
||||
/// 数据类型 1
|
||||
/// </summary>
|
||||
UHD_Enum_DataType DataType;
|
||||
unsigned char Other1;
|
||||
/// <summary>
|
||||
/// 通道号
|
||||
/// </summary>
|
||||
unsigned char Channel;
|
||||
unsigned char Other2;
|
||||
unsigned short ZDChannel;
|
||||
/// <summary>
|
||||
/// 帧计数 2 0 ~ 65535 循环递增
|
||||
/// </summary>
|
||||
unsigned short FrameIndex;
|
||||
/// <summary>
|
||||
/// 帧起止标识 1 0x0
|
||||
/// </summary>
|
||||
unsigned char FrameBeginFlag;
|
||||
struct_DateTime DateTm;
|
||||
/// <summary>
|
||||
/// 采样率 4 单位Hz
|
||||
/// </summary>
|
||||
unsigned int SampleFreq_Hz;
|
||||
/// <summary>
|
||||
/// 带宽 4 单位Hz
|
||||
/// </summary>
|
||||
unsigned int BandWidth_Hz;
|
||||
/// <summary>
|
||||
/// 中心频点 4 单位Hz,低位
|
||||
/// </summary>
|
||||
unsigned int CenterFreq_Hz_Low;
|
||||
/// <summary>
|
||||
/// 中心频点 2 单位Hz,高位
|
||||
/// </summary>
|
||||
unsigned short CenterFreq_Hz_High;
|
||||
union
|
||||
{
|
||||
unsigned char other5[18];
|
||||
struct
|
||||
{
|
||||
unsigned char other4[6];
|
||||
/// <summary>
|
||||
/// FFT长度 65536
|
||||
/// </summary>
|
||||
int FFTPoint;
|
||||
unsigned char other5[2];
|
||||
float other6;
|
||||
/// <summary>
|
||||
/// 段内帧号
|
||||
/// </summary>
|
||||
unsigned short SubFrame;
|
||||
} FFT;
|
||||
} Param;
|
||||
//数据 2048 共1024个数据,1个数据2字节。
|
||||
} UHD_Struct_KFFT, UHD_Struct_KDDC, UHD_Struct_ZDDC;
|
||||
#pragma endregion
|
||||
#pragma endregion
|
||||
#pragma pack(pop)
|
||||
#pragma endregion
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
#ifndef __ERROR_CALLBACK_H__
|
||||
#define __ERROR_CALLBACK_H__
|
||||
|
||||
extern "C" {
|
||||
typedef void (*error_cbk_t)(const char *file_name ,const char *func_name,const char *err_msg);
|
||||
extern error_cbk_t g_error_callback;
|
||||
|
||||
ex_declare void error_callback_call( const char *file_name ,const char *func_name,const char *err_msg);
|
||||
ex_declare const char *extract_filename_in_cbk(const char *full_path);
|
||||
|
||||
|
||||
ex_declare void set_error_cbk(error_cbk_t cbk);
|
||||
#define MACROS_ERROR_CBK_CALL(msg) error_callback_call(__FILE__,__func__,msg)
|
||||
|
||||
|
||||
typedef int (*set_error_cbk_t)(error_cbk_t cbk);
|
||||
}
|
||||
|
||||
#endif // __ERROR_CALLBACK_H__
|
||||
@@ -0,0 +1,207 @@
|
||||
#include "main.h"
|
||||
#include <chrono>
|
||||
#include <csignal>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "Core/Base/JSON.h"
|
||||
#include "Core/Base/ThreadManager.h"
|
||||
#include "Core/Base/global_include.h"
|
||||
#include "Core/Shared_Memory/Shared_Memory.h"
|
||||
#include "Core/system/export.h"
|
||||
#include "Core/spdlog/export.h"
|
||||
|
||||
#include "Core/Base/SM_RingBuffer.h"
|
||||
#include "Dll_Global.h"
|
||||
|
||||
|
||||
std::vector<std::string> ddd = {
|
||||
"1A 33 1A 1A F1 DA 08 2A 73 60 8D 78 12 0A EA 28 88 64 25 3C 08 33 22 41",
|
||||
"1A 33 1A 1A F1 D9 13 EA E7 11 8D 78 1D 40 58 BF 41 E2 45 49 09 7B C8 24",
|
||||
"1A 33 1A 1A F1 DA 08 2A 73 60 8D 78 12 0A EA 28 88 64 25 3C 08 33 22 41",
|
||||
"1A 33 1A 1A F1 DA D4 35 F9 69 A0 00 15 BC C2 9E 14 F0 A8 00 00 DE E7 37",
|
||||
"1A 33 1A 1A F1 DB 45 5D 1C 68 A0 00 15 BC FF DD 11 2B 60 04 DB 2F 06 E2",
|
||||
"1A 33 1A 1A F1 DD 0F 74 3E 20 A0 00 15 BC EE 0A 13 30 20 37 FF A9 CE DC",
|
||||
"1A 33 1A 1A F1 DD 50 97 59 30 8D 78 00 6C E1 1F 2E 00 00 00 00 09 43 55",
|
||||
"1A 33 1A 1A F1 DD 73 6B 25 2B 8D 78 16 2D F8 33 00 06 00 49 B8 CF B0 D7",
|
||||
"1A 33 1A 1A F1 DD F1 C2 C2 1D A0 00 15 BC 10 03 0A 80 ED 00 00 98 54 C8",
|
||||
"1A 33 1A 1A F1 DE 62 E9 B6 2A A0 00 15 BC 10 03 0A 80 ED 00 00 98 54 C8",
|
||||
"1A 33 1A 1A F1 DE B4 E1 1E 23 8D 79 A0 53 EA 3E C8 66 57 3C 08 71 74 65",
|
||||
"1A 33 1A 1A F1 DF 17 8E 3F 5D 8D 78 00 6C 58 63 44 5B 32 CB 60 C5 DD 2E",
|
||||
"1A 33 1A 1A F1 DF 3E 49 FD 76 A0 00 0E 3E A8 7A 23 26 E1 0C 22 4E D9 88",
|
||||
"1A 33 1A 1A F1 DF AF 71 5F 6C A0 00 0E 3E A8 7A 23 26 E1 0C 22 4E D9 88",
|
||||
"1A 33 1A 1A F1 E2 0A DD 76 2A A0 00 11 B1 B5 E8 00 30 AA 00 00 D5 D0 A3",
|
||||
};
|
||||
|
||||
|
||||
std::string get_absb() {
|
||||
static size_t index = 0; // 静态变量用于保存当前读取位置
|
||||
index++;
|
||||
if (index == ddd.size()) {
|
||||
index = 0;
|
||||
}
|
||||
return ddd[index];
|
||||
}
|
||||
|
||||
class TextLineReader {
|
||||
public:
|
||||
explicit TextLineReader(const std::string& file_path) {
|
||||
load(file_path);
|
||||
}
|
||||
|
||||
// 每调用一次,返回一行
|
||||
// 返回 true 表示成功取到一行
|
||||
// 返回 false 表示已经没有更多行
|
||||
bool get(std::string& ret_line) {
|
||||
if (index_ >= lines_.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret_line = lines_[index_];
|
||||
++index_;
|
||||
return true;
|
||||
}
|
||||
|
||||
// 重新从第一行开始读
|
||||
void reset() {
|
||||
index_ = 0;
|
||||
}
|
||||
|
||||
// 总行数
|
||||
std::size_t size() const {
|
||||
return lines_.size();
|
||||
}
|
||||
|
||||
// 是否已经读完
|
||||
bool empty() const {
|
||||
return lines_.empty();
|
||||
}
|
||||
|
||||
private:
|
||||
void load(const std::string& file_path) {
|
||||
std::ifstream file(file_path);
|
||||
if (!file.is_open()) {
|
||||
throw std::runtime_error("Failed to open file: " + file_path);
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
lines_.push_back(line);
|
||||
}
|
||||
|
||||
index_ = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::string> lines_;
|
||||
std::size_t index_ = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
std::size_t adsb_read(char *buf, std::size_t len) {
|
||||
|
||||
|
||||
static TextLineReader reader(get_exe_dir() + "/ADS-B_195_0205.txt");
|
||||
std::string line;
|
||||
reader.get(line);
|
||||
auto l = line.size();
|
||||
std::memcpy(buf, line.c_str(), l);
|
||||
return l;
|
||||
}
|
||||
|
||||
int adsb_set_iq_cbk(iq_cbk_t recv_cbk, void *pusr) {
|
||||
auto dg = Dll_Global::instance();
|
||||
dg->recv_cbk = recv_cbk;
|
||||
dg->puser = pusr;
|
||||
|
||||
|
||||
|
||||
dg->init_when_dll();
|
||||
return 0;
|
||||
}
|
||||
int adsb_set_less_30Mhz_ddc_param(uint64_t cf_hz, uint64_t sf_hz, uint64_t bw_hz, int8_t sw) {
|
||||
auto dg = Dll_Global::instance();
|
||||
dg->center_freq = cf_hz;
|
||||
dg->sample_rate = sf_hz; // 设置采样率
|
||||
dg->band_width = bw_hz;
|
||||
return 0;
|
||||
}
|
||||
int adsb_set_less_30Mhz_fft_param(uint64_t fftWin, uint64_t fftLen, int fftPeriod_ms, int8_t sw) {
|
||||
auto dg = Dll_Global::instance();
|
||||
dg->fft_point_number = fftLen;
|
||||
dg->fft_period_ms = fftPeriod_ms;
|
||||
dg->fft_win_type = (UHD_FFTWin)fftWin;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main() {
|
||||
init_signal_config();
|
||||
auto dg = Dll_Global::instance();
|
||||
|
||||
|
||||
dg->init_when_exe();
|
||||
bool debug = false;
|
||||
|
||||
auto mb = get_system_memory()/(1024*1024);
|
||||
auto gb = mb/(1024);
|
||||
std::cout << "当前系统的物理内存大小" << mb << " MB" << std::endl;
|
||||
std::cout << "当前系统的物理内存大小" << gb << " GB" << std::endl;
|
||||
|
||||
dg->dtm.test_and_start_thread("dsp共享内存数据推送", [dg](std::atomic<bool> & running) {
|
||||
bool debug = true;
|
||||
while (running) {
|
||||
auto list = dg->iq_memory_buffer.get_all();
|
||||
// 释放内存池
|
||||
Pool_Guard pg(&dg->iq_memory_buffer.pool, list);
|
||||
|
||||
if (debug && list.size() > 1000) {
|
||||
static Frequency_Limit fl(1.0/60.0);
|
||||
std::ostringstream oss;
|
||||
oss << get_current_millisecond_timestamp() << " 警告: dsp共享内存数据推送数据过多 当前数据队列长度:" << list.size() << std::endl;
|
||||
if (fl.test()) {
|
||||
std::cout << oss.str() << std::endl;
|
||||
}
|
||||
}
|
||||
if (list.empty()) {
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(1));
|
||||
continue;
|
||||
}
|
||||
auto frame_number = list.size();
|
||||
static Frequency_Limit fl(freq);
|
||||
if (fl.test()) {
|
||||
|
||||
std::cout << dg->rb->state_str() << " dsp数据推送" << frame_number << "条" << std::endl;
|
||||
}
|
||||
|
||||
for (int i = 0; i < frame_number; i++) {
|
||||
auto buf = list[i];
|
||||
dg->handle_2112(buf->data());
|
||||
}
|
||||
}
|
||||
});
|
||||
while (!stop_program) {
|
||||
dg->handle_json_call();
|
||||
|
||||
}
|
||||
if (stop_program == SIGINT) {
|
||||
std::cout << "开始关闭所有子线程!" << std::endl;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#define MY_LIBRARY_EXPORTS
|
||||
#ifdef _WIN32 // Windows 平台
|
||||
#ifdef MY_LIBRARY_EXPORTS // 如果正在构建库
|
||||
#define ex_declare __declspec(dllexport) // 导出符号
|
||||
#else
|
||||
#define ex_declare __declspec(dllimport) // 导入符号
|
||||
#endif
|
||||
#else // 对于 Linux 和其他 Unix-like 系统
|
||||
#define ex_declare __attribute__((visibility("default"))) // 导出符号
|
||||
#endif
|
||||
#include <cstdint>
|
||||
#include "./error_callback.h"
|
||||
#include "./device_uhd_c.h"
|
||||
|
||||
extern "C" {
|
||||
ex_declare void adsb_close();
|
||||
ex_declare std::size_t adsb_read(char* buf, std::size_t len);
|
||||
|
||||
// IQ 数据接口
|
||||
typedef void (*iq_cbk_t)(void* phandle, void* pdata, uint64_t length);
|
||||
typedef int (*adsb_set_iq_cbk_t)(iq_cbk_t recv_cbk, void* pusr);
|
||||
typedef int (*adsb_set_less_30Mhz_ddc_param_t)(uint64_t cf_hz, uint64_t sf_hz, uint64_t bw_hz, int8_t sw);
|
||||
typedef int (*adsb_set_less_30Mhz_fft_param_t)(uint64_t fftWin, uint64_t fftLen, int fftPeriod_ms, int8_t sw);
|
||||
ex_declare int adsb_set_iq_cbk(iq_cbk_t recv_cbk, void* pusr);
|
||||
ex_declare int adsb_set_less_30Mhz_ddc_param(uint64_t cf_hz, uint64_t sf_hz, uint64_t bw_hz, int8_t sw);
|
||||
ex_declare int adsb_set_less_30Mhz_fft_param(uint64_t fftWin, uint64_t fftLen, int fftPeriod_ms, int8_t sw);
|
||||
|
||||
|
||||
|
||||
|
||||
int32_t ex_declare init_adsb9002(void **phandle, adsb_msg_cbk_t cbk, void *pusr);
|
||||
int32_t ex_declare free_adsb9002(void **phandle);
|
||||
int ex_declare set_iq_cbk(void *phandle, iq_cbk_t recv_cbk, void *pusr);
|
||||
int ex_declare set_less_30Mhz_ddc_param(void *phandle, uint64_t cf_hz, uint64_t sf_hz, uint64_t bw_hz, int8_t sw);
|
||||
int ex_declare set_less_30Mhz_fft_param(void *phandle, int fftWin, int fftLen, int fftPeriod_ms, int8_t sw);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
using init_adsb9002_ptr_t = int32_t (*)(void **phandle, adsb_msg_cbk_t cbk, void *pusr);
|
||||
using free_adsb9002_ptr_t = int32_t (*)(void **phandle);
|
||||
using set_iq_cbk_ptr_t = int (*)(void *phandle, iq_cbk_t recv_cbk, void *pusr);
|
||||
using set_less_30Mhz_ddc_param_ptr_t = int (*)(void *phandle, uint64_t cf_hz, uint64_t sf_hz, uint64_t bw_hz, int8_t sw);
|
||||
using set_less_30Mhz_fft_param_ptr_t = int (*)(void *phandle, int fftWin, int fftLen, int fftPeriod_ms, int8_t sw);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user