def handle_control(self, msg): # Test whether message is a dict, per UHD requirements if not pmt.is_dict(msg): self.logger.info( "{} received non-dict control message, ignoring".format( self.uuid_str)) return try: keys = pmt.to_python(pmt.dict_keys(msg)) except pmt.wrong_type as e: self.logger.debug( "{} received pair instead of dict, fixing".format( self.uuid_str)) msg = pmt.dict_add(pmt.make_dict(), pmt.car(msg), pmt.cdr(msg)) keys = pmt.to_python(pmt.dict_keys(msg)) self.logger.debug( "echo agent received command with keys: {}".format(keys)) self.handle_control_mod(keys) self.handle_control_demod(keys)
def handle_control(self, msg): # Test whether message is a dict, per UHD requirements if not pmt.is_dict(msg): self.logger.info( "{} received non-dict control message, ignoring".format( self.uuid_str)) return try: keys = pmt.to_python(pmt.dict_keys(msg)) except pmt.wrong_type as e: self.logger.debug( "{} received pair instead of dict, fixing".format( self.uuid_str)) msg = pmt.dict_add(pmt.make_dict(), pmt.car(msg), pmt.cdr(msg)) keys = pmt.to_python(pmt.dict_keys(msg)) print("KEYS: {}".format(keys)) # Check for keys we care about if "freeze" in keys: self.run_mode = "freeze" self.logger.info( "neural demod {}: freezing model and saving state".format( self.uuid_str)) torch.save(self.model.state_dict(), "demod_neural_weights-{}".format(self.uuid_str)) print("Saving final demod constellation @{}".format( self.packet_cnt)) data_vis = gen_demod_grid(points_per_dim=40, min_val=-2.5, max_val=2.5)['data'] labels_si_g = self.demodulate(data_c=data_vis, mode='exploit') numpy.savez("neural_demod_constellation_{:05d}_{}".format( self.packet_cnt, time.strftime('%Y%m%d_%H%M%S')), iq=data_vis, labels=labels_si_g) elif "train" in keys: self.run_mode = "train" self.logger.info("neural demod {}: resuming training".format( self.uuid_str))
def handle_control(self, msg): # Test whether message is a dict, per UHD requirements if not pmt.is_dict(msg): self.logger.info("{} received non-dict control message, ignoring".format(self.uuid_str)) return try: keys = pmt.to_python(pmt.dict_keys(msg)) except pmt.wrong_type as e: self.logger.debug("{} received pair instead of dict, fixing".format(self.uuid_str)) msg = pmt.dict_add(pmt.make_dict(), pmt.car(msg), pmt.cdr(msg)) keys = pmt.to_python(pmt.dict_keys(msg)) # Check for keys we care about if "freeze" in keys: self.run_mode = "freeze" self.logger.info("neural mod {}: freezing model and saving state".format(self.uuid_str)) torch.save(self.model.state_dict(), "mod_neural_weights-{}".format(self.uuid_str)) print("Saving final mod constellation @{}".format(self.train_cnt)) np.save("neural_mod_constellation_{:05d}_{}".format(self.train_cnt, time.strftime('%Y%m%d_%H%M%S')), get_constellation(self)) elif "train" in keys: self.logger.info("neural mod {}: resuming training".format(self.uuid_str)) self.run_mode = "train"
def main(): src_id = 42 dest_id = 84 frame_num = 4711 checksum = range(16) raw_payload = range(16) payload = get_pdu_payload(raw_payload) print(payload, pmt.length(payload)) meta = get_pdu_header(dest_id, src_id, frame_num) # pl = pmt.u print(meta) print(pmt.dict_keys(meta)) print(pmt.dict_values(meta)) meta = set_pdu_header_checksum(meta, checksum) print(meta) K = "00010203 04050607 08090A0B 0C0D0E0F " K += "10111213 14151617 18191A1B 1C1D1E1F" print(K) vals = hex_string_to_int_list(K) print(get_hex_char_string(vals))
def message_handler(self, msg): if not pmt.is_dict(msg): return try: # this will fail if message is a PDU with non-PMT_NIL arguments n = pmt.length(pmt.dict_items(msg)) # a PDU with one element equal to PMT_NIL still looks like a # dictionary...grrrrr! if (n == 1) and (pmt.equal(pmt.car(msg), pmt.PMT_NIL) or pmt.equal(pmt.cdr(msg), pmt.PMT_NIL)): # treat as a pdu car = pmt.car(msg) cdr = pmt.cdr(msg) else: car = msg cdr = pmt.init_u8vector(0, []) except: try: # message is a pdu pmt.length(pmt.dict_items(pmt.car(msg))) car = pmt.car(msg) cdr = pmt.cdr(msg) except: return if self.find_metadata: keys = pmt.dict_keys(car) self.header = [(pmt.nth(i, keys), pmt.symbol_to_string) for i in range(pmt.length(keys))] header = ','.join([ pmt.symbol_to_string(pmt.nth(i, keys)) for i in range(pmt.length(keys)) ]) if self.fid: self.fid.write(header + '\n') # ensure we no longer search for metadata self.find_metadata = False if self.fid: # add metadata if self.add_metadata: self.print_metadata(car) # cdr must be a uniform vector type if not pmt.is_uniform_vector(cdr): self.fid.write('\n') return # add data values = self.data_type_mappings[self.data_type](cdr) if (self.precision > 0) and (self.data_type in [ 'float', 'double', 'complex float', 'complex double' ]): self.fid.write(','.join( ['{:.{n}f}'.format(i, n=self.precision) for i in values])) else: self.fid.write(','.join([str(i) for i in values])) self.fid.write('\n')