SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
datvconstellation.h
Go to the documentation of this file.
1 // Copyright (C) 2018 F4HKW //
3 // for F4EXB / SDRAngel //
4 // using LeanSDR Framework (C) 2016 F4DAV //
5 // //
6 // This program is free software; you can redistribute it and/or modify //
7 // it under the terms of the GNU General Public License as published by //
8 // the Free Software Foundation as version 3 of the License, or //
9 // (at your option) any later version. //
10 // //
11 // This program is distributed in the hope that it will be useful, //
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
14 // GNU General Public License V3 for more details. //
15 // //
16 // You should have received a copy of the GNU General Public License //
17 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
19 
20 #ifndef DATVCONSTELLATION_H
21 #define DATVCONSTELLATION_H
22 
23 #include <vector>
24 
25 #include "leansdr/framework.h"
26 #include "gui/tvscreen.h"
27 
28 namespace leansdr {
29 
30 static const int DEFAULT_GUI_DECIMATION = 64;
31 
32 static inline cstln_lut<eucl_ss, 256> * make_dvbs_constellation(cstln_lut<eucl_ss, 256>::predef c,
33  code_rate r)
34 {
35  float gamma1 = 1, gamma2 = 1, gamma3 = 1;
36  switch (c)
37  {
39  // EN 302 307, section 5.4.3, Table 9
40  switch (r)
41  {
42  case FEC23:
43  case FEC46:
44  gamma1 = 3.15;
45  break;
46  case FEC34:
47  gamma1 = 2.85;
48  break;
49  case FEC45:
50  gamma1 = 2.75;
51  break;
52  case FEC56:
53  gamma1 = 2.70;
54  break;
55  case FEC89:
56  gamma1 = 2.60;
57  break;
58  case FEC910:
59  gamma1 = 2.57;
60  break;
61  default:
62  fail("cstln_lut<256>::make_dvbs_constellation: Code rate not supported with APSK16");
63  return 0;
64  }
65  break;
67  // EN 302 307, section 5.4.4, Table 10
68  switch (r)
69  {
70  case FEC34:
71  gamma1 = 2.84;
72  gamma2 = 5.27;
73  break;
74  case FEC45:
75  gamma1 = 2.72;
76  gamma2 = 4.87;
77  break;
78  case FEC56:
79  gamma1 = 2.64;
80  gamma2 = 4.64;
81  break;
82  case FEC89:
83  gamma1 = 2.54;
84  gamma2 = 4.33;
85  break;
86  case FEC910:
87  gamma1 = 2.53;
88  gamma2 = 4.30;
89  break;
90  default:
91  fail("cstln_lut<eucl_ss, 256>::make_dvbs_constellation: Code rate not supported with APSK32");
92  return 0;
93  }
94  break;
96  // EN 302 307-2, section 5.4.5, Table 13f
97  gamma1 = 2.4;
98  gamma2 = 4.3;
99  gamma3 = 7;
100  break;
101  default:
102  break;
103  }
104  cstln_lut<eucl_ss, 256> *newCstln = new cstln_lut<eucl_ss, 256>(c, 10, gamma1, gamma2, gamma3);
105  newCstln->m_rateCode = (int) r;
106  newCstln->m_typeCode = (int) c;
107  newCstln->m_setByModcod = false;
108  return newCstln;
109 }
110 
111 template<typename T> struct datvconstellation: runnable
112 {
114  unsigned long decimation;
116  cstln_lut<eucl_ss, 256> **cstln; // Optional ptr to optional constellation
119  unsigned long phase;
120  std::vector<int> cstln_rows;
121  std::vector<int> cstln_cols;
122 
124  scheduler *sch,
125  pipebuf<complex<T> > &_in,
126  T _xymin,
127  T _xymax,
128  const char *_name = nullptr,
129  TVScreen *objDATVScreen = nullptr) :
130  runnable(sch, _name ? _name : _in.name),
131  xymin(_xymin),
132  xymax(_xymax),
133  decimation(DEFAULT_GUI_DECIMATION),
134  pixels_per_frame(1024),
135  cstln(0),
136  m_objDATVScreen(objDATVScreen),
137  in(_in),
138  phase(0)
139  {
140  }
141 
142  void run()
143  {
144  //Symbols
145  while (in.readable() >= pixels_per_frame)
146  {
147  if ((!phase) && m_objDATVScreen)
148  {
149  m_objDATVScreen->resetImage();
150 
151  complex<T> *p = in.rd(), *pend = p + pixels_per_frame;
152 
153  for (; p < pend; ++p)
154  {
155  m_objDATVScreen->selectRow(256 * (p->re - xymin) / (xymax - xymin));
156  m_objDATVScreen->setDataColor(
157  256 - 256 * ((p->im - xymin) / (xymax - xymin)),
158  255, 0, 255);
159  }
160 
161  if (cstln && (*cstln))
162  {
163  // Plot constellation points
164  std::vector<int>::const_iterator row_it = cstln_rows.begin();
165  std::vector<int>::const_iterator col_it = cstln_cols.begin();
166 
167  for (;(row_it != cstln_rows.end()) && (col_it != cstln_cols.end()); ++row_it, ++col_it)
168  {
169  m_objDATVScreen->selectRow(*row_it);
170  m_objDATVScreen->setDataColor(*col_it, 250, 250, 5);
171  }
172  }
173 
174  m_objDATVScreen->renderImage(0);
175  }
176 
177  in.read(pixels_per_frame);
178 
179  if (++phase >= decimation) {
180  phase = 0;
181  }
182  }
183  }
184 
185  void draw_begin()
186  {
187  }
188 
190  {
191  if (!(*cstln)) {
192  return;
193  }
194 
195  cstln_rows.clear();
196  cstln_cols.clear();
197 
198  for (int i = 0; i < (*cstln)->nsymbols; ++i)
199  {
200  complex<signed char> *p = &(*cstln)->symbols[i];
201  int x = 256 * (p->re - xymin) / (xymax - xymin);
202  int y = 256 - 256 * (p->im - xymin) / (xymax - xymin);
203 
204  for (int d = -4; d <= 4; ++d)
205  {
206  cstln_rows.push_back(x + d);
207  cstln_cols.push_back(y);
208  cstln_rows.push_back(x);
209  cstln_cols.push_back(y + d);
210  }
211  }
212  }
213 };
214 
215 } // leansdr
216 
217 #endif // DATVCONSTELLATION_H
bool setDataColor(int intCol, int intRed, int intGreen, int intBlue)
Definition: tvscreen.cpp:224
void resetImage()
Definition: tvscreen.cpp:76
cstln_lut< eucl_ss, 256 > ** cstln
std::vector< int > cstln_cols
int m_typeCode
Definition: sdr.h:879
pipereader< complex< T > > in
void renderImage(unsigned char *objData)
Definition: tvscreen.cpp:70
bool m_setByModcod
Definition: sdr.h:881
code_rate
Definition: dvb.h:41
datvconstellation(scheduler *sch, pipebuf< complex< T > > &_in, T _xymin, T _xymax, const char *_name=nullptr, TVScreen *objDATVScreen=nullptr)
void fail(const char *s)
Definition: framework.cpp:11
int32_t i
Definition: decimators.h:244
int m_rateCode
Definition: sdr.h:880
scheduler * sch
Definition: framework.h:199
std::vector< int > cstln_rows
bool selectRow(int intLine)
Definition: tvscreen.cpp:212
void read(unsigned long n)
Definition: framework.h:367