def __init__(self, sample_rate, dict_key, origin_t_secs, origin_t_frac): gr.sync_block.__init__(self, name="retune_uhd_to_timed_tag", in_sig=[numpy.complex64], out_sig=[numpy.complex64]) # setup logger logger_name = 'gr_log.' + self.to_basic_block().alias() if logger_name in gr.logger_get_names(): self.log = gr.logger(logger_name) else: self.log = gr.logger('log') self.set_sample_rate(sample_rate) self.set_ref_time(offset=0, secs=origin_t_secs, frac=origin_t_frac) # this is exposed as a member variable, but really should not be # modified as the downstream block respects this key self.set_tag_key(pmt.intern("set_freq")) self.set_dict_key(dict_key) # time reference key self.time_key = pmt.intern("rx_time") self.message_port_register_in(pmt.intern("command")) self.set_msg_handler(pmt.intern("command"), self.handle_command) self.message_port_register_out(pmt.intern("freq")) # queue for tune commands self.tune_commands = deque((), maxlen=64) self.lock = threading.Lock()
def test_001_t (self): if os.path.exists("debug/transmission_frame.dat") and os.path.exists("debug/transmission_frame_trigger.dat"): self.dab_params = dab.parameters.dab_parameters(1, 208.064e6, True) self.src01 = blocks.file_source_make(gr.sizeof_float * 2 * self.dab_params.num_carriers, "debug/transmission_frame.dat") self.src02 = blocks.file_source_make(gr.sizeof_char, "debug/transmission_frame_trigger.dat") self.dabplus = dab.dabplus_audio_decoder_ff(self.dab_params, 112, 54, 84, 2, True, False, True) self.wav_sink = blocks.wavfile_sink_make("debug/music.wav", 2, 32000) self.file_sink_left = blocks.file_sink_make(gr.sizeof_float, "debug/PCM_left.dat") self.file_sink_right = blocks.file_sink_make(gr.sizeof_float, "debug/PCM_right.dat") self.tb.connect(self.src01, (self.dabplus, 0), self.file_sink_left) self.tb.connect(self.src02, (self.dabplus, 1), self.file_sink_right) self.tb.connect((self.dabplus, 0), (self.wav_sink, 0)) self.tb.connect((self.dabplus, 1), (self.wav_sink, 1)) self.audio = audio.sink_make(32000) self.tb.connect((self.dabplus, 0), (self.audio, 0)) self.tb.connect((self.dabplus, 1), (self.audio, 1)) self.tb.run() else: log = gr.logger("log") log.debug("debug file not found - skipped test") log.set_level("WARN") pass
def __init__(self, samps_per_symb, beta_rrc, cfo_samps, cfo_freqs, corr_reps, body_samps=608): """ Inputs: :param samps_per_symb: number of samples per symbol sent over the air :param beta_rrc: bandwidth expansion parameter for RRC filter :param cfo_samps: integer number of samples for the CFO correction header portion :param cfo_freqs: list of frequencies present in the CFO correction header, Hz positive values only: freqs are added as cosines to mirror in negative frequency portion :param corr_reps: integer number of repetitions for correlation header Golay sequences """ gr.basic_block.__init__(self, name="echo_packet_wrapper", in_sig=None, out_sig=None) self.wrapper = EchoPacketWrapper(samps_per_symb=samps_per_symb, beta_rrc=beta_rrc, cfo_samps=cfo_samps, cfo_freqs=cfo_freqs, corr_repetitions=corr_reps) self.nsamples = self.wrapper.full_packet_length(body_samps) * samps_per_symb self.port_in_id = pmt.intern("body") self.port_out_id = pmt.intern("frame") self.message_port_register_in(self.port_in_id) self.message_port_register_out(self.port_out_id) self.set_msg_handler(self.port_in_id, self.handle_body) self.uuid = uuid.uuid4() self.uuid_str = str(self.uuid)[-6:] self.npackets = 0 self.logger = gr.logger("log_debug") self.logger.set_level("DEBUG")
def __init__(self, bits_per_symbol, block_length=10000, preamble=None, log_ber_interval=10): DemodulatorClassic.__init__(self, bits_per_symbol=bits_per_symbol, block_length=block_length) gr.basic_block.__init__(self, name="demod_classic", in_sig=None, out_sig=None) self.port_id_in = pmt.intern("symbols") self.port_id_out = pmt.intern("bits") self.message_port_register_in(self.port_id_in) self.message_port_register_out(self.port_id_out) self.set_msg_handler(self.port_id_in, self.handle_packet) if preamble is not numpy.ndarray: preamble = numpy.array(preamble) self.preamble = preamble self.packet_cnt = 0 self.ber = None self.log_ber_interval = log_ber_interval self.uuid = uuid.uuid4() self.uuid_str = str(self.uuid)[-6:] self.logger = gr.logger("log_debug") self.logger.set_level("DEBUG") self.logger.info("classic demod {}: {} bits per symbol".format( self.uuid_str, self.bits_per_symbol)) with open("ber_{}.csv".format(self.uuid_str), "w") as f: f.write("iter,BER\n")
def __init__(self, length): """ Packet Length Checker Sends every received PDU through the passthrough port, and only packets with the right length through the validated port :param length: Expected number of samples in the PDU """ gr.basic_block.__init__(self, name="packet_length_check", in_sig=None, out_sig=None) self.length = length self.port_id_in = pmt.intern("in") self.port_id_passthrough = pmt.intern("passthrough") self.port_id_validated = pmt.intern("validated") self.port_id_failed = pmt.intern("failed") self.message_port_register_in(self.port_id_in) self.message_port_register_out(self.port_id_passthrough) self.message_port_register_out(self.port_id_validated) self.message_port_register_out(self.port_id_failed) self.set_msg_handler(self.port_id_in, self.handle_packet) self.npackets = 0 self.logger = gr.logger("log_debug") self.logger.set_level("DEBUG")
def test_001_t(self): log = gr.logger("log") if os.path.exists("debug/transmission_frame.dat") and os.path.exists( "debug/transmission_frame_trigger.dat"): self.dab_params = dab.parameters.dab_parameters(1, 208.064e6, True) self.src01 = blocks.file_source_make( gr.sizeof_float * 2 * self.dab_params.num_carriers, "debug/transmission_frame.dat") self.src02 = blocks.file_source_make( gr.sizeof_char, "debug/transmission_frame_trigger.dat") self.msc = dab.msc_decode(self.dab_params, 54, 84, 2, 1, 1) self.firecode = dab.firecode_check_bb_make(14) self.file_sink_subch_decoded = blocks.file_sink_make( gr.sizeof_char, "debug/subch_decoded.dat") self.file_sink_firecode_checked = blocks.file_sink_make( gr.sizeof_char, "debug/checked_firecode.dat") self.tb.connect(self.src01, (self.msc, 0), self.firecode, self.file_sink_firecode_checked) self.tb.connect(self.src02, (self.msc, 1)) self.tb.connect(self.msc, self.file_sink_subch_decoded) self.tb.run() else: log.debug("debug file not found - skipped test") log.set_level("WARN") pass
def __init__(self, packet_len_bits_no_header, reset_len, num_packets): gr.sync_block.__init__(self, name="prbs_sink_pdu", in_sig=None, out_sig=None) self.log = gr.logger("log") self.packet_len_bits_no_header = packet_len_bits_no_header self.reset_len = reset_len self.num_packets = num_packets self.generator = prbs_generator.PRBSGenerator(reset_len=reset_len) self.all_packets_received_ctr = 0 self.wrong_length_packets_after_fec_ctr = 0 self.erroneous_packets_after_fec_ctr = 0 self.correct_packets_received_ctr = 0 self.collected_packets = np.zeros(self.num_packets) self.statistics = None self.message_port_register_in(pmt.intern("all")) self.message_port_register_in(pmt.intern("corrected")) self.set_msg_handler(pmt.intern("all"), self.all_handler) self.set_msg_handler(pmt.intern("corrected"), self.corrected_handler)
def __init__( self, downlink_frequency, uplink_frequency, api_key, api_url, root_cert_path, groundstation_id, plan_id, corrections_per_second, verbose, test_channel=None ): # This last argument test_channel is used only for unit testing purposes. gr.sync_block.__init__(self, name="groundstation_api_doppler", in_sig=None, out_sig=None) self.downlink_frequency = downlink_frequency self.uplink_frequency = uplink_frequency self.api_key = api_key self.api_url = api_url self.root_cert_path = root_cert_path self.groundstation_id = groundstation_id self.plan_id = plan_id self.corrections_per_second = corrections_per_second self.verbose = verbose self.test_channel = test_channel self.stopped = False self.message_port_register_out(pmt.intern("downlink_shift")) self.message_port_register_out(pmt.intern("uplink_shift")) self.log = gr.logger("log")
def __init__( self, api_key, api_url, root_cert_path, groundstation_id, plan_id, stream_tag, verbose, test_channel=None ): # This last argument test_channel is used only for unit testing purposes. gr.sync_block.__init__(self, name="groundstation_api", in_sig=None, out_sig=None) self.api_key = api_key self.api_url = api_url self.root_cert_path = root_cert_path self.groundstation_id = groundstation_id self.plan_id = plan_id self.stream_tag = stream_tag self.verbose = verbose self.test_channel = test_channel self.message_port_register_out(pmt.intern("command")) self.register_port_and_message_handler("bitstream") self.register_port_and_message_handler("ax25") self.register_port_and_message_handler("iq") self.queue = Queue() self.lock = threading.Lock() self.stopped = False self.log = gr.logger("log")
def test_001_t (self): if os.path.exists("debug/transmission_frame.dat") and os.path.exists("debug/transmission_frame_trigger.dat"): self.dab_params = grdab.parameters.dab_parameters(1, 208.064e6, True) self.src01 = blocks.file_source_make(gr.sizeof_float * 2 * self.dab_params.num_carriers, "debug/transmission_frame.dat") self.src02 = blocks.file_source_make(gr.sizeof_char, "debug/transmission_frame_trigger.dat") self.dabplus = grdab.dabplus_audio_decoder_ff(self.dab_params, 112, 54, 84, 2, True, False, True) self.wav_sink = blocks.wavfile_sink_make("debug/music.wav", 2, 32000) self.file_sink_left = blocks.file_sink_make(gr.sizeof_float, "debug/PCM_left.dat") self.file_sink_right = blocks.file_sink_make(gr.sizeof_float, "debug/PCM_right.dat") self.tb.connect(self.src01, (self.dabplus, 0), self.file_sink_left) self.tb.connect(self.src02, (self.dabplus, 1), self.file_sink_right) self.tb.connect((self.dabplus, 0), (self.wav_sink, 0)) self.tb.connect((self.dabplus, 1), (self.wav_sink, 1)) self.audio = audio.sink_make(32000) self.tb.connect((self.dabplus, 0), (self.audio, 0)) self.tb.connect((self.dabplus, 1), (self.audio, 1)) self.tb.run() else: log = gr.logger("log") log.debug("debug file not found - skipped test") log.set_level("WARN") pass
def test_001_t(self): if os.path.exists("debug/PCM_left.dat") and os.path.exists( "debug/PCM_right.dat"): self.src_left = blocks.file_source_make(gr.sizeof_float, "debug/PCM_left.dat") self.src_right = blocks.file_source_make(gr.sizeof_float, "debug/PCM_right.dat") self.f2s_1 = blocks.float_to_short_make(1, 32767) self.f2s_2 = blocks.float_to_short_make(1, 32767) self.mp4_encode = dab.mp4_encode_sb_make(14, 2, 32000, 1) self.mp4_decode = dab.mp4_decode_bs_make(14) self.s2f_1 = blocks.short_to_float_make(1, 32767) self.s2f_2 = blocks.short_to_float_make(1, 32767) self.audio = audio.sink_make(32000) self.tb.connect(self.src_left, self.f2s_1, (self.mp4_encode, 0)) self.tb.connect(self.src_right, self.f2s_2, (self.mp4_encode, 1)) self.tb.connect(self.mp4_encode, self.mp4_decode, self.s2f_1, (self.audio, 0)) self.tb.connect((self.mp4_decode, 1), self.s2f_2, (self.audio, 1)) self.tb.run() # check data else: log = gr.logger("log") log.debug("debug file not found - skipped test") log.set_level("WARN")
def __init__(self, p_integ): gr.basic_block.__init__(self, name="md_sel_cc", in_sig=[numpy.complex64], out_sig=[numpy.complex64]) # Parameter self.offset = 210 # in simulation bestimmt self.fs = 48000 # self.generated_samples = 0 self.symbol_found = 0 self.symbol_start = 0 self.symbol_start_offset = 0 # Symbollänge + buffer, um zu verhindern das Maxima direkt nach dem Symbol vorkommen #self.set_history(1024+256+30) #set multiple #self.set_ #self.set_history((1024+256)*2) self.set_output_multiple(1024*2) self.mode = 0 # OFDM Paramter aller 4 Modes festlegen self.gi_len = np.array([0, 128, 256,256,352]) self.sym_len = np.array([0,1280,1280,960,800]) self.modes = ['Nicht erkannt', 'A', 'B', 'C', 'D'] # Time Sync self.est_t = 0 self.found_t = 0 # Mode Detection self.new_mode_detected = 0 # Fine Freq Sync self.fine_freq_off = 0 # Logger self.log = gr.logger( 'log_debug' ) self.log.debug('DEBUG LOG') self.log.set_level('ERROR') # Schätzer aktivieren self.enable_integration = p_integ # Schätzer über Zeit integrieren Zeitsync self.n_estimations_t = 0.0 self.estimation_t = 0.0 self.confidence_t = 0.0 self.estim_var_t = 100.0 # Varianz des Schätzers, rech klein bei der feinen Freq sync # Schätzer über Zeit integrieren Zeitsync self.n_estimations_f = 0.0 self.estimation_f = 0.0 self.confidence_f = 0.0 self.estim_var_f = 10.0 # Varianz des Schätzers, rech klein bei der feinen Freq sync
def test_001_t (self): log = gr.logger("log") if os.path.exists("debug/rs_encoded.dat") and os.path.exists("debug/rs_encoded.dat"): self.dp = dab.parameters.dab_parameters(1, 208.064e6, True) # sources self.fib_src = dab.fib_source_b_make(1, 1, 'Galaxy_News', 'Wasteland_Radio', 'Country_Mix01', 0x09, [2], [14]) self.fib_pack = blocks.unpacked_to_packed_bb_make(1, gr.GR_MSB_FIRST) self.subch_src01 = blocks.file_source_make(gr.sizeof_char, "debug/rs_encoded.dat", True) self.subch_src02 = blocks.file_source_make(gr.sizeof_char, "debug/rs_encoded_2.dat", True) # encoder self.fib_enc = dab.fic_encode(self.dp) self.msc_encoder = dab.msc_encode(self.dp, 14, 2) self.msc_encoder2 = dab.msc_encode(self.dp, 14, 2) # multiplexer self.mux = dab.dab_transmission_frame_mux_bb_make(1, 2, [84, 84]) # mapper self.unpack = blocks.packed_to_unpacked_bb_make(1, gr.GR_MSB_FIRST) self.map = dab.mapper_bc_make(self.dp.num_carriers) # demapper self.s2v = blocks.stream_to_vector_make(gr.sizeof_gr_complex, self.dp.num_carriers) self.soft_interleaver = dab.complex_to_interleaved_float_vcf_make(self.dp.num_carriers) # decode self.fic_decoder = dab.fic_decode(self.dp) self.msc_dec = dab.dabplus_audio_decoder_ff(self.dp, 112, 0, 84, 2, True) # audio sink self.audio = audio.sink_make(32000) # control stream self.trigger_src = blocks.vector_source_b([1] + [0] * 74, True) # connect everything self.tb.connect(self.fib_src, self.fib_enc, (self.mux, 0)) self.tb.connect(self.subch_src01, self.msc_encoder, (self.mux, 1)) self.tb.connect(self.subch_src02, self.msc_encoder2, (self.mux, 2)) self.tb.connect((self.mux, 0), self.unpack, self.map, self.s2v, self.soft_interleaver, (self.msc_dec, 0)) self.tb.connect(self.soft_interleaver, (self.fic_decoder, 0)) self.tb.connect(self.trigger_src, (self.fic_decoder, 1)) self.tb.connect(self.trigger_src, (self.msc_dec, 1)) self.tb.connect((self.msc_dec, 0), (self.audio, 0)) self.tb.connect((self.msc_dec, 1), (self.audio, 1)) self.tb.run () pass else: log.debug("debug file not found - skipped test") log.set_level("WARN") pass
def __init__(self, encapsulation_from, custom_dlt, custom_dissector_name): gr.basic_block.__init__(self, name="rftap_encap", in_sig=[], out_sig=[]) # setup logger logger_name = 'gr_log.' + self.to_basic_block().alias() if logger_name in gr.logger_get_names(): self.log = gr.logger(logger_name) else: self.log = gr.logger('log') self.encapsulation_from = encapsulation_from self.custom_dlt = custom_dlt self.custom_dissector_name = custom_dissector_name self.message_port_register_in(self.PMT_IN) self.set_msg_handler(self.PMT_IN, self.handle_msg) self.message_port_register_out(self.PMT_OUT)
def __init__(self, output_path="/tmp", fname_format="", archive=False): gr.basic_block.__init__(self, name="file_archiver", in_sig=None, out_sig=None) self.message_port_register_in(pmt.intern("pdu")) self.set_msg_handler(pmt.intern("pdu"), self.handler) # setup logger logger_name = 'gr_log.' + self.to_basic_block().alias() if logger_name in gr.logger_get_names(): self.log = gr.logger(logger_name) else: self.log = gr.logger('log') # protection mutex self.mutex = threading.Lock() # file pdu dictionary elements self.filename_tag = pmt.intern('fname') self.freq_tag = pmt.intern("rx_freq") self.rate_tag = pmt.intern("rx_rate") self.time_tag = pmt.intern("rx_time") # frequency specifiers self.freq_specs = [('%fcM', 1e6), ('%fck', 1e3), ('%fcc', 1.)] # rate specifiers self.rate_specs = [('%fsM', 1e6), ('%fsk', 1e3), ('%fsc', 1.)] # where to copy files self.set_output_path(output_path) # filename format self.set_fname_format(fname_format) # set archive self.set_archive(archive)
def __init__(self, parent, usrp_source): gr.sync_block.__init__(self, name="usrp_gps_time_sync", in_sig=None, out_sig=None) # setup logger logger_name = 'gr_log.' + self.to_basic_block().alias() if logger_name in gr.logger_get_names(): self.log = gr.logger(logger_name) else: self.log = gr.logger('log') self.parent = parent self.usrp_source = usrp_source self.usrp_source_object = None self.message_port_register_in(timing_utils.PMTCONSTSTR__in()) self.set_msg_handler(timing_utils.PMTCONSTSTR__in(), self.msg_handler) # current gps status self.has_gpsdo = False self.gps_locked = False
def test_001_t (self): if os.path.exists("debug/mp2_encoded.dat"): self.src_mp2 = blocks.file_source_make(gr.sizeof_char, "debug/mp2_encoded.dat") self.unpack = blocks.packed_to_unpacked_bb_make(1, gr.GR_MSB_FIRST) self.mp2_decode = grdab.mp2_decode_bs_make(14) self.sink_left = blocks.file_sink_make(gr.sizeof_short, "debug/mp2_decoded_left.dat") self.sink_right = blocks.file_sink_make(gr.sizeof_short, "debug/mp2_decoded_right.dat") self.tb.connect(self.src_mp2, self.unpack, (self.mp2_decode, 0), self.sink_left) self.tb.connect((self.mp2_decode, 1), self.sink_right) self.tb.run() else: log = gr.logger("log") log.debug("debug file not found - skipped test") log.set_level("WARN") pass
def __init__(self, bits_per_symbol, preamble=None, log_ber_interval=10, spy_length=64, spy_threshold=0.1): ModulatorClassic.__init__(self, bits_per_symbol, max_amplitude=0.09) gr.basic_block.__init__(self, name="modulator_classic", in_sig=None, out_sig=None) # Echo protocol variables assert preamble is not None, "Preamble must be provided" if preamble is not np.ndarray: preamble = np.array(preamble) self.preamble = preamble self.preamble_si = util_data.bits_to_integers(self.preamble, self.bits_per_symbol) self.log_ber_interval = log_ber_interval # Message port setup and variables self.port_id_in = pmt.intern("bits") self.port_id_update = pmt.intern("update") self.port_id_out = pmt.intern("symbols") self.message_port_register_in(self.port_id_in) self.message_port_register_in(self.port_id_update) self.message_port_register_out(self.port_id_out) self.set_msg_handler(self.port_id_in, self.handle_packet) self.set_msg_handler(self.port_id_update, self.handle_update) self.packet_cnt = 0 self.ber_cnt = 0 # Packet header and spy variables self.spy_length = spy_length assert self.spy_length % self.bits_per_symbol == 0 self.spy_threshold = spy_threshold self.reedsolomon = reedsolo.RSCodec(4) self.rs_length = 4 * 2 * 8 # 4 bytes data, 4 bytes parity, 8 bits per byte # Logging stuff self.uuid = uuid.uuid4() self.uuid_str = str(self.uuid)[-6:] self.logger = gr.logger("log_debug") self.logger.set_level("DEBUG") self.logger.info("classic mod {}: {} bits per symbol".format( self.uuid_str, self.bits_per_symbol)) with open("ber_echo_{}.csv".format(self.uuid_str), "w") as f: f.write("train_iter,BER\n")
def __init__(self, mode, fs): gr.basic_block.__init__(self, name="mixer_cc", in_sig=[numpy.complex64], out_sig=[numpy.complex64]) self.mode = mode self.ffactor = 1 self.set_output_multiple(1028) # Sonstiges self.samples_generated = 0 # Logger self.log = gr.logger('log_debug') self.log.debug('DEBUG LOG') self.log.set_level('DEBUG')
def test_001_t (self): if os.path.exists("debug/reed_solomon_repaired.dat"): self.src = blocks.file_source_make(gr.sizeof_char, "debug/reed_solomon_repaired.dat") self.mp4 = grdab.mp4_decode_bs_make(14) self.s2f_left = blocks.short_to_float_make(1, 32767) self.s2f_right = blocks.short_to_float_make(1, 32767) self.audio = audio.sink_make(32000) self.tb.connect(self.src, (self.mp4, 0), self.s2f_left, (self.audio, 0)) self.tb.connect((self.mp4, 1), self.s2f_right, (self.audio, 1)) self.tb.run() else: log = gr.logger("log") log.debug("debug file not found - skipped test") log.set_level("WARN") pass
def __init__(self): gr.sync_block.__init__(self, name="add_message_to_stream_async", in_sig=[numpy.complex64], out_sig=[numpy.complex64]) self.message_port_register_in(pmt.intern("msgs")) self.set_msg_handler(pmt.intern("msgs"), self.handle_message) self.msg_queue = numpy.zeros((0,), dtype=numpy.complex64) self.msgs_received = 0 self.uuid = uuid.uuid4() self.uuid_str = str(self.uuid)[-6:] self.logger = gr.logger("log_debug") self.logger.set_level("DEBUG") self.logger.info("async_msg2strm {}".format(self.uuid_str))
def __init__(self, bits_per_symbol, block_length=10000, preamble=None, log_ber_interval=10, spy_length=64, spy_threshold=0.1, alias="demod_classic"): DemodulatorClassic.__init__(self, bits_per_symbol=bits_per_symbol, block_length=block_length, max_amplitude=0.09) gr.basic_block.__init__(self, name="demod_classic", in_sig=None, out_sig=None) self.alias = alias self.port_id_in = pmt.intern("symbols") self.port_id_out = pmt.intern("bits") self.port_id_corrupt = pmt.intern("corrupt") self.message_port_register_in(self.port_id_in) self.message_port_register_out(self.port_id_out) self.message_port_register_out(self.port_id_corrupt) self.set_msg_handler(self.port_id_in, self.handle_packet) if preamble is not np.ndarray: preamble = np.array(preamble) self.preamble = preamble self.packet_cnt = 0 self.update_cnt = 0 self.ber = None self.log_ber_interval = log_ber_interval self.spy_length = spy_length assert self.spy_length % self.bits_per_symbol == 0 self.spy_threshold = spy_threshold self.reedsolomon = reedsolo.RSCodec(4) self.rs_length = 4 * 2 * 8 # 4 bytes data, 4 bytes parity, 8 bits per byte self.uuid = uuid.uuid4() self.uuid_str = str(self.uuid)[-6:] self.logger = gr.logger("log_debug") self.logger.set_level("DEBUG") self.logger.info("classic demod {}: {} bits per symbol".format( self.uuid_str, self.bits_per_symbol)) with open("ber_{}.csv".format(self.uuid_str), "w") as f: f.write("iter,BER\n")
def __init__(self, samps_per_symb, beta_rrc, cfo_samps, corr_reps, body_size, threshold=10): """ Packet detector. :param samps_per_symb: number of samples per symbol sent over the air :param beta_rrc: bandwidth expansion parameter for RRC filter :param cfo_samps: number of sample in CFO estimation field :param corr_reps: number of repetitions of Golay sequence in channel estimation fields :param body_size: number of samples in the body of a packet :param threshold: threshold for detection of packet by Golay correlation relative to normalized perfect correlation of 1.0 """ gr.sync_block.__init__(self, name="echo_packet_detect", in_sig=[np.complex64], out_sig=None) self.samps_per_symb = samps_per_symb self.beta_rrc = beta_rrc self.cfo_samps = cfo_samps self.corr_reps = corr_reps self.body_size = body_size self.threshold = threshold self.wrapper = EchoPacketWrapper(samps_per_symb=samps_per_symb, beta_rrc=beta_rrc, cfo_samps=cfo_samps, cfo_freqs=[0.25], corr_repetitions=corr_reps) # Require that a full cfo field and channel est field be present at the same time self.nhistory = (self.wrapper.corr_samps) * self.samps_per_symb - 1 self.set_history(self.nhistory + 1) # GNURadio actually gives you N-1 history items self.drop_history = 0 self.state = self.SEARCHING self.pkt_buf = None # Buffer to build packets in when broken across calls to work self.missing_samples = 0 # Nonzero when the tail of a packet is missing from a work call self.port_id_out = pmt.intern("frame") self.message_port_register_out(self.port_id_out) self.npackets = 0 self.uuid = uuid.uuid4() self.uuid_str = str(self.uuid)[-6:] self.logger = gr.logger("log_debug") self.logger.set_level("DEBUG") self.logger.info("DETECTOR {}: Packet Size = {} samples".format( self.uuid_str, self.wrapper.full_packet_length(self.body_size)))
def test_001_t (self): log = gr.logger("log") if os.path.exists("debug/transmission_frame.dat") and os.path.exists("debug/transmission_frame_trigger.dat"): self.dab_params = grdab.parameters.dab_parameters(1 , 208.064e6, True) self.src01 = blocks.file_source_make(gr.sizeof_float * 2*self.dab_params.num_carriers, "debug/transmission_frame.dat") self.src02 = blocks.file_source_make(gr.sizeof_char, "debug/transmission_frame_trigger.dat") self.msc = grdab.msc_decode(self.dab_params, 54, 84, 2, 1, 1) self.firecode = grdab.firecode_check_bb_make(14) self.file_sink_subch_decoded = blocks.file_sink_make(gr.sizeof_char, "debug/subch_decoded.dat") self.file_sink_firecode_checked = blocks.file_sink_make(gr.sizeof_char, "debug/checked_firecode.dat") self.tb.connect(self.src01, (self.msc, 0), self.firecode, self.file_sink_firecode_checked) self.tb.connect(self.src02, (self.msc, 1)) self.tb.connect(self.msc, self.file_sink_subch_decoded) self.tb.run () else: log.debug("debug file not found - skipped test") log.set_level("WARN") pass
def __init__(self, timeout): gr.basic_block.__init__(self, name="watchdog", in_sig=[], out_sig=[]) self.timeout = timeout self.port_out = pmt.intern("out") self.port_in = pmt.intern("in") self.message_port_register_out(self.port_out) self.message_port_register_in(self.port_in) self.set_msg_handler(self.port_in, self.handle_msg) self.timer = threading.Timer(self.timeout, self.alarm) self.uuid = uuid.uuid4() self.uuid_str = str(self.uuid)[-6:] self.npackets = 0 self.logger = gr.logger("log_debug") self.logger.set_level("DEBUG") self.timer.start()
def test_001_t(self): if os.path.exists("debug/PCM_piano_left.dat") and os.path.exists( "debug/PCM_piano_right.dat"): self.src_left = blocks.file_source_make( gr.sizeof_short, "debug/PCM_piano_left.dat") self.src_right = blocks.file_source_make( gr.sizeof_short, "debug/PCM_piano_right.dat") self.mp2 = dab.mp2_encode_sb_make(14, 2, 48000) self.file_sink = blocks.file_sink_make(gr.sizeof_char, "debug/mp2_encoded.mp2") self.tb.connect(self.src_left, (self.mp2, 0), self.file_sink) self.tb.connect(self.src_right, (self.mp2, 1)) self.tb.run() # check data else: log = gr.logger("log") log.debug("debug file not found - skipped test") log.set_level("WARN") pass
def test_001_t(self): if os.path.exists("debug/mp2_encoded.dat"): self.src_mp2 = blocks.file_source_make(gr.sizeof_char, "debug/mp2_encoded.dat") self.unpack = blocks.packed_to_unpacked_bb_make(1, gr.GR_MSB_FIRST) self.mp2_decode = dab.mp2_decode_bs_make(14) self.sink_left = blocks.file_sink_make( gr.sizeof_short, "debug/mp2_decoded_left.dat") self.sink_right = blocks.file_sink_make( gr.sizeof_short, "debug/mp2_decoded_right.dat") self.tb.connect(self.src_mp2, self.unpack, (self.mp2_decode, 0), self.sink_left) self.tb.connect((self.mp2_decode, 1), self.sink_right) self.tb.run() else: log = gr.logger("log") log.debug("debug file not found - skipped test") log.set_level("WARN") pass
def __init__(self, prepend_min, prepend_max, append_min, append_max): gr.basic_block.__init__(self, name="rand_zeros_extend_c", in_sig=None, out_sig=None) self.prepend_min = prepend_min self.prepend_max = prepend_max self.append_min = append_min self.append_max = append_max self.port_id_in = pmt.intern("frame") self.port_id_out = pmt.intern("extended") self.message_port_register_in(self.port_id_in) self.message_port_register_out(self.port_id_out) self.set_msg_handler(self.port_id_in, self.handle_frame) self.npackets = 0 self.logger = gr.logger("log_debug") self.logger.set_level("DEBUG")
def __init__(self, fs, fft_len, mode): gr.sync_block.__init__(self, name="phase_sync_cc", in_sig=[numpy.complex64], out_sig=[numpy.complex64]) self.fs = 48000 self.mode = 0 # OFDM Paramter aller 4 Modes festlegen # Im Moment nur für Mode B self.ofdm_freq_pilots = [16, 48, 64] self.ofdm_freq_phases = [331, 651, 555] self.ofdm_freq_abs = numpy.sqrt(2) # Phasen berechnen self.ofdm_freq_phases = numpy.exp( numpy.multiply((1j * 2 * numpy.pi / 1024), self.ofdm_freq_phases)) # Amplitude berechnen self.ofdm_freq_ref = numpy.multiply(self.ofdm_freq_phases, self.ofdm_freq_abs) self.ofdm_freq_phases = numpy.angle(self.ofdm_freq_phases) # Negative Frequenzen nach oben verschieben self.ofdm_freq_pilots = [x + 512 for x in self.ofdm_freq_pilots] self.gi_len = numpy.array([0, 128, 256, 256, 352]) self.sym_len = numpy.array([0, 1280, 1280, 960, 800]) self.fft_len = self.sym_len - self.gi_len self.modes = ['Nicht erkannt', 'A', 'B', 'C', 'D'] #bzw. self.fft_len # wird erst relevant, sobald Mode erkannt... self.set_output_multiple(1024) self.phase_offset = 0 self.ncnt = 0 # Logger self.log = gr.logger('log_debug') self.log.debug('DEBUG LOG') self.log.set_level('DEBUG')
def __init__(self, p_integ): gr.basic_block.__init__(self, name="fsync_cc", in_sig=[numpy.complex64], out_sig=[numpy.complex64]) # Parameter self.set_output_multiple(2048) self.freq_range = 10 self.ofdm_pilots = [16, 48, 64] # Mode A # Mode B # Iniitialisierungen self.mode = 0 self.ffactor = 0 self.items_consumed = 0 self.items_created = 0 self.offset = 0 self.var = 100 # Logger self.log = gr.logger('log_debug') self.log.debug('DEBUG LOG') self.log.set_level('ERROR') # Schätzer aktivieren self.enable_integration = p_integ #Schätzer über mehrere Symbolef self.estimation_k = 0.0 self.n_estimations = 0.0 self.estim_var_start = 100.0 # var des Schätzers, recht groß in manchen fällen für grobe f sync self.confidence = self.estim_var_start
def __init__( self, seed=0, hidden_layers=(64, ), bits_per_symbol=2, preamble=None, log_constellation_interval=10, init_weights="", activation_fn_hidden='tanh', # kernel_initializer_hidden=normc_initializer(1.0), # bias_initializer_hidden=tf.glorot_uniform_initializer(), activation_fn_output=None, # kernel_initializer_output=normc_initializer(1.0), # bias_initializer_output=tf.glorot_uniform_initializer(), optimizer=torch.optim.Adam, # initial_eps=1e-1, # max_eps=2e-1, # min_eps=1e-4, lambda_prob=1e-10, loss_type='l2', # explore_prob=0.5, # strong_supervision_prob=0., stepsize_mu=1e-3, # stepsize_eps=1e-5, stepsize_cross_entropy=1e-3, cross_entropy_weight=1.0, ): gr.basic_block.__init__(self, name="demodulator_neural", in_sig=None, out_sig=None) DemodulatorNeural.__init__( self, seed=seed, hidden_layers=hidden_layers, bits_per_symbol=bits_per_symbol, activation_fn_hidden=activation_fn_hidden, # kernel_initializer_hidden=kernel_initializer_hidden, # bias_initializer_hidden=bias_initializer_hidden, activation_fn_output=activation_fn_output, # kernel_initializer_output=kernel_initializer_output, # bias_initializer_output=bias_initializer_output, optimizer=optimizer, # initial_eps=initial_eps, # max_eps=max_eps, # min_eps=min_eps, lambda_prob=lambda_prob, loss_type=loss_type, # explore_prob=explore_prob, # strong_supervision_prob=strong_supervision_prob, stepsize_mu=stepsize_mu, # stepsize_eps=stepsize_eps, stepsize_cross_entropy=stepsize_cross_entropy, cross_entropy_weight=cross_entropy_weight) if preamble is None: raise Exception("You must provide a preamble") if preamble is not numpy.ndarray: preamble = numpy.array(preamble) assert len( preamble.shape ) == 1, "Preamble must be a vector, not a matrix with a dimension of size 1" self.preamble = preamble self.preamble_si = bits_to_integers(numpy.array(self.preamble), self.bits_per_symbol) self.run_mode = "train" # Be careful not to clobber the parent class' mode here! if len(init_weights) > 0: self.model.load_state_dict(torch.load(init_weights)) self.run_mode = "freeze" # Message ports self.port_id_in = pmt.intern("symbols") self.port_id_out = pmt.intern("bits") self.port_id_ctrl = pmt.intern("control") self.message_port_register_in(self.port_id_in) self.message_port_register_in(self.port_id_ctrl) self.message_port_register_out(self.port_id_out) self.set_msg_handler(self.port_id_in, self.handle_packet) self.set_msg_handler(self.port_id_ctrl, self.handle_control) # Counters self.packet_cnt = 0 self.log_constellation_interval = log_constellation_interval self.uuid = uuid.uuid4() self.uuid_str = str(self.uuid)[-6:] self.logger = gr.logger("log_debug") self.logger.set_level("DEBUG") self.logger.info("neural demod {}: {} bits per symbol".format( self.uuid_str, self.bits_per_symbol)) if len(init_weights) > 0: self.logger.info( "neural demod {}: initialized weights from {}".format( self.uuid_str, init_weights)) with open("ber_{}.csv".format(self.uuid_str), "w") as f: f.write("iter,BER\n")
def __init__( self, timeslots=15, subcarriers=64, active_subcarriers=60, overlap=2, subcarrier_map=list(range(1, 61)), cp_len=16, cs_len=8, ramp_len=8, frequency_domain_taps=list(range(30)), map_resources_per_timeslot=True, preamble=[1.0 + 1.0j] * 128, channel_estimator_id=1, gfdm_constellation=digital.constellation_qpsk().base(), ic_iterations=2, activate_phase_compensation=True, activate_cfo_compensation=True, sync_tag_key="frame_start", antenna_port=None, ): gr.hier_block2.__init__( self, "receiver_cc", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(3, 3, gr.sizeof_gr_complex), ) self.logger = gr.logger(f"gr_log.{self.symbol_name()}") internal_sync_tag_key = sync_tag_key snr_tag_key = "snr_lin" cnr_tag_key = "cnr" if antenna_port is not None: internal_sync_tag_key = f"{sync_tag_key}{antenna_port}" snr_tag_key = f"{snr_tag_key}{antenna_port}" cnr_tag_key = f"{cnr_tag_key}{antenna_port}" self.logger.debug( f"{sync_tag_key=}, {internal_sync_tag_key=}, {snr_tag_key=}, {cnr_tag_key=}" ) self.logger.debug( f"{activate_cfo_compensation=}, {activate_phase_compensation=}" ) preamble = np.array(preamble) block_len = timeslots * subcarriers full_block_len = block_len + cp_len + cs_len preamble_len = preamble.size full_preamble_len = cp_len + preamble_len + cs_len # frame_len includes preamble, payload and CP+CS for both frame_len = full_preamble_len + full_block_len sc_map_is_dc_free = subcarrier_map[0] != 0 self.extract_burst = gfdm.extract_burst_cc( frame_len, cp_len, sync_tag_key, activate_cfo_compensation, internal_sync_tag_key, ) self.remove_prefix_data = gfdm.remove_prefix_cc( frame_len, block_len, full_preamble_len + cp_len, internal_sync_tag_key ) self.remove_prefix_preamble = gfdm.remove_prefix_cc( frame_len, preamble_len, cp_len, internal_sync_tag_key ) self.channel_estimator = gfdm.channel_estimator_cc( timeslots, subcarriers, active_subcarriers, sc_map_is_dc_free, channel_estimator_id, preamble, snr_tag_key, cnr_tag_key, ) self.advanced_receiver = gfdm.advanced_receiver_sb_cc( timeslots, subcarriers, overlap, ic_iterations, frequency_domain_taps, gfdm_constellation, subcarrier_map, activate_phase_compensation, ) self.resource_demapper = gfdm.resource_demapper_cc( timeslots, subcarriers, active_subcarriers, subcarrier_map, map_resources_per_timeslot, ) self.connect( (self, 0), (self.extract_burst, 0), (self.remove_prefix_data, 0), (self.advanced_receiver, 0), (self.resource_demapper, 0), (self, 0), ) self.connect( (self.extract_burst, 0), (self.remove_prefix_preamble, 0), (self.channel_estimator, 0), (self.advanced_receiver, 1), ) self.connect((self.channel_estimator, 0), (self, 1)) self.connect((self.extract_burst, 0), (self, 2))
def main(args): nargs = len(args) if nargs == 1: infile = args[0] outfile = None elif nargs == 2: infile = args[0] outfile = args[1] else: sys.stderr.write("Usage: dvbt-hackrf.py infile [output_file]\n") sys.exit(1) ## Config Options config = DVBTConfig('dvbt.conf') # DVB-T Parameters channel_mhz = config.get_channel_mhz() mode = config.get_mode() code_rate = config.get_code_rate() constellation = config.get_constellation() guard_interval = config.get_guard_interval() # Hack-RF Parameters center_freq = config.get_center_freq() rf_gain = config.get_hackrf_rf_gain() if_gain = config.get_hackrf_if_gain() bb_gain = config.get_hackrf_bb_gain() ## samp_rate = 10000000.0 if mode == dvbt.T2k: factor = 1 carriers = 2048 elif mode == dvbt.T8k: factor = 4 carriers = 8192 if guard_interval == dvbt.G1_32: gi = carriers / 32 elif guard_interval == dvbt.G1_16: gi = carriers / 16 elif guard_interval == dvbt.G1_8: gi = carriers / 8 elif guard_interval == dvbt.G1_4: gi = carriers / 4 if channel_mhz == 8: bandwidth = 8750000 elif channel_mhz == 7: bandwidth = 7000000 elif channel_mhz == 6: bandwidth = 6000000 elif channel_mhz == 5: bandwidth = 5000000 else: bandwidth = 8750000 log = gr.logger("dvbt-hackrf") log.set_level("DEBUG") log.debug("logger initilized") tb = gr.top_block() log.debug("top block initialized") src = blocks.file_source(gr.sizeof_char, infile, True) log.debug("source block initialized") dvbt_energy_dispersal = dvbt.energy_dispersal(1 * factor) dvbt_reed_solomon_enc = dvbt.reed_solomon_enc(2, 8, 0x11d, 255, 239, 8, 51, (8 * factor)) dvbt_convolutional_interleaver = dvbt.convolutional_interleaver( (136 * factor), 12, 17) dvbt_inner_coder = dvbt.inner_coder(1, (1512 * factor), constellation, dvbt.NH, code_rate) dvbt_bit_inner_interleaver = dvbt.bit_inner_interleaver( (1512 * factor), constellation, dvbt.NH, mode) dvbt_symbol_inner_interleaver = dvbt.symbol_inner_interleaver( (1512 * factor), mode, 1) dvbt_dvbt_map = dvbt.dvbt_map((1512 * factor), constellation, dvbt.NH, mode, 1) dvbt_reference_signals = dvbt.reference_signals(gr.sizeof_gr_complex, (1512 * factor), carriers, constellation, dvbt.NH, code_rate, code_rate, dvbt.G1_32, mode, 0, 0) fft_vxx = fft.fft_vcc(carriers, False, (window.rectangular(carriers)), True, 10) digital_ofdm_cyclic_prefixer = digital.ofdm_cyclic_prefixer( carriers, carriers + (gi), 0, "") rational_resampler_xxx = filter.rational_resampler_ccc(interpolation=70, decimation=64, taps=None, fractional_bw=None) blocks_multiply_const_vxx = blocks.multiply_const_vcc((0.0022097087, )) log.debug("DVB-T blocks initialized") out = osmosdr.sink(args="numchan=1") out.set_sample_rate(samp_rate) out.set_center_freq(center_freq, 0) out.set_freq_corr(0, 0) out.set_gain(rf_gain, 0) out.set_if_gain(if_gain, 0) out.set_bb_gain(bb_gain, 0) out.set_antenna("", 0) out.set_bandwidth(0, 0) log.debug("Output block initialized") tb.connect(src, dvbt_energy_dispersal) tb.connect(dvbt_energy_dispersal, dvbt_reed_solomon_enc) tb.connect(dvbt_reed_solomon_enc, dvbt_convolutional_interleaver) tb.connect(dvbt_convolutional_interleaver, dvbt_inner_coder) tb.connect(dvbt_inner_coder, dvbt_bit_inner_interleaver) tb.connect(dvbt_bit_inner_interleaver, dvbt_symbol_inner_interleaver) tb.connect(dvbt_symbol_inner_interleaver, dvbt_dvbt_map) tb.connect(dvbt_dvbt_map, dvbt_reference_signals) tb.connect(dvbt_reference_signals, fft_vxx) tb.connect(fft_vxx, digital_ofdm_cyclic_prefixer) tb.connect(digital_ofdm_cyclic_prefixer, blocks_multiply_const_vxx) tb.connect(blocks_multiply_const_vxx, rational_resampler_xxx) tb.connect(rational_resampler_xxx, out) log.debug("all blocks connected") if outfile: dst = blocks.file_sink(gr.sizeof_gr_complex, outfile) tb.connect(blocks_multiply_const_vxx, dst) log.debug("running gnuradio") tb.run()
def __init__(self, verbose_mode=True, radio_host_name="ndr651", radio_host_port=8617, tengig_iface_list=['eth10', 'eth11'], num_tuners=1, tuner1_param_list=[False, 900e6, 0], tuner2_param_list=[False, 900e6, 0], num_wbddcs=1, wbddc1_param_list=["eth10", 40001, 0, 0, False], wbddc2_param_list=["eth10", 40002, 0, 0, False], num_nbddcs=1, nbddc1_param_list=["eth10", 41001, 0, 0, False, 0.0], nbddc2_param_list=["eth10", 41002, 0, 0, False, 0.0], nbddc3_param_list=["eth10", 41003, 0, 0, False, 0.0], nbddc4_param_list=["eth10", 41004, 0, 0, False, 0.0], nbddc5_param_list=["eth10", 41005, 0, 0, False, 0.0], nbddc6_param_list=["eth10", 41006, 0, 0, False, 0.0], nbddc7_param_list=["eth10", 41007, 0, 0, False, 0.0], nbddc8_param_list=["eth10", 41008, 0, 0, False, 0.0], nbddc9_param_list=["eth10", 41009, 0, 0, False, 0.0], nbddc10_param_list=["eth10", 41010, 0, 0, False, 0.0], nbddc11_param_list=["eth10", 41011, 0, 0, False, 0.0], nbddc12_param_list=["eth10", 41012, 0, 0, False, 0.0], nbddc13_param_list=["eth10", 41013, 0, 0, False, 0.0], nbddc14_param_list=["eth10", 41014, 0, 0, False, 0.0], nbddc15_param_list=["eth10", 41015, 0, 0, False, 0.0], nbddc16_param_list=["eth10", 41016, 0, 0, False, 0.0], tagged=False, debug=False, ): gr.hier_block2.__init__( self, "[CyberRadio] NDR651 Source", gr.io_signature(0, 0, 0), gr.io_signaturev(num_wbddcs + num_nbddcs + 1, num_wbddcs + num_nbddcs + 1, [gr.sizeof_char*1] + num_wbddcs * [gr.sizeof_gr_complex*1] + \ num_nbddcs * [gr.sizeof_gr_complex*1]), ) self.logger = gr.logger("CyberRadio") self.logger.set_level("INFO") self.tuner_param_lists = {} self.wbddc_sources = {} self.wbddc_param_lists = {} self.nbddc_sources = {} self.nbddc_param_lists = {} self.verbose_mode = verbose_mode self.radio_host_name = radio_host_name self.radio_host_port = radio_host_port self.tengig_iface_list = tengig_iface_list self.num_tuners = num_tuners self.tuner_param_lists[1] = tuner1_param_list self.tuner_param_lists[2] = tuner2_param_list self.num_wbddcs = num_wbddcs self.wbddc_param_lists[1] = wbddc1_param_list self.wbddc_param_lists[2] = wbddc2_param_list self.num_nbddcs = num_nbddcs self.nbddc_param_lists[1] = nbddc1_param_list self.nbddc_param_lists[2] = nbddc2_param_list self.nbddc_param_lists[3] = nbddc3_param_list self.nbddc_param_lists[4] = nbddc4_param_list self.nbddc_param_lists[5] = nbddc5_param_list self.nbddc_param_lists[6] = nbddc6_param_list self.nbddc_param_lists[7] = nbddc7_param_list self.nbddc_param_lists[8] = nbddc8_param_list self.nbddc_param_lists[9] = nbddc9_param_list self.nbddc_param_lists[10] = nbddc10_param_list self.nbddc_param_lists[11] = nbddc11_param_list self.nbddc_param_lists[12] = nbddc12_param_list self.nbddc_param_lists[13] = nbddc13_param_list self.nbddc_param_lists[14] = nbddc14_param_list self.nbddc_param_lists[15] = nbddc15_param_list self.nbddc_param_lists[16] = nbddc16_param_list self.tagged = tagged self.debug = debug self.CyberRadio_file_like_object_source_0 = CyberRadio.file_like_object_source() self.connect((self.CyberRadio_file_like_object_source_0, 0), (self, 0)) self.CyberRadio_NDR_driver_interface_0 = CyberRadio.NDR_driver_interface( radio_type="ndr651", verbose=verbose_mode, log_file=self.CyberRadio_file_like_object_source_0, connect_mode="tcp", host_name=radio_host_name, host_port=radio_host_port, ) self.vita_tail_size = self.CyberRadio_NDR_driver_interface_0.getVitaTailSize() self.vita_payload_size = self.CyberRadio_NDR_driver_interface_0.getVitaPayloadSize() self.vita_header_size = self.CyberRadio_NDR_driver_interface_0.getVitaHeaderSize() self.iq_swapped = self.CyberRadio_NDR_driver_interface_0.isIqSwapped() self.byte_swapped = self.CyberRadio_NDR_driver_interface_0.isByteswapped() # tengig_iface_info = Nested dictionary caching info for our 10GigE # interfaces. Keyed by interface name and datum keyword ("index", # , "destMAC", "sourceIP", or "destIP"). self.tengig_iface_info = {} self._get_tengig_iface_info() # UDP destination info needs to be tracked dynamically, since # DDCs can be freely assigned to any 10GigE port but there are # not enough DIP table entries to hard-code any assignments. self.udp_dest_dip_entries = {} self.udp_dest_dip_entry_range = self.CyberRadio_NDR_driver_interface_0.getGigEDipEntryIndexRange() self._set_udp_dest_info() for tuner_index in xrange(1, self.num_tuners + 1, 1): self._set_tuner_param_list(tuner_index, self.tuner_param_lists[tuner_index]) for wbddc_index in xrange(1, self.num_wbddcs + 1, 1): self.wbddc_sources[wbddc_index] = self._get_configured_wbddc( wbddc_index, self.wbddc_param_lists[wbddc_index]) self.connect((self.wbddc_sources[wbddc_index], 0), (self, wbddc_index)) for nbddc_index in xrange(1, self.num_nbddcs + 1, 1): self.nbddc_sources[nbddc_index] = self._get_configured_nbddc( nbddc_index, self.nbddc_param_lists[nbddc_index]) self.connect((self.nbddc_sources[nbddc_index], 0), (self, self.num_wbddcs + nbddc_index))
def main(args): nargs = len(args) if nargs == 1: infile = args[0] outfile = None elif nargs == 2: infile = args[0] outfile = args[1] else: sys.stderr.write("Usage: dvbt-hackrf.py infile [output_file]\n"); sys.exit(1) ## Config Options config = DVBTConfig('dvbt.conf') # DVB-T Parameters channel_mhz = config.get_channel_mhz() mode = config.get_mode() code_rate = config.get_code_rate() constellation = config.get_constellation() guard_interval = config.get_guard_interval() # Hack-RF Parameters center_freq = config.get_center_freq() rf_gain = config.get_hackrf_rf_gain() if_gain = config.get_hackrf_if_gain() bb_gain = config.get_hackrf_bb_gain() ## samp_rate = 10000000.0 if mode == dvbt.T2k: factor = 1 carriers = 2048 elif mode == dvbt.T8k: factor = 4 carriers = 8192 if guard_interval == dvbt.G1_32: gi = carriers / 32 elif guard_interval == dvbt.G1_16: gi = carriers / 16 elif guard_interval == dvbt.G1_8: gi = carriers / 8 elif guard_interval == dvbt.G1_4: gi = carriers / 4 if channel_mhz == 8: bandwidth = 8750000 elif channel_mhz == 7: bandwidth = 7000000 elif channel_mhz == 6: bandwidth = 6000000 elif channel_mhz == 5: bandwidth = 5000000 else: bandwidth = 8750000 log=gr.logger("dvbt-hackrf") log.set_level("DEBUG"); log.debug("logger initilized") tb = gr.top_block() log.debug("top block initialized") src = blocks.file_source(gr.sizeof_char, infile, True) log.debug("source block initialized") dvbt_energy_dispersal = dvbt.energy_dispersal(1 * factor) dvbt_reed_solomon_enc = dvbt.reed_solomon_enc(2, 8, 0x11d, 255, 239, 8, 51, (8 * factor)) dvbt_convolutional_interleaver = dvbt.convolutional_interleaver((136 * factor), 12, 17) dvbt_inner_coder = dvbt.inner_coder(1, (1512 * factor), constellation, dvbt.NH, code_rate) dvbt_bit_inner_interleaver = dvbt.bit_inner_interleaver((1512 * factor), constellation, dvbt.NH, mode) dvbt_symbol_inner_interleaver = dvbt.symbol_inner_interleaver((1512 * factor), mode, 1) dvbt_dvbt_map = dvbt.dvbt_map((1512 * factor), constellation, dvbt.NH, mode, 1) dvbt_reference_signals = dvbt.reference_signals(gr.sizeof_gr_complex, (1512 * factor), carriers, constellation, dvbt.NH, code_rate, code_rate, dvbt.G1_32, mode, 0, 0) fft_vxx = fft.fft_vcc(carriers, False, (window.rectangular(carriers)), True, 10) digital_ofdm_cyclic_prefixer = digital.ofdm_cyclic_prefixer(carriers, carriers+(gi), 0, "") rational_resampler_xxx = filter.rational_resampler_ccc(interpolation=70, decimation=64, taps=None, fractional_bw=None) blocks_multiply_const_vxx = blocks.multiply_const_vcc((0.0022097087, )) log.debug("DVB-T blocks initialized") out = osmosdr.sink(args="numchan=1") out.set_sample_rate(samp_rate) out.set_center_freq(center_freq, 0) out.set_freq_corr(0, 0) out.set_gain(rf_gain, 0) out.set_if_gain(if_gain, 0) out.set_bb_gain(bb_gain, 0) out.set_antenna("", 0) out.set_bandwidth(0, 0) log.debug("Output block initialized") tb.connect(src, dvbt_energy_dispersal) tb.connect(dvbt_energy_dispersal, dvbt_reed_solomon_enc) tb.connect(dvbt_reed_solomon_enc, dvbt_convolutional_interleaver) tb.connect(dvbt_convolutional_interleaver, dvbt_inner_coder) tb.connect(dvbt_inner_coder, dvbt_bit_inner_interleaver) tb.connect(dvbt_bit_inner_interleaver, dvbt_symbol_inner_interleaver) tb.connect(dvbt_symbol_inner_interleaver, dvbt_dvbt_map) tb.connect(dvbt_dvbt_map, dvbt_reference_signals) tb.connect(dvbt_reference_signals, fft_vxx) tb.connect(fft_vxx, digital_ofdm_cyclic_prefixer) tb.connect(digital_ofdm_cyclic_prefixer, blocks_multiply_const_vxx) tb.connect(blocks_multiply_const_vxx, rational_resampler_xxx) tb.connect(rational_resampler_xxx, out) log.debug("all blocks connected") if outfile: dst = blocks.file_sink(gr.sizeof_gr_complex, outfile) tb.connect(blocks_multiply_const_vxx, dst) log.debug("running gnuradio") tb.run()
if guard_interval == dvbt2.GI_1_32: gi = fftsize / 32 elif guard_interval == dvbt2.GI_1_16: gi = fftsize / 16 elif guard_interval == dvbt2.GI_1_8: gi = fftsize / 8 elif guard_interval == dvbt2.GI_1_4: gi = fftsize / 4 elif guard_interval == dvbt2.GI_1_128: gi = fftsize / 128 elif guard_interval == dvbt2.GI_19_128: gi = (fftsize * 19) / 128 elif guard_interval == dvbt2.GI_19_256: gi = (fftsize * 19) / 256 log=gr.logger("dvbt2-hackrf") log.set_level("DEBUG"); log.debug("logger initilized") tb = gr.top_block() log.debug("top block initialized") src = blocks.file_source(gr.sizeof_char, infile, True) log.debug("source block initialized") dvbt2_bbheader = dvbt2.bbheader_bb(frame_size, code_rate, input_mode, dvbt2.INBAND_OFF, fec_blocks, 4000000) dvbt2_bbscrambler = dvbt2.bbscrambler_bb(frame_size, code_rate) dvbt2_bch = dvbt2.bch_bb(frame_size, code_rate) dvbt2_ldpc = dvbt2.ldpc_bb(frame_size, code_rate) dvbt2_interleaver = dvbt2.interleaver_bb(frame_size, code_rate, constellation) dvbt2_modulator = dvbt2.modulator_bc(frame_size, constellation, rotation)