// Set up of the B2xx
board---------------------------------------------------------
// Create USRP
uhd_usrp_handle usrp;
fprintf(stderr, "Creating USRP with args \"%s\"...\n", device_args);
EXECUTE_OR_GOTO(free_option_strings,
uhd_usrp_make(&usrp, device_args)
)
// Create RX streamer
uhd_rx_streamer_handle rx_streamer;
EXECUTE_OR_GOTO(free_usrp,
uhd_rx_streamer_make(&rx_streamer)
)
// Create RX metadata
uhd_rx_metadata_handle md;
EXECUTE_OR_GOTO(free_rx_streamer,
uhd_rx_metadata_make(&md)
)
// Create other necessary structs
uhd_tune_request_t tune_request = {
.target_freq = freq,
.rf_freq_policy = UHD_TUNE_REQUEST_POLICY_AUTO,
.dsp_freq_policy = UHD_TUNE_REQUEST_POLICY_AUTO,
};
uhd_tune_result_t tune_result;
uhd_stream_args_t stream_args = {
.cpu_format = "sc16", //sc16
.otw_format = "sc8", //sc8
.args = "",
.channel_list = &channel,
.n_channels = 0
};
// Set rate
fprintf(stderr, "Setting RX Rate: %f...\n", rate);
EXECUTE_OR_GOTO(free_rx_metadata,
uhd_usrp_set_rx_rate(usrp, rate, channel)
)
// See what rate actually is
EXECUTE_OR_GOTO(free_rx_metadata,
uhd_usrp_get_rx_rate(usrp, channel, &rate)
)
fprintf(stderr, "Actual RX Rate: %f...\n", rate);
// Set gain
fprintf(stderr, "Setting RX Gain: %f dB...\n", gain);
EXECUTE_OR_GOTO(free_rx_metadata,
uhd_usrp_set_rx_gain(usrp, gain, channel, "")
)
// See what gain actually is
EXECUTE_OR_GOTO(free_rx_metadata,
uhd_usrp_get_rx_gain(usrp, channel, "", &gain)
)
fprintf(stderr, "Actual RX Gain: %f...\n", gain);
// Set frequency
fprintf(stderr, "Setting RX frequency: %f MHz...\n", freq/1e6);
EXECUTE_OR_GOTO(free_rx_metadata,
uhd_usrp_set_rx_freq(usrp, &tune_request, channel, &tune_result)
)
// See what frequency actually is
EXECUTE_OR_GOTO(free_rx_metadata,
uhd_usrp_get_rx_freq(usrp, channel, &freq)
)
int64_t aux_secs=0,aux_secs_loop=0;
double aux_frac_secs=0.0;
uhd_rx_metadata_error_code_t error_code;
if(use_PPS)
{
printf("Using PPS\n");
EXECUTE_OR_GOTO(free_rx_metadata,
uhd_usrp_set_time_source(usrp, "external",channel)
)
sleep(0.25);
EXECUTE_OR_GOTO(free_rx_metadata,
uhd_usrp_set_clock_source(usrp, "internal",channel)
)
sleep(1.5);
EXECUTE_OR_GOTO(free_rx_metadata,
uhd_usrp_get_time_last_pps(usrp, channel,
&aux_secs,&aux_frac_secs)
)
printf("Get Last PPS.....%d -
%f\n",(int)aux_secs,aux_frac_secs);
do{
EXECUTE_OR_GOTO(free_rx_metadata,
uhd_usrp_get_time_last_pps(usrp, channel,
&aux_secs_loop,&aux_frac_secs)
)
sleep(0.25);
}while(aux_secs==aux_secs_loop);
sleep(1.5);
EXECUTE_OR_GOTO(free_rx_metadata,
uhd_usrp_set_time_next_pps(usrp,0,0.0,channel)
)
sleep(1.5);
}
EXECUTE_OR_GOTO(free_rx_metadata,
uhd_usrp_get_time_now(usrp, channel,
&aux_secs_loop,&aux_frac_secs)
)
printf("Get Time NOW.....%d -
%f\n",(int)aux_secs_loop,aux_frac_secs);
// Set up buffer
samps_per_buff_2=samps_per_buff;
EXECUTE_OR_GOTO(free_rx_streamer,
uhd_rx_streamer_max_num_samps(rx_streamer, &samps_per_buff_2)
)
uhd_stream_cmd_t stream_cmd = {
.stream_mode = UHD_STREAM_MODE_START_CONTINUOUS,
.num_samps = 0,
.stream_now = false,
.time_spec_full_secs = 2
};
EXECUTE_OR_GOTO(free_rx_streamer,
uhd_usrp_get_rx_stream(usrp, &stream_args, rx_streamer)
)
EXECUTE_OR_GOTO(free_buffer,
uhd_rx_streamer_issue_stream_cmd(rx_streamer, &stream_cmd)
)
// Ettus B2xx Read loop
for(loop_samps=0;loop_samps<tot_samps;loop_samps++)
{
num_rx_samps = 0;
EXECUTE_OR_GOTO(close_file,
uhd_rx_streamer_recv(rx_streamer, buffs_ptr,
samps_per_buff, &md, 3.0, false, &num_rx_samps) //Actual reading.
)
EXECUTE_OR_GOTO(close_file,
uhd_rx_metadata_error_code(md, &error_code)
)
if(error_code != UHD_RX_METADATA_ERROR_CODE_NONE){ // If there
is an error in the reading it will breake the loop and jump to close
the file.
fprintf(stderr, "Error code 0x%x was returned during
streaming. Aborting.\n", return_code);
goto close_file;
}
num_rx_samps2=num_rx_samps;
if(fork_start==1){ //Wait for child process to finish, only
after first run..
sem_wait(fft_done);}
memcpy(glob_var,buff,(samps_per_buff * 2 * sizeof(d_type)));
sem_post(fft_start); // realse the child process for the FFT
and kept reading.
fork_start=1;
if (verbose) {
time_t full_secs;
double frac_secs;
uhd_rx_metadata_time_spec(md, &full_secs, &frac_secs);
fprintf(stderr, "Received packet: %zu samps request
%zu samples recieved, %d full secs, %f frac secs\n",
samps_per_buff,
num_rx_samps,
(int)full_secs,
frac_secs);
}
if(*fft_go==5)
goto close_file;
num_acc_samps += num_rx_samps;
}
El lun., 22 abr. 2019 a las 23:16, Marcus D. Leech via USRP-users
(<usrp-users@lists.ettus.com>) escribió:
On 04/22/2019 09:36 PM, Guillermo Gancio via USRP-users wrote:
Hi all,
I have a question trying to sync the start of data burst with a PPS signal.
With the options....
.stream_mode = UHD_STREAM_MODE_START_CONTINUOUS,
.num_samps = 0,
.stream_now = true
the code works ok, but when I change to....
.stream_now = false,
.time_spec_full_secs = 2
The code gives...
UHD Error:
The receive packet handler caught a value exception.
ValueError: bad vrt header or packet fragment
Error code 0x0 was returned during streaming. Aborting.
Before this I set the time_source to external and set the next PPS to 0 with...
You might need to share more of your code, and also, what version of UHD
are you using?
EXECUTE_OR_GOTO(free_rx_metadata,uhd_usrp_get_time_last_pps(usrp,
channel, &aux_secs,&aux_frac_secs) )
do{
sleep(0.25);
EXECUTE_OR_GOTO(free_rx_metadata,
uhd_usrp_get_time_last_pps(usrp, channel,
&aux_secs_loop,&aux_frac_secs) )
}while(aux_secs==aux_secs_loop);
sleep(0.25);
EXECUTE_OR_GOTO(free_rx_metadata,
uhd_usrp_set_time_next_pps(usrp, 0, 0.0,channel))
Any help will be very appreciated!
Thanks!
_______________________________________________
USRP-users mailing list
USRP-users@lists.ettus.com
http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com
_______________________________________________
USRP-users mailing list
USRP-users@lists.ettus.com
http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com