Allow NULL args in rf_open()

master
ismagom 9 years ago
parent cafb8e1ab0
commit bfd6fca7d0

@ -185,7 +185,7 @@ int rf_blade_open(char *args, void **h)
*h = handler; *h = handler;
printf("Opening bladeRF...\n"); printf("Opening bladeRF...\n");
int status = bladerf_open(&handler->dev, NULL); int status = bladerf_open(&handler->dev, args);
if (status) { if (status) {
fprintf(stderr, "Unable to open device: %s\n", bladerf_strerror(status)); fprintf(stderr, "Unable to open device: %s\n", bladerf_strerror(status));
return status; return status;

@ -101,15 +101,17 @@ const char* srslte_rf_get_devname(srslte_rf_t *rf) {
int srslte_rf_open_devname(srslte_rf_t *rf, char *devname, char *args) { int srslte_rf_open_devname(srslte_rf_t *rf, char *devname, char *args) {
/* Try to open the device if name is provided */ /* Try to open the device if name is provided */
if (devname) { if (devname) {
int i=0; if (devname[0] != '\0') {
while(available_devices[i] != NULL) { int i=0;
if (!strcmp(available_devices[i]->name, devname)) { while(available_devices[i] != NULL) {
rf->dev = available_devices[i]; if (!strcmp(available_devices[i]->name, devname)) {
return available_devices[i]->srslte_rf_open(args, &rf->handler); rf->dev = available_devices[i];
return available_devices[i]->srslte_rf_open(args, &rf->handler);
}
i++;
} }
i++; printf("Device %s not found. Switching to auto mode\n", devname);
} }
printf("Device %s not found. Switching to auto mode\n", devname);
} }
/* If in auto mode or provided device not found, try to open in order of apperance in available_devices[] array */ /* If in auto mode or provided device not found, try to open in order of apperance in available_devices[] array */

@ -204,96 +204,105 @@ float rf_uhd_get_rssi(void *h) {
int rf_uhd_open(char *args, void **h) int rf_uhd_open(char *args, void **h)
{ {
*h = NULL; if (h) {
*h = NULL;
rf_uhd_handler_t *handler = (rf_uhd_handler_t*) malloc(sizeof(rf_uhd_handler_t)); rf_uhd_handler_t *handler = (rf_uhd_handler_t*) malloc(sizeof(rf_uhd_handler_t));
if (!handler) { if (!handler) {
perror("malloc"); perror("malloc");
return -1; return -1;
} }
*h = handler; *h = handler;
/* Set priority to UHD threads */ /* Set priority to UHD threads */
uhd_set_thread_priority(uhd_default_thread_priority, true); uhd_set_thread_priority(uhd_default_thread_priority, true);
/* Set correct options for the USRP device */ /* Set correct options for the USRP device */
uhd_string_vector_handle devices_str; uhd_string_vector_handle devices_str;
uhd_string_vector_make(&devices_str); uhd_string_vector_make(&devices_str);
uhd_usrp_find("", &devices_str); uhd_usrp_find("", &devices_str);
/* If device type or name not given in args, choose a B200 */ // Allow NULL parameter
if (args[0]=='\0') { if (args == NULL) {
// If B200 is available, use it args = "";
if (find_string(devices_str, "type=b200") && !strstr(args, "recv_frame_size")) {
args = "type=b200,recv_frame_size=9232,num_recv_frames=64,send_frame_size=9232,num_send_frames=64";
} }
}
/* Create UHD handler */ /* If device type or name not given in args, choose a B200 */
printf("Opening USRP with args: %s\n", args); if (args[0]=='\0') {
uhd_error error = uhd_usrp_make(&handler->usrp, args); // If B200 is available, use it
if (error) { if (find_string(devices_str, "type=b200") && !strstr(args, "recv_frame_size")) {
fprintf(stderr, "Error opening UHD: code %d\n", error); args = "type=b200,recv_frame_size=9232,num_recv_frames=64,send_frame_size=9232,num_send_frames=64";
return -1; }
} }
size_t channel = 0; /* Create UHD handler */
uhd_stream_args_t stream_args = { printf("Opening USRP with args: %s\n", args);
.cpu_format = "fc32", uhd_error error = uhd_usrp_make(&handler->usrp, args);
.otw_format = "sc16", if (error) {
.args = "", fprintf(stderr, "Error opening UHD: code %d\n", error);
.channel_list = &channel, return -1;
.n_channels = 1 }
};
/* Initialize rx and tx stremers */
uhd_rx_streamer_make(&handler->rx_stream);
error = uhd_usrp_get_rx_stream(handler->usrp, &stream_args, handler->rx_stream);
if (error) {
fprintf(stderr, "Error opening RX stream: %d\n", error);
return -1;
}
uhd_tx_streamer_make(&handler->tx_stream);
error = uhd_usrp_get_tx_stream(handler->usrp, &stream_args, handler->tx_stream);
if (error) {
fprintf(stderr, "Error opening TX stream: %d\n", error);
return -1;
}
uhd_rx_streamer_max_num_samps(handler->rx_stream, &handler->rx_nof_samples); size_t channel = 0;
uhd_tx_streamer_max_num_samps(handler->tx_stream, &handler->tx_nof_samples); uhd_stream_args_t stream_args = {
.cpu_format = "fc32",
uhd_meta_range_make(&handler->rx_gain_range); .otw_format = "sc16",
uhd_usrp_get_rx_gain_range(handler->usrp, "", 0, handler->rx_gain_range); .args = "",
.channel_list = &channel,
// Make metadata objects for RX/TX .n_channels = 1
uhd_rx_metadata_make(&handler->rx_md); };
uhd_rx_metadata_make(&handler->rx_md_first);
uhd_tx_metadata_make(&handler->tx_md, false, 0, 0, false, false); /* Initialize rx and tx stremers */
uhd_rx_streamer_make(&handler->rx_stream);
/* Find out if the master clock rate is configurable */ error = uhd_usrp_get_rx_stream(handler->usrp, &stream_args, handler->rx_stream);
double cur_clock, new_clock; if (error) {
uhd_usrp_get_master_clock_rate(handler->usrp, 0, &cur_clock); fprintf(stderr, "Error opening RX stream: %d\n", error);
printf("Trying to dynamically change Master clock...\n");
uhd_usrp_set_master_clock_rate(handler->usrp, cur_clock/2, 0);
uhd_usrp_get_master_clock_rate(handler->usrp, 0, &new_clock);
if (new_clock == cur_clock) {
handler->dynamic_rate = false;
/* Master clock rate is not configurable. Check if it is compatible with LTE */
int cur_clock_i = (int) cur_clock;
if (cur_clock_i % 1920000) {
fprintf(stderr, "Error: LTE sampling rates are not supported. Master clock rate is %.1f MHz\n", cur_clock/1e6);
return -1; return -1;
}
uhd_tx_streamer_make(&handler->tx_stream);
error = uhd_usrp_get_tx_stream(handler->usrp, &stream_args, handler->tx_stream);
if (error) {
fprintf(stderr, "Error opening TX stream: %d\n", error);
return -1;
}
uhd_rx_streamer_max_num_samps(handler->rx_stream, &handler->rx_nof_samples);
uhd_tx_streamer_max_num_samps(handler->tx_stream, &handler->tx_nof_samples);
uhd_meta_range_make(&handler->rx_gain_range);
uhd_usrp_get_rx_gain_range(handler->usrp, "", 0, handler->rx_gain_range);
// Make metadata objects for RX/TX
uhd_rx_metadata_make(&handler->rx_md);
uhd_rx_metadata_make(&handler->rx_md_first);
uhd_tx_metadata_make(&handler->tx_md, false, 0, 0, false, false);
/* Find out if the master clock rate is configurable */
double cur_clock, new_clock;
uhd_usrp_get_master_clock_rate(handler->usrp, 0, &cur_clock);
printf("Trying to dynamically change Master clock...\n");
uhd_usrp_set_master_clock_rate(handler->usrp, cur_clock/2, 0);
uhd_usrp_get_master_clock_rate(handler->usrp, 0, &new_clock);
if (new_clock == cur_clock) {
handler->dynamic_rate = false;
/* Master clock rate is not configurable. Check if it is compatible with LTE */
int cur_clock_i = (int) cur_clock;
if (cur_clock_i % 1920000) {
fprintf(stderr, "Error: LTE sampling rates are not supported. Master clock rate is %.1f MHz\n", cur_clock/1e6);
return -1;
} else {
printf("Master clock is not configurable. Using standard symbol sizes and sampling rates.\n");
srslte_use_standard_symbol_size(true);
}
} else { } else {
printf("Master clock is not configurable. Using standard symbol sizes and sampling rates.\n"); printf("Master clock is configurable. Using reduced symbol sizes and sampling rates.\n");
srslte_use_standard_symbol_size(true); handler->dynamic_rate = true;
} }
return 0;
} else { } else {
printf("Master clock is configurable. Using reduced symbol sizes and sampling rates.\n"); return SRSLTE_ERROR_INVALID_INPUTS;
handler->dynamic_rate = true;
} }
return 0;
} }

Loading…
Cancel
Save