diff --git a/pcs/agents/acu_interface/aculib.py b/pcs/agents/acu_interface/aculib.py index 189853a..ab9fc49 100644 --- a/pcs/agents/acu_interface/aculib.py +++ b/pcs/agents/acu_interface/aculib.py @@ -146,6 +146,19 @@ def abort(self): self.log.info(response) return response + def position_broadcast(self, udp_host: str, udp_port: int): + """Switch ON the position broadcasting from the TCS + :param udp_host + :param udp_port + """ + data = {"destination_host": udp_host, + "destination_port": udp_port} + cmd = f"{self.url_prefix}/acu/position-broadcast" + + print ("COMING HERE?") + response = self.post(cmd, data) + self.log.info(response.json()) + return response def move_to(self, azimuth: float, elevation: float): """send telescope to a given azimuth,elevation diff --git a/pcs/agents/acu_interface/agent.py b/pcs/agents/acu_interface/agent.py index f349db4..86677cf 100644 --- a/pcs/agents/acu_interface/agent.py +++ b/pcs/agents/acu_interface/agent.py @@ -88,17 +88,22 @@ def __init__(self, agent, config, device='acu_sim', startup=False): startup=False) #register tasks + agent.register_task('tcs_broadcast', + self.tcs_broadcast, + blocking=True, + aborter=self._simple_task_abort) + agent.register_task('go_to', self.go_to, blocking=True, aborter=self._simple_task_abort) agent.register_task('az_scan', self.az_scan, - blocking=False, + blocking=True, aborter=self._simple_task_abort) agent.register_task('fromfile_scan', self.fromfile_scan, - blocking=False, + blocking=True, aborter=self._simple_task_abort) @@ -254,6 +259,39 @@ def datagramReceived(self, data, src_addr): #self.agent.feeds['acu_udp_stream'].flush_buffer() return True, 'Acquisition exited cleanly.' + @ocs_agent.param('udp_host', type=str) + @ocs_agent.param('udp_port', type=int) + def tcs_broadcast(self, session, params): + """tcs_broadcast(udp_host, udp_port) + + **Task** - Switch ON the position data stream broadcasting from + the TCS api. With the given UDP host address and port, the ACU + starts broadcasting the posotion data stream that the interface + agent can listen to and write the stream in the PCS HK. + + Parameters: + udp_host (str): UDP host address + udp_port (int): udp port number + """ + udp_host = params['udp_host'] + udp_port = params['udp_port'] + + self.log.info(f'Requested TCS broadcasting to switch ON at UDP host: {udp_host}, port: {udp_port}') + certs = self.acu_conf['certs'] + + tcs = aculib.observatory_control_system( + self.acu_conf['base_url'], + self.log, + server_cert=certs['server_cert'], + client_cert=certs['client_cert'], + client_key=certs['client_key'], + verify_cert=certs['verify'] + ) + msg = tcs.position_broadcast(udp_host, udp_port) + self.log.info(f"UDP stream broadcasting executed with response code: {msg.status_code}") + + return True, msg.text + @ocs_agent.param('az', type=float) @ocs_agent.param('el', type=float) def go_to(self, session, params): @@ -298,7 +336,7 @@ def go_to(self, session, params): return True, msg.text @ocs_agent.param('scan_params', type=dict) - def az_scan(): + def az_scan(self, session, params): """az_scan(start_time, turnaround_time, elevation, speed, num_scans, azimuth_range) @@ -343,7 +381,7 @@ def az_scan(): @ocs_agent.param('scan_filename', type=str) - def fromfile_scan(): + def fromfile_scan(self, session, params): """fromfile_scan(scan_filename) **Task** - Send scan commands for a predefined arbitrary path which @@ -413,3 +451,6 @@ def main(args=None): if __name__=='__main__': main() + + + diff --git a/tests/acu-agent/test_azscan.py b/tests/acu-agent/test_azscan.py new file mode 100644 index 0000000..e274802 --- /dev/null +++ b/tests/acu-agent/test_azscan.py @@ -0,0 +1,41 @@ +#!/bin/python + +from ocs.ocs_client import OCSClient +import time +from datetime import datetime + +client = OCSClient('acu1') +print (client.tcs_broadcast(udp_host='172.17.0.1', udp_port=5601)) +time.sleep(5) + +#''' +print (client.broadcast.start()) + +print('\nMonitoring (ctrl-c to stop and exit)...\n') + +#aximuth scan parameters +num_scans = 20 +scan_param = {'start_time': float(datetime.utcnow().timestamp()), + 'turnaround_time': 1.0, + 'elevation': 20.0, + 'speed': 1.0, + 'num_scans': num_scans, + 'azimuth_range': [10.0, 110.0]} + +#execute the scan +print (f"Moving telescope for Azimuth Scan ...") +client.az_scan(scan_params=scan_param) + +stay_alive = 3900 #seconds +it = 0 +while it*10 < stay_alive: + print (client.az_scan.status()) + time.sleep(10) + it += 1 + + +print('Stopping data acquisition ...') +print (client.broadcast.stop()) +#''' + + diff --git a/tests/acu-agent/test_move+acq.py b/tests/acu-agent/test_move+acq.py new file mode 100644 index 0000000..6a54d08 --- /dev/null +++ b/tests/acu-agent/test_move+acq.py @@ -0,0 +1,43 @@ +#!/bin/python +''' +This script runs the test to command telescope to move to +a preset point. In addition it also turns on the udp stream capture +and writing into g3 files while the movement operation in place. + +Test runs for 5 minute and exists by stopping the broadcast. +''' + +from ocs.ocs_client import OCSClient +import time + +client = OCSClient('acu1') + +print (client.tcs_broadcast(udp_host='172.17.0.1', udp_port=5601)) +time.sleep(5) + +print (client.broadcast.start()) + +print('\nMonitoring (ctrl-c to stop and exit)...\n') + +az_pos = 100.0 +el_pos = 80.0 + +mv_cmd = False + +try: + for i in range(50): + time.sleep(6) + print (client.broadcast.status()) + r = client.broadcast.status() + print (r.session.get('data')) + if not(mv_cmd): + print (f"Moving telescope to Az: {az_pos}, El: {el_pos}") + client.go_to(az=az_pos, el=el_pos) + mv_cmd = True + print (client.go_to.status()) +except KeyboardInterrupt: + print('Exiting on ctrl-c...') + print () + +print('Stopping data acquisition ...') +print (client.broadcast.stop())