From 078e7fab372bbf70884e7a1a71058fbbe58a7442 Mon Sep 17 00:00:00 2001 From: f4exb Date: Thu, 4 Mar 2021 08:43:04 +0100 Subject: [PATCH] DATV: external LDPC tool implementation (1) --- plugins/channelrx/demoddatv/CMakeLists.txt | 6 +++ plugins/channelrx/demoddatv/datvdemodsink.cpp | 37 +++++++++++++++++-- .../demoddatv/ldpctool/ldpc_tool.cpp | 5 ++- plugins/channelrx/demoddatv/leansdr/dvbs2.h | 10 ++--- 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/plugins/channelrx/demoddatv/CMakeLists.txt b/plugins/channelrx/demoddatv/CMakeLists.txt index ec09af710..143d3c1aa 100644 --- a/plugins/channelrx/demoddatv/CMakeLists.txt +++ b/plugins/channelrx/demoddatv/CMakeLists.txt @@ -75,4 +75,10 @@ target_link_libraries(demoddatv ${SWRESAMPLE_LIBRARIES} ) +add_executable(ldpctool + ldpctool/ldpc_tool.cpp + ldpctool/tables_handler.cpp +) + install(TARGETS demoddatv DESTINATION ${INSTALL_PLUGINS_DIR}) +install(TARGETS ldpctool DESTINATION ${INSTALL_BIN_DIR}) diff --git a/plugins/channelrx/demoddatv/datvdemodsink.cpp b/plugins/channelrx/demoddatv/datvdemodsink.cpp index 81f35e18c..cb461111a 100644 --- a/plugins/channelrx/demoddatv/datvdemodsink.cpp +++ b/plugins/channelrx/demoddatv/datvdemodsink.cpp @@ -369,8 +369,12 @@ void DATVDemodSink::CleanUpDATVFramework(bool blnRelease) } // INPUT - //if(p_rawiq!=nullptr) delete p_rawiq; - //if(p_rawiq_writer!=nullptr) delete p_rawiq_writer; + if (p_rawiq != nullptr) { + delete p_rawiq; + } + if (p_rawiq_writer != nullptr) { + delete p_rawiq_writer; + } //if(p_preprocessed!=nullptr) delete p_preprocessed; //DVB-S2 @@ -1137,6 +1141,7 @@ void DATVDemodSink::InitDATVS2Framework() if (m_settings.m_softLDPC) { +#if 0 // External LDPC decoder mode. // Deinterleave into soft bits. p_fecframes = new leansdr::pipebuf >(m_objScheduler, "FEC frames", BUF_FRAMES); @@ -1153,6 +1158,30 @@ void DATVDemodSink::InitDATVS2Framework() p_vbitcount, p_verrcount ); +#else + // External LDPC decoder mode. + // Deinterleave into soft bits. + // TBD Latency + p_fecframes = new leansdr::pipebuf >(m_objScheduler, "FEC frames", BUF_FRAMES); + p_s2_deinterleaver = new leansdr::s2_deinterleaver( + m_objScheduler, + *(leansdr::pipebuf< leansdr::plslot > *) p_slots_dvbs2, + *(leansdr::pipebuf< leansdr::fecframe > *) p_fecframes + ); + // Decode FEC-protected frames into plain BB frames. + leansdr::s2_fecdec_helper *r_fecdec = + new leansdr::s2_fecdec_helper( + m_objScheduler, + *(leansdr::pipebuf< leansdr::fecframe > *) p_fecframes, + *(leansdr::pipebuf *) p_bbframes, + "/opt/install/sdrangel/bin/ldpctool", + p_vbitcount, + p_verrcount) + ; + const int nhelpers = 6; + r_fecdec->nhelpers = nhelpers; + r_fecdec->must_buffer = false; +#endif } else { @@ -1290,8 +1319,8 @@ void DATVDemodSink::feed(const SampleVector::const_iterator& begin, const Sample m_objScheduler->step(); m_lngReadIQ=0; - //delete p_rawiq_writer; - //p_rawiq_writer = new leansdr::pipewriter(*p_rawiq); + delete p_rawiq_writer; + p_rawiq_writer = new leansdr::pipewriter(*p_rawiq); } } diff --git a/plugins/channelrx/demoddatv/ldpctool/ldpc_tool.cpp b/plugins/channelrx/demoddatv/ldpctool/ldpc_tool.cpp index ca6219e16..d1ac52894 100644 --- a/plugins/channelrx/demoddatv/ldpctool/ldpc_tool.cpp +++ b/plugins/channelrx/demoddatv/ldpctool/ldpc_tool.cpp @@ -19,6 +19,7 @@ Copyright 2019 #include #include "testbench.h" #include "algorithms.h" +#include "ldpc.h" #if 0 #include "flooding_decoder.h" @@ -28,7 +29,7 @@ static const int DEFAULT_TRIALS = 50; static const int DEFAULT_TRIALS = 25; #endif -ldpctool::LDPCInterface *create_ldpc(char *standard, char prefix, int number); +//ldpctool::LDPCInterface *create_ldpc(char *standard, char prefix, int number); void fail(const char *msg) { @@ -109,7 +110,7 @@ int main(int argc, char **argv) if (!tabname) fail("unsupported modcod"); - ldpctool::LDPCInterface *ldpc = create_ldpc((char *)"S2", tabname[0], atoi(tabname + 1)); + ldpctool::LDPCInterface *ldpc = ldpctool::create_ldpc((char *)"S2", tabname[0], atoi(tabname + 1)); if (!ldpc) { diff --git a/plugins/channelrx/demoddatv/leansdr/dvbs2.h b/plugins/channelrx/demoddatv/leansdr/dvbs2.h index 3161c3915..bdd35f743 100644 --- a/plugins/channelrx/demoddatv/leansdr/dvbs2.h +++ b/plugins/channelrx/demoddatv/leansdr/dvbs2.h @@ -2419,7 +2419,7 @@ struct s2_fecdec_helper : runnable for (int i = 0; i < p->nprocs; ++i) { helper_instance *h = &p->procs[i]; - size_t iosize = (pin->pls.framebits() / 8) * sizeof(SOFTBYTE); + int iosize = (pin->pls.framebits() / 8) * sizeof(SOFTBYTE); // fprintf(stderr, "Writing %lu to fd %d\n", iosize, h->fd_tx); int nw = write(h->fd_tx, pin->bytes, iosize); if (nw < 0 && errno == EWOULDBLOCK) @@ -2494,7 +2494,7 @@ struct s2_fecdec_helper : runnable char mc_arg[16]; sprintf(mc_arg, "%d", pls->modcod); const char *sf_arg = pls->sf ? "--shortframes" : NULL; - const char *argv[] = {command, "--modcod", mc_arg, sf_arg, NULL}; + const char *argv[] = {command, "--trials", "10", "--modcod", mc_arg, sf_arg, NULL}; execve(command, (char *const *)argv, NULL); fatal(command); } @@ -2514,7 +2514,7 @@ struct s2_fecdec_helper : runnable { // Read corrected frame from helper const s2_pls *pls = &job->pls; - size_t iosize = (pls->framebits() / 8) * sizeof(ldpc_buf[0]); + int iosize = (pls->framebits() / 8) * sizeof(ldpc_buf[0]); int nr = read(job->h->fd_rx, ldpc_buf, iosize); if (nr < 0) fatal("read(LDPC helper)"); @@ -2526,8 +2526,8 @@ struct s2_fecdec_helper : runnable const fec_info *fi = &fec_infos[job->pls.sf][mcinfo->rate]; uint8_t *hardbytes = softbytes_harden(ldpc_buf, fi->kldpc / 8, bch_buf); size_t cwbytes = fi->kldpc / 8; - size_t msgbytes = fi->Kbch / 8; - size_t chkbytes = cwbytes - msgbytes; + //size_t msgbytes = fi->Kbch / 8; + //size_t chkbytes = cwbytes - msgbytes; bch_interface *bch = s2bch.bchs[job->pls.sf][mcinfo->rate]; int ncorr = bch->decode(hardbytes, cwbytes); if (sch->debug2)