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.
datvdvbs2constellation.h
Go to the documentation of this file.
1 // Copyright (C) 2019 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 DATVDVBS2CONSTELLATION_H
21 #define DATVDVBS2CONSTELLATION_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_DVBS2_DECIMATION = 64;
31 
32 static inline cstln_lut<llr_ss, 256> * make_dvbs2_constellation(cstln_lut<llr_ss, 256>::predef c,
33  code_rate r)
34 {
35  float gamma1 = 1, gamma2 = 1, gamma3 = 1;
36 
37  switch (c)
38  {
40  // EN 302 307, section 5.4.3, Table 9
41  switch (r)
42  {
43  case FEC23:
44  case FEC46:
45  gamma1 = 3.15;
46  break;
47  case FEC34:
48  gamma1 = 2.85;
49  break;
50  case FEC45:
51  gamma1 = 2.75;
52  break;
53  case FEC56:
54  gamma1 = 2.70;
55  break;
56  case FEC89:
57  gamma1 = 2.60;
58  break;
59  case FEC910:
60  gamma1 = 2.57;
61  break;
62  default:
63  fail("cstln_lut<256>::make_dvbs2_constellation: Code rate not supported with APSK16");
64  return 0;
65  }
66  break;
68  // EN 302 307, section 5.4.4, Table 10
69  switch (r)
70  {
71  case FEC34:
72  gamma1 = 2.84;
73  gamma2 = 5.27;
74  break;
75  case FEC45:
76  gamma1 = 2.72;
77  gamma2 = 4.87;
78  break;
79  case FEC56:
80  gamma1 = 2.64;
81  gamma2 = 4.64;
82  break;
83  case FEC89:
84  gamma1 = 2.54;
85  gamma2 = 4.33;
86  break;
87  case FEC910:
88  gamma1 = 2.53;
89  gamma2 = 4.30;
90  break;
91  default:
92  fail("cstln_lut<llr_ss, 256>::make_dvbs2_constellation: Code rate not supported with APSK32");
93  return 0;
94  }
95  break;
97  // EN 302 307-2, section 5.4.5, Table 13f
98  gamma1 = 2.4;
99  gamma2 = 4.3;
100  gamma3 = 7;
101  break;
102  default:
103  break;
104  }
105 
106  cstln_lut<llr_ss, 256> *newCstln = new cstln_lut<llr_ss, 256>(c, 10, gamma1, gamma2, gamma3);
107  newCstln->m_rateCode = (int) r;
108  newCstln->m_typeCode = (int) c;
109  newCstln->m_setByModcod = false;
110  return newCstln;
111 }
112 
113 template<typename T> struct datvdvbs2constellation: runnable
114 {
116  unsigned long decimation;
118  /*cstln_lut<llr_ss, 256>*/ cstln_base **cstln; // Optional ptr to optional constellation
121  unsigned long phase;
122  std::vector<int> cstln_rows;
123  std::vector<int> cstln_cols;
124 
126  scheduler *sch,
127  pipebuf<complex<T> > &_in,
128  T _xymin,
129  T _xymax,
130  const char *_name = nullptr,
131  TVScreen *objDATVScreen = nullptr) :
132  runnable(sch, _name ? _name : _in.name),
133  xymin(_xymin),
134  xymax(_xymax),
135  decimation(DEFAULT_GUI_DVBS2_DECIMATION),
136  pixels_per_frame(1024),
137  cstln(0),
138  m_objDATVScreen(objDATVScreen),
139  in(_in),
140  phase(0)
141  {
142  }
143 
144  void run()
145  {
146 
147  phase=0;
148  //Symbols
149  while (in.readable() >= pixels_per_frame)
150  {
151  if ((!phase) && m_objDATVScreen)
152  {
153  m_objDATVScreen->resetImage();
154 
155  complex<T> *p = in.rd(), *pend = p + pixels_per_frame;
156 
157  for (; p < pend; ++p)
158  {
159  m_objDATVScreen->selectRow(256 * (p->re - xymin) / (xymax - xymin));
160  m_objDATVScreen->setDataColor(
161  256 - 256 * ((p->im - xymin) / (xymax - xymin)),
162  255, 0, 255);
163  }
164 
165  if (cstln && (*cstln))
166  {
167  // Plot constellation points
168  std::vector<int>::const_iterator row_it = cstln_rows.begin();
169  std::vector<int>::const_iterator col_it = cstln_cols.begin();
170 
171  for (;(row_it != cstln_rows.end()) && (col_it != cstln_cols.end()); ++row_it, ++col_it)
172  {
173  m_objDATVScreen->selectRow(*row_it);
174  m_objDATVScreen->setDataColor(*col_it, 250, 250, 250);
175  }
176  }
177 
178  m_objDATVScreen->renderImage(0);
179  }
180 
181  in.read(pixels_per_frame);
182 
183  if (++phase >= decimation) {
184  phase = 0;
185  }
186  }
187  }
188 
189  void draw_begin()
190  {
191  }
192 
194  {
195  if (!(*cstln)) {
196  return;
197  }
198 
199  cstln_rows.clear();
200  cstln_cols.clear();
201 
202  for (int i = 0; i < (*cstln)->nsymbols; ++i)
203  {
204  complex<signed char> *p = &(*cstln)->symbols[i];
205  int x = 256 * (p->re - xymin) / (xymax - xymin);
206  int y = 256 - 256 * (p->im - xymin) / (xymax - xymin);
207 
208  for (int d = -4; d <= 4; ++d)
209  {
210  cstln_rows.push_back(x + d);
211  cstln_cols.push_back(y);
212  cstln_rows.push_back(x);
213  cstln_cols.push_back(y + d);
214  }
215  }
216  }
217 };
218 
219 } // leansdr
220 
221 #endif // DATVDVBS2CONSTELLATION_H
bool setDataColor(int intCol, int intRed, int intGreen, int intBlue)
Definition: tvscreen.cpp:224
void resetImage()
Definition: tvscreen.cpp:76
void renderImage(unsigned char *objData)
Definition: tvscreen.cpp:70
code_rate
Definition: dvb.h:41
datvdvbs2constellation(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
scheduler * sch
Definition: framework.h:199
bool selectRow(int intLine)
Definition: tvscreen.cpp:212
void read(unsigned long n)
Definition: framework.h:367