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,70 +0,0 @@
program allsim
! Generate simulated data for WSJT-X slow modes: JT4, JT9, JT65, QRA64,
! and WSPR. Also unmodulated carrier and 20 WPM CW.
use wavhdr
use packjt
parameter (NMAX=60*12000)
type(hdr) h
integer*2 iwave(NMAX) !Generated waveform (no noise)
integer itone(206) !Channel symbols (values 0-8)
integer icw(250)
real*4 dat(NMAX)
character message*22,msgsent*22,arg*8
nargs=iargc()
if(nargs.ne.1) then
print*,'Usage: allsim <snr>'
go to 999
endif
call getarg(1,arg)
read(arg,*) snrdb !S/N in dB (2500 hz reference BW)
message='CQ KA2ABC FN20'
rmsdb=25.
rms=10.0**(0.05*rmsdb)
sig=10.0**(0.05*snrdb)
npts=NMAX
call init_random_seed() !Seed Fortran RANDOM_NUMBER generator
call sgran() !Seed C rand generator (used in gran)
h=default_header(12000,npts)
open(10,file='000000_0000.wav',access='stream',status='unknown')
do i=1,npts !Generate gaussian noise
dat(i)=gran()
enddo
itone=0
call addit(itone,12000,85,6912,400,sig,dat) !Unmodulated carrier
call morse('CQ CQ DE KA2ABC KA2ABC',icw,ncw)
! print*,ncw
! write(*,3001) icw(1:ncw)
!3001 format(50i1)
call addcw(icw,ncw,600,sig,dat) !CW
call genwspr(message,msgsent,itone)
call addit(itone,12000,86,8192,800,sig,dat) !WSPR (only 59 s of data)
call gen9(message,0,msgsent,itone,itype)
call addit(itone,12000,85,6912,1000,sig,dat) !JT9
call gen4(message,0,msgsent,itone,itype)
call addit(itone,11025,206,2520,1200,sig,dat) !JT4
call genqra64(message,0,msgsent,itone,itype)
call addit(itone,12000,84,6912,1400,sig,dat) !QRA64
call gen65(message,0,msgsent,itone,itype)
call addit(itone,11025,126,4096,1600,sig,dat) !JT65
iwave(1:npts)=nint(rms*dat(1:npts))
write(10) h,iwave(1:npts)
close(10)
999 end program allsim
@@ -0,0 +1,312 @@
/*
Functions used by wsprsim
*/
#include "wsprsim_utils.h"
#include "wsprd_utils.h"
#include "nhash.h"
#include "fano.h"
static char get_locator_character_code(char ch);
static char get_callsign_character_code(char ch);
static long unsigned int pack_grid4_power(char const *grid4, int power);
static long unsigned int pack_call(char const *callsign);
static void pack_prefix(char *callsign, int32_t *n, int32_t *m, int32_t *nadd );
static void interleave(unsigned char *sym);
char get_locator_character_code(char ch) {
if( ch >=48 && ch <=57 ) { //0-9
return ch-48;
}
if( ch == 32 ) { //space
return 36;
}
if( ch >= 65 && ch <= 82 ) { //A-Z
return ch-65;
}
return -1;
}
char get_callsign_character_code(char ch) {
if( ch >=48 && ch <=57 ) { //0-9
return ch-48;
}
if( ch == 32 ) { //space
return 36;
}
if( ch >= 65 && ch <= 90 ) { //A-Z
return ch-55;
}
return -1;
}
long unsigned int pack_grid4_power(char const *grid4, int power) {
long unsigned int m;
m=(179-10*grid4[0]-grid4[2])*180+10*grid4[1]+grid4[3];
m=m*128+power+64;
return m;
}
long unsigned int pack_call(char const *callsign) {
unsigned int i;
long unsigned int n;
char call6[6];
memset(call6,' ',sizeof(call6));
// callsign is 6 characters in length. Exactly.
size_t call_len = strlen(callsign);
if( call_len > 6 ) {
return 0;
}
if( isdigit(callsign[2]) ) {
for (i=0; i<call_len; i++) {
call6[i]=callsign[i];
}
} else if( isdigit(callsign[1]) ) {
for (i=1; i<call_len+1; i++) {
call6[i]=callsign[i-1];
}
}
for (i=0; i<6; i++) {
call6[i]=get_callsign_character_code(call6[i]);
}
n = call6[0];
n = n*36+call6[1];
n = n*10+call6[2];
n = n*27+call6[3]-10;
n = n*27+call6[4]-10;
n = n*27+call6[5]-10;
return n;
}
void pack_prefix(char *callsign, int32_t *n, int32_t *m, int32_t *nadd ) {
size_t i;
char * call6 = calloc(7,sizeof (char));
size_t i1=strcspn(callsign,"/");
if( callsign[i1+2] == 0 ) {
//single char suffix
for (i=0; i<i1; i++) {
call6[i]=callsign[i];
}
call6[i] = '\0';
*n=pack_call(call6);
*nadd=1;
int nc = callsign[i1+1];
if( nc >= 48 && nc <= 57 ) {
*m=nc-48;
} else if ( nc >= 65 && nc <= 90 ) {
*m=nc-65+10;
} else {
*m=38;
}
*m=60000-32768+*m;
} else if( callsign[i1+3]==0 ) {
//two char suffix
for (i=0; i<i1; i++) {
call6[i]=callsign[i];
}
*n=pack_call(call6);
*nadd=1;
*m=10*(callsign[i1+1]-48)+(callsign[i1+2]-48);
*m=60000 + 26 + *m;
} else {
char const * pfx = strtok (callsign,"/");
char const * call = strtok(NULL," ");
*n = pack_call (call);
size_t plen=strlen (pfx);
if( plen ==1 ) {
*m=36;
*m=37*(*m)+36;
} else if( plen == 2 ) {
*m=36;
} else {
*m=0;
}
for (i=0; i<plen; i++) {
int nc = callsign[i];
if( nc >= 48 && nc <= 57 ) {
nc=nc-48;
} else if ( nc >= 65 && nc <= 90 ) {
nc=nc-65+10;
} else {
nc=36;
}
*m=37*(*m)+nc;
}
*nadd=0;
if( *m > 32768 ) {
*m=*m-32768;
*nadd=1;
}
}
free (call6);
}
void interleave(unsigned char *sym)
{
unsigned char tmp[162];
unsigned char p, i, j;
p=0;
i=0;
while (p<162) {
j=((i * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32;
if (j < 162 ) {
tmp[j]=sym[p];
p=p+1;
}
i=i+1;
}
for (i=0; i<162; i++) {
sym[i]=tmp[i];
}
}
int get_wspr_channel_symbols(char* rawmessage, char* hashtab, unsigned char* symbols) {
int m=0, ntype=0;
long unsigned int n=0;
int i, j, ihash;
unsigned char pr3[162]=
{1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0,
0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1,
0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1,
1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1,
0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0,
0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1,
0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1,
0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0,
0,0};
int nu[10]={0,-1,1,0,-1,2,1,0,-1,1};
char *callsign, *grid, *powstr;
char grid4[5], message[23];
memset(message,0,sizeof(char)*23);
i=0;
while ( rawmessage[i] != 0 && i<23 ) {
message[i]=rawmessage[i];
i++;
}
size_t i1=strcspn(message," ");
size_t i2=strcspn(message,"/");
size_t i3=strcspn(message,"<");
size_t i4=strcspn(message,">");
size_t mlen=strlen(message);
// Use the presence and/or absence of "<" and "/" to decide what
// type of message. No sanity checks! Beware!
if( i1 > 3 && i1 < 7 && i2 == mlen && i3 == mlen ) {
// Type 1 message: K9AN EN50 33
// xxnxxxx xxnn nn
callsign = strtok(message," ");
grid = strtok(NULL," ");
powstr = strtok(NULL," ");
int power = atoi(powstr);
n = pack_call(callsign);
for (i=0; i<4; i++) {
grid4[i]=get_locator_character_code(*(grid+i));
}
m = pack_grid4_power(grid4,power);
} else if ( i3 == 0 && i4 < mlen ) {
// Type 3: <K1ABC> EN50WC 33
// <PJ4/K1ABC> FK52UD 37
// send hash instead of callsign to make room for 6 char grid.
// if 4-digit locator is specified, 2 spaces are added to the end.
callsign=strtok(message,"<> ");
grid=strtok(NULL," ");
powstr=strtok(NULL," ");
int power = atoi(powstr);
if( power < 0 ) power=0;
if( power > 60 ) power=60;
power=power+nu[power%10];
ntype=-(power+1);
ihash=nhash(callsign,strlen(callsign),(uint32_t)146);
m=128*ihash + ntype + 64;
char grid6[7];
memset(grid6,0,sizeof(char)*7);
j=strlen(grid);
for(i=0; i<j-1; i++) {
grid6[i]=grid[i+1];
}
grid6[5]=grid[0];
n = pack_call(grid6);
} else if ( i2 < mlen ) { // just looks for a right slash
// Type 2: PJ4/K1ABC 37
callsign = strtok (message," ");
if( i2==0 || i2>strlen(callsign) ) return 0; //guards against pathological case
powstr = strtok (NULL," ");
int power = atoi (powstr);
if( power < 0 ) power=0;
if( power > 60 ) power=60;
power=power+nu[power%10];
int n1, ng, nadd;
pack_prefix(callsign, &n1, &ng, &nadd);
ntype=power + 1 + nadd;
m=128*ng+ntype+64;
n=n1;
} else {
return 0;
}
// pack 50 bits + 31 (0) tail bits into 11 bytes
unsigned char it, data[11];
memset(data,0,sizeof(char)*11);
it=0xFF & (n>>20);
data[0]=it;
it=0xFF & (n>>12);
data[1]=it;
it=0xFF & (n>>4);
data[2]=it;
it= ((n&(0x0F))<<4) + ((m>>18)&(0x0F));
data[3]=it;
it=0xFF & (m>>10);
data[4]=it;
it=0xFF & (m>>2);
data[5]=it;
it=(m & 0x03)<<6 ;
data[6]=it;
data[7]=0;
data[8]=0;
data[9]=0;
data[10]=0;
if( printdata ) {
printf("Data is :");
for (i=0; i<11; i++) {
printf("%02X ",data[i]);
}
printf("\n");
}
// make sure that the 11-byte data vector is unpackable
// unpack it with the routine that the decoder will use and display
// the result. let the operator decide whether it worked.
char *check_call_loc_pow, *check_callsign;
check_call_loc_pow=malloc(sizeof(char)*23);
check_callsign=malloc(sizeof(char)*13);
signed char check_data[11];
memcpy(check_data,data,sizeof(char)*11);
unpk_(check_data,hashtab,check_call_loc_pow,check_callsign);
// printf("Will decode as: %s\n",check_call_loc_pow);
unsigned int nbytes=11; // The message with tail is packed into almost 11 bytes.
unsigned char channelbits[nbytes*8*2]; /* 162 rounded up */
memset(channelbits,0,sizeof(char)*nbytes*8*2);
encode(channelbits,data,nbytes);
interleave(channelbits);
for (i=0; i<162; i++) {
symbols[i]=2*channelbits[i]+pr3[i];
}
free(check_call_loc_pow);
free(check_callsign);
return 1;
}
@@ -1,139 +0,0 @@
module ft8_decode
type :: ft8_decoder
procedure(ft8_decode_callback), pointer :: callback
contains
procedure :: decode
end type ft8_decoder
abstract interface
subroutine ft8_decode_callback (this,sync,snr,dt,freq,decoded,nap,qual)
import ft8_decoder
implicit none
class(ft8_decoder), intent(inout) :: this
real, intent(in) :: sync
integer, intent(in) :: snr
real, intent(in) :: dt
real, intent(in) :: freq
character(len=22), intent(in) :: decoded
integer, intent(in) :: nap
real, intent(in) :: qual
end subroutine ft8_decode_callback
end interface
contains
subroutine decode(this,callback,iwave,nQSOProgress,nfqso,nftx,newdat, &
nutc,nfa,nfb,nexp_decode,ndepth,nagain,lapon,napwid,mycall12, &
mygrid6,hiscall12,hisgrid6)
! use wavhdr
use timer_module, only: timer
include 'fsk4hf/ft8_params.f90'
! type(hdr) h
class(ft8_decoder), intent(inout) :: this
procedure(ft8_decode_callback) :: callback
real s(NH1,NHSYM)
real sbase(NH1)
real candidate(3,200)
real dd(15*12000)
logical, intent(in) :: lapon,nagain
logical newdat,lsubtract,ldupe,bcontest
character*12 mycall12, hiscall12
character*6 mygrid6,hisgrid6
integer*2 iwave(15*12000)
integer apsym(KK)
character datetime*13,message*22
character*22 allmessages(100)
integer allsnrs(100)
save s,dd
bcontest=iand(nexp_decode,128).ne.0
this%callback => callback
write(datetime,1001) nutc !### TEMPORARY ###
1001 format("000000_",i6.6)
call ft8apset(mycall12,mygrid6,hiscall12,hisgrid6,bcontest,apsym,iaptype)
dd=iwave
ndecodes=0
allmessages=' '
allsnrs=0
ifa=nfa
ifb=nfb
if(nagain) then
ifa=nfqso-10
ifb=nfqso+10
endif
! For now:
! ndepth=1: no subtraction, 1 pass, belief propagation only
! ndepth=2: subtraction, 2 passes, belief propagation only
! ndepth=3: subtraction, 2 passes, bp+osd
if(ndepth.eq.1) npass=1
if(ndepth.ge.2) npass=3
do ipass=1,npass
newdat=.true. ! Is this a problem? I hijacked newdat.
syncmin=1.5
if(ipass.eq.1) then
lsubtract=.true.
if(ndepth.eq.1) lsubtract=.false.
elseif(ipass.eq.2) then
n2=ndecodes
if(ndecodes.eq.0) cycle
lsubtract=.true.
elseif(ipass.eq.3) then
if((ndecodes-n2).eq.0) cycle
lsubtract=.false.
endif
call timer('sync8 ',0)
call sync8(dd,ifa,ifb,syncmin,nfqso,s,candidate,ncand,sbase)
call timer('sync8 ',1)
do icand=1,ncand
sync=candidate(3,icand)
f1=candidate(1,icand)
xdt=candidate(2,icand)
xbase=10.0**(0.1*(sbase(nint(f1/3.125))-40.0))
nsnr0=min(99,nint(10.0*log10(sync) - 25.5)) !### empirical ###
call timer('ft8b ',0)
call ft8b(dd,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,napwid, &
lsubtract,nagain,iaptype,mygrid6,bcontest,sync,f1,xdt,xbase, &
apsym,nharderrors,dmin,nbadcrc,iappass,iera,message,xsnr)
nsnr=nint(xsnr)
xdt=xdt-0.5
hd=nharderrors+dmin
call timer('ft8b ',1)
if(nbadcrc.eq.0) then
! call jtmsg(message,iflag)
if(bcontest) call fix_contest_msg(mygrid6,message)
! if(iand(iflag,31).ne.0) message(22:22)='?'
ldupe=.false.
do id=1,ndecodes
if(message.eq.allmessages(id).and.nsnr.le.allsnrs(id)) ldupe=.true.
enddo
if(.not.ldupe) then
ndecodes=ndecodes+1
allmessages(ndecodes)=message
allsnrs(ndecodes)=nsnr
endif
! write(81,1004) nutc,ncand,icand,ipass,iaptype,iappass, &
! nharderrors,dmin,hd,min(sync,999.0),nint(xsnr), &
! xdt,nint(f1),message
!1004 format(i6.6,2i4,3i2,i3,3f6.1,i4,f6.2,i5,2x,a22)
! flush(81)
if(.not.ldupe .and. associated(this%callback)) then
qual=1.0-(nharderrors+dmin)/60.0 ! scale qual to [0.0,1.0]
call this%callback(sync,nsnr,xdt,f1,message,iaptype,qual)
endif
endif
enddo
! h=default_header(12000,NMAX)
! open(10,file='subtract.wav',status='unknown',access='stream')
! iwave=nint(dd)
! write(10) h,iwave
! close(10)
enddo
return
end subroutine decode
end module ft8_decode
@@ -0,0 +1,77 @@
// Status=review
image::RadioTab.png[align="center",alt="Radio Tab"]
_WSJT-X_ offers CAT (Computer Aided Transceiver) control of relevant
features of most modern transceivers. To configure the program for
your radio, select the *Radio* tab.
- Select your radio type from the drop-down list labeled *Rig*, or
*None* if you do not wish to use CAT control.
- Alternatively, if you have configured your station for control by
*DX Lab Suite Commander*, *Ham Radio Deluxe*, *Hamlib NET rigctl*, or
*Omni-Rig*, you may select one of those program names from the *Rig*
list. In these cases the entry field immediately under _CAT Control_
will be relabeled as *Network Server*. Leave this field blank to
access the default instance of your control program, running on the
same computer. If the control program runs on a different computer
and/or port, specify it here. Hover the mouse pointer over the entry
field to see the required formatting details.
- Select *Omni-Rig Rig 1* or *Omni-Rig Rig 2* to connect to an
_Omni-Rig_ server running on the same computer. Note that _Omni-Rig_
is available only under Windows.
- Set *Poll Interval* to the desired interval for _WSJT-X_ to query
your radio. For most radios a small number (say, 1 3 s) is
suitable.
- _CAT Control_: To have _WSJT-X_ control the radio directly rather
than though another program, make the following settings:
* Select the *Serial Port* used to communicate with your radio.
* _Serial Port Parameters_: Set values for *Baud Rate*, *Data Bits*,
*Stop Bits*, and *Handshake* method. Consult your radio's user guide
for the proper parameter values.
* _Force Control Lines_: A few station setups require the CAT serial
ports *RTS* and/or *DTR* control lines to be forced high or
low. Check these boxes only if you are sure they are needed (for
example, to power the radio serial interface).
- _PTT Method_: select *VOX*, *CAT*, *DTR*, or *RTS* as the desired
method for T/R switching. If your choice is *DTR* or *RTS*, select
the desired serial port (which may be the same one as used for
CAT control).
- _Transmit Audio Source_: some radios permit you to choose the
connector that will accept Tx audio. If this choice is enabled,
select *Rear/Data* or *Front/Mic*.
- _Mode_: _WSJT-X_ uses upper sideband mode for both transmitting and
receiving. Select *USB*, or choose *Data/Pkt* if your radio offers
such an option and uses it to enable the rear-panel audio line input.
Some radios also offer wider and/or flatter passbands when set to
*Data/Pkt* mode. Select *None* if you do not want _WSJT-X_ to change
the radio's Mode setting.
- _Split Operation_: Significant advantages result from using *Split*
mode (separate VFOs for Rx and Tx) if your radio supports it. If it
does not, _WSJT-X_ can emulate such behavior. Either method will
result in a cleaner transmitted signal, by keeping the Tx audio always
in the range 1500 to 2000 Hz so that audio harmonics cannot pass
through the Tx sideband filter. Select *Rig* to use the radio's Split
mode, or *Fake It* to have _WSJT-X_ adjust the VFO frequency as
needed, when T/R switching occurs. Choose *None* if you do not
wish to use split operation.
When all required settings have been made, click *Test CAT* to test
communication between _WSJT-X_ and your radio. The button should turn
green to indicate that proper communication has been established.
Failure of the CAT-control test turns the button red and displays an
error message. After a successful CAT test, toggle the *Test PTT*
button to confirm that your selected method of T/R control is working
properly. (If you selected *VOX* for _PTT Method_, you can test T/R
switching later by using the *Tune* button on the main window.)