예제 #1
0
def main():
    """
    Start up everything and run main loop from here.
    """
    # setup a logger
    logfile = "logs/rx-%d.log" % (time.time())
    os.system("mkdir -p logs")
    log = l.logger(logfile)
    log.log("Starting receiver")
    os.system("rm rx-current.log;ln -s %s rx-current.log" % (logfile))

    ic = iono_config.get_config()

    s = ic.s
    log.log("Sweep freqs:")
    log.log(str(s.freqs))
    log.log("Sweep length %1.2f s Freq step %1.2f" %
            (s.sweep_len_s, s.freq_dur))

    # Configuring USRP
    sample_rate = ic.sample_rate

    # number of samples per freq
    N = int(sample_rate * s.freq_dur)

    # configure usrp
    usrp = uhd.usrp.MultiUSRP("addr=%s,recv_buff_size=500000000" %
                              (ic.rx_addr))
    usrp.set_rx_rate(sample_rate)
    subdev_spec = uhd.usrp.SubdevSpec(ic.rx_subdev)
    usrp.set_rx_subdev_spec(subdev_spec)

    # Synchronizing clock
    gl.sync_clock(usrp, log, min_sync_time=ic.min_gps_lock_time)

    # figure out when to start the cycle.
    t_now = usrp.get_time_now().get_real_secs()
    t0 = np.uint64(
        np.floor(t_now / (s.sweep_len_s)) * s.sweep_len_s + s.sweep_len_s)
    print("starting next sweep at %1.2f in %1.2f s, time now %1.2f" %
          (t0, t0 - t_now, t_now))

    # start with initial frequency
    tune_req = uhd.libpyuhd.types.tune_request(s.freq(0))
    usrp.set_rx_freq(tune_req)

    # start reading data
    housekeeping_thread = threading.Thread(target=housekeeping,
                                           args=(usrp, log, ic))
    housekeeping_thread.daemon = True
    housekeeping_thread.start()

    # infinitely loop on receive
    receive_continuous(usrp, t0, t_now, ic, log)
예제 #2
0
                    f0=s.freq(next_freq_idx),
                    gpio_state=gpio_state)
            gpio_state = (gpio_state + 1) % 2

            # check that GPS is still locked.
            gps_mon.check()

        t0 += n.uint64(s.sweep_len_s)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-c',
        '--config',
        default="config/default.ini",
        help='''Configuration file. (default: %(default)s)''',
    )
    parser.add_argument(
        '-v',
        '--verbose',
        action="store_true",
        help='''Increase output verbosity. (default: %(default)s)''',
    )
    op = parser.parse_args()

    ic = iono_config.get_config(config=op.config,
                                write_waveforms=True,
                                quiet=not op.verbose)
    main(ic)
예제 #3
0
파일: tx_uhd.py 프로젝트: peje66/ionosonde
def main():
    """
    The main loop for the ionosonde transmitter
    """
    t_start=time.time()
    os.system("mkdir -p logs")
    logfname="logs/tx-%d.log"%(t_start)
    log=l.logger(logfname)
    os.system("ln -sf %s tx-current.log"%(logfname))
    log.log("Starting TX sweep",print_msg=True)

    # this is the sweep configuration
    ic=iono_config.get_config()
    s=ic.s
    
    sample_rate=ic.sample_rate
    
    # use the address configured for the transmitter
    usrp = uhd.usrp.MultiUSRP("addr=%s"%(ic.tx_addr))
    usrp.set_tx_rate(sample_rate)
    usrp.set_rx_rate(sample_rate)
    
    rx_subdev_spec=uhd.usrp.SubdevSpec(ic.rx_subdev)
    tx_subdev_spec=uhd.usrp.SubdevSpec(ic.tx_subdev)
    
    usrp.set_tx_subdev_spec(tx_subdev_spec)
    usrp.set_rx_subdev_spec(rx_subdev_spec)

    # wait until GPS is locked, then align USRP time with global ref
    gl.sync_clock(usrp,log,min_sync_time=ic.min_gps_lock_time)
    gps_mon=gl.gpsdo_monitor(usrp,log,ic.gps_holdover_time)
    
    # start with first frequency on tx and rx
    tune_req=uhd.libpyuhd.types.tune_request(s.freq(0))
    usrp.set_tx_freq(tune_req)
    usrp.set_rx_freq(tune_req)

    # hold SWR measurement about half of the transmit waveform length, so
    # we have no timing issues
    swr_buffer=n.empty(int(0.5*sample_rate*s.freq_dur),dtype=n.complex64)
     
    # figure out when to start the cycle
    t_now=usrp.get_time_now().get_real_secs()    
    t0=n.uint64(n.floor(t_now/(s.sweep_len_s))*s.sweep_len_s+s.sweep_len_s)
    print("starting next sweep at %1.2f"%(s.sweep_len_s))

    gpio_state=0
    while True:
        log.log("Starting sweep at %1.2f"%(t0))
        for i in range(s.n_freqs):
            f0,dt=s.pars(i)
            
            print("f=%f code %s"%(f0/1e6,s.code(i)))
            transmit_waveform(usrp,n.uint64(t0+dt),s.waveform(i),swr_buffer,f0,log,ic)                
            
            # tune to next frequency 0.0 s before end
            next_freq_idx=(i+1)%s.n_freqs
            tune_at(usrp,t0+dt+s.freq_dur-0.05,ic,f0=s.freq(next_freq_idx),gpio_state=gpio_state)
            gpio_state=(gpio_state+1)%2
            
            # check that GPS is still locked.
            gps_mon.check()

        t0+=n.uint64(s.sweep_len_s)
예제 #4
0
    iono_ofname = "%s/ionogram-%s.h5" % (dname, datestr)
    print("Saving ionogram %s" % (iono_ofname))
    with h5py.File(iono_ofname, "w") as ho:
        ho["I"] = IS
        ho["I_rvec"] = rvec
        ho["t0"] = t0
        ho["lat"] = ic.lat
        ho["lon"] = ic.lon
        ho["I_fvec"] = sfreqs
        ho["ionogram_version"] = 1

    delete_old_files(t0)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-c',
        '--config',
        default="config/default.ini",
        help='''Configuration file. (default: %(default)s)''',
    )
    op = parser.parse_args()

    # don't create waveform files.
    ic = iono_config.get_config(config=op.config, write_waveforms=False)
    print("Starting analysis %s" %
          (datetime.fromtimestamp(time.time()).strftime("%FT%T")))
    analyze_latest_sweep(ic)
예제 #5
0
    ofname="%s/raw-%s.h5"%(dname,datestr)
    if ic.save_raw_voltage:
        save_raw_data(ofname,
                      t0,
                      z_all,
                      ic.s.freqs,
                      ic.station_id,
                      sr=ic.sample_rate/ic.dec,
                      freq_dur=ic.s.freq_dur)

        
    iono_ofname="%s/ionogram-%s.h5"%(dname,datestr)
    print("Saving ionogram %s"%(iono_ofname))
    ho=h5py.File(iono_ofname,"w")
    ho["I"]=IS    
    ho["I_rvec"]=rvec
    ho["t0"]=t0
    ho["lat"]=ic.lat
    ho["lon"]=ic.lon
    ho["I_fvec"]=sfreqs
    ho["ionogram_version"]=1
    ho.close()
    
    delete_old_files(t0)

if __name__ == "__main__":

    ic=iono_config.get_config(write_waveforms=False)
    print("Starting analysis %f"%(time.time()))
    analyze_latest_sweep(ic)