def issue_stop_cmd (self, xml): self.log(2, "issue_stop_cmd()") # determine which beams this command corresponds to for ibeam in range(int(xml['obs_cmd']['beam_configuration']['nbeam']['#text'])): state = xml['obs_cmd']['beam_configuration']['beam_state_' + str(ibeam)]['#text'] if state == "1" or state == "on": b = xml['obs_cmd']['beam_configuration']['beam_state_' + str(ibeam)]['@name'] if b in self.beam_states.keys(): self.log(1, "issue_stop_cmd: beam=" + b) obs = {} self.beam_states[b]["lock"].acquire() self.beam_states[b]["state"] = "Stopping" obs["COMMAND"] = "STOP" # inject the observation parameters o = self.beam_states[b]["config"]["observation_parameters"] # if no UTC_STOP has been specified, set it to now if o["utc_stop"]["#text"] == "None": o["utc_stop"]["#text"] = times.getUTCTime() obs["UTC_STOP"] = o["utc_stop"]["#text"] self.beam_states[b]["lock"].release() # convert to a single ascii string obs_header = Config.writeDictToString (obs) # work out which streams correspond to these beams for istream in range(int(self.cfg["NUM_STREAM"])): (host, beam_idx, subband) = self.cfg["STREAM_"+str(istream)].split(":") beam = self.cfg["BEAM_" + beam_idx] self.log(2, "issue_stop_cmd: host="+host+" beam="+beam+" subband="+subband) # connect to streams for this beam only if beam == b: # control port the this recv stream ctrl_port = int(self.cfg["STREAM_CTRL_PORT"]) + istream # connect to recv agent and provide observation configuration self.log(3, "issue_stop_cmd: openSocket("+host+","+str(ctrl_port)+")") sock = sockets.openSocket (DL, host, ctrl_port, 1) if sock: self.log(3, "issue_stop_cmd: sending obs_header len=" + str(len(obs_header))) sock.send(obs_header) self.log(3, "issue_stop_cmd: command sent") sock.close() self.log(3, "issue_stop_cmd: socket closed") # connect to spip_gen and issue stop command for UTC # assumes gen host is the same as the recv host! # gen_port = int(self.cfg["STREAM_GEN_PORT"]) + istream # sock = sockets.openSocket (DL, host, gen_port, 1) # if sock: # sock.send(obs_header) # sock.close() # update the dict of observing info for this beam self.beam_states[b]["lock"].acquire() self.beam_states[b]["state"] = "Idle" self.beam_states[b]["lock"].release()
def issue_start_cmd (self, xml): self.log(2, "TCSDaemon::issue_start_cmd nbeam=" + xml['obs_cmd']['beam_configuration']['nbeam']['#text']) # determine which beams this command corresponds to for ibeam in range(int(xml['obs_cmd']['beam_configuration']['nbeam']['#text'])): state = xml['obs_cmd']['beam_configuration']['beam_state_' + str(ibeam)]['#text'] self.log(2, "TCSDaemon::issue_start_cmd beam state=" + state) if state == "1" or state == "on": b = xml['obs_cmd']['beam_configuration']['beam_state_' + str(ibeam)]['@name'] self.log(2, "TCSDaemon::issue_start_cmd beam name=" + b) if b in self.beam_states.keys(): self.log(2, "TCSDaemon::issue_start_cmd config=" + str(self.beam_states[b]["config"].keys())) obs_config = {} self.beam_states[b]["lock"].acquire() utc_start = "unset" source = "unset" # add source parameters s = self.beam_states[b]["config"]["source_parameters"] for k in s.keys(): key = s[k]["@key"] val = s[k]["#text"] obs_config[key] = val self.log (1, key + "=" + val) if key == "SOURCE": source = val # add the observation parameters o = self.beam_states[b]["config"]["observation_parameters"] self.log(1, "TCSDaemon::issue_start_cmd o=" + str(o)) self.log(1, "TCSDaemon::issue_start_cmd checking value of supplied UTC start: [" + o["utc_start"]["#text"] + "]" ) # if no UTC_START has been specified, set it to +5 seconds if o["utc_start"]["#text"] == "None": utc_start = times.getUTCTime(self.start_offset_seconds) o["utc_start"]["#text"] = utc_start self.log(1, "TCSDaemon::issue_start_cmd utc_start=" + utc_start) else: self.log(1, "TCSDaemon::issue_start_cmd utc_start already set " + o["utc_start"]["#text"]) for k in o.keys(): key = o[k]["@key"] try: val = o[k]["#text"] except KeyError as e: val = '' obs_config[key] = val self.log(1, key + "=" + val) # add the calibration parameters o = self.beam_states[b]["config"]["calibration_parameters"] for k in o.keys(): key = o[k]["@key"] try: val = o[k]["#text"] except KeyError as e: val = '' obs_config[key] = val self.log(1, key + "=" + val) # hack for DSPSR requiring this parameter if key == "CAL_FREQ": obs_config["CALFREQ"] = val # extract the stream informatiom s = self.beam_states[b]["config"]["stream_configuration"] # determine the number of streams present in the configure command nstream = s["nstream"]["#text"] if int(nstream) != int(self.cfg["NUM_STREAM"]): self.log(1, "TCSDaemon::issue_start_cmd number of streams in config and command did not match") # record which streams are processing which modes stream_modes = {} # work out which streams correspond to these beams for istream in range(int(nstream)): stream_active = False stream_xml = self.beam_states[b]["config"]["stream" + str(istream)] # make a deep copy of the common configuration stream_config = copy.deepcopy (obs_config) # inject custom fields into header custom = stream_xml["custom_parameters"] for k in custom.keys(): key = custom[k]["@key"] try: val = custom[k]["#text"] except KeyError as e: val = '' stream_config[key] = val self.log(2, key + "=" + val) modes = stream_xml["processing_modes"] for k in modes.keys(): key = modes[k]["@key"] val = modes[k]["#text"] stream_config[key] = val self.log(2, key + "=" + val) # inject processing parameters into header if val == "true" or val == "1": if not (k in stream_modes.keys()): stream_modes[k] = [] stream_modes[k].append(istream) stream_active = True self.log (2, "TCSDaemon::issue_start_cmd mode=" + k) p = stream_xml[k + "_processing_parameters"] for l in p.keys(): pkey = p[l]["@key"] try: pval = p[l]["#text"] except KeyError as e: val = '' stream_config[pkey] = pval self.log(2, pkey + "=" + pval) # ensure the start command is set stream_config["COMMAND"] = "START" stream_config["OBS_OFFSET"] = "0" # convert to a single ascii string obs_header = Config.writeDictToString (stream_config) (host, beam_idx, subband) = self.cfg["STREAM_"+str(istream)].split(":") beam = self.cfg["BEAM_" + beam_idx] # connect to streams for this beam only if stream_active and beam == b: self.log(2, "TCSDaemon::issue_start_cmd host="+host+" beam="+beam+" subband="+subband) # control port the this recv stream ctrl_port = int(self.cfg["STREAM_CTRL_PORT"]) + istream self.log(2, host + ":" + str(ctrl_port) + " <- start") # connect to recv agent and provide observation configuration self.log(2, "TCSDaemon::issue_start_cmd openSocket("+host+","+str(ctrl_port)+")") recv_sock = sockets.openSocket (DL, host, ctrl_port, 5) if recv_sock: self.log(3, "TCSDaemon::issue_start_cmd sending obs_header length=" + str(len(obs_header))) recv_sock.send(obs_header) self.log(3, "TCSDaemon::issue_start_cmd header sent") recv_sock.close() self.log(3, "TCSDaemon::issue_start_cmd socket closed") else: self.log(-2, "TCSDaemon::issue_start_cmd failed to connect to "+host+":"+str(ctrl_port)) # connect to spip_gen and issue start command for UTC # assumes gen host is the same as the recv host! # gen_port = int(self.cfg["STREAM_GEN_PORT"]) + istream # sock = sockets.openSocket (DL, host, gen_port, 1) # if sock: # sock.send(obs_header) # sock.close() utc_start = self.beam_states[b]["config"]["observation_parameters"]["utc_start"]["#text"] # update the dict of observing info for this beam self.beam_states[b]["state"] = "Recording" self.beam_states[b]["lock"].release() # now handle the active streams for mode in stream_modes.keys(): self.log(1, "TCSDaemon::issue_start_cmd mode=" + mode + " streams=" + str(stream_modes[mode])) self.prepare_observation (beam, utc_start, source, mode, stream_modes[mode])
def issue_start_cmd(self, xml): self.log( 2, "TCSDaemon::issue_start_cmd nbeam=" + xml['obs_cmd']['beam_configuration']['nbeam']['#text']) # determine which beams this command corresponds to for ibeam in range( int(xml['obs_cmd']['beam_configuration']['nbeam']['#text'])): state = xml['obs_cmd']['beam_configuration']['beam_state_' + str(ibeam)]['#text'] self.log(2, "TCSDaemon::issue_start_cmd beam state=" + state) if state == "1" or state == "on": b = xml['obs_cmd']['beam_configuration']['beam_state_' + str(ibeam)]['@name'] self.log(2, "TCSDaemon::issue_start_cmd beam name=" + b) if b in self.beam_states.keys(): self.log( 2, "TCSDaemon::issue_start_cmd config=" + str(self.beam_states[b]["config"].keys())) obs_config = {} self.beam_states[b]["lock"].acquire() utc_start = "unset" source = "unset" # add source parameters s = self.beam_states[b]["config"]["source_parameters"] for k in s.keys(): key = s[k]["@key"] val = s[k]["#text"] obs_config[key] = val self.log(1, key + "=" + val) if key == "SOURCE": source = val # add the observation parameters o = self.beam_states[b]["config"]["observation_parameters"] self.log(1, "TCSDaemon::issue_start_cmd o=" + str(o)) self.log( 1, "TCSDaemon::issue_start_cmd checking value of supplied UTC start: [" + o["utc_start"]["#text"] + "]") # if no UTC_START has been specified, set it to +5 seconds if o["utc_start"]["#text"] == "None": utc_start = times.getUTCTime(self.start_offset_seconds) o["utc_start"]["#text"] = utc_start self.log( 1, "TCSDaemon::issue_start_cmd utc_start=" + utc_start) else: self.log( 1, "TCSDaemon::issue_start_cmd utc_start already set " + o["utc_start"]["#text"]) for k in o.keys(): key = o[k]["@key"] try: val = o[k]["#text"] except KeyError as e: val = '' obs_config[key] = val self.log(1, key + "=" + val) # add the calibration parameters o = self.beam_states[b]["config"]["calibration_parameters"] for k in o.keys(): key = o[k]["@key"] try: val = o[k]["#text"] except KeyError as e: val = '' obs_config[key] = val self.log(1, key + "=" + val) # hack for DSPSR requiring this parameter if key == "CAL_FREQ": obs_config["CALFREQ"] = val # extract the stream informatiom s = self.beam_states[b]["config"]["stream_configuration"] # determine the number of streams present in the configure command nstream = s["nstream"]["#text"] if int(nstream) != int(self.cfg["NUM_STREAM"]): self.log( 1, "TCSDaemon::issue_start_cmd number of streams in config and command did not match" ) # record which streams are processing which modes stream_modes = {} # work out which streams correspond to these beams for istream in range(int(nstream)): stream_active = False stream_xml = self.beam_states[b]["config"][ "stream" + str(istream)] # make a deep copy of the common configuration stream_config = copy.deepcopy(obs_config) # inject custom fields into header custom = stream_xml["custom_parameters"] for k in custom.keys(): key = custom[k]["@key"] try: val = custom[k]["#text"] except KeyError as e: val = '' stream_config[key] = val self.log(2, key + "=" + val) modes = stream_xml["processing_modes"] for k in modes.keys(): key = modes[k]["@key"] val = modes[k]["#text"] stream_config[key] = val self.log(2, key + "=" + val) # inject processing parameters into header if val == "true" or val == "1": if not (k in stream_modes.keys()): stream_modes[k] = [] stream_modes[k].append(istream) stream_active = True self.log( 2, "TCSDaemon::issue_start_cmd mode=" + k) p = stream_xml[k + "_processing_parameters"] for l in p.keys(): pkey = p[l]["@key"] try: pval = p[l]["#text"] except KeyError as e: val = '' stream_config[pkey] = pval self.log(2, pkey + "=" + pval) # ensure the start command is set stream_config["COMMAND"] = "START" stream_config["OBS_OFFSET"] = "0" # convert to a single ascii string obs_header = Config.writeDictToString(stream_config) (host, beam_idx, subband) = self.cfg["STREAM_" + str(istream)].split(":") beam = self.cfg["BEAM_" + beam_idx] # connect to streams for this beam only if stream_active and beam == b: self.log( 2, "TCSDaemon::issue_start_cmd host=" + host + " beam=" + beam + " subband=" + subband) # control port the this recv stream ctrl_port = int( self.cfg["STREAM_CTRL_PORT"]) + istream self.log(2, host + ":" + str(ctrl_port) + " <- start") # connect to recv agent and provide observation configuration self.log( 2, "TCSDaemon::issue_start_cmd openSocket(" + host + "," + str(ctrl_port) + ")") recv_sock = sockets.openSocket( DL, host, ctrl_port, 5) if recv_sock: self.log( 3, "TCSDaemon::issue_start_cmd sending obs_header length=" + str(len(obs_header))) recv_sock.send(obs_header) self.log( 3, "TCSDaemon::issue_start_cmd header sent") recv_sock.close() self.log( 3, "TCSDaemon::issue_start_cmd socket closed") else: self.log( -2, "TCSDaemon::issue_start_cmd failed to connect to " + host + ":" + str(ctrl_port)) # connect to spip_gen and issue start command for UTC # assumes gen host is the same as the recv host! # gen_port = int(self.cfg["STREAM_GEN_PORT"]) + istream # sock = sockets.openSocket (DL, host, gen_port, 1) # if sock: # sock.send(obs_header) # sock.close() utc_start = self.beam_states[b]["config"][ "observation_parameters"]["utc_start"]["#text"] # update the dict of observing info for this beam self.beam_states[b]["state"] = "Recording" self.beam_states[b]["lock"].release() # now handle the active streams for mode in stream_modes.keys(): self.log( 1, "TCSDaemon::issue_start_cmd mode=" + mode + " streams=" + str(stream_modes[mode])) self.prepare_observation(beam, utc_start, source, mode, stream_modes[mode])
def issue_stop_cmd(self, xml): self.log(2, "issue_stop_cmd()") # determine which beams this command corresponds to for ibeam in range( int(xml['obs_cmd']['beam_configuration']['nbeam']['#text'])): state = xml['obs_cmd']['beam_configuration']['beam_state_' + str(ibeam)]['#text'] if state == "1" or state == "on": b = xml['obs_cmd']['beam_configuration']['beam_state_' + str(ibeam)]['@name'] if b in self.beam_states.keys(): self.log(1, "issue_stop_cmd: beam=" + b) obs = {} self.beam_states[b]["lock"].acquire() self.beam_states[b]["state"] = "Stopping" obs["COMMAND"] = "STOP" # inject the observation parameters o = self.beam_states[b]["config"]["observation_parameters"] # if no UTC_STOP has been specified, set it to now if o["utc_stop"]["#text"] == "None": o["utc_stop"]["#text"] = times.getUTCTime() obs["UTC_STOP"] = o["utc_stop"]["#text"] self.beam_states[b]["lock"].release() # convert to a single ascii string obs_header = Config.writeDictToString(obs) # work out which streams correspond to these beams for istream in range(int(self.cfg["NUM_STREAM"])): (host, beam_idx, subband) = self.cfg["STREAM_" + str(istream)].split(":") beam = self.cfg["BEAM_" + beam_idx] self.log( 2, "issue_stop_cmd: host=" + host + " beam=" + beam + " subband=" + subband) # connect to streams for this beam only if beam == b: # control port the this recv stream ctrl_port = int( self.cfg["STREAM_CTRL_PORT"]) + istream # connect to recv agent and provide observation configuration self.log( 3, "issue_stop_cmd: openSocket(" + host + "," + str(ctrl_port) + ")") sock = sockets.openSocket(DL, host, ctrl_port, 1) if sock: self.log( 3, "issue_stop_cmd: sending obs_header len=" + str(len(obs_header))) sock.send(obs_header) self.log(3, "issue_stop_cmd: command sent") sock.close() self.log(3, "issue_stop_cmd: socket closed") # connect to spip_gen and issue stop command for UTC # assumes gen host is the same as the recv host! # gen_port = int(self.cfg["STREAM_GEN_PORT"]) + istream # sock = sockets.openSocket (DL, host, gen_port, 1) # if sock: # sock.send(obs_header) # sock.close() # update the dict of observing info for this beam self.beam_states[b]["lock"].acquire() self.beam_states[b]["state"] = "Idle" self.beam_states[b]["lock"].release()
def issue_start_cmd(self, xml): # determine which beams this command corresponds to for ibeam in range(int(xml['obs_cmd']['beam_configuration']['nbeam'])): if xml['obs_cmd']['beam_configuration'][ 'beam_state_' + str(ibeam)]['#text'] == "on": b = xml['obs_cmd']['beam_configuration']['beam_state_' + str(ibeam)]['@name'] if b in self.beam_states.keys(): obs = {} self.beam_states[b]["lock"].acquire() obs["COMMAND"] = "START" obs["SOURCE"] = self.beam_states[b]["source"] obs["RA"] = self.beam_states[b]["ra"] obs["DEC"] = self.beam_states[b]["dec"] obs["TOBS"] = self.beam_states[b]["tobs"] obs["OBSERVER"] = self.beam_states[b]["observer"] obs["PID"] = self.beam_states[b]["pid"] obs["MODE"] = self.beam_states[b]["mode"] obs["CALFREQ"] = self.beam_states[b]["calfreq"] obs["OBS_OFFSET"] = "0" # if no UTC_START has been specified, set it to +5 seconds if self.beam_states[b]["utc_start"] == None: self.beam_states[b]["utc_start"] = times.getUTCTime(5) obs["UTC_START"] = self.beam_states[b]["utc_start"] # inject custom fields into header for f in self.beam_states[b]["custom_fields"].split(' '): obs[f.upper()] = self.beam_states[b][f] self.beam_states[b]["lock"].release() obs["PERFORM_FOLD"] = "1" obs["PERFORM_SEARCH"] = "0" obs["PERFORM_TRANS"] = "0" # convert to a single ascii string obs_header = Config.writeDictToString(obs) self.log(1, "issue_start_cmd: beam=" + b) # work out which streams correspond to these beams for istream in range(int(self.cfg["NUM_STREAM"])): (host, beam_idx, subband) = self.cfg["STREAM_" + str(istream)].split(":") beam = self.cfg["BEAM_" + beam_idx] self.log( 2, "issue_start_cmd: host=" + host + " beam=" + beam + " subband=" + subband) # connect to streams for this beam only if beam == b: # control port the this recv stream ctrl_port = int( self.cfg["STREAM_CTRL_PORT"]) + istream # connect to recv agent and provide observation configuration self.log( 3, "issue_start_cmd: openSocket(" + host + "," + str(ctrl_port) + ")") recv_sock = sockets.openSocket( DL, host, ctrl_port, 1) if recv_sock: self.log( 3, "issue_start_cmd: sending obs_header") recv_sock.send(obs_header) self.log(3, "issue_start_cmd: header sent") recv_sock.close() self.log(3, "issue_start_cmd: socket closed") # connect to spip_gen and issue start command for UTC # assumes gen host is the same as the recv host! # gen_port = int(self.cfg["STREAM_GEN_PORT"]) + istream # sock = sockets.openSocket (DL, host, gen_port, 1) # if sock: # sock.send(obs_header) # sock.close() # update the dict of observing info for this beam self.beam_states[b]["lock"].acquire() self.beam_states[b]["state"] = "Recording" self.beam_states[b]["lock"].release()