tau_gen.py
#!/usr/bin/python
# To learn more about python and download it
# have look at http://www.python.org
# This program to generate a tlan file are WITHOUT any error checks
# or other clever ways to make/check a tarlan file which will run and/or give
# any sensible output, so if you use this script it is upto you to check
# that the tarlan ouput file is valid and fullfill your needs!!!
# Import all necessery modules
# string, getopt and sys are all python system modules
# tlan_mod is the module containing functions for writing tlan files
import string,getopt,sys,tlan_mod
# This is for the UHF in Tromso
Station='u'
###### Setup section
exp_name='tautest' # Name of experiment
ipp=11160 # IPP length (us)
samp_speed=12 # Sampling speed (us)
n_frac=3 # Fractionality
baud_len=samp_speed*n_frac # Baud length
loops=32 # Number of loops in a complete cycle
sub_loops=2 # Number of sub loops (frequency alternating)
code_len=16 # Number of Bauds send in each cycle
signal_ch='CH1' # Channel board used for signal sampling
gain_ch='CH2' # Channel board used as gain channel
trx_frq=[13,14] # Transmit frequncies used
trx_start=[100,100] # When transmitting should start relative the start of each IPP (us)
samp_len=364 # Nummer of samples taken in each IPP
noise_samp=15 # Number of samples of noise or calibration in every IPP
noise_end=30 # Time from IPP end when noise is turned off (us)
pre_noise=30 # Time to turn on noise source before sampling (us)
start_samp=980 # When to start sampling relative the start of each IPP (us)
code_fil=exp_name+'.ac' # File with transmit codes
######
# Open the t_to ps file for writing
t_to_ps=open('t_to_ps_'+Station+'.txt','w')
trx_dict=[{'ac':1,'frq':(trx_frq),'start':(trx_start),'code_len':code_len,'baud_len':baud_len}]
ac_code=[]
k=i=0
# open the file containing codes to transmit
# This file should haveeach code set as one line
# Read in all codes and put them into a vector called ac_code
for line in open(code_fil,'r').readlines():
cols=string.split(line)
for jj in range(len(cols)):
ac_code.append(string.atoi(cols[jj]))
i=i+1
# Open the tlan file for writing
sys.stdout=open(exp_name+'-'+Station+'.tlan','w')
# Start looping through all subcycles and code sets
for j in range(1,loops+1):
for i in range(sub_loops):
# Write some comments at top of each IPP
tlan_mod.Print_Comm('%%%%'*5)
tlan_mod.Print_Comm('%%%% IPP %d subcycle %d '%(j,i+1))
tlan_mod.Print_Comm('%%%%'*5)
tlan_mod.Print_Comm('SETTCR\t%d'%(ipp*k))
# Only first IPP
if(j==1 and i==0):
tlan_mod.Print_Comm('AT\t%d\tCHQPULS,AD1L,AD1R,STFIR'%(1))
# At tcr+6 us enable proper NCO
tlan_mod.Print_Comm('AT\t%d\tNCOSEL%d'%(6,i))
# Init. the transmitter and do RXPROT and LOPROT
tlan_mod.TRX_Setup(i,['ac'],trx_dict)
# Transmit the proper code for this IPP
tlan_mod.AC_Trx(i,j,['ac'],trx_dict,ac_code,ipp*k,t_to_ps)
# Do BEAMOF and do RXPOFF and LOPOFF
tlan_mod.TRX_Stop(i,['ac'],trx_dict)
tlan_mod.Print_Comm('%%%% Signal reception')
# Start sampling signal and gain channels
tlan_mod.Print_Comm(signal_ch+','+gain_ch,start_samp)
# Stop sampling signal and gain channels
tlan_mod.Print_Comm(signal_ch+'OFF'+','+gain_ch+'OFF',start_samp+samp_len*samp_speed)
# Write to t_to_ps file used in GUISDAP
t1=start_samp+ipp*k
t2=t1+samp_len*samp_speed
t_to_ps.write('%d\t%d\t%d\t%d\n'%(t1,t2,2,trx_frq[i]))
t_to_ps.write('%d\t%d\t%d\t%d\n'%(t1,t2,2,trx_frq[(i+1)%2]))
tlan_mod.Print_Comm('%%%% Calibration')
# Start noise injection
tlan_mod.Print_Comm('CALON',ipp-noise_samp*samp_speed-noise_end-pre_noise)
# Start sampling noise injection
tlan_mod.Print_Comm(signal_ch+','+gain_ch,ipp-noise_samp*samp_speed-noise_end)
# Turn off sampling and noise injection
tlan_mod.Print_Comm(signal_ch+'OFF'+','+gain_ch+'OFF'+','+'CALOFF',ipp-noise_end)
# Write to t_to_ps file used in GUISDAP
t2=ipp*(k+1)-noise_end
t1=t2-noise_samp*samp_speed-pre_noise
t_to_ps.write('%d\t%d\t%d\t%d\n'%(t1,t2,1,0))
t4=ipp*(k+1)-noise_end
t3=t4-noise_samp*samp_speed
t_to_ps.write('%d\t%d\t%d\t%d\n'%(t3,t4,2,trx_frq[i]))
t_to_ps.write('%d\t%d\t%d\t%d\n'%(t3,t4,2,trx_frq[(i+1)%2]))
# Do STC and BUFLIP
tlan_mod.Print_Comm('STC',ipp-5)
tlan_mod.Print_Comm('BUFLIP',ipp-4)
k=k+1;
tlan_mod.Print_Comm('SETTCR\t%d'%(0))
tlan_mod.Print_Comm('REP',ipp*k)
t_to_ps.close
tlan_mod.py
def Same_Code(Code,Start):
loops=0
first_code=Code[Start]
for i in Code[Start+1:]:
loops=loops+1
if i != first_code : break
if loops == 0:
loops=1
return loops
def Print_Comm(Command,At=-1):
if At>0:
print 'AT\t%3.1f\t%s'%(At,Command)
else:
print Command
def TRX_Setup(phase=-1,types=[],Trx_Dict={}):
if len(Trx_Dict)>0:
for x in range(len(Trx_Dict)):
for y in range(len(types)):
if Trx_Dict[x].has_key(types[y]):
Freq=int(Trx_Dict[x]['frq'][phase])
Time_Start=int(Trx_Dict[x]['start'][phase])-50
Print_Comm('RXPROT,LOPROT',Time_Start-30)
Print_Comm('BEAMON,F%d'%Freq,Time_Start)
Print_Comm('%%%%\n' '%%%% - Transmission -\n' '%%%%')
def TRX_Stop(phase=-1,types=[],Trx_Dict={}):
if len(Trx_Dict)>0:
for x in range(len(Trx_Dict)):
for y in range(len(types)):
if Trx_Dict[x].has_key(types[y]):
Time_Stop=int(Trx_Dict[x]['baud_len'])*int(Trx_Dict[x]['code_len'])
Time_Stop=int(Trx_Dict[x]['baud_len'])*int(Trx_Dict[x]['code_len'])
Time_Start=int(Trx_Dict[x]['start'][phase])
Print_Comm('RXPOFF',Time_Stop+100+Time_Start)
Print_Comm('LOPOFF',Time_Stop+150+Time_Start)
def AC_Trx_Sim(Baud_Len,Code,t_start,bit_rf,bit_ff):
pos=plus=minus=0
if Code[0] == -1:
phase=bit_ff
sign='-'*Same_Code(Code,0)
else:
phase=str(bit_ff)+'OFF'
sign='+'*Same_Code(Code,0)
print '%% The next long block is a replica of the transmitter code'
print '%% used for test purposes'
print 'AT\t',t_start,'\tBRX'+str(bit_rf)+',B'+str(phase),'\t\t%',sign,
j=1
pos=0
for i in Code[1:]:
pos=pos+1
if i == -1:
phase_next=str(bit_ff)
length=Same_Code(Code,pos)
sign='-'*length
else:
phase_next=str(bit_ff)+'OFF'
length=Same_Code(Code,pos)
sign='+'*length
if phase != phase_next:
print
phase=phase_next
last_t=t_start+Baud_Len*j
print 'AT\t',last_t,'\tBRX'+str(phase),'\t\t%',
print sign,
last_sign=sign[0]
j=j+1
bauds=int((((-last_t+(t_start+Baud_Len*j))-Baud_Len)/Baud_Len))
print '\b'+last_sign*bauds
t_start=t_start+Baud_Len*j
Print_Comm('BRX'+str(bit_rf)+'OFF,BRX'+str(bit_ff),t_start)
print '%% test tranmission block stop here'
def AC_Trx(phase,cycle,types,Trx_Dict,Code,tcr,t_to_ps):
if len(Trx_Dict)>0:
for x in range(len(Trx_Dict)):
for y in range(len(types)):
if Trx_Dict[x].has_key(types[y]):
frq=int(Trx_Dict[x]['frq'][phase])
t_start=int(Trx_Dict[x]['start'][phase])
Baud_Len=int(Trx_Dict[x]['baud_len'])
code_len=int(Trx_Dict[x]['code_len'])
Code=Code[code_len*(cycle-1):code_len*cycle]
pos=plus=minus=0
if Code[0] == -1:
phase=0
sign='-'*Same_Code(Code,0)
else:
phase=180
sign='+'*Same_Code(Code,0)
print 'AT\t',t_start,'\tRFON,PHA'+str(phase),'\t\t%',sign,
t1=t_start+tcr
if(phase==180):
com=1
else:
com=-1
j=1
pos=0
for i in Code[1:]:
pos=pos+1
if i == -1:
phase_next=0
length=Same_Code(Code,pos)
sign='-'*length
else:
phase_next=180
length=Same_Code(Code,pos)
sign='+'*length
if phase != phase_next:
print
phase=phase_next
last_t=t_start+Baud_Len*j
print 'AT\t',last_t,'\tPHA'+str(phase),'\t\t\t%',
print sign,
t2=last_t+tcr
t_to_ps.write('%d\t%d\t%d\t%d\n'%(t1,t2,com,frq))
t1=t2
if(phase==180):
com=1
else:
com=-1
last_sign=sign[0]
j=j+1
bauds=int((((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