Commit 22edc2f3 authored by Fabio Vitello's avatar Fabio Vitello
Browse files

#595 First version of IF distributor client, just to test connections

parent af9f0597
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
<?xml version='1.0' encoding='ISO-8859-1'?>

<IFDistConfiguration xmlns="urn:schemas-cosylab-com:IFDistConfiguration:1.0"
             	xmlns:baci="urn:schemas-cosylab-com:BACI:1.0"
				xmlns:cdb="urn:schemas-cosylab-com:CDB:1.0"
				xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
				IP="ifd.noto.ira.inaf.it"
				PORT="5000"> 

</IFDistConfiguration>
 No newline at end of file
+64 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- 
     Andre Orlati, andrea.orlati@inaf.it
-->
<xs:schema
    targetNamespace="urn:schemas-cosylab-com:IFDistConfiguration:1.0"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="urn:schemas-cosylab-com:IFDistConfiguration:1.0"
	 xmlns:cdb="urn:schemas-cosylab-com:CDB:1.0"
	 xmlns:baci="urn:schemas-cosylab-com:BACI:1.0"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

	<xs:import namespace="urn:schemas-cosylab-com:CDB:1.0" schemaLocation="CDB.xsd"/>
	<xs:import namespace="urn:schemas-cosylab-com:BACI:1.0" schemaLocation="BACI.xsd"/>
    
    
   <xs:simpleType name="AttIDType">
	   <xs:restriction base="xs:unsignedInt">
   	   <xs:minInclusive value="0" />
         <xs:maxInclusive value="3" />
      </xs:restriction>
	</xs:simpleType>

   <xs:simpleType name="AttValueType">
	   <xs:restriction base="xs:decimal">
   	   <xs:minInclusive value="0.0" />
         <xs:maxInclusive value="31.5" />
      </xs:restriction>
	</xs:simpleType>

   <xs:complexType name="AttHeader">
   	<xs:attribute name="ID" type="AttIDType"   />
      <xs:attribute name="Value" type="AttValueType" />
	</xs:complexType> 
    
	<xs:complexType name="BoardHeader">
        <xs:sequence>
            <xs:element name="Attenuator" type="AttHeader" minOccurs="1" maxOccurs="unbounded" />
        </xs:sequence>
        <xs:attribute name="number" type="xs:unsignedInt" use="required"/>
   </xs:complexType>
   
  	<xs:complexType name="ConfigurationHeader">
 		<xs:sequence>
         <xs:element name="Board" type="BoardHeader" minOccurs="1" maxOccurs="unbounded" />
      </xs:sequence>
      <xs:attribute name="name" type="xs:string" use="required" />
 	</xs:complexType>
   
   <xs:complexType name="IFDistConfigurationType">
		<xs:sequence>	
			<xs:element name="Configuration" type="ConfigurationHeader" minOccurs="0" maxOccurs="unbounded" />
		</xs:sequence>

		<xs:attribute name="IP" type="xs:string" use="required" />
      <xs:attribute name="PORT" type="xs:unsignedShort" use="required" />

	</xs:complexType>


    <xs:element name="IFDistConfiguration" type="IFDistConfigurationType" />
</xs:schema>
+129 −0
Original line number Diff line number Diff line
#!/usr/bin/env python

# This is a python script that can be used to configure the IF distributor. 
# The script is adapted from DMED. 
# PARAMETERS:
#  input1,[ingresso] per selezionare cosa si vuole in uscita su A
'''
input1,[ingresso] per selezionare cosa si vuole in uscita su A
input2,[ingresso] per selezionare cosa si vuole in uscita su B

input1 o input2 senza parametri ritorna l'ingresso selezionato come
ACK,input1=ingresso

att1,[valore] setta attenuazione A
att2,[valore] setta attenuazione B

att1 o att2 senza parametri ritorna il valore di attenuazione impostato come
ACK,att1=valore

i valori consentiti di ingresso per A sono:
0 nessun ingresso selezionato
1 ricevitore in vertex Right Pol
2 ricevitore L Right Pol
3 ricevitore X Right Pol
4 ricevitore S Right Pol
5 spare1
6 spare2

i valori consentiti di ingresso per B sono:
0 nessun ingresso selezionato
1 ricevitore in vertex Left Pol
2 ricevitore L Left Pol
3 ricevitore X Left Pol
4 ricevitore S Left Pol
5 ricevitore S Right Pol (per oss. geo)
6 spare1

i valori consentiti per att1 e att2 sono:
da 0 a 63. Ogni step corrisponde a 0.5 dB

Un comando errato ottiene in risposta
NAK
'''
#who                                   when           what
#fabio vitello (fabio.vitello@inaf.it)  28/06/2021     Creation



from Acspy.Clients.SimpleClient import PySimpleClient
import ACSLog
import maciErrType
import cdbErrType
import maciErrTypeImpl
import ManagementErrorsImpl
from IRAPy import logger,userLogger
from SimpleParserPy import add_user_message
import xml.etree.ElementTree as ET
import sys,getopt
import os
import socket
import time
from collections import namedtuple

def send_command(ip, port, command):
	s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	try:
		s.connect((ip,int(port)))
	except socket.error:
		return "Fail"
	s.sendall(command)
	time.sleep(0.1)
	response=s.recv(1024)
	s.close()
	response=response.strip().split('\n')
	return response

def cdb(xmlstr):
	root=ET.fromstring(xmlstr)
	configurations=root.findall('{urn:schemas-cosylab-com:IFDistConfiguration:1.0}Configuration')
	
	return root.items()[0][1],root.items()[1][1]
	
def main(argv):
	#check we are at the Noto
	station=os.environ['STATION']
	dataPath="alma/DataBlock/IFDist"
	xmlstring=""    
	data=[]
	found=False
	if station!="Noto":
		newEx = ManagementErrorsImpl.UnsupportedOperationExImpl()
		add_user_message(newEx,"The command is not available or it is not supported")
		userLogger.logExcpetion(newEx)
		simpleClient.disconnect()
		sys.exit(1)
    
	simpleClient = PySimpleClient()
	
	try:
		xmlstring=simpleClient.getCDBRecord(dataPath)
	except cdbErrType.CDBRecordDoesNotExistEx as ex:
		newEx = ComponentErrorsImpl.CDBAccessExImpl( exception=ex, create=1 )
		add_user_message(newEx,"Unable to load IFDist configuration")
		userLogger.logException(newEx)
		simpleClient.disconnect()
		sys.exit(1)
	
	try:
		ip,port=cdb(xmlstring)
	except:
		newEx = ComponentErrorsImpl.CDBFieldFormatExImpl()
		add_user_message(newEx,"Unable to parse IFDist configuration")
		userLogger.logException(newEx)
		simpleClient.disconnect()
		sys.exit(1)
	
	
	userLogger.logNotice("IFDist setup according to %s configuration"%(argv[0]))	
				
	if not found:
		newEx = ComponentErrorsImpl.ValidationErrorExImpl()
		add_user_message(newEx,"The required IFDist configuration is not known")
		userLogger.logException(newEx)
		simpleClient.disconnect()
		sys.exit(1)
	
if __name__=="__main__":
   main(sys.argv[1:])  
	
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ NT_ERRORS:=NotoActiveSurfaceErrors
NT_INTERFACES:=NotoAntennaInterface NotoReceiversInterface NotoWeatherStationInterface NotoActiveSurfaceInterface \
                NotoMinorServoInterface
NT_LIBRARIES:=
NT_SERVERS:= NotoReceivers NotoMount NotoWeatherStation NotoActiveSurface NotoMinorServo NotoPyLocalOscillator
NT_SERVERS:= NotoReceivers NotoMount NotoWeatherStation NotoActiveSurface NotoMinorServo NotoPyLocalOscillator NotoPyIfDistributor
NT_CLIENTS:=NotoMountTextClient 
NT_MISC:=NotoScripts

@@ -153,7 +153,7 @@ ifeq ($(STATION),Noto)
		AntennaBoss Observatory OTF PointingModel Refraction SkySource Moon FitsWriter Scheduler ReceiversBoss ExternalClients CalibrationTool \
		TotalPower NotoMount CustomLogger \
		AntennaBossTextClient ObservatoryTextClient GenericBackendTextClient ReceiversBossTextClient SystemTerminal SchedulerTextClient \
		NotoMountTextClient CustomLoggingClient Scripts
		NotoMountTextClient CustomLoggingClient Scripts NotoPyIfDistributor

	IDL_DOC:=Managment Antenna Backends Metrology
	CPP_DOC:=Libraries AntennaImplementation ManagementImplementation BackendsImplementation ReceiversImplementation