Example #1
0
def run_info(args):
    try:
        file = IQFile(args.file)
    except Exception as e:
        print(e, file=sys.stderr)
        return 1

    print(file.info(), file=sys.stderr)
    return 0
Example #2
0
def run_extract(args):
    try:
        file_in = IQFile(args.input)
    except Exception as e:
        print(e, file=sys.stderr)
        return 1

    # start   stop    length  INVALID
    # start   stop    none    start   stop
    # start   none    length  start   start+length
    # start   none    none    start   end
    # none    stop    length  Stop-length stop
    # none    stop    none    0   stop
    # none    none    length  0   length
    # none    none    none    INVALID

    if args.start and args.stop and args.length:
        raise ExtractError('Too many offset arguments')
    elif args.start and args.stop and not args.length:
        off_start = args.start.to_samples(file_in.sample_rate)
        off_stop  = args.stop.to_samples(file_in.sample_rate)
    elif args.start and not args.stop and args.length:
        off_start = args.start.to_samples(file_in.sample_rate)
        off_stop  = off_start + args.length.to_samples(file_in.sample_rate)
    elif args.start and not args.stop and not args.length:
        off_start = args.start.to_samples(file_in.sample_rate)
        off_stop  = file_in.samples
    elif not args.start and args.stop and args.length:
        off_stop  = args.stop.to_samples(file_in.sample_rate)
        off_start = off_stop - args.length.to_samples(file_in.sample_rate)
    elif not args.start and args.stop and not args.length:
        off_start = 0
        off_stop = args.stop.to_samples(file_in.sample_rate)
    elif not args.start and not args.stop and args.length:
        off_start = 0
        off_stop = args.length.to_samples(file_in.sample_rate)
    else:
        raise ExtractError('No offset arguments given')

    # Sanity checks on borders:
    if not (0 <= off_start <= off_stop <= file_in.samples):
        raise ExtractError('Given offsets not reasonable')

    # Until now, the offsets are in samples:
    byte_start = off_start * file_in.samplesize * 2
    byte_stop  = off_stop  * file_in.samplesize * 2

    file_out = IQFile(args.output, create=True)
    file_out.copy_header(file_in)
    file_out.write_header()

    for block in file_in.read_raw_iq(byte_start, byte_stop):
        file_out.write_iq(block)

    return 0
Example #3
0
def run_tag(args):
    try:
        iqfile = IQFile(args.file)
    except Exception as e:
        print(e, file=sys.stderr)
        return 1

    if (not args.auto and not iqfile.has_header and
            (args.sample_rate is None or args.center is None)):
        print('Missing required arguments --center and --sample-rate', file=sys.stderr)
        return 1

    if args.auto:
        filename = os.path.split(args.file)[1]
        if filename.startswith('gqrx_'):
            try:
                _, date, time, frequency, samplerate, _ = filename.split('_')
                dt = datetime.strptime(date + time, '%Y%m%d%H%M%S')
                frequency = int(frequency)
                samplerate = int(samplerate)
                text = 'Tag autodetected'
            except:
                print('Autodetection not possible, please enter manually', file=sys.stderr)
                return 1
        else:
            print('Autodetection not possible, please enter parameters manually', file=sys.stderr)
            return 1
    elif iqfile.has_header:
        frequency = args.frequency or iqfile.frequency
        samplerate = args.sample_rate or iqfile.sample_rate
        text = args.text or iqfile.text
    else:
        dt = datetime.now()
        frequency = args.center
        samplerate = args.sample_rate
        text = args.text if args.text else ''

    iqfile.frequency = frequency
    iqfile.datetime = dt
    iqfile.sample_rate = samplerate
    iqfile.text = text
    iqfile.write_header()

    return 0