From 0edd7fd2bc7af1ac72f305dbb9d2f3a12a89dbcb Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 3 Mar 2013 22:11:57 +0100 Subject: [PATCH] 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 :-) --- src/zapit/src/scan.cpp | 7 +++++-- src/zapit/src/zapit.cpp | 13 ++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/zapit/src/scan.cpp b/src/zapit/src/scan.cpp index 6129d5d2d..3c3614d2f 100644 --- a/src/zapit/src/scan.cpp +++ b/src/zapit/src/scan.cpp @@ -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; } diff --git a/src/zapit/src/zapit.cpp b/src/zapit/src/zapit.cpp index 9db98d4bc..c22adefaf 100644 --- a/src/zapit/src/zapit.cpp +++ b/src/zapit/src/zapit.cpp @@ -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;