samcrow / uhd-rust

Rust bindings to the UHD (USRP Hardware Driver) library
13 stars 12 forks source link

Can't task X310 with continuous Rx stream #8

Open mwk088 opened 1 year ago

mwk088 commented 1 year ago

I have been using this great repository to write my rust code for finding, probing and tasking Ettus radios. I currently have it working great for the N210 and the B210mini, but cannot get the X310 stream to send packets continuously. Does anyone have any ideas or examples? I have some code pasted below.

Thank you, Mark

`

        const NUM_SAMPLES: usize = 8192;
        let one_packet = true;
        let running = self.running.clone();
        set_running(&running, true);
        let mut chan_len: Vec<usize> = vec![];
        let mut buffer = uhd::alloc_boxed_slice::<Complex<f32>, NUM_SAMPLES>();
        if 1 == self.radio_config.num_ant {
            chan_len = vec![0];
            let mut buffer = uhd::alloc_boxed_slice::<Complex<f32>, NUM_SAMPLES>();
        } else if 2 == self.radio_config.num_ant {
            chan_len = vec![0, 1];
        }

        // Connect to the USRP
        let usrp: &mut Usrp = self.usrp_conn.as_mut().unwrap();

        // let testy = usrp.get_rx_sample_rate(0).unwrap();
        // let testy2 = usrp.get_rx_sample_rate(1).unwrap();
        //Build the streamer
        let args = uhd::StreamArgs::<Complex32>::builder()
            .wire_format("sc16".to_string())
            .channels(chan_len)
            .build();

        // Set up the data type
        let mut receiver = usrp.get_rx_stream(&args).unwrap();
        // Start the Stream
        receiver
            .send_command(&StreamCommand {
                command_type: StreamCommandType::StartContinuous,
                time: StreamTime::Now,
            })
            .into_report()
            .change_context(RadioError::RadioConfigError(format!(
                "Could not Start the Stream"
            )))
            .attach_printable(format!("Could not Start the Stream"))?;

        let mut counter = 0;
        let mut data_vecu8 = vec![0; NUM_SAMPLES];

        let mut recv_meta_handle: uhd_sys::uhd_rx_metadata_handle = ptr::null_mut();
        unsafe { uhd_sys::uhd_rx_metadata_make(&mut recv_meta_handle) };

        'outer: loop {
            let metadata = receiver
                .receive(&mut [buffer.as_mut()], TIMEOUT, one_packet)
                .into_report()
                .change_context(RadioError::RadioConfigError(format!(
                    "Could not receive the samples"
                )))
                .attach_printable(format!("Could not receive the samples"))?;
            let recv_samp = &buffer[..NUM_SAMPLES];
            let f_time = metadata.time_spec().unwrap().fraction;
            let i_time = metadata.time_spec().unwrap().seconds;`