1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-23 16:38:37 -05:00
sdrangel/plugins/channelrx/demoddatv/datvconstellation.h

139 lines
4.6 KiB
C
Raw Normal View History

2018-02-22 16:52:49 -05:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 F4HKW //
// for F4EXB / SDRAngel //
// using LeanSDR Framework (C) 2016 F4DAV //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef DATVCONSTELLATION_H
#define DATVCONSTELLATION_H
#include <sys/time.h>
#include <vector>
2018-02-22 16:52:49 -05:00
#include "leansdr/framework.h"
2018-03-11 11:39:02 -04:00
#include "gui/tvscreen.h"
2018-02-22 16:52:49 -05:00
namespace leansdr
{
2018-02-24 18:07:08 -05:00
static const int DEFAULT_GUI_DECIMATION = 64;
2018-02-22 16:52:49 -05:00
2018-02-24 18:07:08 -05:00
template<typename T> struct datvconstellation: runnable
{
2018-02-25 19:04:45 -05:00
T xymin, xymax;
2018-02-24 18:07:08 -05:00
unsigned long decimation;
unsigned long pixels_per_frame;
cstln_lut<256> **cstln; // Optional ptr to optional constellation
2018-03-11 11:39:02 -04:00
TVScreen *m_objDATVScreen;
2018-02-24 18:07:08 -05:00
pipereader<complex<T> > in;
unsigned long phase;
std::vector<int> cstln_rows;
std::vector<int> cstln_cols;
2018-02-24 18:07:08 -05:00
2018-03-11 11:39:02 -04:00
datvconstellation(scheduler *sch, pipebuf<complex<T> > &_in, T _xymin, T _xymax, const char *_name = 0, TVScreen *objDATVScreen = 0) :
2018-02-25 19:04:45 -05:00
runnable(sch, _name ? _name : _in.name),
xymin(_xymin),
xymax(_xymax),
decimation(DEFAULT_GUI_DECIMATION),
pixels_per_frame(1024),
cstln(0),
2018-02-25 19:04:45 -05:00
m_objDATVScreen(objDATVScreen),
in(_in),
phase(0)
2018-02-24 18:07:08 -05:00
{
}
void run()
2018-02-22 16:52:49 -05:00
{
//Symbols
2018-02-24 18:07:08 -05:00
while (in.readable() >= pixels_per_frame)
2018-02-22 16:52:49 -05:00
{
if ((!phase) && m_objDATVScreen)
2018-02-22 16:52:49 -05:00
{
m_objDATVScreen->resetImage();
2018-02-24 18:07:08 -05:00
complex<T> *p = in.rd(), *pend = p + pixels_per_frame;
2018-02-22 16:52:49 -05:00
2018-02-24 18:07:08 -05:00
for (; p < pend; ++p)
2018-02-22 16:52:49 -05:00
{
if (m_objDATVScreen != 0)
2018-02-22 16:52:49 -05:00
{
2018-02-25 19:04:45 -05:00
m_objDATVScreen->selectRow(256 * (p->re - xymin) / (xymax - xymin));
m_objDATVScreen->setDataColor(256 - 256 * ((p->im - xymin) / (xymax - xymin)), 255, 0, 255);
2018-02-22 16:52:49 -05:00
}
}
2018-02-24 18:07:08 -05:00
if (cstln && (*cstln))
2018-02-22 16:52:49 -05:00
{
2018-02-24 18:07:08 -05:00
// Plot constellation points
2018-02-22 16:52:49 -05:00
std::vector<int>::const_iterator row_it = cstln_rows.begin();
std::vector<int>::const_iterator col_it = cstln_cols.begin();
for (; (row_it != cstln_rows.end()) && (col_it != cstln_cols.end()); ++row_it, ++col_it)
2018-02-22 16:52:49 -05:00
{
m_objDATVScreen->selectRow(*row_it);
m_objDATVScreen->setDataColor(*col_it, 250, 250, 5);
2018-02-22 16:52:49 -05:00
}
}
m_objDATVScreen->renderImage(0);
2018-02-22 16:52:49 -05:00
}
in.read(pixels_per_frame);
2018-02-24 18:07:08 -05:00
if (++phase >= decimation)
2018-02-22 16:52:49 -05:00
{
phase = 0;
}
2018-02-24 18:07:08 -05:00
}
}
2018-02-22 16:52:49 -05:00
2018-02-24 18:07:08 -05:00
void draw_begin()
{
}
2018-02-22 16:52:49 -05:00
void calculate_cstln_points()
{
if (!(*cstln)) {
return;
}
cstln_rows.clear();
cstln_cols.clear();
for (int i = 0; i < (*cstln)->nsymbols; ++i)
{
complex<signed char> *p = &(*cstln)->symbols[i];
int x = 256 * (p->re - xymin) / (xymax - xymin);
int y = 256 - 256 * (p->im - xymin) / (xymax - xymin);
for (int d = -4; d <= 4; ++d)
{
cstln_rows.push_back(x + d);
cstln_cols.push_back(y);
cstln_rows.push_back(x);
cstln_cols.push_back(y + d);
}
}
}
2018-02-24 18:07:08 -05:00
};
2018-02-22 16:52:49 -05:00
}
#endif // DATVCONSTELLATION_H