From 083c6475d9f110c7031507a6ff75b591ce0b809c Mon Sep 17 00:00:00 2001 From: Sam Stenvall Date: Mon, 24 Jun 2024 13:24:08 +0300 Subject: [PATCH 1/3] Move determining of high sub-band and IF to separate functions The axe implementation was generic, and now that they're separated we can properly test them --- src/adapter.c | 27 +++++++++++++++++++-------- src/adapter.h | 2 ++ src/axe.c | 34 ++++++++-------------------------- src/dvb.c | 15 ++++----------- 4 files changed, 33 insertions(+), 45 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 4788e14116..75657ea739 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -619,16 +619,9 @@ int compare_slave_parameters(adapter *ad, transponder *tp) { // master adapter is used by other int diseqc = (tp->diseqc > 0) ? tp->diseqc - 1 : 0; int pol = (tp->pol - 1) & 1; - int hiband = 0; + int hiband = get_lnb_hiband(tp, &tp->diseqc_param); int freq = tp->freq; - if (tp->pol > 2 && tp->diseqc_param.lnb_circular > 0) - hiband = 0; - else if (freq < tp->diseqc_param.lnb_switch) - hiband = 0; - else - hiband = 1; - if (ad->master_source >= 0 && ad->master_source < MAX_ADAPTERS) master = a[ad->master_source]; @@ -1218,6 +1211,24 @@ int mark_pids_add(int sid, int aid, char *pids) { return 0; } +int get_lnb_hiband(transponder *tp, diseqc *diseqc_param) { + if (tp->pol > 2 && diseqc_param->lnb_circular > 0) + return 0; + if (tp->freq < diseqc_param->lnb_switch) + return 0; + return 1; +} + +int get_lnb_int_freq(transponder *tp, diseqc *diseqc_param) { + int freq = tp->freq; + + if (tp->pol > 2 && diseqc_param->lnb_circular > 0) + return (freq - diseqc_param->lnb_circular); + if (freq < diseqc_param->lnb_switch) + return (freq - diseqc_param->lnb_low); + return (freq - diseqc_param->lnb_high); +} + int compare_tunning_parameters(int aid, transponder *tp) { adapter *ad = get_adapter(aid); if (!ad) diff --git a/src/adapter.h b/src/adapter.h index 7e9d43cd08..71c4f79355 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -169,6 +169,8 @@ void set_timeout_adapters(char *o); void set_adapter_dmxsource(char *o); void reset_pids_type(int aid, int clear_pat); void reset_ecm_type_for_pmt(int aid, int pmt); +int get_lnb_hiband(transponder *tp, diseqc *diseqc_param); +int get_lnb_int_freq(transponder *tp, diseqc *diseqc_param); int delsys_match(adapter *ad, int del_sys); int get_enabled_pids(adapter *ad, int *pids, int lpids); int get_all_pids(adapter *ad, int *pids, int lpids); diff --git a/src/axe.c b/src/axe.c index 48069ccc6e..a04819981d 100644 --- a/src/axe.c +++ b/src/axe.c @@ -273,28 +273,10 @@ adapter *axe_use_adapter(int input) { return ad; } -int axe_get_hiband(transponder *tp, diseqc *diseqc_param) { - if (tp->pol > 2 && diseqc_param->lnb_circular > 0) - return 0; - if (tp->freq < diseqc_param->lnb_switch) - return 0; - return 1; -} - -int axe_get_freq(transponder *tp, diseqc *diseqc_param) { - int freq = tp->freq; - - if (tp->pol > 2 && diseqc_param->lnb_circular > 0) - return (freq - diseqc_param->lnb_circular); - if (freq < diseqc_param->lnb_switch) - return (freq - diseqc_param->lnb_low); - return (freq - diseqc_param->lnb_high); -} - int axe_tune_check(adapter *ad, transponder *tp, diseqc *diseqc_param, int diseqc) { int pol = (tp->pol - 1) & 1; - int hiband = axe_get_hiband(tp, diseqc_param); + int hiband = get_lnb_hiband(tp, diseqc_param); LOGM( "axe: tune check for adapter %d, pol %d/%d, hiband %d/%d, diseqc %d/%d", ad->id, ad->old_pol, pol, ad->old_hiband, hiband, ad->old_diseqc, @@ -416,8 +398,8 @@ int axe_setup_switch(adapter *ad) { if (master >= 0) { input = master; diseqc_param = &adm->diseqc_param; - hiband = axe_get_hiband(tp, diseqc_param); - freq = axe_get_freq(tp, diseqc_param); + hiband = get_lnb_hiband(tp, diseqc_param); + freq = get_lnb_int_freq(tp, diseqc_param); if (!axe_tune_check(adm, tp, diseqc_param, diseqc)) { send_diseqc(adm, adm->fe2, diseqc, adm->old_diseqc != diseqc, pol, hiband, @@ -429,7 +411,7 @@ int axe_setup_switch(adapter *ad) { goto axe; } } else if (opts.quattro) { - hiband = axe_get_hiband(tp, diseqc_param); + hiband = get_lnb_hiband(tp, diseqc_param); if (opts.quattro_hiband == 1 && hiband) { LOG("axe_fe: hiband is not allowed for quattro config (adapter " "%d)", @@ -450,8 +432,8 @@ int axe_setup_switch(adapter *ad) { } adm->old_diseqc = diseqc = 0; diseqc_param = &adm->diseqc_param; - hiband = axe_get_hiband(tp, diseqc_param); - freq = axe_get_freq(tp, diseqc_param); + hiband = get_lnb_hiband(tp, diseqc_param); + freq = get_lnb_int_freq(tp, diseqc_param); if (!axe_tune_check(adm, tp, diseqc_param, 0)) { send_diseqc(adm, adm->fe2, 0, 0, pol, hiband, diseqc_param); adm->old_pol = pol; @@ -476,8 +458,8 @@ int axe_setup_switch(adapter *ad) { ad->fe2); } - hiband = axe_get_hiband(tp, diseqc_param); - freq = axe_get_freq(tp, diseqc_param); + hiband = get_lnb_hiband(tp, diseqc_param); + freq = get_lnb_int_freq(tp, diseqc_param); if (diseqc_param->switch_type == SWITCH_UNICABLE) { freq = send_unicable(ad, ad->fe2, freq / 1000, diseqc, pol, hiband, diff --git a/src/dvb.c b/src/dvb.c index a03de02800..33b70dbcbe 100644 --- a/src/dvb.c +++ b/src/dvb.c @@ -1030,17 +1030,7 @@ int setup_switch(adapter *ad) { frontend_fd = master->fe; - if (tp->pol > 2 && tp->diseqc_param.lnb_circular > 0) { - freq = (freq - tp->diseqc_param.lnb_circular); - hiband = 0; - } else if (freq < tp->diseqc_param.lnb_switch) { - freq = (freq - tp->diseqc_param.lnb_low); - hiband = 0; - } else { - freq = (freq - tp->diseqc_param.lnb_high); - hiband = 1; - } - + // Send the appropriate commands to setup the LNB/switch if (tp->diseqc_param.switch_type == SWITCH_UNICABLE) { freq = send_unicable(ad, frontend_fd, freq / 1000, diseqc, pol, hiband, &tp->diseqc_param); @@ -1050,6 +1040,9 @@ int setup_switch(adapter *ad) { &tp->diseqc_param); hiband = pol = 0; // do not care about polarity and hiband on Unicable } else { + freq = get_lnb_int_freq(tp, &tp->diseqc_param); + hiband = get_lnb_hiband(tp, &tp->diseqc_param); + int do_setup_switch = 0; int change_par = 0; if (ad->old_pol != pol || ad->old_hiband != hiband || From 225031692db347fd5b223064a4e72375be48cdc9 Mon Sep 17 00:00:00 2001 From: Sam Stenvall Date: Mon, 24 Jun 2024 14:11:40 +0300 Subject: [PATCH 2/3] Fix determining intermediate frequency for C-band LNBs Closes #1146 --- src/adapter.c | 6 +-- src/minisatip.c | 7 +++- tests/Makefile.in | 1 + tests/test_adapter.c | 99 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 tests/test_adapter.c diff --git a/src/adapter.c b/src/adapter.c index 75657ea739..73412312cc 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -1224,9 +1224,9 @@ int get_lnb_int_freq(transponder *tp, diseqc *diseqc_param) { if (tp->pol > 2 && diseqc_param->lnb_circular > 0) return (freq - diseqc_param->lnb_circular); - if (freq < diseqc_param->lnb_switch) - return (freq - diseqc_param->lnb_low); - return (freq - diseqc_param->lnb_high); + if (diseqc_param->lnb_switch > 0 && freq > diseqc_param->lnb_switch) + return (freq - diseqc_param->lnb_high); + return abs(freq - diseqc_param->lnb_low); } int compare_tunning_parameters(int aid, transponder *tp) { diff --git a/src/minisatip.c b/src/minisatip.c index 4d1a991a54..877c169fb7 100644 --- a/src/minisatip.c +++ b/src/minisatip.c @@ -404,8 +404,11 @@ Help\n\ \n\ * -L --lnb specifies the adapter and LNB parameters (low, high and switch frequency)\n\ * eg: -L *:9750-10600-11700 - sets all the adapters to use Universal LNB parameters (default)\n\ - * eg: -L *:10750-10750-10750 - sets the parameters for Sky NZ LNB using 10750 Mhz\n\ - * eg: -L 0:10750-10750-10750,1:9750-10600-11700 - adapter 0 has a SKY NZ LNB, adapter 1 has an Universal LNB\n\ + * eg: -L *:10750-0-0 - sets all adapters to use 10750 MHz Ku-band LNB parameters (e.g. Sky NZ)\n\ + * eg: -L *:5150-0-0 - sets all adapters to use 5150 MHz C-band LNB parameters\n\ + * eg: -L 0:10750-0-0,1:9750-10600-11700 - adapter 0 has a SKY NZ LNB, adapter 1 has an Universal LNB\n\ + \n\ + For backward-compatibility reasons, linear LNB parameters may also be specified as *:5150-5150-5150 instead of *:5150-0-0\n\ \n\ * -m --mac xx: simulate xx as local mac address, generates UUID based on mac\n\ * eg: -m 001122334455 \n\ diff --git a/tests/Makefile.in b/tests/Makefile.in index 714c067c1e..b53c34e937 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -15,6 +15,7 @@ else endif SOURCES=\ + test_adapter.c \ test_opts.c \ test_ca.c \ test_pmt.c \ diff --git a/tests/test_adapter.c b/tests/test_adapter.c new file mode 100644 index 0000000000..20641c195a --- /dev/null +++ b/tests/test_adapter.c @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2014-2022 Catalin Toda + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + */ +#define _GNU_SOURCE + +#include "adapter.h" +#include "minisatip.h" +#include "utils.h" +#include "utils/testing.h" + +#include +#include + +int test_get_lnb_hiband() { + return 0; +} + +int test_get_lnb_int_freq_universal() { + transponder tp; + diseqc diseqc_param = { + .lnb_low = 9750000, + .lnb_high = 10600000, + .lnb_switch = 11700000 + }; + + tp.freq = 10778000; + int freq = get_lnb_int_freq(&tp, &diseqc_param); + ASSERT(freq == 1028000, "Universal LNB IF parsed incorrectly"); + + tp.freq = 12322000; + freq = get_lnb_int_freq(&tp, &diseqc_param); + ASSERT(freq == 1722000, "Universal LNB IF parsed incorrectly"); + + return 0; +} + +int test_get_lnb_int_freq_kuband() { + transponder tp; + diseqc diseqc_param = { + .lnb_low = 10750000, + .lnb_high = 0, + .lnb_switch = 0, + }; + + tp.freq = 12267000; + int freq = get_lnb_int_freq(&tp, &diseqc_param); + ASSERT(freq == 1517000, "Ku-band LNB IF parsed incorrectly"); + + return 0; +} + +int test_get_lnb_int_freq_cband() { + transponder tp; + diseqc diseqc_param = { + .lnb_low = 5150000, + .lnb_high = 0, + .lnb_switch = 0 + }; + + tp.freq = 3773000; + int freq = get_lnb_int_freq(&tp, &diseqc_param); + ASSERT(freq == 1377000, "C-band LNB IF parsed incorrectly"); + + // Should also work with low = high = switch + diseqc_param.lnb_high = diseqc_param.lnb_switch = 5150000; + freq = get_lnb_int_freq(&tp, &diseqc_param); + ASSERT(freq == 1377000, "C-band LNB IF parsed incorrectly"); + + return 0; +} + +int main() { + opts.log = 1; + opts.debug = 255; + strcpy(thread_info[thread_index].thread_name, "test_adapter"); + + TEST_FUNC(test_get_lnb_hiband(), "test test_get_lnb_hiband with universal LNB parameters"); + TEST_FUNC(test_get_lnb_int_freq_universal(), "test get_lnb_int_freq with universal LNB parameters"); + TEST_FUNC(test_get_lnb_int_freq_kuband(), "test get_lnb_int_freq with typical Ku-band linear LNB parameters"); + TEST_FUNC(test_get_lnb_int_freq_cband(), "test get_lnb_int_freq with C-band LNB parameters"); + + return 0; +} From ddec5132dc6770b277be28c2926be4b2672f2df2 Mon Sep 17 00:00:00 2001 From: Sam Stenvall Date: Mon, 24 Jun 2024 14:19:27 +0300 Subject: [PATCH 3/3] Fix determining "hiband" for linear LNBs --- src/adapter.c | 6 +++--- tests/test_adapter.c | 51 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 73412312cc..105465821f 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -1214,9 +1214,9 @@ int mark_pids_add(int sid, int aid, char *pids) { int get_lnb_hiband(transponder *tp, diseqc *diseqc_param) { if (tp->pol > 2 && diseqc_param->lnb_circular > 0) return 0; - if (tp->freq < diseqc_param->lnb_switch) - return 0; - return 1; + if (diseqc_param->lnb_switch > 0 && tp->freq > diseqc_param->lnb_switch) + return 1; + return 0; } int get_lnb_int_freq(transponder *tp, diseqc *diseqc_param) { diff --git a/tests/test_adapter.c b/tests/test_adapter.c index 20641c195a..e0f690dc52 100644 --- a/tests/test_adapter.c +++ b/tests/test_adapter.c @@ -27,7 +27,22 @@ #include #include -int test_get_lnb_hiband() { +int test_get_lnb_hiband_universal() { + transponder tp; + diseqc diseqc_param = { + .lnb_low = 9750000, + .lnb_high = 10600000, + .lnb_switch = 11700000 + }; + + tp.freq = 10778000; + int hiband = get_lnb_hiband(&tp, &diseqc_param); + ASSERT(hiband == 0, "Universal LNB hiband parsed incorrectly"); + + tp.freq = 12322000; + hiband = get_lnb_hiband(&tp, &diseqc_param); + ASSERT(hiband == 1, "Universal LNB hiband parsed incorrectly"); + return 0; } @@ -50,6 +65,21 @@ int test_get_lnb_int_freq_universal() { return 0; } +int test_get_lnb_hiband_kuband() { + transponder tp; + diseqc diseqc_param = { + .lnb_low = 10750000, + .lnb_high = 0, + .lnb_switch = 0, + }; + + tp.freq = 12267000; + int hiband = get_lnb_hiband(&tp, &diseqc_param); + ASSERT(hiband == 0, "Ku-band LNB hiband parsed incorrectly"); + + return 0; +} + int test_get_lnb_int_freq_kuband() { transponder tp; diseqc diseqc_param = { @@ -65,6 +95,21 @@ int test_get_lnb_int_freq_kuband() { return 0; } +int test_get_lnb_hiband_cband() { + transponder tp; + diseqc diseqc_param = { + .lnb_low = 5150000, + .lnb_high = 0, + .lnb_switch = 0, + }; + + tp.freq = 3773000; + int hiband = get_lnb_hiband(&tp, &diseqc_param); + ASSERT(hiband == 0, "C-band LNB hiband parsed incorrectly"); + + return 0; +} + int test_get_lnb_int_freq_cband() { transponder tp; diseqc diseqc_param = { @@ -90,9 +135,11 @@ int main() { opts.debug = 255; strcpy(thread_info[thread_index].thread_name, "test_adapter"); - TEST_FUNC(test_get_lnb_hiband(), "test test_get_lnb_hiband with universal LNB parameters"); + TEST_FUNC(test_get_lnb_hiband_universal(), "test test_get_lnb_hiband with universal LNB parameters"); TEST_FUNC(test_get_lnb_int_freq_universal(), "test get_lnb_int_freq with universal LNB parameters"); + TEST_FUNC(test_get_lnb_hiband_kuband(), "test get_lnb_hiband with Ku-band linear LNB parameters"); TEST_FUNC(test_get_lnb_int_freq_kuband(), "test get_lnb_int_freq with typical Ku-band linear LNB parameters"); + TEST_FUNC(test_get_lnb_hiband_cband(), "test get_lnb_hiband with C-band linear LNB parameters"); TEST_FUNC(test_get_lnb_int_freq_cband(), "test get_lnb_int_freq with C-band LNB parameters"); return 0;