Esempio n. 1
0
def main():
    parser = optparse.OptionParser()
    parser.add_option('-s',
                      '--sample_rate',
                      dest='sample_rate',
                      type='int',
                      default=48000,
                      help='Sample rate in Hz')
    parser.add_option('-b',
                      '--pause_period',
                      dest='pause_period',
                      type='int',
                      default=64,
                      help='Period (in samples) of a blank symbol')
    parser.add_option('-n',
                      '--one_period',
                      dest='one_period',
                      type='int',
                      default=16,
                      help='Period (in samples) of a one symbol')
    parser.add_option('-z',
                      '--zero_period',
                      dest='zero_period',
                      type='int',
                      default=8,
                      help='Period (in samples) of a zero symbol')
    parser.add_option('-p',
                      '--packet_size',
                      dest='packet_size',
                      type='int',
                      default=256,
                      help='Packet size in bytes')
    parser.add_option('-g',
                      '--page_size',
                      dest='page_size',
                      type='int',
                      default=1024,
                      help='Flash page size')
    parser.add_option('-k',
                      '--blank_duration',
                      dest='blank_duration',
                      type='int',
                      default=60,
                      help='Duration of the blank between pages, in ms')
    parser.add_option('-o',
                      '--output_file',
                      dest='output_file',
                      default=None,
                      help='Write output file to FILE',
                      metavar='FILE')

    options, args = parser.parse_args()
    #data = file(args[0], 'rb').read()
    with open(args[0], 'rb') as input_file:
        data = input_file.read()

    if len(args) != 1:
        logging.fatal('Specify one, and only one firmware .bin file!')
        sys.exit(1)

    output_file = options.output_file
    if not output_file:
        if '.bin' in args[0]:
            output_file = args[0].replace('.bin', '.wav')
        else:
            output_file = args[0] + '.wav'

    encoder = FskEncoder(options.sample_rate, options.pause_period,
                         options.one_period, options.zero_period,
                         options.packet_size)
    writer = audio_stream_writer.AudioStreamWriter(output_file,
                                                   options.sample_rate, 16, 1)

    blank_duration = options.blank_duration * 0.001
    for block in encoder.code(data, options.page_size, blank_duration):
        if len(block):
            writer.append(block)
    writer.close()
Esempio n. 2
0
def main():
    parser = optparse.OptionParser()
    parser.add_option('-s',
                      '--sample_rate',
                      dest='sample_rate',
                      type='int',
                      default=48000,
                      help='Sample rate in Hz')
    parser.add_option('-b',
                      '--pause_period',
                      dest='pause_period',
                      type='int',
                      default=64,
                      help='Period (in samples) of a blank symbol')
    parser.add_option('-n',
                      '--one_period',
                      dest='one_period',
                      type='int',
                      default=16,
                      help='Period (in samples) of a one symbol')
    parser.add_option('-z',
                      '--zero_period',
                      dest='zero_period',
                      type='int',
                      default=8,
                      help='Period (in samples) of a zero symbol')
    parser.add_option('-p',
                      '--packet_size',
                      dest='packet_size',
                      type='int',
                      default=256,
                      help='Packet size in bytes')
    parser.add_option('-g',
                      '--page_size',
                      dest='page_size',
                      type='int',
                      default=1024,
                      help='Flash page size')
    parser.add_option('-o',
                      '--output_file',
                      dest='output_file',
                      default=None,
                      help='Write output file to FILE',
                      metavar='FILE')
    parser.add_option('-t',
                      '--target',
                      dest='target',
                      default='stm32f1',
                      help='Set page size and erase time for TARGET',
                      metavar='TARGET')

    options, args = parser.parse_args()
    data = file(args[0], 'rb').read()
    if len(args) != 1:
        logging.fatal('Specify one, and only one firmware .bin file!')
        sys.exit(1)

    if options.target not in ['stm32f1', 'stm32f3', 'stm32f4']:
        logging.fatal('Unknown target: %s' % options.target)
        sys.exit(2)

    output_file = options.output_file
    if not output_file:
        if '.bin' in args[0]:
            output_file = args[0].replace('.bin', '.wav')
        else:
            output_file = args[0] + '.wav'

    encoder = FskEncoder(options.sample_rate, options.pause_period,
                         options.one_period, options.zero_period,
                         options.packet_size)
    writer = audio_stream_writer.AudioStreamWriter(output_file,
                                                   options.sample_rate, 16, 1)

    # INTRO
    for block in encoder.code_intro():
        writer.append(block)

    blank_duration = 1.0
    if options.target in PAGE_SIZE.keys():
        for block in encoder.code(data, PAGE_SIZE[options.target],
                                  PAUSE[options.target]):
            if len(block):
                writer.append(block)
    elif options.target == 'stm32f4':
        for x in xrange(0, len(data), STM32F4_BLOCK_SIZE):
            address = STM32F4_APPLICATION_START + x
            block = data[x:x + STM32F4_BLOCK_SIZE]
            pause = 2.5 if address in STM32F4_SECTOR_BASE_ADDRESS else 0.2
            for block in encoder.code(block, STM32F4_BLOCK_SIZE, pause):
                if len(block):
                    writer.append(block)
        blank_duration = 5.0
    for block in encoder.code_outro(blank_duration):
        writer.append(block)
Esempio n. 3
0
def main():
    parser = optparse.OptionParser()
    parser.add_option('-s',
                      '--sample_rate',
                      dest='sample_rate',
                      type='int',
                      default=48000,
                      help='Sample rate in Hz')
    parser.add_option('-c',
                      '--carrier_frequency',
                      dest='carrier_frequency',
                      type='int',
                      default=6000,
                      help='Carrier frequency in Hz')
    parser.add_option('-b',
                      '--baud_rate',
                      dest='baud_rate',
                      type='int',
                      default=12000,
                      help='Baudrate in bps')
    parser.add_option('-p',
                      '--packet_size',
                      dest='packet_size',
                      type='int',
                      default=256,
                      help='Packet size in bytes')
    parser.add_option('-o',
                      '--output_file',
                      dest='output_file',
                      default=None,
                      help='Write output file to FILE',
                      metavar='FILE')
    parser.add_option('-t',
                      '--target',
                      dest='target',
                      default='stm32f1',
                      help='Set page size and erase time for TARGET',
                      metavar='TARGET')

    options, args = parser.parse_args()
    data = file(args[0], 'rb').read()
    if len(args) != 1:
        logging.fatal('Specify one, and only one firmware .bin file!')
        sys.exit(1)

    if options.target not in ['stm32f1', 'stm32f4']:
        logging.fatal('Unknown target: %s' % options.target)
        sys.exit(2)

    output_file = options.output_file
    if not output_file:
        if '.bin' in args[0]:
            output_file = args[0].replace('.bin', '.wav')
        else:
            output_file = args[0] + '.wav'

    encoder = QpskEncoder(options.sample_rate, options.carrier_frequency,
                          options.baud_rate, options.packet_size)
    writer = audio_stream_writer.AudioStreamWriter(output_file,
                                                   options.sample_rate, 16, 1)

    # INTRO
    for block in encoder.code_intro():
        writer.append(block)

    blank_duration = 1.0
    if options.target == 'stm32f1':
        for block in encoder.code(data, STM32F1_PAGE_SIZE, 0.06):
            if len(block):
                writer.append(block)
    elif options.target == 'stm32f4':
        for x in xrange(0, len(data), STM32F4_BLOCK_SIZE):
            address = STM32F4_APPLICATION_START + x
            block = data[x:x + STM32F4_BLOCK_SIZE]
            pause = 2.5 if address in STM32F4_SECTOR_BASE_ADDRESS else 0.2
            for block in encoder.code(block, STM32F4_BLOCK_SIZE, pause):
                if len(block):
                    writer.append(block)
        blank_duration = 5.0
    for block in encoder.code_outro(blank_duration):
        writer.append(block)