def handle_msg(self, msg): if pmt.dict_has_key(msg, pmt.intern(self.len_tag_key)): packet_len = pmt.to_python(msg)[self.len_tag_key] msg = pmt.dict_delete(msg, pmt.intern(self.len_tag_key)) msg = pmt.dict_add(msg, pmt.intern(self.len_tag_key), pmt.from_long(packet_len * 8)) self.message_port_pub(self.msg_buf_out, msg)
def handle_msg(self, msg): ''' This function handles messages from a text entry box like QT GUI Message Edit. ''' self.command = pmt.dict_delete(self.command, pmt.intern("source_id")) self.command = pmt.dict_delete(self.command, pmt.intern("ra")) self.command = pmt.dict_delete(self.command, pmt.intern("dec")) self.command = pmt.dict_delete(self.command, pmt.intern("az")) self.command = pmt.dict_delete(self.command, pmt.intern("el")) key = pmt.car(msg) val = pmt.cdr(msg) str_key = pmt.symbol_to_string(key) if str_key == "source_id": self.command = pmt.dict_add(self.command, key, val) self.message_port_pub(pmt.intern("command"), self.command) elif str_key == "azel": azel_pair = pmt.symbol_to_string(val).split(',') az = pmt.from_double(float(azel_pair[0].strip())) el = pmt.from_double(float(azel_pair[1].strip())) self.command = pmt.dict_add(self.command, pmt.intern("az"), az) self.command = pmt.dict_add(self.command, pmt.intern("el"), el) self.message_port_pub(pmt.intern("command"), self.command) elif str_key == "radec": radec_pair = pmt.symbol_to_string(val).split(',') ra = pmt.from_double(float(radec_pair[0].strip())) dec = pmt.from_double(float(radec_pair[1].strip())) self.command = pmt.dict_add(self.command, pmt.intern("ra"), ra) self.command = pmt.dict_add(self.command, pmt.intern("dec"), dec) self.message_port_pub(pmt.intern("command"), self.command) else: print("Wrong value in left-hand space of Message Edit box.\n"\ "Must be either source_id, radec, or azel. Try again.\n")
def wait_duration(self): '''This function handles the sequencing of the on-off scan. ''' #this command tells the control block to point # on-source for the given duration self.message_port_pub(pmt.intern("command"), self.command) time.sleep(self.dur) #this command will instruct the command block to point off #source by the given offsets self.command = pmt.dict_add(self.command, self.azoff_key, self.azoff_val) self.command = pmt.dict_add(self.command, self.eloff_key, self.eloff_val) self.message_port_pub(pmt.intern("command"), self.command) self.command = pmt.dict_delete(self.command, self.azoff_key) self.command = pmt.dict_delete(self.command, self.azoff_key)
def update_timestamp(hdr, seg_size): if pmt.dict_has_key(hdr, pmt.string_to_symbol("rx_time")): r = pmt.dict_ref(hdr, pmt.string_to_symbol("rx_time"), pmt.PMT_NIL) secs = pmt.tuple_ref(r, 0) fracs = pmt.tuple_ref(r, 1) secs = float(pmt.to_uint64(secs)) fracs = pmt.to_double(fracs) t = secs + fracs else: sys.stderr.write("Could not find key 'time': \ invalid or corrupt data file.\n") sys.exit(1) new_hdr = pmt.dict_delete(hdr, pmt.intern("rx_time")) if pmt.dict_has_key(hdr, pmt.intern("rx_rate")): r = pmt.dict_ref(hdr, pmt.intern("rx_rate"), pmt.PMT_NIL) rate = pmt.to_double(r) new_t = t + float(seg_size) / rate new_secs = long(new_t) new_fracs = new_t - new_secs time_val = pmt.make_tuple(pmt.from_uint64(new_secs), pmt.from_double(new_fracs)) new_hdr = pmt.dict_add(new_hdr, pmt.intern("rx_time"), time_val) return new_hdr
def update_timestamp(hdr,seg_size): if pmt.dict_has_key(hdr, pmt.string_to_symbol("rx_time")): r = pmt.dict_ref(hdr, pmt.string_to_symbol("rx_time"), pmt.PMT_NIL) secs = pmt.tuple_ref(r, 0) fracs = pmt.tuple_ref(r, 1) secs = float(pmt.to_uint64(secs)) fracs = pmt.to_double(fracs) t = secs + fracs else: sys.stderr.write("Could not find key 'time': \ invalid or corrupt data file.\n") sys.exit(1) new_hdr = pmt.dict_delete(hdr, pmt.intern("rx_time")) if pmt.dict_has_key(hdr, pmt.intern("rx_rate")): r = pmt.dict_ref(hdr, pmt.intern("rx_rate"), pmt.PMT_NIL) rate = pmt.to_double(r) new_t = t + float(seg_size)/rate new_secs = long(new_t) new_fracs = new_t - new_secs time_val = pmt.make_tuple(pmt.from_uint64(new_secs), pmt.from_double(new_fracs)) new_hdr = pmt.dict_add(new_hdr, pmt.intern("rx_time"), time_val) return new_hdr
def make_header(options, filename): extras_present = False if options.freq is not None: extras_present = True # Open the file and make the header hdr_filename = filename + '.hdr' hdr_file = open(hdr_filename, 'wb') header = pmt.make_dict() # Fill in header vals # TODO - Read this from blocks.METADATA_VERSION ver_val = pmt.from_long(long(0)) rate_val = pmt.from_double(options.sample_rate) time_val = pmt.make_tuple(pmt.from_uint64(options.time_sec), pmt.from_double(options.time_fsec)) ft_to_sz = parse_file_metadata.ftype_to_size # Map shortname to properties enum_type = SNAME_TO_ENUM[options.format] type_props = SNAME_DEFS[enum_type] size_val = pmt.from_long(type_props[0]) cplx_val = pmt.from_bool(type_props[1]) type_val = pmt.from_long(type_props[2]) fmt = type_props[2] file_samp_len = long(options.length) seg_size = long(options.seg_size) bytes_val = pmt.from_uint64(long(seg_size * ft_to_sz[fmt])) # Set header vals header = pmt.dict_add(header, pmt.intern("version"), ver_val) header = pmt.dict_add(header, pmt.intern("size"), size_val) header = pmt.dict_add(header, pmt.intern("type"), type_val) header = pmt.dict_add(header, pmt.intern("cplx"), cplx_val) header = pmt.dict_add(header, pmt.intern("rx_time"), time_val) header = pmt.dict_add(header, pmt.intern("rx_rate"), rate_val) header = pmt.dict_add(header, pmt.intern("bytes"), bytes_val) if extras_present: freq_key = pmt.intern("rx_freq") freq_val = pmt.from_double(options.freq) extras = pmt.make_dict() extras = pmt.dict_add(extras, freq_key, freq_val) extras_str = pmt.serialize_str(extras) start_val = pmt.from_uint64(blocks.METADATA_HEADER_SIZE + len(extras_str)) else: start_val = pmt.from_uint64(blocks.METADATA_HEADER_SIZE) header = pmt.dict_add(header, pmt.intern("strt"), start_val) num_segments = file_samp_len / seg_size if options.verbose: print "Wrote %d headers to: %s (Version %d)" % ( num_segments + 1, hdr_filename, pmt.to_long(ver_val)) for x in range(0, num_segments, 1): # Serialize and write out file if extras_present: header_str = pmt.serialize_str(header) + extras_str else: header_str = pmt.serialize_str(header) hdr_file.write(header_str) # Update header based on sample rate and segment size header = update_timestamp(header, seg_size) # Last header is special b/c file size is probably not mult. of seg_size header = pmt.dict_delete(header, pmt.intern("bytes")) bytes_remaining = ft_to_sz[fmt] * (file_samp_len - num_segments * long(seg_size)) bytes_val = pmt.from_uint64(bytes_remaining) header = pmt.dict_add(header, pmt.intern("bytes"), bytes_val) # Serialize and write out file if extras_present: header_str = pmt.serialize_str(header) + extras_str else: header_str = pmt.serialize_str(header) hdr_file.write(header_str) hdr_file.close()
def make_header(options, filename): extras_present = False if options.freq is not None: extras_present = True # Open the file and make the header hdr_filename = filename + '.hdr' hdr_file = open(hdr_filename, 'wb') header = pmt.make_dict() # Fill in header vals # TODO - Read this from blocks.METADATA_VERSION ver_val = pmt.from_long(long(0)) rate_val = pmt.from_double(options.sample_rate) time_val = pmt.make_tuple(pmt.from_uint64(options.time_sec), pmt.from_double(options.time_fsec)) ft_to_sz = parse_file_metadata.ftype_to_size # Map shortname to properties enum_type = SNAME_TO_ENUM[options.format] type_props = SNAME_DEFS[enum_type] size_val = pmt.from_long(type_props[0]) cplx_val = pmt.from_bool(type_props[1]) type_val = pmt.from_long(type_props[2]) fmt = type_props[2] file_samp_len = long(options.length) seg_size = long(options.seg_size) bytes_val = pmt.from_uint64(long(seg_size*ft_to_sz[fmt])) # Set header vals header = pmt.dict_add(header, pmt.intern("version"), ver_val) header = pmt.dict_add(header, pmt.intern("size"), size_val) header = pmt.dict_add(header, pmt.intern("type"), type_val) header = pmt.dict_add(header, pmt.intern("cplx"), cplx_val) header = pmt.dict_add(header, pmt.intern("rx_time"), time_val) header = pmt.dict_add(header, pmt.intern("rx_rate"), rate_val) header = pmt.dict_add(header, pmt.intern("bytes"), bytes_val) if extras_present: freq_key = pmt.intern("rx_freq") freq_val = pmt.from_double(options.freq) extras = pmt.make_dict() extras = pmt.dict_add(extras, freq_key, freq_val) extras_str = pmt.serialize_str(extras) start_val = pmt.from_uint64(blocks.METADATA_HEADER_SIZE + len(extras_str)) else: start_val = pmt.from_uint64(blocks.METADATA_HEADER_SIZE) header = pmt.dict_add(header, pmt.intern("strt"), start_val) num_segments = file_samp_len/seg_size if options.verbose: print "Wrote %d headers to: %s (Version %d)" % (num_segments+1, hdr_filename,pmt.to_long(ver_val)) for x in range(0,num_segments,1): # Serialize and write out file if extras_present: header_str = pmt.serialize_str(header) + extras_str else: header_str = pmt.serialize_str(header) hdr_file.write(header_str) # Update header based on sample rate and segment size header = update_timestamp(header,seg_size) # Last header is special b/c file size is probably not mult. of seg_size header = pmt.dict_delete(header,pmt.intern("bytes")) bytes_remaining = ft_to_sz[fmt]*(file_samp_len - num_segments*long(seg_size)) bytes_val = pmt.from_uint64(bytes_remaining) header = pmt.dict_add(header,pmt.intern("bytes"),bytes_val) # Serialize and write out file if extras_present: header_str = pmt.serialize_str(header) + extras_str else: header_str = pmt.serialize_str(header) hdr_file.write(header_str) hdr_file.close()
def handle_msg(self, msg): ''' This function handles input from the QT GUI Message Edit Box.''' self.command = pmt.dict_delete(self.command, pmt.intern("source_id")) self.command = pmt.dict_delete(self.command, pmt.intern("ra")) self.command = pmt.dict_delete(self.command, pmt.intern("dec")) self.command = pmt.dict_delete(self.command, pmt.intern("az")) self.command = pmt.dict_delete(self.command, pmt.intern("el")) key = pmt.car(msg) val = pmt.cdr(msg) str_key = pmt.symbol_to_string(key) if str_key == "source_id": self.command = pmt.dict_add(self.command, key, val) self.command = pmt.dict_delete(self.command, self.azoff_key) self.command = pmt.dict_delete(self.command, self.eloff_key) thr.Thread(target=self.wait_duration).start() elif str_key == "azel": azel_pair = pmt.symbol_to_string(val).split(',') az = pmt.from_double(float(azel_pair[0].strip())) el = pmt.from_double(float(azel_pair[1].strip())) self.command = pmt.dict_add(self.command, pmt.intern("az"), az) self.command = pmt.dict_add(self.command, pmt.intern("el"), el) self.command = pmt.dict_delete(self.command, self.azoff_key) self.command = pmt.dict_delete(self.command, self.eloff_key) thr.Thread(target=self.wait_duration).start() elif str_key == "radec": radec_pair = pmt.symbol_to_string(val).split(',') ra = pmt.from_double(float(radec_pair[0].strip())) dec = pmt.from_double(float(radec_pair[1].strip())) self.command = pmt.dict_add(self.command, pmt.intern("ra"), ra) self.command = pmt.dict_add(self.command, pmt.intern("dec"), dec) self.command = pmt.dict_delete(self.command, self.azoff_key) self.command = pmt.dict_delete(self.command, self.eloff_key) thr.Thread(target=self.wait_duration).start() else: print("Wrong value in left-hand space of Message Edit box.\n"\ "Must be either source_id, radec, or azel. Try again.\n")