Skip to content
Snippets Groups Projects
stationtest.py 88.6 KiB
Newer Older
				##Write results to file
				#for rcuind in range(num_rcu) :
					#f_logfac.write(str(element+1) + ' ' + str(rcuind) + ' ' + str(round(meet_data[rcuind]/ref_data[rcuind])) + '\n')  
					#if meet_data[rcuind] < factor*ref_data[rcuind] :        
						#if rcuind == 0 :
							#tilenumb=0
						#else:
						#f_log.write('Element ' + str(element+1) + ', Tile ' + str(tilenumb) + ' in RCU: ' + str(rcuind)+ ' factor: ' + str(round(meet_data[rcuind]/ref_data[rcuind])) + '\n')
						
						## store station testlog	
						#if ModemFail[tilenumb] != 1:
							#if Severity<SeverityOfThisTest: Severity=SeverityOfThisTest
							#if Priority<PriorityOfThisTest: Priority=PriorityOfThisTest
							#st_log.write('HBAmd5>: Sv=%s Pr=%s, Tile %s - RCU %s; Element %s Broken. RF-signal to low : (Factor = %s, CtrlWord = %s)\n' % (SeverityLevel[SeverityOfThisTest], PriorityLevel[PriorityOfThisTest], str(tilenumb), rcuind, str(element+1), str(round(meet_data[rcuind]/ref_data[rcuind])), temp_ctrl))
							#sr.setResult('FAILED')
				
		#f_log.close
		#f_logfac.close
	return	


################################################################################
# Function HBA test
#

# functions belonging to HBA test:

def capture_data(dir_name,num_rcu,hba_elements,ctrl_word,sleeptime,subband_nr,element):
	meet_data=list(range(0, num_rcu))
        rm_files(dir_name,'*')
        ctrl_string='='
        for ind in range(hba_elements) :
               if ind == element:
			ctrl_string=ctrl_string + '128,'
	       else:	
			ctrl_string=ctrl_string + '2,'
	strlength=len(ctrl_string)
        ctrl_string=ctrl_string[0:strlength-1]
	cmd_str='rspctl --hbadelay' + ctrl_string + ' 2>/dev/null'
        os.popen(cmd_str)
	time.sleep(sleeptime)
        print('Capture HBA element ' + str(element+1) + ' data')
        rec_stat(dir_name,num_rcu)
        # get list of all files in dir_name
 	files = open_dir(dir_name)
        
        # start processing the element measurements
	for file_cnt in range(len(files)) :
		f, frames_to_process, rcu_nr  = open_file(files, file_cnt)
                if frames_to_process > 0 : 
		   	sst_data = read_frame(f)
                   	sst_subband = sst_data[subband_nr]
		   	meet_data[rcu_nr] = sst_subband
		f.close
	return meet_data

def switchon_hba() :
	
	try:
           os.popen3("rspctl --rcumode=5 --sel=0:31")
           time.sleep(1)
	   os.popen3("rspctl --rcumode=5 --sel=32:63")
           time.sleep(1)
	   os.popen3("rspctl --rcumode=5 --sel=64:95")
           time.sleep(1)
	   os.popen3("rspctl --rcumode=5 --sel=96:127")
           time.sleep(1)
	   os.popen3("rspctl --rcumode=5 --sel=128:159")
           time.sleep(1)
	   os.popen3("rspctl --rcumode=5 --sel=160:191")
           time.sleep(1)
	except:
          print("This is a NL station")
        os.popen("rspctl --rcuenable=1")
        return 
	
# HBA test
def HBAtest():
	SeverityOfThisTest=2
	PriorityOfThisTest=2
	global Severity
	global Priority
	
	if StID in NoHBAelementtestPossible: 
		print ('No HBA elementtest Possible!!!')
		if Severity<SeverityOfThisTest: Severity=SeverityOfThisTest
		if Priority<PriorityOfThisTest: Priority=PriorityOfThisTest
		st_log.write('HBAmd5>: Sv=%s Pr=%s, No HBA elementtest Possible!!!\n' % (SeverityLevel[SeverityOfThisTest], PriorityLevel[PriorityOfThisTest]))
	else:
		debug=0
		
		print ('HBA element test')
		sr.setId('HBAmd5>: ')	
		subband_nr=155
		if StationType == International: subband_nr = HBASubband[StID]
		if debug: print((' subband_nr of %s = %d %d' % (StID,subband_nr,HBASubband[StID])))

		sub_time=[]
		sub_file=[]
		dir_name = '/opt/stationtest/test/hbatest/hbadatatest/' #Work directory will be cleaned
		if not(os.path.exists(dir_name)):
			os.mkdir(dir_name)
		rmfile = '*.log'
		hba_elements=16
		sleeptime=10
		ctrl_word=[128,253]
		ctrl_string='='
		# read in arguments
#		if len(sys.argv) < 2 :
#			subband_nr=155
#		else :
#			subband_nr = int(sys.argv[1])
		print(' Dir name is ' + dir_name)
		if len(sys.argv) < 3 :
			if StationType == International:
				num_rcu=192
			else:
				num_rcu=96
		else :
			num_rcu = int(sys.argv[2])
		print(' Number of RCUs is ' + str(num_rcu))
		#print ' Number of the used Subband is ' + str(subband_nr)
		print((' Number of the used Subband of %s is  = %d' % (StID,subband_nr)))
		ref_data=list(range(0, num_rcu))
		os.chdir(dir_name)
		#os.popen("rspctl --clock=200")
		#print 'Clock is set to 200 MHz'
		#time.sleep(10)
		#---------------------------------------------
		# capture reference data (all HBA elements off)
		rm_files(dir_name,'*')
		switchon_hba()
		#os.popen("rspctl --rcumode=5 2>/dev/null")
		#os.popen("rspctl --rcuenable=1 2>/dev/null")
		time.sleep(2)
	#	To simulate a defect antenna:
		if debug==2:
			os.popen3("rspctl --rcu=0x10037880 --sel=50:53")
			time.sleep(1)
		for ind in range(hba_elements) :
			ctrl_string=ctrl_string + '2,'
		strlength=len(ctrl_string)
		ctrl_string=ctrl_string[0:strlength-1]
		cmd_str='rspctl --hbadelay' + ctrl_string + ' 2>/dev/null'
		os.popen(cmd_str)
		time.sleep(sleeptime)
		print('Capture reference data')
		rec_stat(dir_name,num_rcu)
		#rm_files(dir_name,rmfile)
		# get list of all files in dir_name
		files = open_dir(dir_name)
		# start processing the reference measurement
		for file_cnt in range(len(files)) :
			f, frames_to_process, rcu_nr  = open_file(files, file_cnt)
			if frames_to_process > 0 : 
				sst_data = read_frame(f)
				sst_subband = sst_data[subband_nr]
				ref_data[rcu_nr] = sst_subband
				#if rcu_nr==0:
				#	print ' waarde is ' + str(sst_subband)
			f.close
		#---------------------------------------------
		# capture hba element data for all elements
		for temp_ctrl in ctrl_word:
			print('Capture data for control word: ' + str(temp_ctrl))
			# init log file
			filename='/opt/stationtest/test/hbatest/HBA_elements_' + str(temp_ctrl)
			f_log = file(filename, 'w')
			writestring=' ************ \n \n LOG File for HBA element test (used ctrl word for active element:' + str(temp_ctrl) +' \n \n *************** \n \n'
			f_log.write(writestring)
			filename='/opt/stationtest/test/hbatest/HBA_factors_' + str(temp_ctrl)
			f_logfac = file(filename, 'w')
			for element in range(hba_elements) :
				meet_data=capture_data(dir_name,num_rcu,hba_elements,temp_ctrl,sleeptime,subband_nr,element)
	
				#Find the factor
				data_tmp=10*numpy.log10(meet_data)
				data_tmp=numpy.sort(data_tmp)
				median=data_tmp[len(data_tmp)/2]
				factor=median/2
				print('Processing element ' + str(element) + ' using a limit of ' + str(round(factor,1)) + ' dB')
				#Write results to file
				for rcuind in range(num_rcu) :
					#print ('ref_data = %d rcuind = %d' % (ref_data[rcuind],rcuind))
					if ref_data[rcuind] != 0: f_logfac.write(str(element+1) + ' ' + str(rcuind) + ' ' + str(round(meet_data[rcuind]/ref_data[rcuind])) + '\n')
					if meet_data[rcuind] < factor*ref_data[rcuind] :        
						if rcuind == 0 :
							tilenumb=0
						else:
						f_log.write('Element ' + str(element+1) + ', Tile ' + str(tilenumb) + ' in RCU: ' + str(rcuind)+ ' factor: ' + str(round(meet_data[rcuind]/ref_data[rcuind])) + '\n')
						
						# store station testlog	
						if ModemFail[tilenumb] != 1:
							if Severity<SeverityOfThisTest: Severity=SeverityOfThisTest
							if Priority<PriorityOfThisTest: Priority=PriorityOfThisTest
							st_log.write('HBAmd5>: Sv=%s Pr=%s, Tile %s - RCU %s; Element %s Broken. RF-signal to low : (Factor = %s, CtrlWord = %s)\n' % (SeverityLevel[SeverityOfThisTest], PriorityLevel[PriorityOfThisTest], str(tilenumb), rcuind, str(element+1), str(round(meet_data[rcuind]/ref_data[rcuind])), temp_ctrl))
							sr.setResult('FAILED')
################################################################################
# Function WriteAll: To leave message on the station!
#
def WriteAll(msg):
	res = os.popen3('wall %s' % (msg))[1].readlines()

################################################################################
# Main program
Message=('!!!     This station will be in use for a test! Please do not use the station!     !!!')

WriteAll(Message)
GotoSwlevel2()			# Set system in software level 2
CheckNtpd()			# Check the pps and GPS ST
##makeRSPVersionGold()		# make RSP Version gold ST
CheckRSPVersion()		# Check RSP Version ST
CheckTDSStatus160()		# Set clock to 200 MHz and check if locked
CheckRSPStatus()		# Check status bits form the RSP ST
CheckTDSStatus200()		# Set clock to 200 MHz and check if locked
CheckRSPStatus()		# Check status bits form the RSP ST
GotoSwlevel2()			# Set system in software level 2 again (via level 1). Switching the clock will hold the TBBdriver
#makeTBBVersionGold()		# make TBB Version ST
CheckTBBVersion()		# CHeck TBB Version ST
#makeTBBMemGold()		# make TBB Memory gold ST
#CheckTBBMemory()		# Verify TBB memory modules on the TBB ST
#CheckTBBSize()			# Verify the size of the TBB memory modules ST
#RCUHBAModemTest()		# Verify the control modem on the RCU ST (Gaat nog iets fout op CS003!!!!!
#PseudoRandomTBBTest()		# Verify the RCU - RSP - TBB LVDS interfaces by capturing pseudo random data on TBB
#CheckSPUStatus()		# Verify the RSP - SPU I2C interface by reading the SPU sensor data ST
#CheckRSPTdI2C() 		# Verify the RSP - TD I2C interface by reading the TD sensor data ST
#Bist()				# Build In Self Test for RSP (BIST) ST
#PseudoRandomRSPTest()		# Verify the RCU -> RSP LVDS interfaces by capturing pseudo random data on RSP
##RCUHBAModemTest()		# Verify the control modem on the RCU

#SerdesRingTestOff()		# Verify the Serdes ring connection between the RSP boards with ring is off
#SerdesRingTestOn()		# Verify the Serdes ring connection between the RSP boards with ring is on

res = os.popen3('rspctl --rcuprsg=0')[1].readlines()
LBAtest()			# Check LBH and LBL antenna's in mode 1 and 3 ST
HBAModemTest()			# Test of the HBA server modems
HBAtest()			# Check HBA tiles in mode 5
HBANaStest()			# HBA Noise and Spurious


Message=('!!!     The test is ready and the station can be used again!                       !!!')
WriteAll(Message)


################################################################################
# End of the subrack test

res = os.popen3('rspctl --rcuprsg=0')[1].readlines()
#cli.command('rspctl --rcuprsg=0') 
sr.setId('Subrack - ')
dt = sr.getRunTime()
sr.appendLog(2,'Duration: %02dm:%02ds' % (dt // 60 % 60, dt % 60))
sr.appendLog(0,sr.getResult())
sr.closeLog()

################################################################################
# End of the station test

# Define station testlog
st_log.write('Status>: %s\n' % sr.getResult())
if Priority > 0 or Severity > 0:
	st_log.write('Sever >: %s\n' % SeverityLevel[Severity])
	st_log.write('Prio  >: %s\n' % PriorityLevel[Priority])
st_log.write('TestTm>: %02dm:%02ds\n' % (dt // 60 % 60, dt % 60))
#st_log.flush
st_log.close()
time.sleep(1)
res = os.popen3('swlevel 1')[1].readlines()	# Put station in current saving mode.....
# Change write permissions for al log files
res = os.popen3("chmod g+w %s" % (TestlogName))[1].readlines()
#res = os.popen3("chmod 755 %s" % (TestlogName))[1].readlines()

# Finaly move temporary logfile to final logfile
res = os.popen3("scp -rp %s %s" % (TestlogName , HistlogName))[1].readlines()
if debug: print(res)
time.sleep(1)
res = os.popen3("mv %s %s" % (TestlogName , TestlogNameFinalized))
if debug: print(res)
print(('TestlogName: ',TestlogName))
print(('HistlogName: ',HistlogName))
print(('TestlogNameFinalized: ',TestlogNameFinalized))