From: c vw Date: Thu, 9 Jan 2020 17:44:06 +0000 (+0100) Subject: new implementation of canTransmit() X-Git-Url: https://git.rkrishnan.org/Site/listings/$sch_link?a=commitdiff_plain;h=9c3c1c3e9747c44faa85580d9547ffb600f061ba;p=pihpsdr.git new implementation of canTransmit() --- diff --git a/frequency.c b/frequency.c index 9505fbd..149202f 100644 --- a/frequency.c +++ b/frequency.c @@ -510,11 +510,86 @@ g_print("getBand for %lld is %s (%d)\n",frequency,info->info,info->band); return result; } +/////////////////////////////////////////////////////// +// // +// New, self-contained version of canTransmit() // +// // +/////////////////////////////////////////////////////// + +#include "radio.h" +#include "vfo.h" +#include "band.h" + int canTransmit() { - int result=0; - if(info!=0) { - result=info->transmit; + int result; + long long txfreq, flow, fhigh; + int txb, txvfo, txmode; + BAND *txband; + int i; + + // + // If there is no transmitter, we cannot transmit + // + if (!can_transmit) return 0; + + // + // In the code canTransmit() is always ORed with tx_out_of_band, + // but this should be done in ONE PLACE (here) + // + if (tx_out_of_band) return 1; + + txvfo=get_tx_vfo(); + txb=vfo[txvfo].band; + + // + // See if we have a band + // + if (txb == bandGen) return 0; + + // + // Determine the edges of our band + // and the edges of our TX signal + // + txband=band_get_band(vfo[txvfo].band); + txfreq=get_tx_freq(); + txmode=get_tx_mode(); + + switch (txmode) { + case modeCWU: + flow = fhigh = cw_is_on_vfo_freq ? txfreq : txfreq + cw_keyer_sidetone_frequency; + break; + case modeCWL: + flow = fhigh = cw_is_on_vfo_freq ? txfreq : txfreq - cw_keyer_sidetone_frequency; + break; + default: + flow = txfreq + transmitter->filter_low; + fhigh= txfreq + transmitter->filter_high; + break; + } + + if (txb == band60) { + // + // For 60m band, ensure signal is within one of the "channels" + // + result=0; + for(i=0;i=low_freq && fhigh<=hi_freq) { +//fprintf(stderr,"60m channel OK: chan=%d flow=%lld fhigh=%lld\n", i, flow, fhigh); + result = 1; + break; + } + } +//fprintf(stderr,"60m channel NOT FOUND: flow=%lld fhigh=%lld\n", flow, fhigh); + } else { + // + // For other bands, return true if signal within band + // + result = flow >= txband->frequencyMin && fhigh <= txband->frequencyMax; } +//fprintf(stderr,"CANTRANSMIT: low=%lld high=%lld transmit=%d\n", flow, fhigh, result); return result; } diff --git a/vfo.c b/vfo.c index 25cceac..598900f 100644 --- a/vfo.c +++ b/vfo.c @@ -1049,39 +1049,6 @@ void vfo_update() { cairo_set_source_rgb(cr, 1.0, 1.0, 0.0); cairo_show_text(cr, temp_text); - - long long txfreq; - int txlow, txhigh; - - if (can_transmit) { - txfreq = (txvfo == 0) ? af : bf; - if (transmitter->xit_enabled) txfreq += transmitter->xit; - // - // In CW modes, the signal is generated explicitly (without WDSP), - // so we can assume a zero-width filter. Note that the CW signal - // can be on the VFO frequency or offset by the side tone freq. - // - switch (transmitter->mode) { - case modeCWU: - txlow = txhigh = cw_is_on_vfo_freq ? 0 : cw_keyer_sidetone_frequency; - break; - case modeCWL: - txlow = txhigh = cw_is_on_vfo_freq ? 0 : -cw_keyer_sidetone_frequency; - break; - default: - txlow =transmitter->filter_low; - txhigh=transmitter->filter_high; - break; - } - } else { - // - // If there is no transmitter, use VFO frequency of active receiver - // - txfreq = (id == 0) ? af : bf; - txlow = 0; - txhigh =0; - } - getFrequencyInfo(txfreq, txlow, txhigh); /* cairo_move_to(cr, (my_width/4)*3, 50); cairo_show_text(cr, getFrequencyInfo(af));