zapit: add delay when retrying SCR tuning

this is not exactly the algorithm as described in EN50494
sect.8, but rand() is probably good enough :-)
This commit is contained in:
Stefan Seyfried
2013-03-03 22:11:57 +01:00
parent 6c4b9741ec
commit 0edd7fd2bc
2 changed files with 15 additions and 5 deletions

View File

@@ -156,8 +156,11 @@ bool CServiceScan::tuneFrequency(FrontendParameters *feparams, uint8_t polarizat
if (abort_scan) if (abort_scan)
break; break;
retry--; retry--;
if (retry) if (retry) {
printf("[unicable] [scan] retrying tune, retry=%d\n", retry); int rand_us = (rand() * 1000000LL / RAND_MAX);
printf("[scan] SCR retrying tune, retry=%d after %dms\n", retry, rand_us/1000);
usleep(rand_us);
}
} while (retry > 0); } while (retry > 0);
return false; return false;
} }

View File

@@ -511,8 +511,9 @@ bool CZapit::ZapIt(const t_channel_id channel_id, bool forupdate, bool startplay
live_channel_id = current_channel->getChannelID(); live_channel_id = current_channel->getChannelID();
SaveSettings(false); SaveSettings(false);
srand(time(NULL));
/* retry tuning twice when using unicable */ /* retry tuning twice when using unicable, TODO: EN50494 sect.8 specifies 4 retries... */
int retry = (live_fe->getDiseqcType() == DISEQC_UNICABLE) * 2; int retry = (live_fe->getDiseqcType() == DISEQC_UNICABLE) * 2;
again: again:
if(!TuneChannel(live_fe, newchannel, transponder_change)) { if(!TuneChannel(live_fe, newchannel, transponder_change)) {
@@ -521,7 +522,11 @@ bool CZapit::ZapIt(const t_channel_id channel_id, bool forupdate, bool startplay
SendEvent(CZapitClient::EVT_TUNE_COMPLETE, &chid, sizeof(t_channel_id)); SendEvent(CZapitClient::EVT_TUNE_COMPLETE, &chid, sizeof(t_channel_id));
return false; return false;
} }
printf("[zapit] %s:1 unicable retry tuning %d\n", __func__, retry); int rand_us = (rand() * 1000000LL / RAND_MAX); /* max. 1 second delay */
printf("[zapit] %s:1 SCR retry tuning %d after %dms\n", __func__, retry, rand_us / 1000);
/* EN50494 sect.8 specifies an elaborated way of calculating the delay, but I'm
* pretty sure rand() is not much worse :-) */
usleep(rand_us);
live_fe->tuned = false; live_fe->tuned = false;
retry--; retry--;
goto again; goto again;
@@ -536,7 +541,9 @@ bool CZapit::ZapIt(const t_channel_id channel_id, bool forupdate, bool startplay
failed = !ParsePatPmt(current_channel); failed = !ParsePatPmt(current_channel);
if (failed && retry > 0) { if (failed && retry > 0) {
printf("[zapit] %s:2 unicable retry tuning %d\n", __func__, retry); int rand_us = (rand() * 1000000LL / RAND_MAX);
printf("[zapit] %s:2 SCR retry tuning %d after %dms\n", __func__, retry, rand_us / 1000);
usleep(rand_us);
live_fe->tuned = false; live_fe->tuned = false;
retry--; retry--;
goto again; goto again;