Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intermediate frequency and tone for C-band LNBs #1149

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -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 (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) {
int freq = tp->freq;

if (tp->pol > 2 && diseqc_param->lnb_circular > 0)
return (freq - diseqc_param->lnb_circular);
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) {
adapter *ad = get_adapter(aid);
if (!ad)
Expand Down
2 changes: 2 additions & 0 deletions src/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 8 additions & 26 deletions src/axe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)",
Expand All @@ -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;
Expand All @@ -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,
Expand Down
15 changes: 4 additions & 11 deletions src/dvb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 ||
Expand Down
7 changes: 5 additions & 2 deletions src/minisatip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ else
endif

SOURCES=\
test_adapter.c \
test_opts.c \
test_ca.c \
test_pmt.c \
Expand Down
146 changes: 146 additions & 0 deletions tests/test_adapter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Copyright (C) 2014-2022 Catalin Toda <[email protected]>
*
* 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 <string.h>
#include <linux/dvb/frontend.h>

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;
}

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_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 = {
.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_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 = {
.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_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;
}
Loading