-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
180 lines (160 loc) · 6.05 KB
/
main.cpp
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
/******************************************************************************
* w_scan_cpp - a dtv channel scanner based on VDR (www.tvdr.de) and it's
* Plugins.
*
* See the README file for copyright information and how to reach the author.
*****************************************************************************/
#include <chrono>
#include "Helpers.h"
#include "CmdOpts.h"
#include "Satellites.h"
#include "Countries.h"
#include "Library.h"
#include "Lnb.h"
#include "DiSEqC.h"
#include "ScanControl.h"
#include "OutputFormats.h"
#include "Femon.h"
#include "Version.h"
int main(int argc, char* argv[]) {
Message("/*******************************************************************************");
Message(" * w_scan_cpp Version " + version);
Message(" ******************************************************************************/\n");
if (not(ParseArguments(argc, argv))) {
ErrorMessage("Error reading command line arguments. Exit!");
return -1;
}
if (WirbelscanSetup.HelpText) {
UnloadLibraries();
return 0;
}
InitCharTables();
for(auto l:libs) {
l->Plugin()->Initialize();
l->Plugin()->Start();
}
Message("/*******************************************************************************");
Message(" * devices");
Message(" ******************************************************************************/");
if (satip == nullptr) {
if (WirbelscanSetup.adapter.empty()) {
cDvbDevice::Initialize();
}
else {
if (WirbelscanSetup.adapter.find("/dev/dvb/adapter") == 0) {
std::string s(WirbelscanSetup.adapter);
s.erase(0, std::string("/dev/dvb/adapter").size());
int a = std::stoi(s.substr(0, s.find("frontend")-1));
s.erase(0, s.find("frontend") + std::string("frontend").size());
int f = std::stoi(s);
new cDvbDevice(a, f);
}
else if (WirbelscanSetup.adapter.find_first_of("0123456789") == 0) {
int a = std::stoi(WirbelscanSetup.adapter);
new cDvbDevice(a, 0);
}
}
}
else
Message("skip DVB devices - using satip plugin.");
while (!cDevice::WaitForAllDevicesReady(3));
if (satip) {
std::string Reply;
for(int i=0; (i < 5) and not SVDRP(satip, "LIST", Reply); i++) {
SVDRP(satip, "SCAN", Reply);
Message(Reply);
mSleep(3000);
}
for(auto line:SplitStr(Reply, '\n')) {
if (not ParseSatipServer(line))
continue;
Message("using " + WirbelscanSetup.SatipDesc + "@" + WirbelscanSetup.SatipAddr);
}
if (WirbelscanSetup.SatipAddr.empty()) {
Message("no satip server found.");
return -1;
}
}
for(int i = 0; i < cDevice::NumDevices(); i++) {
cDevice* d = cDevice::GetDevice(i);
cDvbDevice* dvb = dynamic_cast<cDvbDevice*>(d);
std::string name = "Device" + std::to_string(i);
if (d->NumProvidedSystems() < 1) {
name += ": Device or resource busy";
}
else if (*d->DeviceName() != nullptr) {
if (dvb) {
name += " dvb:";
name += "a" + std::to_string(dvb->Adapter());
name += "f" + std::to_string(dvb->Frontend());
name += ": ";
}
else
name += " plg: ";
name += *d->DeviceName();
}
Message(name);
}
if (OutputFormat == "FEMON")
return SignalMonitor(cDevice::GetDevice(0), WirbelscanSetup.FemonChannel);
Message("/*******************************************************************************");
Message(" * Scan Type");
Message(" ******************************************************************************/");
switch(WirbelscanSetup.DVB_Type) {
case 5 /* A */: {
Message(" ATSC");
Message(" country = " + CountryNames[WirbelscanSetup.CountryIndex]);
break;
}
case 1 /* C */: {
Message(" DVB-C");
Message(" country = " + CountryNames[WirbelscanSetup.CountryIndex]);
break;
}
case 2 /* S */: {
Message(" DVB-S/S2");
Message(" satellite = " + SatNames[WirbelscanSetup.SatIndex]);
PrintLnb();
if (Setup.DiSEqC)
PrintDiseqc();
break;
}
default/* T */: {
Message(" DVB-T/T2");
Message(" country = " + CountryNames[WirbelscanSetup.CountryIndex]);
break;
}
}
auto Start = std::chrono::high_resolution_clock::now();
bool Continue = StartScan();
while(Continue) {
mSleep(500);
Continue = Scanning();
}
std::vector<TChannel> data;
if (Import(data) and not data.empty()) {
auto Stop = std::chrono::high_resolution_clock::now();
auto Elapsed = std::chrono::duration_cast<std::chrono::seconds>(Stop - Start).count();
if (WirbelscanSetup.ParseLCN and WirbelscanSetup.verbosity > 4) {
extern std::string VdrChannel(TChannel c);
extern std::vector<TChannel> UniqueChannels(const std::vector<TChannel>& List);
for(auto c:UniqueChannels(data)) dlog(5, BackFill(IntToStr(c.LCN),6) + VdrChannel(c));
}
Message(std::to_string(data.size()) + " services. scan time: " +
IntToStr(Elapsed / 60, 2, false, '0') + ":" + IntToStr(Elapsed % 60, 2, false, '0'));
if (OutputFormat == "VDR") PrintVDR(data);
else if (OutputFormat == "INI") PrintIni(data);
else if (OutputFormat == "VLC") PrintVLC(data, false);
else if (OutputFormat == "VLC_SAT>IP") PrintVLC(data, true);
else if (OutputFormat == "XINE") PrintXine(data);
else if (OutputFormat == "MPLAYER") PrintXine(data, true);
else if (OutputFormat == "INITIAL") PrintInitial(data);
else if (OutputFormat == "XML") PrintXML(data);
else if (OutputFormat == "DAT") PrintDat(data, WirbelscanSetup.OutputFile);
else if (OutputFormat == "SATELLITES.DAT") PrintSatellitesDat(data);
else Message("no output format defined - try again!");
}
for(auto l:libs)
l->Plugin()->Stop();
UnloadLibraries();
}