SDRPlusPlus/decoder_modules/falcon9_decoder/src/main.cpp

263 lines
7.2 KiB
C++
Raw Normal View History

2021-03-20 21:53:44 +01:00
#include <imgui.h>
#include <config.h>
#include <core.h>
#include <gui/style.h>
#include <signal_path/signal_path.h>
#include <module.h>
#include <options.h>
2021-07-26 03:11:51 +02:00
#include <gui/gui.h>
2021-03-20 21:53:44 +01:00
#include <dsp/pll.h>
#include <dsp/stream.h>
#include <dsp/demodulator.h>
#include <dsp/window.h>
#include <dsp/resampling.h>
#include <dsp/processing.h>
#include <dsp/routing.h>
#include <dsp/deframing.h>
#include <falcon_fec.h>
#include <falcon_packet.h>
#include <dsp/sink.h>
#include <gui/widgets/symbol_diagram.h>
2021-03-21 19:51:38 +01:00
#include <fstream>
2021-03-20 21:53:44 +01:00
#define CONCAT(a, b) ((std::string(a) + b).c_str())
SDRPP_MOD_INFO {
/* Name: */ "falcon9_decoder",
/* Description: */ "Falcon9 telemetry decoder for SDR++",
/* Author: */ "Ryzerth",
/* Version: */ 0, 1, 0,
/* Max instances */ -1
};
#define INPUT_SAMPLE_RATE 6000000
2021-03-29 21:53:43 +02:00
std::ofstream file("output.ts");
2021-03-20 21:53:44 +01:00
class Falcon9DecoderModule : public ModuleManager::Instance {
public:
Falcon9DecoderModule(std::string name) {
this->name = name;
2021-04-17 22:37:50 +02:00
vfo = sigpath::vfoManager.createVFO(name, ImGui::WaterfallVFO::REF_CENTER, 0, 4000000, INPUT_SAMPLE_RATE, 4000000, 4000000, true);
2021-03-20 21:53:44 +01:00
// dsp::Splitter<float> split;
// dsp::Reshaper<float> reshape;
// dsp::HandlerSink<float> symSink;
// dsp::stream<float> thrInput;
// dsp::Threshold thr;
demod.init(vfo->output, INPUT_SAMPLE_RATE, 2000000.0f);
2021-03-21 19:51:38 +01:00
recov.init(&demod.out, (float)INPUT_SAMPLE_RATE / 3571400.0f, powf(0.01f, 2) / 4.0f, 0.01, 100e-6f); // 0.00765625f, 0.175f, 0.005f
2021-03-20 21:53:44 +01:00
split.init(&recov.out);
split.bindStream(&reshapeInput);
split.bindStream(&thrInput);
reshape.init(&reshapeInput, 1024, 198976);
symSink.init(&reshape.out, symSinkHandler, this);
thr.init(&thrInput);
deframe.init(&thr.out, 10232, syncWord, 32);
falconRS.init(&deframe.out);
pkt.init(&falconRS.out);
sink.init(&pkt.out, sinkHandler, this);
demod.start();
recov.start();
split.start();
reshape.start();
symSink.start();
sink.start();
pkt.start();
falconRS.start();
deframe.start();
thr.start();
2021-03-21 19:51:38 +01:00
#ifdef _WIN32
ffplay = _popen("ffplay -framedrop -infbuf -hide_banner -loglevel panic -window_title \"Falcon 9 Cameras\" -", "wb");
#else
ffplay = popen("ffplay -framedrop -infbuf -hide_banner -loglevel panic -window_title \"Falcon 9 Cameras\" -", "wb");
#endif
2021-03-20 21:53:44 +01:00
gui::menu.registerEntry(name, menuHandler, this, this);
}
~Falcon9DecoderModule() {
}
2021-07-26 03:11:51 +02:00
void postInit() {}
2021-03-20 21:53:44 +01:00
void enable() {
2021-04-17 22:37:50 +02:00
vfo = sigpath::vfoManager.createVFO(name, ImGui::WaterfallVFO::REF_CENTER, 0, 4000000, INPUT_SAMPLE_RATE, 4000000, 4000000, true);
2021-03-20 21:53:44 +01:00
demod.setInput(vfo->output);
demod.start();
recov.start();
split.start();
reshape.start();
symSink.start();
sink.start();
pkt.start();
falconRS.start();
deframe.start();
thr.start();
enabled = true;
}
void disable() {
demod.stop();
recov.stop();
split.stop();
reshape.stop();
symSink.stop();
sink.stop();
pkt.stop();
falconRS.stop();
deframe.stop();
thr.stop();
sigpath::vfoManager.deleteVFO(vfo);
enabled = false;
}
bool isEnabled() {
return enabled;
}
private:
static void menuHandler(void* ctx) {
Falcon9DecoderModule* _this = (Falcon9DecoderModule*)ctx;
float menuWidth = ImGui::GetContentRegionAvailWidth();
if (!_this->enabled) { style::beginDisabled(); }
ImGui::SetNextItemWidth(menuWidth);
_this->symDiag.draw();
if (_this->logsVisible) {
if (ImGui::Button("Hide logs", ImVec2(menuWidth, 0))) { _this->logsVisible = false; }
}
else {
if (ImGui::Button("Show logs", ImVec2(menuWidth, 0))) { _this->logsVisible = true; }
}
if (_this->logsVisible) {
std::lock_guard<std::mutex> lck(_this->logsMtx);
ImGui::Begin("Falcon9 Telemetry");
ImGui::BeginTabBar("Falcon9Tabs");
// GPS Logs
ImGui::BeginTabItem("GPS");
if (ImGui::Button("Clear logs##GPSClear")) { _this->gpsLogs.clear(); }
ImGui::BeginChild(ImGuiID("GPSChild"));
ImGui::TextUnformatted(_this->gpsLogs.c_str());
2021-07-26 03:11:51 +02:00
ImGui::SetScrollHereY(1.0f);
2021-03-20 21:53:44 +01:00
ImGui::EndChild();
ImGui::EndTabItem();
// STMM1A Logs
ImGui::BeginTabItem("STMM1A");
ImGui::EndTabItem();
// STMM1B Logs
ImGui::BeginTabItem("STMM1B");
ImGui::EndTabItem();
// STMM1C Logs
ImGui::BeginTabItem("STMM1C");
ImGui::EndTabItem();
ImGui::EndTabBar();
ImGui::End();
}
if (!_this->enabled) { style::endDisabled(); }
}
static void sinkHandler(uint8_t* data, int count, void* ctx) {
Falcon9DecoderModule* _this = (Falcon9DecoderModule*)ctx;
uint16_t length = (((data[0] & 0b1111) << 8) | data[1]) + 2;
uint64_t pktId = ((uint64_t)data[2] << 56) | ((uint64_t)data[3] << 48) | ((uint64_t)data[4] << 40) | ((uint64_t)data[5] << 32)
| ((uint64_t)data[6] << 24) | ((uint64_t)data[7] << 16) | ((uint64_t)data[8] << 8) | data[9];
if (pktId == 0x0117FE0800320303 || pktId == 0x0112FA0800320303) {
data[length - 2] = 0;
_this->logsMtx.lock();
_this->gpsLogs += (char*)(data + 25);
_this->logsMtx.unlock();
}
else if (pktId == 0x01123201042E1403) {
fwrite(data + 25, 1, 940, _this->ffplay);
2021-03-29 21:53:43 +02:00
file.write((char*)(data + 25), 940);
2021-03-20 21:53:44 +01:00
}
//printf("%016" PRIX64 ": %d bytes, %d full\n", pktId, length, count);
}
static void symSinkHandler(float* data, int count, void* ctx) {
Falcon9DecoderModule* _this = (Falcon9DecoderModule*)ctx;
float* buf = _this->symDiag.acquireBuffer();
2021-03-20 21:53:44 +01:00
memcpy(buf, data, 1024*sizeof(float));
_this->symDiag.releaseBuffer();
}
std::string name;
bool enabled = true;
bool logsVisible = false;
std::mutex logsMtx;
std::string gpsLogs = "";
// DSP Chain
dsp::FloatFMDemod demod;
2021-03-29 21:53:43 +02:00
dsp::MMClockRecovery<float> recov;
2021-03-20 21:53:44 +01:00
dsp::Splitter<float> split;
dsp::stream<float> reshapeInput;
dsp::Reshaper<float> reshape;
dsp::HandlerSink<float> symSink;
dsp::stream<float> thrInput;
dsp::Threshold thr;
uint8_t syncWord[32] = {0,0,0,1,1,0,1,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,0,1};
dsp::Deframer deframe;
dsp::FalconRS falconRS;
dsp::FalconPacketSync pkt;
dsp::HandlerSink<uint8_t> sink;
FILE* ffplay;
VFOManager::VFO* vfo;
ImGui::SymbolDiagram symDiag;
};
MOD_EXPORT void _INIT_() {
// Nothing
}
MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) {
return new Falcon9DecoderModule(name);
}
MOD_EXPORT void _DELETE_INSTANCE_(void* instance) {
delete (Falcon9DecoderModule*)instance;
}
MOD_EXPORT void _END_() {
// Nothing either
}