Merged master 8748

This commit is contained in:
Jordan Sherer
2018-08-05 11:33:30 -04:00
parent 8f8772f1bd
commit 62899069bf
1222 changed files with 70382 additions and 406763 deletions
@@ -1,499 +0,0 @@
program wspr5d
! Decode WSPR-LF data read from *.c5 or *.wav files.
! WSPR-LF is a potential WSPR-like mode intended for use at LF and MF.
! It uses an LDPC (300,60) code, OQPSK modulation, and 5 minute T/R sequences.
!
! Still to do: find and decode more than one signal in the specified passband.
! include 'wsprlf_params.f90'
parameter (NDOWN=30)
parameter (KK=60)
parameter (ND=300)
parameter (NS=109)
parameter (NR=3)
parameter (NN=NR+NS+ND)
parameter (NSPS0=8640)
parameter (NSPS=16)
parameter (N2=2*NSPS)
parameter (NZ=NSPS*NN)
parameter (NZ400=288*NN)
parameter (NMAX=300*12000)
character arg*8,message*22,cbits*50,infile*80,fname*16,datetime*11
character*120 data_dir
complex csync(0:NZ-1) !Sync symbols only, from cbb
complex c400(0:NZ400-1) !Complex waveform
complex c(0:NZ-1) !Complex waveform
complex cd(0:NZ-1) !Complex waveform
complex ca(0:NZ-1) !Complex waveform
complex zz
real*8 fMHz
real rxdata(ND),llr(ND) !Soft symbols
real pp(32) !Shaped pulse for OQPSK
real sbits(412),softbits(9)
real fpks(20)
integer id(NS+ND) !NRZ values (+/-1) for Sync and Data
integer isync(48) !Long sync vector
integer ib13(13) !Barker 13 code
integer ihdr(11)
integer*8 n8
integer*2 iwave(NMAX) !Generated full-length waveform
integer*1 idat(7)
integer*1 decoded(KK),apmask(ND),cw(ND)
integer*1 hbits(412),bits(13)
data ib13/1,1,1,1,1,-1,-1,1,1,-1,1,-1,1/
nargs=iargc()
if(nargs.lt.2) then
print*,'Usage: wspr5d [-a <data_dir>] [-f fMHz] file1 [file2 ...]'
go to 999
endif
iarg=1
data_dir="."
call getarg(iarg,arg)
if(arg(1:2).eq.'-a') then
call getarg(iarg+1,data_dir)
iarg=iarg+2
endif
call getarg(iarg,arg)
if(arg(1:2).eq.'-f') then
call getarg(iarg+1,arg)
read(arg,*) fMHz
iarg=iarg+2
endif
open(13,file=trim(data_dir)//'/ALL_WSPR.TXT',status='unknown', &
position='append')
maxn=8 !Default value
twopi=8.0*atan(1.0)
fs=NSPS*12000.0/NSPS0 !Sample rate
dt=1.0/fs !Sample interval (s)
tt=NSPS*dt !Duration of "itone" symbols (s)
ts=2*NSPS*dt !Duration of OQPSK symbols (s)
baud=1.0/tt !Keying rate for "itone" symbols (baud)
txt=NZ*dt !Transmission length (s)
do i=1,32 !Half-sine pulse shape
pp(i)=sin(0.5*(i-1)*twopi/(32))
enddo
n8=z'cbf089223a51'
do i=1,48
isync(i)=-1
if(iand(n8,1).eq.1) isync(i)=1
n8=n8/2
enddo
! Define array id() for sync symbols
id=0
do j=1,48 !First group of 48
id(2*j-1)=2*isync(j)
enddo
do j=1,13 !Barker 13 code
id(j+96)=2*ib13(j)
enddo
do j=1,48 !Second group of 48
id(2*j+109)=2*isync(j)
enddo
csync=0.
do j=1,205
if(abs(id(j)).eq.2) then
ia=nint((j-0.5)*N2)
ib=ia+N2-1
csync(ia:ib)=pp*id(j)/abs(id(j))
endif
enddo
do ifile=iarg,nargs
call getarg(ifile,infile)
open(10,file=infile,status='old',access='stream')
j1=index(infile,'.c5')
j2=index(infile,'.wav')
if(j1.gt.0) then
read(10,end=999) fname,ntrmin,fMHz,c400
read(fname(8:11),*) nutc
write(datetime,'(i11)') nutc
else if(j2.gt.0) then
read(10,end=999) ihdr,iwave
read(infile(j2-4:j2-1),*) nutc
datetime=infile(j2-11:j2-1)
call wspr5_downsample(iwave,c400)
else
print*,'Wrong file format?'
go to 999
endif
close(10)
fa=100.0
fb=150.0
fs400=400.0
call getfc1(c400,fs400,fa,fb,fc1,xsnr) !First approx for freq
!write(*,*) datetime,'initial guess ',fc1
npeaks=5
call getfc2(c400,npeaks,fs400,fc1,fpks) !Refined freq
do idf=1,npeaks ! consider the top npeak peaks
fc2=fpks(idf)
call downsample(c400,fc1+fc2,cd)
s2=sum(cd*conjg(cd))/(16*412)
cd=cd/sqrt(s2)
do is=0,8 ! dt search range is narrow, to save time.
idt=is/2
if( mod(is,2).eq. 1 ) idt=-(is+1)/2
xdt=real(22+idt)/22.222 - 1.0
ca=cshift(cd,22+idt)
do iseq=1,3 ! try sequence estimation lengths of 3, 6, and 9 bits.
k=1-2*iseq
nseq=iseq*3
do i=1,408,iseq*4
k=k+iseq*2
j=(i+1)*16
call mskseqdet(nseq,ca(j),pp,id(k),softbits,1,phase)
hbits(i:i+iseq*4)=bits
sbits(i:i+iseq*4)=bits
sbits(i+1)=softbits(1)
sbits(i+2)=softbits(2)
if( id(k+1) .ne. 0 ) sbits(i+2)=id(k+1)*25
sbits(i+3)=softbits(3)
if( iseq .ge. 2 ) then
sbits(i+5)=softbits(4)
sbits(i+6)=softbits(5)
if( id(k+3) .ne. 0 ) sbits(i+6)=id(k+3)*25
sbits(i+7)=softbits(6)
if( iseq .eq. 3 ) then
sbits(i+9)=softbits(7)
sbits(i+10)=softbits(8)
if( id(k+5) .ne. 0 ) sbits(i+10)=id(k+5)*25
sbits(i+11)=softbits(9)
endif
endif
enddo
j=1
do i=1,205
if( abs(id(i)) .ne. 2 ) then
rxdata(j)=sbits(2*i-1)
j=j+1
endif
enddo
do i=1,204
rxdata(j)=sbits(2*i)
j=j+1
enddo
rxav=sum(rxdata)/ND
rx2av=sum(rxdata*rxdata)/ND
rxsig=sqrt(rx2av-rxav*rxav)
rxdata=rxdata/rxsig
! sigma=0.84
sigma=1.20
llr=2*rxdata/(sigma*sigma)
apmask=0
max_iterations=40
ifer=0
nbadcrc=0
call bpdecode300(llr,apmask,max_iterations,decoded,niterations,cw)
! niterations will be equal to the Hamming distance between hard received word and the codeword
if(niterations.lt.0) call osd300(llr,3,decoded,niterations,cw)
if(niterations.ge.0) call chkcrc10(decoded,nbadcrc)
if(niterations.lt.0 .or. nbadcrc.ne.0) ifer=1
if( ifer.eq.0 ) then
write(cbits,1200) decoded(1:50)
1200 format(50i1)
read(cbits,1202) idat
1202 format(6b8,b2)
idat(7)=ishft(idat(7),6)
call wqdecode(idat,message,itype)
nsnr=nint(xsnr)
freq=fMHz + 1.d-6*(fc1+fc2)
nfdot=0
write(13,1210) datetime,0,nsnr,xdt,freq,message,nfdot
1210 format(a11,2i4,f6.2,f12.7,2x,a22,i3)
write(*,1212) datetime(8:11),nsnr,xdt,freq,nfdot,message,'*',idf,nseq,is,niterations
1212 format(a4,i4,f5.1,f11.6,i3,2x,a22,a1,i3,i3,i3,i4)
goto 888
endif
enddo !iseq
enddo
enddo
888 continue
enddo
write(*,1120)
1120 format("<DecodeFinished>")
999 end program wspr5d
subroutine getmetric(ib,ps,xmet)
real ps(0:511)
xm1=0
xm0=0
do i=0,511
if( iand(i/ib,1) .eq. 1 .and. ps(i) .gt. xm1 ) xm1=ps(i)
if( iand(i/ib,1) .eq. 0 .and. ps(i) .gt. xm0 ) xm0=ps(i)
enddo
xmet=xm1-xm0
return
end subroutine getmetric
subroutine mskseqdet(ns,cdat,pp,bsync,softbits,ncoh,phase)
!
! Detect sequences of 3, 6, or 9 bits (ns).
! Sync bits are assumed to be known.
!
complex cdat(16*12),cbest(16*12),cideal(16*12)
complex cdf(16*12),cfac,zz
real cm(0:511),cmbest(0:511)
real pp(32),softbits(9)
integer bit(13),bestbits(13),sgn(13)
integer bsync(7)
twopi=8.0*atan(1.0)
dt=30.0*18.0/12000.0
cmax=0;
fbest=0.0;
np=2**ns-1
idfmax=40
if( ncoh .eq. 1 ) idfmax=0
do idf=0,idfmax
if( mod(idf,2).eq.1 ) deltaf=idf/2*0.02
if( mod(idf,2).eq.1 ) deltaf=-(idf+1)/2*0.02
dphi=twopi*deltaf*dt
cfac=cmplx(cos(dphi),sin(dphi))
cdf=1.0
do i=2,16*(ns-1)
cdf(i)=cdf(i-1)*cfac
enddo
cm=0
ibflag=0
do i=0,np
bit(1)=(bsync(1)+2)/4
bit(2)=iand(i/(2**(ns-1)),1)
bit(3)=iand(i/(2**(ns-2)),1)
if( bsync(2).ne.0 ) then ! force the barker bits
bit(3)=(bsync(2)+2)/4
endif
bit(4)=iand(i/(2**(ns-3)),1)
bit(5)=(bsync(3)+2)/4
if( ns .ge. 6 ) then
bit(6)=iand(i/(2**(ns-4)),1)
bit(7)=iand(i/(2**(ns-5)),1)
if( bsync(4).ne.0 ) then ! force the barker bits
bit(7)=(bsync(4)+2)/4
endif
bit(8)=iand(i/(2**(ns-6)),1)
bit(9)=(bsync(5)+2)/4
if( ns .eq. 9 ) then
bit(10)=iand(i/4,1)
bit(11)=iand(i/2,1)
if( bsync(6).ne.0 ) then ! force the barker bits
bit(11)=(bsync(6)+2)/4
endif
bit(12)=iand(i/1,1)
bit(13)=(bsync(7)+2)/4
endif
endif
sgn=2*bit-1
cideal(1:16) =cmplx(sgn(1)*pp(17:32),sgn(2)*pp(1:16))
cideal(17:32) =cmplx(sgn(3)*pp(1:16),sgn(2)*pp(17:32))
cideal(33:48) =cmplx(sgn(3)*pp(17:32),sgn(4)*pp(1:16))
cideal(49:64) =cmplx(sgn(5)*pp(1:16),sgn(4)*pp(17:32))
if( ns .ge. 6 ) then
cideal(65:80) =cmplx(sgn(5)*pp(17:32),sgn(6)*pp(1:16))
cideal(81:96) =cmplx(sgn(7)*pp(1:16),sgn(6)*pp(17:32))
cideal(97:112) =cmplx(sgn(7)*pp(17:32),sgn(8)*pp(1:16))
cideal(113:128)=cmplx(sgn(9)*pp(1:16),sgn(8)*pp(17:32))
if( ns .eq. 9 ) then
cideal(129:144) =cmplx(sgn(9)*pp(17:32),sgn(10)*pp(1:16))
cideal(145:160) =cmplx(sgn(11)*pp(1:16),sgn(10)*pp(17:32))
cideal(161:176) =cmplx(sgn(11)*pp(17:32),sgn(12)*pp(1:16))
cideal(177:192)=cmplx(sgn(13)*pp(1:16),sgn(12)*pp(17:32))
endif
endif
cideal=cideal*cdf
cm(i)=abs(sum(cdat(1:64*ns/3)*conjg(cideal(1:64*ns/3))))/1.e3
if( cm(i) .gt. cmax ) then
ibflag=1
cmax=cm(i)
bestbits=bit
cbest=cideal
fbest=deltaf
zz=sum(cdat*conjg(cbest))/1.e3
phase=atan2(imag(zz),real(zz))
endif
enddo
if( ibflag .eq. 1 ) then ! new best found
cmbest=cm
endif
enddo
softbits=0.0
call getmetric(1,cmbest,softbits(ns))
call getmetric(2,cmbest,softbits(ns-1))
call getmetric(4,cmbest,softbits(ns-2))
if( ns .ge. 6 ) then
call getmetric(8,cmbest,softbits(ns-3))
call getmetric(16,cmbest,softbits(ns-4))
call getmetric(32,cmbest,softbits(ns-5))
if( ns .eq. 9 ) then
call getmetric(64,cmbest,softbits(3))
call getmetric(128,cmbest,softbits(2))
call getmetric(256,cmbest,softbits(1))
endif
endif
end subroutine mskseqdet
subroutine downsample(ci,f0,co)
parameter(NI=412*288,NO=NI/18)
complex ci(0:NI-1),ct(0:NI-1)
complex co(0:NO-1)
df=400.0/NI
ct=ci
call four2a(ct,NI,1,-1,1) !c2c FFT to freq domain
i0=nint(f0/df)
co=0.0
co(0)=ct(i0)
b=3.0
do i=1,NO/2
arg=(i*df/b)**2
filt=exp(-arg)
co(i)=ct(i0+i)*filt
co(NO-i)=ct(i0-i)*filt
enddo
co=co/NO
call four2a(co,NO,1,1,1) !c2c FFT back to time domain
return
end subroutine downsample
subroutine getfc1(c,fs,fa,fb,fc1,xsnr)
! include 'wsprlf_params.f90'
parameter (NZ=288*412)
parameter (NSPS=288)
parameter (N2=2*NSPS)
parameter (NFFT1=16*NSPS)
parameter (NH1=NFFT1/2)
complex c(0:NZ-1) !Complex waveform
complex c2(0:NFFT1-1) !Short spectra
real s(-NH1+1:NH1) !Coarse spectrum
nspec=NZ/N2
df1=fs/NFFT1
s=0.
do k=1,nspec
ia=(k-1)*N2
ib=ia+N2-1
c2(0:N2-1)=c(ia:ib)
c2(N2:)=0.
call four2a(c2,NFFT1,1,-1,1)
do i=0,NFFT1-1
j=i
if(j.gt.NH1) j=j-NFFT1
s(j)=s(j) + real(c2(i))**2 + aimag(c2(i))**2
enddo
enddo
! call smo121(s,NFFT1)
smax=0.
ipk=0
fc1=0.
ia=nint(fa/df1)
ib=nint(fb/df1)
do i=ia,ib
f=i*df1
if(s(i).gt.smax) then
smax=s(i)
ipk=i
fc1=f
endif
! write(51,3001) f,s(i),db(s(i))
! 3001 format(f10.3,e12.3,f10.3)
enddo
! The following is for testing SNR calibration:
sp3n=(s(ipk-1)+s(ipk)+s(ipk+1)) !Sig + 3*noise
base=(sum(s)-sp3n)/(NFFT1-3.0) !Noise per bin
psig=sp3n-3*base !Sig only
pnoise=(2500.0/df1)*base !Noise in 2500 Hz
xsnr=db(psig/pnoise)
xsnr=xsnr+5.0
return
end subroutine getfc1
subroutine getfc2(c,npeaks,fs,fc1,fpks)
! include 'wsprlf_params.f90'
parameter (NZ=288*412)
parameter (NSPS=288)
parameter (N2=2*NSPS)
parameter (NFFT1=16*NSPS)
parameter (NH1=NFFT1/2)
complex c(0:NZ-1) !Complex waveform
complex cs(0:NZ-1) !For computing spectrum
real a(5)
real freqs(413),sp2(413),fpks(npeaks)
integer pkloc(1)
df=fs/NZ
baud=fs/NSPS
a(1)=-fc1
a(2:5)=0.
call twkfreq1(c,NZ,fs,a,cs) !Mix down by fc1
! Filter, square, then FFT to get refined carrier frequency fc2.
call four2a(cs,NZ,1,-1,1) !To freq domain
ia=nint(0.75*baud/df)
cs(ia:NZ-1-ia)=0. !Save only freqs around fc1
! do i=1,NZ/2
! filt=1/(1+((i*df)**2/(0.50*baud)**2)**8)
! cs(i)=cs(i)*filt
! cs(NZ+1-i)=cs(NZ+1-i)*filt
! enddo
call four2a(cs,NZ,1,1,1) !Back to time domain
cs=cs/NZ
cs=cs*cs !Square the data
call four2a(cs,NZ,1,-1,1) !Compute squared spectrum
! Find two peaks separated by baud
pmax=0.
fc2=0.
! ja=nint(0.3*baud/df)
ja=nint(0.5*baud/df)
k=1
sp2=0.0
do j=-ja,ja
f2=j*df
ia=nint((f2-0.5*baud)/df)
if(ia.lt.0) ia=ia+NZ
ib=nint((f2+0.5*baud)/df)
p=real(cs(ia))**2 + aimag(cs(ia))**2 + &
real(cs(ib))**2 + aimag(cs(ib))**2
if(p.gt.pmax) then
pmax=p
fc2=0.5*f2
endif
freqs(k)=0.5*f2
sp2(k)=p
k=k+1
! write(52,1200) f2,p,db(p)
!1200 format(f10.3,2f15.3)
enddo
do i=1,npeaks
pkloc=maxloc(sp2)
ipk=pkloc(1)
fpks(i)=freqs(ipk)
ipk0=max(1,ipk-2)
ipk1=min(413,ipk+2)
! ipk0=ipk
! ipk1=ipk
sp2(ipk0:ipk1)=0.0
enddo
return
end subroutine getfc2
@@ -1,54 +0,0 @@
program ft8d
! Decode FT8 data read from *.wav files.
! FT8 is a potential mode intended for use at 6m (and maybe HF). It uses an
! LDPC (174,87) code, 8-FSK modulation, and 15 second T/R sequences. Otherwise
! should behave like JT65 and JT9 as used on HF bands, except that QSOs are
! 4 x faster.
! Reception and Demodulation algorithm:
! ... tbd ...
include 'ft8_params.f90'
character*12 arg
character infile*80,datetime*13
real s(NH1,NHSYM)
real candidate(3,100)
integer ihdr(11)
integer*2 iwave(NMAX) !Generated full-length waveform
nargs=iargc()
if(nargs.lt.3) then
print*,'Usage: ft8d MaxIt Norder file1 [file2 ...]'
print*,'Example ft8d 40 2 *.wav'
go to 999
endif
call getarg(1,arg)
read(arg,*) max_iterations
call getarg(2,arg)
read(arg,*) norder
nfiles=nargs-2
twopi=8.0*atan(1.0)
fs=12000.0 !Sample rate
dt=1.0/fs !Sample interval (s)
tt=NSPS*dt !Duration of "itone" symbols (s)
ts=2*NSPS*dt !Duration of OQPSK symbols (s)
baud=1.0/tt !Keying rate (baud)
txt=NZ*dt !Transmission length (s)
do ifile=1,nfiles
call getarg(ifile+2,infile)
open(10,file=infile,status='old',access='stream')
read(10,end=999) ihdr,iwave
close(10)
j2=index(infile,'.wav')
read(infile(j2-6:j2-1),*) nutc
datetime=infile(j2-13:j2-1)
call sync8(iwave,s,candidate,ncand)
call ft8b(datetime,s,candidate,ncand)
enddo ! ifile loop
999 end program ft8d
@@ -1,100 +0,0 @@
#include "logbook.h"
#include <QDebug>
#include <QFontMetrics>
#include <QStandardPaths>
#include <QDir>
namespace
{
auto logFileName = "wsjtx_log.adi";
auto countryFileName = "cty.dat";
}
void LogBook::init()
{
QDir dataPath {QStandardPaths::writableLocation (QStandardPaths::DataLocation)};
QString countryDataFilename;
if (dataPath.exists (countryFileName))
{
// User override
countryDataFilename = dataPath.absoluteFilePath (countryFileName);
}
else
{
countryDataFilename = QString {":/"} + countryFileName;
}
_countries.init(countryDataFilename);
_countries.load();
_worked.init(_countries.getCountryNames());
_log.init(dataPath.absoluteFilePath (logFileName));
_log.load();
_setAlreadyWorkedFromLog();
/*
int QSOcount = _log.getCount();
int count = _worked.getWorkedCount();
qDebug() << QSOcount << "QSOs and" << count << "countries worked in file" << logFilename;
*/
// QString call = "ok1ct";
// QString countryName;
// bool callWorkedBefore,countryWorkedBefore;
// match(/*in*/call, /*out*/ countryName,callWorkedBefore,countryWorkedBefore);
// qDebug() << countryName;
}
void LogBook::_setAlreadyWorkedFromLog()
{
QList<QString> calls = _log.getCallList();
QString c;
foreach(c,calls)
{
QString countryName = _countries.find(c);
if (countryName.length() > 0)
{
_worked.setAsWorked(countryName);
//qDebug() << countryName << " worked " << c;
}
}
}
void LogBook::match(/*in*/const QString call,
/*out*/ QString &countryName,
bool &callWorkedBefore,
bool &countryWorkedBefore)
{
if (call.length() > 0)
{
QString currentMode = "JT9"; // JT65 == JT9 in ADIF::match()
QString currentBand = ""; // match any band
callWorkedBefore = _log.match(call,currentBand,currentMode);
countryName = _countries.find(call);
if (countryName.length() > 0) // country was found
countryWorkedBefore = _worked.getHasWorked(countryName);
else
{
countryName = "where?"; //error: prefix not found
countryWorkedBefore = false;
}
}
//qDebug() << "Logbook:" << call << ":" << countryName << "Cty B4:" << countryWorkedBefore << "call B4:" << callWorkedBefore;
}
void LogBook::addAsWorked(const QString call, const QString band, const QString mode, const QString date)
{
//qDebug() << "adding " << call << " as worked";
_log.add(call,band,mode,date);
QString countryName = _countries.find(call);
if (countryName.length() > 0)
_worked.setAsWorked(countryName);
}
@@ -1,800 +0,0 @@
#include "FrequencyList.hpp"
#include <cstdlib>
#include <utility>
#include <limits>
#include <QMetaType>
#include <QAbstractTableModel>
#include <QString>
#include <QList>
#include <QListIterator>
#include <QVector>
#include <QStringList>
#include <QMimeData>
#include <QDataStream>
#include <QByteArray>
#include <QDebugStateSaver>
#include "Radio.hpp"
#include "Bands.hpp"
#include "pimpl_impl.hpp"
#include "moc_FrequencyList.cpp"
namespace
{
FrequencyList::FrequencyItems const default_frequency_list =
{
{198000, Modes::FreqCal, IARURegions::R1}, // BBC Radio 4 Droitwich
{4996000, Modes::FreqCal, IARURegions::R1}, // RWM time signal
{9996000, Modes::FreqCal, IARURegions::R1}, // RWM time signal
{14996000, Modes::FreqCal, IARURegions::R1}, // RWM time signal
{660000, Modes::FreqCal, IARURegions::R2},
{880000, Modes::FreqCal, IARURegions::R2},
{1210000, Modes::FreqCal, IARURegions::R2},
{2500000, Modes::FreqCal, IARURegions::ALL},
{3330000, Modes::FreqCal, IARURegions::ALL},
{5000000, Modes::FreqCal, IARURegions::ALL},
{7850000, Modes::FreqCal, IARURegions::ALL},
{10000000, Modes::FreqCal, IARURegions::ALL},
{14670000, Modes::FreqCal, IARURegions::ALL},
{15000000, Modes::FreqCal, IARURegions::ALL},
{20000000, Modes::FreqCal, IARURegions::ALL},
{136000, Modes::WSPR, IARURegions::ALL},
{136130, Modes::JT65, IARURegions::ALL},
{136130, Modes::JT9, IARURegions::ALL},
{474200, Modes::JT65, IARURegions::ALL},
{474200, Modes::JT9, IARURegions::ALL},
{474200, Modes::WSPR, IARURegions::ALL},
{1836600, Modes::WSPR, IARURegions::ALL},
{1838000, Modes::JT65, IARURegions::ALL}, // squeezed allocations
{1839000, Modes::JT9, IARURegions::ALL},
{1840000, Modes::FT8, IARURegions::ALL},
{3570000, Modes::JT65, IARURegions::ALL}, // JA compatible
{3572000, Modes::JT9, IARURegions::ALL},
{3573000, Modes::FT8, IARURegions::ALL}, // above as below JT65
// is out of DM allocation
{3572600, Modes::WSPR, IARURegions::ALL}, // needs guard marker
// and lock out
{7038600, Modes::WSPR, IARURegions::ALL},
{7074000, Modes::FT8, IARURegions::ALL},
{7076000, Modes::JT65, IARURegions::ALL},
{7078000, Modes::JT9, IARURegions::ALL},
{10136000, Modes::FT8, IARURegions::ALL},
{10138000, Modes::JT65, IARURegions::ALL},
{10138700, Modes::WSPR, IARURegions::ALL},
{10140000, Modes::JT9, IARURegions::ALL},
{14095600, Modes::WSPR, IARURegions::ALL},
{14074000, Modes::FT8, IARURegions::ALL},
{14076000, Modes::JT65, IARURegions::ALL},
{14078000, Modes::JT9, IARURegions::ALL},
{18100000, Modes::FT8, IARURegions::ALL},
{18102000, Modes::JT65, IARURegions::ALL},
{18104000, Modes::JT9, IARURegions::ALL},
{18104600, Modes::WSPR, IARURegions::ALL},
{21074000, Modes::FT8, IARURegions::ALL},
{21076000, Modes::JT65, IARURegions::ALL},
{21078000, Modes::JT9, IARURegions::ALL},
{21094600, Modes::WSPR, IARURegions::ALL},
{24915000, Modes::FT8, IARURegions::ALL},
{24917000, Modes::JT65, IARURegions::ALL},
{24919000, Modes::JT9, IARURegions::ALL},
{24924600, Modes::WSPR, IARURegions::ALL},
{28074000, Modes::FT8, IARURegions::ALL},
{28076000, Modes::JT65, IARURegions::ALL},
{28078000, Modes::JT9, IARURegions::ALL},
{28124600, Modes::WSPR, IARURegions::ALL},
{50000000, Modes::Echo, IARURegions::ALL},
{50276000, Modes::JT65, IARURegions::R2},
{50276000, Modes::JT65, IARURegions::R3},
{50260000, Modes::MSK144, IARURegions::R2},
{50260000, Modes::MSK144, IARURegions::R3},
{50293000, Modes::WSPR, IARURegions::R2},
{50293000, Modes::WSPR, IARURegions::R3},
{50310000, Modes::JT65, IARURegions::ALL},
{50312000, Modes::JT9, IARURegions::ALL},
{50313000, Modes::FT8, IARURegions::ALL},
{50360000, Modes::MSK144, IARURegions::R1},
{70100000, Modes::FT8, IARURegions::R1},
{70102000, Modes::JT65, IARURegions::R1},
{70104000, Modes::JT9, IARURegions::R1},
{70091000, Modes::WSPR, IARURegions::R1},
{70230000, Modes::MSK144, IARURegions::R1},
{144000000, Modes::Echo, IARURegions::ALL},
{144120000, Modes::JT65, IARURegions::ALL},
{144120000, Modes::Echo, IARURegions::ALL},
{144360000, Modes::MSK144, IARURegions::R1},
{144150000, Modes::MSK144, IARURegions::R2},
{144489000, Modes::WSPR, IARURegions::ALL},
{222065000, Modes::Echo, IARURegions::R2},
{222065000, Modes::JT65, IARURegions::R2},
{432065000, Modes::Echo, IARURegions::ALL},
{432065000, Modes::JT65, IARURegions::ALL},
{432300000, Modes::WSPR, IARURegions::ALL},
{432360000, Modes::MSK144, IARURegions::ALL},
{902065000, Modes::JT65, IARURegions::ALL},
{1296065000, Modes::Echo, IARURegions::ALL},
{1296065000, Modes::JT65, IARURegions::ALL},
{1296500000, Modes::WSPR, IARURegions::ALL},
{2301000000, Modes::Echo, IARURegions::ALL},
{2301065000, Modes::JT4, IARURegions::ALL},
{2301065000, Modes::JT65, IARURegions::ALL},
{2304065000, Modes::Echo, IARURegions::ALL},
{2304065000, Modes::JT4, IARURegions::ALL},
{2304065000, Modes::JT65, IARURegions::ALL},
{2320065000, Modes::Echo, IARURegions::ALL},
{2320065000, Modes::JT4, IARURegions::ALL},
{2320065000, Modes::JT65, IARURegions::ALL},
{3400065000, Modes::Echo, IARURegions::ALL},
{3400065000, Modes::JT4, IARURegions::ALL},
{3400065000, Modes::JT65, IARURegions::ALL},
{3456065000, Modes::Echo, IARURegions::ALL},
{3456065000, Modes::JT4, IARURegions::ALL},
{3456065000, Modes::JT65, IARURegions::ALL},
{5760065000, Modes::Echo, IARURegions::ALL},
{5760065000, Modes::JT4, IARURegions::ALL},
{5760065000, Modes::JT65, IARURegions::ALL},
{10368100000, Modes::Echo, IARURegions::ALL},
{10368100000, Modes::JT4, IARURegions::ALL},
{10368100000, Modes::JT65, IARURegions::ALL},
{24048100000, Modes::Echo, IARURegions::ALL},
{24048100000, Modes::JT4, IARURegions::ALL},
{24048100000, Modes::JT65, IARURegions::ALL},
};
}
#if !defined (QT_NO_DEBUG_STREAM)
QDebug operator << (QDebug debug, FrequencyList::Item const& item)
{
QDebugStateSaver saver {debug};
debug.nospace () << "FrequencyItem("
<< item.frequency_ << ", "
<< item.region_ << ", "
<< item.mode_ << ')';
return debug;
}
#endif
QDataStream& operator << (QDataStream& os, FrequencyList::Item const& item)
{
return os << item.frequency_
<< item.mode_
<< item.region_;
}
QDataStream& operator >> (QDataStream& is, FrequencyList::Item& item)
{
return is >> item.frequency_
>> item.mode_
>> item.region_;
}
class FrequencyList::impl final
: public QAbstractTableModel
{
public:
impl (Bands const * bands, QObject * parent)
: QAbstractTableModel {parent}
, bands_ {bands}
, region_filter_ {IARURegions::ALL}
, mode_filter_ {Modes::ALL}
{
}
FrequencyItems frequency_list (FrequencyItems);
QModelIndex add (Item);
void add (FrequencyItems);
// Implement the QAbstractTableModel interface
int rowCount (QModelIndex const& parent = QModelIndex {}) const override;
int columnCount (QModelIndex const& parent = QModelIndex {}) const override;
Qt::ItemFlags flags (QModelIndex const& = QModelIndex {}) const override;
QVariant data (QModelIndex const&, int role = Qt::DisplayRole) const override;
bool setData (QModelIndex const&, QVariant const& value, int role = Qt::EditRole) override;
QVariant headerData (int section, Qt::Orientation, int = Qt::DisplayRole) const override;
bool removeRows (int row, int count, QModelIndex const& parent = QModelIndex {}) override;
bool insertRows (int row, int count, QModelIndex const& parent = QModelIndex {}) override;
QStringList mimeTypes () const override;
QMimeData * mimeData (QModelIndexList const&) const override;
static int constexpr num_cols {SENTINAL};
static auto constexpr mime_type = "application/wsjt.Frequencies";
Bands const * bands_;
FrequencyItems frequency_list_;
Region region_filter_;
Mode mode_filter_;
};
FrequencyList::FrequencyList (Bands const * bands, QObject * parent)
: QSortFilterProxyModel {parent}
, m_ {bands, parent}
{
setSourceModel (&*m_);
setSortRole (SortRole);
}
FrequencyList::~FrequencyList ()
{
}
auto FrequencyList::frequency_list (FrequencyItems frequency_list) -> FrequencyItems
{
return m_->frequency_list (frequency_list);
}
auto FrequencyList::frequency_list () const -> FrequencyItems const&
{
return m_->frequency_list_;
}
auto FrequencyList::frequency_list (QModelIndexList const& model_index_list) const -> FrequencyItems
{
FrequencyItems list;
Q_FOREACH (auto const& index, model_index_list)
{
list << m_->frequency_list_[mapToSource (index).row ()];
}
return list;
}
void FrequencyList::frequency_list_merge (FrequencyItems const& items)
{
m_->add (items);
}
int FrequencyList::best_working_frequency (Frequency f) const
{
int result {-1};
auto const& target_band = m_->bands_->find (f);
if (!target_band.isEmpty ())
{
Radio::FrequencyDelta delta {std::numeric_limits<Radio::FrequencyDelta>::max ()};
// find a frequency in the same band that is allowed
for (int row = 0; row < rowCount (); ++row)
{
auto const& source_row = mapToSource (index (row, 0)).row ();
auto const& candidate_frequency = m_->frequency_list_[source_row].frequency_;
auto const& band = m_->bands_->find (candidate_frequency);
if (band == target_band)
{
// take closest band match
Radio::FrequencyDelta new_delta = f - candidate_frequency;
if (std::abs (new_delta) < std::abs (delta))
{
delta = new_delta;
result = row;
}
}
}
}
return result;
}
int FrequencyList::best_working_frequency (QString const& target_band) const
{
int result {-1};
if (!target_band.isEmpty ())
{
// find a frequency in the same band that is allowed
for (int row = 0; row < rowCount (); ++row)
{
auto const& source_row = mapToSource (index (row, 0)).row ();
auto const& band = m_->bands_->find (m_->frequency_list_[source_row].frequency_);
if (band == target_band)
{
return row;
}
}
}
return result;
}
void FrequencyList::reset_to_defaults ()
{
m_->frequency_list (default_frequency_list);
}
QModelIndex FrequencyList::add (Item f)
{
return mapFromSource (m_->add (f));
}
bool FrequencyList::remove (Item f)
{
auto row = m_->frequency_list_.indexOf (f);
if (0 > row)
{
return false;
}
return m_->removeRow (row);
}
namespace
{
bool row_is_higher (QModelIndex const& lhs, QModelIndex const& rhs)
{
return lhs.row () > rhs.row ();
}
}
bool FrequencyList::removeDisjointRows (QModelIndexList rows)
{
bool result {true};
// We must work with source model indexes because we don't want row
// removes to invalidate model indexes we haven't yet processed. We
// achieve that by processing them in decending row order.
for (int r = 0; r < rows.size (); ++r)
{
rows[r] = mapToSource (rows[r]);
}
// reverse sort by row
qSort (rows.begin (), rows.end (), row_is_higher);
Q_FOREACH (auto index, rows)
{
if (result && !m_->removeRow (index.row ()))
{
result = false;
}
}
return result;
}
void FrequencyList::filter (Region region, Mode mode)
{
m_->region_filter_ = region;
m_->mode_filter_ = mode;
invalidateFilter ();
}
bool FrequencyList::filterAcceptsRow (int source_row, QModelIndex const& /* parent */) const
{
bool result {true};
auto const& item = m_->frequency_list_[source_row];
if (m_->region_filter_ != IARURegions::ALL)
{
result = IARURegions::ALL == item.region_ || m_->region_filter_ == item.region_;
}
if (result && m_->mode_filter_ != Modes::ALL)
{
// we pass ALL mode rows unless filtering for FreqCal mode
result = (Modes::ALL == item.mode_ && m_->mode_filter_ != Modes::FreqCal)
|| m_->mode_filter_ == item.mode_;
}
return result;
}
auto FrequencyList::impl::frequency_list (FrequencyItems frequency_list) -> FrequencyItems
{
beginResetModel ();
std::swap (frequency_list_, frequency_list);
endResetModel ();
return frequency_list;
}
QModelIndex FrequencyList::impl::add (Item f)
{
// Any Frequency that isn't in the list may be added
if (!frequency_list_.contains (f))
{
auto row = frequency_list_.size ();
beginInsertRows (QModelIndex {}, row, row);
frequency_list_.append (f);
endInsertRows ();
return index (row, 0);
}
return QModelIndex {};
}
void FrequencyList::impl::add (FrequencyItems items)
{
// Any Frequency that isn't in the list may be added
for (auto p = items.begin (); p != items.end ();)
{
if (frequency_list_.contains (*p))
{
p = items.erase (p);
}
else
{
++p;
}
}
if (items.size ())
{
auto row = frequency_list_.size ();
beginInsertRows (QModelIndex {}, row, row + items.size () - 1);
frequency_list_.append (items);
endInsertRows ();
}
}
int FrequencyList::impl::rowCount (QModelIndex const& parent) const
{
return parent.isValid () ? 0 : frequency_list_.size ();
}
int FrequencyList::impl::columnCount (QModelIndex const& parent) const
{
return parent.isValid () ? 0 : num_cols;
}
Qt::ItemFlags FrequencyList::impl::flags (QModelIndex const& index) const
{
auto result = QAbstractTableModel::flags (index) | Qt::ItemIsDropEnabled;
auto row = index.row ();
auto column = index.column ();
if (index.isValid ()
&& row < frequency_list_.size ()
&& column < num_cols)
{
if (frequency_mhz_column != column)
{
result |= Qt::ItemIsEditable | Qt::ItemIsDragEnabled;
}
}
return result;
}
QVariant FrequencyList::impl::data (QModelIndex const& index, int role) const
{
QVariant item;
auto const& row = index.row ();
auto const& column = index.column ();
if (index.isValid ()
&& row < frequency_list_.size ()
&& column < num_cols)
{
auto const& frequency_item = frequency_list_.at (row);
switch (column)
{
case region_column:
switch (role)
{
case SortRole:
case Qt::DisplayRole:
case Qt::EditRole:
case Qt::AccessibleTextRole:
item = IARURegions::name (frequency_item.region_);
break;
case Qt::ToolTipRole:
case Qt::AccessibleDescriptionRole:
item = tr ("IARU Region");
break;
case Qt::TextAlignmentRole:
item = Qt::AlignHCenter + Qt::AlignVCenter;
break;
}
break;
case mode_column:
switch (role)
{
case SortRole:
case Qt::DisplayRole:
case Qt::EditRole:
case Qt::AccessibleTextRole:
item = Modes::name (frequency_item.mode_);
break;
case Qt::ToolTipRole:
case Qt::AccessibleDescriptionRole:
item = tr ("Mode");
break;
case Qt::TextAlignmentRole:
item = Qt::AlignHCenter + Qt::AlignVCenter;
break;
}
break;
case frequency_column:
switch (role)
{
case SortRole:
case Qt::EditRole:
case Qt::AccessibleTextRole:
item = frequency_item.frequency_;
break;
case Qt::DisplayRole:
{
auto const& band = bands_->find (frequency_item.frequency_);
item = Radio::pretty_frequency_MHz_string (frequency_item.frequency_)
+ " MHz (" + (band.isEmpty () ? "OOB" : band) + ')';
}
break;
case Qt::ToolTipRole:
case Qt::AccessibleDescriptionRole:
item = tr ("Frequency");
break;
case Qt::TextAlignmentRole:
item = Qt::AlignRight + Qt::AlignVCenter;
break;
}
break;
case frequency_mhz_column:
switch (role)
{
case Qt::EditRole:
case Qt::AccessibleTextRole:
item = Radio::frequency_MHz_string (frequency_item.frequency_);
break;
case Qt::DisplayRole:
{
auto const& band = bands_->find (frequency_item.frequency_);
item = Radio::pretty_frequency_MHz_string (frequency_item.frequency_)
+ " MHz (" + (band.isEmpty () ? "OOB" : band) + ')';
}
break;
case Qt::ToolTipRole:
case Qt::AccessibleDescriptionRole:
item = tr ("Frequency (MHz)");
break;
case Qt::TextAlignmentRole:
item = Qt::AlignRight + Qt::AlignVCenter;
break;
}
break;
}
}
return item;
}
bool FrequencyList::impl::setData (QModelIndex const& model_index, QVariant const& value, int role)
{
bool changed {false};
auto const& row = model_index.row ();
if (model_index.isValid ()
&& Qt::EditRole == role
&& row < frequency_list_.size ())
{
QVector<int> roles;
roles << role;
auto& item = frequency_list_[row];
switch (model_index.column ())
{
case region_column:
if (value.canConvert<Region> ())
{
auto region = IARURegions::value (value.toString ());
if (region != item.region_)
{
item.region_ = region;
Q_EMIT dataChanged (model_index, model_index, roles);
changed = true;
}
}
break;
case mode_column:
if (value.canConvert<Mode> ())
{
auto mode = Modes::value (value.toString ());
if (mode != item.mode_)
{
item.mode_ = mode;
Q_EMIT dataChanged (model_index, model_index, roles);
changed = true;
}
}
break;
case frequency_column:
if (value.canConvert<Frequency> ())
{
Radio::Frequency frequency {qvariant_cast <Radio::Frequency> (value)};
if (frequency != item.frequency_)
{
item.frequency_ = frequency;
// mark derived column (1) changed as well
Q_EMIT dataChanged (index (model_index.row (), 1), model_index, roles);
changed = true;
}
}
break;
}
}
return changed;
}
QVariant FrequencyList::impl::headerData (int section, Qt::Orientation orientation, int role) const
{
QVariant header;
if (Qt::DisplayRole == role
&& Qt::Horizontal == orientation
&& section < num_cols)
{
switch (section)
{
case region_column: header = tr ("IARU Region"); break;
case mode_column: header = tr ("Mode"); break;
case frequency_column: header = tr ("Frequency"); break;
case frequency_mhz_column: header = tr ("Frequency (MHz)"); break;
}
}
else
{
header = QAbstractTableModel::headerData (section, orientation, role);
}
return header;
}
bool FrequencyList::impl::removeRows (int row, int count, QModelIndex const& parent)
{
if (0 < count && (row + count) <= rowCount (parent))
{
beginRemoveRows (parent, row, row + count - 1);
for (auto r = 0; r < count; ++r)
{
frequency_list_.removeAt (row);
}
endRemoveRows ();
return true;
}
return false;
}
bool FrequencyList::impl::insertRows (int row, int count, QModelIndex const& parent)
{
if (0 < count)
{
beginInsertRows (parent, row, row + count - 1);
for (auto r = 0; r < count; ++r)
{
frequency_list_.insert (row, Item {0, Mode::ALL, IARURegions::ALL});
}
endInsertRows ();
return true;
}
return false;
}
QStringList FrequencyList::impl::mimeTypes () const
{
QStringList types;
types << mime_type;
return types;
}
QMimeData * FrequencyList::impl::mimeData (QModelIndexList const& items) const
{
QMimeData * mime_data = new QMimeData {};
QByteArray encoded_data;
QDataStream stream {&encoded_data, QIODevice::WriteOnly};
Q_FOREACH (auto const& item, items)
{
if (item.isValid () && frequency_column == item.column ())
{
stream << frequency_list_.at (item.row ());
}
}
mime_data->setData (mime_type, encoded_data);
return mime_data;
}
auto FrequencyList::const_iterator::operator * () const -> Item const&
{
return parent_->frequency_list ().at(parent_->mapToSource (parent_->index (row_, 0)).row ());
}
auto FrequencyList::const_iterator::operator -> () const -> Item const *
{
return &parent_->frequency_list ().at(parent_->mapToSource (parent_->index (row_, 0)).row ());
}
bool FrequencyList::const_iterator::operator != (const_iterator const& rhs) const
{
return parent_ != rhs.parent_ || row_ != rhs.row_;
}
bool FrequencyList::const_iterator::operator == (const_iterator const& rhs) const
{
return parent_ == rhs.parent_ && row_ == rhs.row_;
}
auto FrequencyList::const_iterator::operator ++ () -> const_iterator&
{
++row_;
return *this;
}
auto FrequencyList::begin () const -> const_iterator
{
return const_iterator (this, 0);
}
auto FrequencyList::end () const -> const_iterator
{
return const_iterator (this, rowCount ());
}
auto FrequencyList::find (Frequency f) const -> const_iterator
{
int row {0};
for (; row < rowCount (); ++row)
{
if (m_->frequency_list_[mapToSource (index (row, 0)).row ()].frequency_ == f)
{
break;
}
}
return const_iterator (this, row);
}
auto FrequencyList::filtered_bands () const -> BandSet
{
BandSet result;
for (auto const& item : *this)
{
result << m_->bands_->find (item.frequency_);
}
return result;
}
auto FrequencyList::all_bands (Region region, Mode mode) const -> BandSet
{
BandSet result;
for (auto const& item : m_->frequency_list_)
{
if (region == IARURegions::ALL || item.region_ == region
|| mode == Modes::ALL || item.mode_ == mode)
{
result << m_->bands_->find (item.frequency_);
}
}
return result;
}