Skip to content

Commit

Permalink
Move determining of high sub-band and IF to separate functions
Browse files Browse the repository at this point in the history
The axe implementation was generic, and now that they're separated we can properly test them
  • Loading branch information
Jalle19 committed Jun 24, 2024
1 parent b2c865a commit 083c647
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 45 deletions.
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 (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)
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

0 comments on commit 083c647

Please sign in to comment.