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..7d82ec9cd6 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; +}