Esempio n. 1
0
def main(args):
    nargs = len(args)
    if nargs == 1:
        infile = args[0]
        device = '0'
    elif nargs == 2:
        infile = args[0]
        device = args[1]
    else:
        sys.stderr.write(
            "Usage: dvbt-hackrf.py infile [device-index (default=0)]\n")
        sys.exit(1)

    gainDBm = '3'

    ## 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()

    # HF Parameters
    center_freq = '%d' % (config.get_center_freq() / 1000)
    gain = '%d' % config.get_tsrfsend_gain()
    cell_id = '%d' % config.get_tsrfsend_cell_id()

    ##

    # this is based on the formula found at:
    #  http://www.dveo.com/broadcast/bit-rate-calculation-for-COFDM-modulation.shtml
    #
    # DVB-T modulator maximum play rate depends on code rate, constellation, guard interval, bandwidth.
    # The maximum bit rate can be calculated as below.
    #
    # TBandwidth = {6,000,000, 7,000,000, 8,000,000} in Hz for 6MHz, 7MHz, 8MHz
    # TCodeRate = {1/2, 2/3, 3/4, 5/6, 7/8}
    # TConstellation = {2, 4, 6} <- QPSK = 2, 16QAM=4, 64QAM = 6
    # TGuardInterval = {4/5, 8/9, 16/17, 32/33}, 1/4 = 4/5, 1/8 = 8/9, 1/16 => 16/17, 1/32 => 32/33}
    # 2K/8K mode does not matter
    #
    # Maximum bit rate = 1512 / 2048 * 188 / 204 * 64 / 56 * TBandwidth * TcodeRate * TConstellation * TGuardInterval (bps)
    #                  =             423 / 544             * TBandwidth * TCodeRate * TConstellation * TGuardInterval (bps)
    #

    argBW = '%d' % (channel_mhz * 1000)

    argCR = '1/2'
    if code_rate == dvbt.C1_2:
        argCR = '1/2'
    elif code_rate == dvbt.C2_3:
        argCR = '2/3'
    elif code_rate == dvbt.C3_4:
        argCR = '3/4'
    elif code_rate == dvbt.C5_6:
        argCR = '5/6'
    elif code_rate == dvbt.C7_8:
        argCR = '7/8'
    else:
        raise ValueError("invalid cod_rate")

    argCO = '4'
    if constellation == dvbt.QPSK:
        argCO = '4'
    elif constellation == dvbt.QAM16:
        argCO = '16'
    elif constellation == dvbt.QAM64:
        argCO = '64'
    else:
        raise ValueError("invalid constellation")

    argGI = '1/4'
    if guard_interval == dvbt.G1_32:
        argGI = '1/32'
    elif guard_interval == dvbt.G1_16:
        argGI = '1/16'
    elif guard_interval == dvbt.G1_8:
        argGI = '1/8'
    elif guard_interval == dvbt.G1_4:
        argGI = '1/4'
    else:
        raise ValueError("invalid guard_interval")

    argMO = '2'
    if mode == dvbt.T2k:
        argMO = '2'
    elif mode == dvbt.T8k:
        argMO = '8'
    else:
        raise ValueError("invalid guard_interval")

    os.execl('./tsrfsend', 'tsrfsend', infile, device, center_freq, argBW,
             argCO, argCR, argGI, argMO, cell_id, gain)
Esempio n. 2
0
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()
Esempio n. 3
0
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()
Esempio n. 4
0
def main(args):
    nargs = len(args)
    if nargs == 1:
        infile  = args[0]
        device = '0'
    elif nargs == 2:
        infile   = args[0]
        device  = args[1]
    else:
        sys.stderr.write("Usage: dvbt-hackrf.py infile [device-index (default=0)]\n");
        sys.exit(1)

    gainDBm = '3'

    ## 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()

    # HF Parameters
    center_freq = '%d' % (config.get_center_freq()/1000)
    gain = '%d' % config.get_tsrfsend_gain()
    cell_id = '%d' % config.get_tsrfsend_cell_id()


    ##

    # this is based on the formula found at:
    #  http://www.dveo.com/broadcast/bit-rate-calculation-for-COFDM-modulation.shtml
    #
    # DVB-T modulator maximum play rate depends on code rate, constellation, guard interval, bandwidth.
    # The maximum bit rate can be calculated as below.
    #
    # TBandwidth = {6,000,000, 7,000,000, 8,000,000} in Hz for 6MHz, 7MHz, 8MHz
    # TCodeRate = {1/2, 2/3, 3/4, 5/6, 7/8}
    # TConstellation = {2, 4, 6} <- QPSK = 2, 16QAM=4, 64QAM = 6
    # TGuardInterval = {4/5, 8/9, 16/17, 32/33}, 1/4 = 4/5, 1/8 = 8/9, 1/16 => 16/17, 1/32 => 32/33}
    # 2K/8K mode does not matter
    #
    # Maximum bit rate = 1512 / 2048 * 188 / 204 * 64 / 56 * TBandwidth * TcodeRate * TConstellation * TGuardInterval (bps)
    #                  =             423 / 544             * TBandwidth * TCodeRate * TConstellation * TGuardInterval (bps)
    #

    argBW = '%d' % (channel_mhz * 1000)

    argCR = '1/2'
    if code_rate == dvbt.C1_2:
        argCR = '1/2'
    elif code_rate == dvbt.C2_3:
        argCR = '2/3'
    elif code_rate == dvbt.C3_4:
        argCR = '3/4'
    elif code_rate == dvbt.C5_6:
        argCR = '5/6'
    elif code_rate == dvbt.C7_8:
        argCR = '7/8'
    else:
        raise ValueError("invalid cod_rate")

    argCO = '4'
    if constellation == dvbt.QPSK:
        argCO = '4'
    elif constellation == dvbt.QAM16:
        argCO = '16'
    elif constellation == dvbt.QAM64:
        argCO = '64'
    else:
        raise ValueError("invalid constellation")

    argGI = '1/4'
    if guard_interval == dvbt.G1_32:
        argGI = '1/32'
    elif guard_interval == dvbt.G1_16:
        argGI = '1/16'
    elif guard_interval == dvbt.G1_8:
        argGI = '1/8'
    elif guard_interval == dvbt.G1_4:
        argGI = '1/4'
    else:
        raise ValueError("invalid guard_interval")

    argMO = '2'
    if mode == dvbt.T2k:
        argMO = '2'
    elif mode == dvbt.T8k:
        argMO = '8'
    else:
        raise ValueError("invalid guard_interval")

    os.execl('./tsrfsend', 'tsrfsend', infile, device, center_freq, argBW, argCO, argCR, argGI, argMO, cell_id, gain)