forked from wirbel-at-vdr-portal/wirbelscan-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
273 lines (240 loc) · 9.04 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*******************************************************************************
* wirbelscan: A plugin for the Video Disk Recorder
* See the README file for copyright information and how to reach the author.
******************************************************************************/
#pragma once
#include <string>
#include <array>
#include <map>
#include <utility> // std::move
#include <linux/types.h>
#include <sys/ioctl.h>
#include <vdr/diseqc.h>
#include <repfunc.h>
#include "tlist.h"
#define SCAN_TERRESTRIAL 0 /* DVB-T/T2 */
#define SCAN_CABLE 1 /* DVB-C */
#define SCAN_SATELLITE 2 /* DVB-S/S2 */
#define SCAN_TERRCABLE_ATSC 5 /* ATSC VSB and/or QAM */
#define SCAN_NO_DEVICE 6
#define SCAN_TRANSPONDER 999
#define SCAN_TV ( 1 << 0 )
#define SCAN_RADIO ( 1 << 1 )
#define SCAN_FTA ( 1 << 2 )
#define SCAN_SCRAMBLED ( 1 << 3 )
#define ADAPTER_AUTO 0
#define DVBC_INVERSION_AUTO 0
#define DVBC_QAM_AUTO 0
#define DVBC_QAM_64 1
#define DVBC_QAM_128 2
#define DVBC_QAM_256 3
#define EAST_FLAG 0
#define WEST_FLAG 1
#define MAXSIGNALSTRENGTH 65535
#define MINSIGNALSTRENGTH 16383
#define STDOUT 1
#define SYSLOG 2
#define STDERR 3
#define dlog(level, str) do { _log(__PRETTY_FUNCTION__,__LINE__, level, str); } while(0)
void _log(const char* function, int line, const int level, std::string);
#define fatal(x) dlog(0, x); return -1
#define warning(x) dlog(1, x)
#define info(x) dlog(2, x)
#define verbose(x) dlog(4, x)
/*******************************************************************************
* forward decls.
******************************************************************************/
class cChannel;
class cDevice;
class cDvbDevice;
/*******************************************************************************
* class TParams, provide VDR param string as separate items.
******************************************************************************/
class TParams {
private:
int Value(const char*& s);
public:
TParams();
TParams(std::string& s);
void Parse(std::string& s);
void Print(std::string& dest, char Source); // Source = {'A','C','S','T'}
public:
int Bandwidth;
int FEC;
int FEC_low;
int Guard;
char Polarization;
int Inversion;
int Modulation;
int Pilot;
int Rolloff;
int StreamId;
int SystemId;
int DelSys;
int Transmission;
int MISO;
int Hierarchy;
};
/*******************************************************************************
* class TChannel, internal channel representation.
******************************************************************************/
class TPid {
public:
TPid() : PID(0), Type(0), Lang("") {}
int PID;
int Type;
std::string Lang;
};
struct transposer {
uint8_t cell_id_extension;
uint32_t transposer_frequency;
};
struct cell {
uint16_t cell_id;
// if TFS: up to 6 RF freqs.
int num_center_frequencies;
uint32_t center_frequencies[6];
int num_transposers;
struct transposer transposers[16];
};
class TChannel {
public:
std::string Name; // ':' replaced by '|', may contain ','
std::string Shortname; // ',' replaced by '.'
std::string Provider;
int Frequency; // S:MHz, C,T: MHz,kHz,Hz
int Bandwidth; // 'B' 1712, 5, 6, 7, 8, 10, DVB-T/DVB-T2 only
int FEC; // 'C' 0, 12, 23, 34, 35, 45, 56, 67, 78, 89, 910
int FEC_low; // 'D', DVB-T/DVB-T2 only
int Guard; // 'G' 4, 8, 16, 32, 128, 19128, 19256: DVB-T/DVB-T2 only
char Polarization; // 'H', 'V', 'L', 'R'
int Inversion; // 'I' 0, 1 : DVB-T and DVB-C only
int Modulation; // 'M' 2, 5, 6, 7, 10, 11, 12, 16, 32, 64, 128, 256, 999
// 2 QPSK (DVB-S, DVB-S2, DVB-T, DVB-T2, ISDB-T)
// 5 8PSK (DVB-S, DVB-S2)
// 6 16APSK (DVB-S2)
// 7 32APSK (DVB-S2)
// 10 VSB8 (ATSC aerial)
// 11 VSB16 (ATSC aerial)
// 12 DQPSK (ISDB-T)
// 16 QAM16 (DVB-T, DVB-T2, ISDB-T)
// 32 QAM32
// 64 QAM64 (DVB-C, DVB-T, DVB-T2, ISDB-T)
// 128 QAM128 (DVB-C)
// 256 QAM256 (DVB-C, DVB-T2)
int Pilot; // 'N' 0, 1, 999: DVB-S2 only
int Rolloff; // 'O' 0, 20, 25, 35
int StreamId; // 'P' 0-255
int SystemId; // 'Q' 0-65535
int DelSys; // 'S' 0, 1
int Transmission; // 'T' 1, 2, 4, 8, 16, 32: DVB-T/DVB-T2 only
int MISO; // 'X' 0 = siso, 1 = miso
int Hierarchy; // 'Y' 0, 1, 2, 4
std::string Source; // as defined in the file sources.conf
int Symbolrate; // DVB-S and DVB-C only
//--
TPid VPID; // video PID, type may follow VPID, separated by '='
int PCR; // may follow VPID, separated by '+'
TList<TPid> APIDs; // separated by commas: 101=deu@4. Ends with ';' if Dpids follow.
TList<TPid> DPIDs; // separated by commas: 103=deu@4
int TPID; // The teletext PID. If this channel also carries DVB subtitles,
TList<TPid> SPIDs; // the DVB subtitling PIDs follow the teletext PID, sep by a ';'
TList<int> CAIDs; // hex int (!) list.
int SID; // Service ID
int ONID; // original Network ID
int NID; // Network ID
int TID; // Transport stream ID
int RID; // just to mark invalid channels.
int LCN; // 'Logical Channel Number', usually -1 (invalid)
int LCN_minor; // if used and LCN valid, the LCN part after the dot. -1 otherwise.
int PMT;
bool free_CA_mode;
uint16_t service_type;
int OrbitalPos;
bool West;
bool reported;
bool Tunable;
bool Tested;
TList<struct cell> cells;
public:
TChannel(void);
TChannel& operator= (const cChannel* rhs);
void CopyTransponderData(const TChannel* Channel);
void Params(std::string& s);
void PrintTransponder(std::string& dest);
void Print(std::string& dest);
void VdrChannel(cChannel& c);
bool ValidSatIf(void);
};
/*******************************************************************************
* class TChannels
******************************************************************************/
bool is_different_transponder_deep_scan(const TChannel* a, const TChannel* b, bool auto_allowed);
class TChannels : public TList<TChannel*> {
public:
TChannel* GetByParams(const TChannel* NewTransponder) {
for(auto t:v)
if (!is_different_transponder_deep_scan(t, NewTransponder, true))
return t;
return nullptr;
}
bool IsUniqueTransponder(const TChannel* NewTransponder) {
return (GetByParams(NewTransponder) == nullptr);
}
};
/*******************************************************************************
* class cMySetup
******************************************************************************/
class cMySetup {
public:
int verbosity;
int logFile;
int DVB_Type;
int DVBT_Inversion;
int DVBC_Inversion;
int DVBC_Symbolrate;
int DVBC_QAM;
int DVBC_Network_PID;
int CountryIndex;
int SatIndex;
int enable_s2; /* Includes S2 & T2 */
int ATSC_type;
uint32_t scanflags;
bool update;
uint32_t user[3];
int systems[8];
bool initsystems;
int scan_remove_invalid;
int scan_update_existing;
int scan_append_new;
bool ParseLCN;
std::array<std::string,5> preferred;
int SignalWaitTime;
int LockTimeout;
public:
cMySetup(void);
void InitSystems(void);
};
extern cMySetup wSetup;
extern std::map<char,int> dmap;
/*******************************************************************************
* generic functions
******************************************************************************/
void hexdump(std::string intro, const unsigned char* buf, size_t len);
int IOCTL(int fd, int cmd, void* data);
template<class T> inline void DeleteNullptr(T*& aClass) {
T* temp = aClass;
aClass = nullptr;
delete temp;
}
cDvbDevice* GetDvbDevice(cDevice* d);
int dvbc_modulation(int index);
int dvbc_symbolrate(int index);
void InitSystems(void);
void PrintDvbApi(std::string& s);
unsigned int GetFrontendStatus(cDevice* dev);
bool GetTerrCapabilities (cDevice* dev, bool* CodeRate, bool* Modulation, bool* Inversion, bool* Bandwidth, bool* Hierarchy, bool* TransmissionMode, bool* GuardInterval, bool* DvbT2);
bool GetCableCapabilities(cDevice* dev, bool* Modulation, bool* Inversion);
bool GetAtscCapabilities (cDevice* dev, bool* Modulation, bool* Inversion, bool* VSB, bool* QAM);
bool GetSatCapabilities (cDevice* dev, bool* CodeRate, bool* Modulation, bool* RollOff, bool* DvbS2);
std::string DeviceName(cDevice* dev);