2007-06-21 14:25:01 -04:00
|
|
|
subroutine recvpkt(iarg)
|
|
|
|
|
2008-07-12 14:11:36 -04:00
|
|
|
! Receive timf2 packets from Linrad and stuff data into array id().
|
|
|
|
! (This routine runs in a background thread and will never return.)
|
2007-06-21 14:25:01 -04:00
|
|
|
|
2007-06-23 14:12:39 -04:00
|
|
|
parameter (NSZ=2*60*96000)
|
2007-06-21 14:25:01 -04:00
|
|
|
real*8 d8(NSZ)
|
|
|
|
integer*1 userx_no,iusb
|
|
|
|
integer*2 nblock,nblock0
|
2008-07-24 13:05:55 -04:00
|
|
|
logical synced
|
2007-06-21 14:25:01 -04:00
|
|
|
real*8 center_freq,buf8
|
|
|
|
common/plrscom/center_freq,msec,fqso,iptr,nblock,userx_no,iusb,buf8(174)
|
|
|
|
include 'datcom.f90'
|
2007-06-22 16:32:58 -04:00
|
|
|
include 'gcom1.f90'
|
2007-06-21 14:25:01 -04:00
|
|
|
include 'gcom2.f90'
|
|
|
|
equivalence (id,d8)
|
2008-07-24 11:43:05 -04:00
|
|
|
data nblock0/0/,kb/1/,npkt/0/,nw/0/,ns0/99/
|
2007-07-06 12:28:58 -04:00
|
|
|
data sqave/0.0/,u/0.001/,rxnoise/0.0/,kbuf/1/,lost_tot/0/
|
2007-11-05 14:19:46 -05:00
|
|
|
data multicast0/-99/
|
2007-06-21 14:25:01 -04:00
|
|
|
save
|
|
|
|
|
2007-11-05 14:19:46 -05:00
|
|
|
1 call setup_rsocket(multicast) !Open socket for multicast/unicast data
|
2007-06-21 14:25:01 -04:00
|
|
|
k=0
|
2008-07-24 11:43:05 -04:00
|
|
|
kk=0
|
|
|
|
kxp=0
|
2008-07-24 13:05:55 -04:00
|
|
|
kb=1
|
2007-06-21 14:25:01 -04:00
|
|
|
nsec0=-999
|
2008-07-12 14:11:36 -04:00
|
|
|
fcenter=144.125 !Default (startup) frequency)
|
2007-11-05 14:19:46 -05:00
|
|
|
multicast0=multicast
|
2008-07-24 11:43:05 -04:00
|
|
|
ntx=0
|
2008-07-24 13:05:55 -04:00
|
|
|
synced=.false.
|
2007-06-21 14:25:01 -04:00
|
|
|
|
2007-11-05 14:19:46 -05:00
|
|
|
10 if(multicast.ne.multicast0) go to 1
|
|
|
|
call recv_pkt(center_freq)
|
2008-07-12 14:11:36 -04:00
|
|
|
|
2008-07-24 11:43:05 -04:00
|
|
|
! Should receive a new packet every 174/96000 = 0.0018125 s
|
|
|
|
npkt=npkt+1
|
|
|
|
nsec=mod(Tsec,86400.d0) !Time according to MAP65
|
|
|
|
nseclr=msec/1000 !Time according to Linrad
|
|
|
|
fcenter=center_freq
|
2008-07-23 16:27:47 -04:00
|
|
|
|
2008-07-24 11:43:05 -04:00
|
|
|
! Reset buffer pointers at start of minute.
|
|
|
|
ns=mod(nsec,60)
|
|
|
|
if(ns.lt.ns0) then
|
|
|
|
if(ntx.eq.0) kb=3-kb
|
|
|
|
k=(kb-1)*60*96000
|
2008-07-23 16:27:47 -04:00
|
|
|
ndone1=0
|
2008-07-24 11:43:05 -04:00
|
|
|
ntx=0
|
|
|
|
lost_tot=0
|
|
|
|
kxp=k
|
|
|
|
npkt=0
|
2008-07-24 13:05:55 -04:00
|
|
|
synced=.true.
|
2007-06-30 10:28:31 -04:00
|
|
|
endif
|
2008-07-24 11:43:05 -04:00
|
|
|
ns0=ns
|
2007-06-30 10:28:31 -04:00
|
|
|
|
2008-07-24 11:43:05 -04:00
|
|
|
if(transmitting.eq.1) ntx=1
|
2008-07-23 16:27:47 -04:00
|
|
|
|
|
|
|
! Check for lost packets
|
2007-06-30 10:28:31 -04:00
|
|
|
lost=nblock-nblock0-1
|
2008-07-24 11:43:05 -04:00
|
|
|
if(lost.ne.0) then
|
2007-07-06 12:28:58 -04:00
|
|
|
nb=nblock
|
|
|
|
if(nb.lt.0) nb=nb+65536
|
|
|
|
nb0=nblock0
|
|
|
|
if(nb0.lt.0) nb0=nb0+65536
|
|
|
|
lost_tot=lost_tot + lost ! Insert zeros for the lost data.
|
2007-06-30 10:28:31 -04:00
|
|
|
do i=1,174*lost
|
|
|
|
k=k+1
|
|
|
|
d8(k)=0
|
|
|
|
enddo
|
|
|
|
endif
|
2008-07-12 14:11:36 -04:00
|
|
|
nblock0=nblock
|
2007-06-30 10:28:31 -04:00
|
|
|
|
2008-07-23 16:27:47 -04:00
|
|
|
tdiff=mod(0.001d0*msec,60.d0)-mod(Tsec,60.d0)
|
|
|
|
if(tdiff.lt.-30.) tdiff=tdiff+60.
|
|
|
|
if(tdiff.gt.30.) tdiff=tdiff-60.
|
2008-07-12 14:11:36 -04:00
|
|
|
|
2008-07-23 16:27:47 -04:00
|
|
|
! Test for buffer full
|
|
|
|
if((kb.eq.1 .and. (k+174).gt.NSMAX) .or. &
|
2008-07-24 11:43:05 -04:00
|
|
|
(kb.eq.2 .and. (k+174).gt.2*NSMAX)) go to 20
|
2007-06-30 10:28:31 -04:00
|
|
|
|
2008-07-23 16:27:47 -04:00
|
|
|
! Move data into Rx buffer and compute average signal level.
|
2007-06-30 10:28:31 -04:00
|
|
|
sq=0.
|
|
|
|
do i=1,174
|
|
|
|
k=k+1
|
|
|
|
d8(k)=buf8(i)
|
2007-11-19 11:42:21 -05:00
|
|
|
k2=k
|
|
|
|
n=1
|
|
|
|
if(k.gt.NSMAX) then
|
|
|
|
k2=k2-NSMAX
|
|
|
|
n=2
|
|
|
|
endif
|
2008-07-24 11:43:05 -04:00
|
|
|
x1=id(1,k2,n)
|
|
|
|
x2=id(2,k2,n)
|
|
|
|
x3=id(3,k2,n)
|
|
|
|
x4=id(4,k2,n)
|
|
|
|
sq=sq + x1*x1 + x2*x2 + x3*x3 + x4*x4
|
2007-06-30 10:28:31 -04:00
|
|
|
enddo
|
|
|
|
sqave=sqave + u*(sq-sqave)
|
|
|
|
rxnoise=10.0*log10(sqave) - 48.0
|
2007-07-09 20:15:11 -04:00
|
|
|
kxp=k
|
2007-06-21 14:25:01 -04:00
|
|
|
|
2007-06-30 10:28:31 -04:00
|
|
|
20 if(nsec.ne.nsec0) then
|
|
|
|
nsec0=nsec
|
2008-07-23 16:27:47 -04:00
|
|
|
mutch=nseclr/3600
|
|
|
|
mutcm=mod(nseclr/60,60)
|
|
|
|
mutc=100*mutch + mutcm
|
|
|
|
|
2008-07-24 11:43:05 -04:00
|
|
|
! If we have not transmitted in this minute, see if it's time to start FFTs
|
|
|
|
if(ntx.eq.0) then
|
2008-07-24 13:05:55 -04:00
|
|
|
if(ns.ge.nt1 .and. ndone1.eq.0 .and. synced) then
|
2008-07-24 11:43:05 -04:00
|
|
|
nutc=mutc
|
|
|
|
fcenter=center_freq
|
|
|
|
kbuf=kb
|
|
|
|
kk=k
|
|
|
|
ndiskdat=0
|
|
|
|
ndone1=1
|
|
|
|
endif
|
2008-07-12 14:11:36 -04:00
|
|
|
|
|
|
|
! See if it's time to start second stage of processing
|
2008-07-24 12:34:59 -04:00
|
|
|
if(ndone1.eq.1 .and. ns.ge.nt2) then
|
2008-07-24 11:43:05 -04:00
|
|
|
kk=k
|
|
|
|
nlost=lost_tot ! Save stats for printout
|
|
|
|
endif
|
2007-06-30 10:28:31 -04:00
|
|
|
endif
|
2008-07-23 16:27:47 -04:00
|
|
|
|
2008-07-24 11:43:05 -04:00
|
|
|
tt=npkt*174.0/96000.0
|
|
|
|
! if(ns.le.5 .or. ns.ge.46) write(*,3001) ns,ndone1,kb, &
|
|
|
|
! kbuf,ntx,kk,tdiff,tt
|
|
|
|
!3001 format(5i4,i11,2f8.2)
|
2008-07-23 16:27:47 -04:00
|
|
|
|
2007-06-21 14:25:01 -04:00
|
|
|
endif
|
|
|
|
go to 10
|
|
|
|
|
|
|
|
end subroutine recvpkt
|