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)
break;
retry--;
if (retry)
printf("[unicable] [scan] retrying tune, retry=%d\n", retry);
if (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);
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();
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;
again:
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));
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;
retry--;
goto again;
@@ -536,7 +541,9 @@ bool CZapit::ZapIt(const t_channel_id channel_id, bool forupdate, bool startplay
failed = !ParsePatPmt(current_channel);
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;
retry--;
goto again;