95 lines
3.1 KiB
C++
95 lines
3.1 KiB
C++
#ifndef PLANTSUNCAT_DSP2_H
|
|
#define PLANTSUNCAT_DSP2_H
|
|
#include <chrono>
|
|
#include <condition_variable>
|
|
#include <deque>
|
|
#include <memory_resource>
|
|
#include "../server/WebSocket_Manager.h"
|
|
#include "global.h"
|
|
class Global;
|
|
#define USE_PROCESS 0
|
|
#ifdef USE_PROCESS
|
|
#include "Psc_Cpp_Core/Shared_Memory/Shared_Memory.h"
|
|
#endif
|
|
// #ifdef WIN32
|
|
// #define USE_PROCESS 1
|
|
// #endif
|
|
// #define USE_PROCESS 1
|
|
extern BaseLogger* dsp_logger;
|
|
class DSP_Config_Data {
|
|
public:
|
|
std::uint64_t frame_rate;
|
|
bool debug;
|
|
PSC_USE_JSON
|
|
};
|
|
class DSP_Config : public Base_DSP, public DSP_Config_Data {
|
|
public:
|
|
~DSP_Config();
|
|
void close_dsp_device() const;
|
|
void init_update(const Psc::JSON* that_json) {
|
|
Get_J(center_freq);
|
|
Get_J(band_width);
|
|
Get_J(sample_rate);
|
|
Get_J(fft_point_number);
|
|
}
|
|
void from_json(const Psc::JSON* that_json) {
|
|
Base_DSP::from_base_json(that_json);
|
|
DSP_Config_Data::from_base_json(that_json);
|
|
}
|
|
Psc::JSON to_base_json() const {
|
|
return Base_DSP::to_base_json() += DSP_Config_Data::to_base_json();
|
|
}
|
|
void init_env();
|
|
void set_fft_point_number(uint64_t fft_point_number, bool force = false);
|
|
std::atomic<bool> record_iq_stream_ing = false;
|
|
struct Memory_Buffer {
|
|
using Batch = std::pmr::deque<std::pmr::string>;
|
|
Batch wait_all(const std::atomic<bool>& running) {
|
|
std::unique_lock lock(m);
|
|
ready.wait_for(lock, std::chrono::milliseconds(100), [&] {
|
|
return !data.empty() || !running.load(std::memory_order_acquire);
|
|
});
|
|
Batch result(data.get_allocator().resource());
|
|
result.swap(data);
|
|
return result;
|
|
}
|
|
void push(void* pdata, uint64_t length) {
|
|
{
|
|
std::lock_guard lock(m);
|
|
if (data.size() == max_frames) {
|
|
data.pop_front();
|
|
++dropped_frames;
|
|
}
|
|
data.emplace_back(static_cast<char*>(pdata), length);
|
|
}
|
|
ready.notify_one();
|
|
}
|
|
std::uint64_t dropped() const {
|
|
return dropped_frames.load(std::memory_order_relaxed);
|
|
}
|
|
protected:
|
|
static constexpr std::size_t max_frames = 4096;
|
|
Batch data;
|
|
std::atomic<std::uint64_t> dropped_frames{};
|
|
std::mutex m;
|
|
std::condition_variable ready;
|
|
};
|
|
#if USE_PROCESS
|
|
void adsb_set_less_30Mhz_ddc_param(double center_freq, double sample_rate, double band_width, int sw);
|
|
void adsb_set_less_30Mhz_fft_param(UHD_FFTWin fft_win_type, size_t fft_point_number, size_t fft_period_ms, int sw);
|
|
Psc::SM_Block_RingBuffer json_func_call = Psc::SM_Block_RingBuffer("json_func_call2", 1000);
|
|
Psc::SM_Block_RingBuffer rb = Psc::SM_Block_RingBuffer("rb", 2112 * 1000);
|
|
Psc::Pure_Share_Memory psm = Psc::Pure_Share_Memory("fft_data", 65536);
|
|
void restart_device();
|
|
#else
|
|
void server(Global* g);
|
|
std::shared_ptr<WebSocket_Manager> ws_fft;
|
|
std::shared_ptr<WebSocket_Manager> ws_iq;
|
|
Memory_Buffer iq_memory_buffer;
|
|
std::vector<std::uint8_t> fft_data;
|
|
std::mutex fft_mtx;
|
|
void* lib{};
|
|
#endif
|
|
};
|
|
#endif
|