Example #1
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