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
|
/******************************************************************************
* 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 "Helpers.h"
#include "Femon.h"
#include "CmdOpts.h"
/*******************************************************************************
* class cData, a dummy receiver.
******************************************************************************/
class cData : public cReceiver, cThread {
private:
protected:
virtual void Activate(bool On);
virtual void Receive(const uchar* Data, int Length);
virtual void Action(void);
public:
cData();
virtual ~cData() { cReceiver::Detach(); };
};
cData::cData() : cReceiver(NULL, 99), cThread("cData") { }
void cData::Receive(const uchar* Data, int Length) {
(void)Data;
(void)Length;
}
void cData::Action(void) {
while(Running())
mSleep(100);
};
void cData::Activate(bool On) {
if (On) Start();
else Cancel(0);
};
/*******************************************************************************
* signal strength hints
******************************************************************************/
std::string StrengthHint(cChannel& Channel, double Strength) {
std::string s;
double min = -1e9, max = 1e9;
char src = Channel.Source() >> 24;
int mod = cDvbTransponderParameters(Channel.Parameters()).Modulation();
int sys = cDvbTransponderParameters(Channel.Parameters()).System();
switch(src) {
case 'A':
break;
case 'C': {
switch(mod) {
case 3: /* M64 */ min = 47, max = 67; break;
case 4: /* M128 */ min = 51, max = 71; break;
case 5: /* M256 */ min = 54, max = 74; break;
default:;
}
}
break;
case 'S':
min = 47, max = 77; /* any */
break;
case 'T':
if (sys == 0)
switch(mod) {
case 0: /* M4 */ min = 33, max = 74; break;
case 1: /* M16 */ min = 36, max = 74; break;
case 3: /* M64 */ min = 45, max = 74; break;
default:;
}
else
switch(mod) {
case 0: /* M4 */ min = 33, max = 74; break;
case 1: /* M16 */ min = 35, max = 74; break;
case 3: /* M64 */ min = 39, max = 74; break;
case 5: /* M256 */ min = 43, max = 74; break;
default:;
}
break;
default:;
}
return Strength < min ? "(too low)" :
Strength > max ? "(too high)" :
Strength < (min + 6) ? "(a bit low)" :
Strength > (max -3) ? "(a bit high)" :
"";
}
/*******************************************************************************
* SignalMonitor(), print femon-like signal stats.
******************************************************************************/
static const int strength_available = 0x01;
static const int cnr_available = 0x02;
static const int ber_available = 0x08;
static const int status_available = 0x20;
int SignalMonitor(cDevice* Device, std::string& Channel) {
if (Device == nullptr) {
ErrorMessage("No Device");
return -1;
}
cChannel aChannel;
if (not aChannel.Parse(Channel.c_str())) {
ErrorMessage("Invalid Channel: '" + Channel + "'");
return -1;
}
if (*Device->DeviceName() != nullptr)
Message("monitoring device '" + std::string(*Device->DeviceName()) + "'");
for(;;) {
if (not Device->SwitchChannel(&aChannel, false)) {
Message("tuning failed - try again..");
mSleep(1000);
continue;
}
cData* data = new cData();
Device->AttachReceiver(data);
for(;;) {
double SignalLevel_dBm, CNR_dB, BER;
int result = 0, DemodState, i, SignalLevel_rel;
bool HasLock;
std::string s;
if (not Device->SignalStats(result, &SignalLevel_dBm, &CNR_dB, nullptr, &BER, nullptr, &DemodState))
result = 0;
HasLock = (result & status_available ) ? (DemodState & 0x10) > 0 : Device->HasLock();
SignalLevel_rel = (result & strength_available) ? 0 : Device->SignalStrength();
if (satip) {
/* Bug in satip plugin, plugin reports "no signal" as -71.67dBm,
* where it should be "no signal" (not to be reported),
* see https://github.com/rofafor/vdr-plugin-satip/issues/80
*/
if (SignalLevel_dBm < -71.5)
result &= ~strength_available;
/* Bug in satip plugin, plugin initializes tuners cached dBm value
* to 0.0dBm (a very large value in terms of signal),
* see https://github.com/rofafor/vdr-plugin-satip/issues/80
*/
if (SignalLevel_dBm > -18.5)
result &= ~strength_available;
}
if (HasLock)
s = "lock 1 | ";
else
s = "lock 0 | ";
if (result & strength_available)
s += "signal " + FloatToStr(SignalLevel_dBm + 108.75, 5, 2, false) + "dBuV " +
StrengthHint(aChannel, SignalLevel_dBm + 108.75) + " | ";
else
if (SignalLevel_rel > -1)
s += "signal " + IntToStr(SignalLevel_rel) + "% | ";
/* w/o lock, demods may not report valid stats for
* quality, cnr, ber
*/
if (HasLock) {
if ((i = Device->SignalQuality()) > -1)
s += "quality " + IntToStr(i) + "% | ";
if (result & cnr_available)
s += "snr " + FloatToStr(CNR_dB, 4, 2, false) + "dB | ";
if (result & ber_available) {
s += "ber " + ExpToStr(BER);
if (BER > 1e-4)
s += " (too high)";
}
}
Message(s);
mSleep(1000);
}
delete data;
}
return 0;
}
|