Fixed issue with new UHD driver blocking SIGINT

master
ismagom 9 years ago
parent a5b52179fa
commit 6c068d061f

@ -34,13 +34,12 @@
#include <sys/time.h>
#include <unistd.h>
#include <assert.h>
#include <signal.h>
#include "srslte/srslte.h"
#include "srslte/cuhd/cuhd.h"
#include "srslte/cuhd/cuhd_utils.h"
#define B210_DEFAULT_GAIN_CORREC 100.0
cell_search_cfg_t cell_detect_config = {
5000, // maximum number of frames to receive for MIB decoding
50, // maximum number of frames to receive for PSS correlation
@ -114,7 +113,16 @@ int parse_args(prog_args_t *args, int argc, char **argv) {
/**********************************************************************/
/* TODO: Do something with the output data */
uint8_t data[10000];
uint8_t data[1000000];
bool go_exit = false;
void sig_int_handler(int signo)
{
printf("SIGINT received. Exiting...\n");
if (signo == SIGINT) {
go_exit = true;
}
}
int cuhd_recv_wrapper(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *q) {
DEBUG(" ---- Receive %d samples ---- \n", nsamples);
@ -167,6 +175,12 @@ int main(int argc, char **argv) {
cuhd_set_rx_gain(uhd, 50);
}
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
signal(SIGINT, sig_int_handler);
cuhd_set_master_clock_rate(uhd, 30.72e6);
/* set receiver frequency */
@ -174,12 +188,18 @@ int main(int argc, char **argv) {
cuhd_rx_wait_lo_locked(uhd);
printf("Tunning receiver to %.3f MHz\n", (double ) prog_args.uhd_freq/1000000);
ret = cuhd_search_and_decode_mib(uhd, &cell_detect_config, prog_args.force_N_id_2, &cell);
if (ret < 0) {
fprintf(stderr, "Error searching cell\n");
return -1;
} else if (ret == 0) {
printf("Cell not found\n");
uint32_t ntrial=0;
do {
ret = cuhd_search_and_decode_mib(uhd, &cell_detect_config, prog_args.force_N_id_2, &cell);
if (ret < 0) {
fprintf(stderr, "Error searching for cell\n");
exit(-1);
} else if (ret == 0 && !go_exit) {
printf("Cell not found after %d trials. Trying again (Press Ctrl+C to exit)\n", ntrial++);
}
} while (ret == 0 && !go_exit);
if (go_exit) {
exit(0);
}
@ -247,7 +267,7 @@ int main(int argc, char **argv) {
float rx_gain_offset = 0;
/* Main loop */
while (sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1) {
while ((sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1) && !go_exit) {
ret = srslte_ue_sync_get_buffer(&ue_sync, &sf_buffer);
if (ret < 0) {

@ -133,6 +133,7 @@ bool go_exit = false;
void sig_int_handler(int signo)
{
printf("SIGINT received. Exiting...\n");
if (signo == SIGINT) {
go_exit = true;
}
@ -177,6 +178,10 @@ int main(int argc, char **argv) {
exit(-1);
}
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
signal(SIGINT, sig_int_handler);
for (freq=0;freq<nof_freqs && !go_exit;freq++) {

@ -33,6 +33,7 @@
#include <sys/select.h>
#include <pthread.h>
#include <semaphore.h>
#include <signal.h>
#include "srslte/srslte.h"
@ -98,6 +99,7 @@ srslte_netsink_t net_sink;
int prbset_num = 1, last_prbset_num = 1;
int prbset_orig = 0;
void usage(char *prog) {
printf("Usage: %s [agmfoncvpu]\n", prog);
#ifndef DISABLE_UHD
@ -297,6 +299,18 @@ void base_free() {
}
}
bool go_exit = false;
void sig_int_handler(int signo)
{
printf("SIGINT received. Exiting...\n");
if (signo == SIGINT) {
go_exit = true;
}
}
unsigned int
reverse(register unsigned int x)
{
@ -491,6 +505,12 @@ int main(int argc, char **argv) {
#ifndef DISABLE_UHD
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
signal(SIGINT, sig_int_handler);
cuhd_set_master_clock_rate(uhd, 30.72e6);
if (!output_file_name) {
@ -525,7 +545,7 @@ int main(int argc, char **argv) {
bool start_of_burst = true;
srslte_softbuffer_tx_reset(&softbuffer);
while (nf < nof_frames || nof_frames == -1) {
while ((nf < nof_frames || nof_frames == -1) && !go_exit) {
for (sf_idx = 0; sf_idx < SRSLTE_NSUBFRAMES_X_FRAME && (nf < nof_frames || nof_frames == -1); sf_idx++) {
bzero(sf_buffer, sizeof(cf_t) * sf_n_re);

@ -227,9 +227,9 @@ void parse_args(prog_args_t *args, int argc, char **argv) {
uint8_t data[20000];
bool go_exit = false;
void sig_int_handler(int signo)
{
printf("SIGINT received. Exiting...\n");
if (signo == SIGINT) {
go_exit = true;
}
@ -304,7 +304,13 @@ int main(int argc, char **argv) {
cuhd_set_rx_gain(uhd, 50);
cell_detect_config.init_agc = 50;
}
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
signal(SIGINT, sig_int_handler);
cuhd_set_master_clock_rate(uhd, 30.72e6);
/* set receiver frequency */
@ -318,11 +324,14 @@ int main(int argc, char **argv) {
if (ret < 0) {
fprintf(stderr, "Error searching for cell\n");
exit(-1);
} else if (ret == 0) {
} else if (ret == 0 && !go_exit) {
printf("Cell not found after %d trials. Trying again (Press Ctrl+C to exit)\n", ntrial++);
}
} while (ret == 0);
} while (ret == 0 && !go_exit);
if (go_exit) {
exit(0);
}
/* set sampling frequency */
int srate = srslte_sampling_freq_hz(cell.nof_prb);
if (srate != -1) {

@ -163,14 +163,6 @@ void parse_args(prog_args_t *args, int argc, char **argv) {
/* TODO: Do something with the output data */
uint8_t data_rx[20000];
bool go_exit = false;
void sig_int_handler(int signo)
{
if (signo == SIGINT) {
go_exit = true;
}
}
int cuhd_recv_wrapper_timed(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *uhd_time) {
DEBUG(" ---- Receive %d samples ---- \n", nsamples);
@ -252,6 +244,15 @@ void rar_msg_fprint(FILE *stream, rar_msg_t *msg)
fprintf(stream, "BI: %d\n", msg->BI);
}
bool go_exit = false;
void sig_int_handler(int signo)
{
printf("SIGINT received. Exiting...\n");
if (signo == SIGINT) {
go_exit = true;
}
}
int rar_unpack(uint8_t *buffer, rar_msg_t *msg)
{
int ret = SRSLTE_ERROR;
@ -311,6 +312,12 @@ int main(int argc, char **argv) {
fprintf(stderr, "Error opening uhd\n");
exit(-1);
}
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
signal(SIGINT, sig_int_handler);
cuhd_set_master_clock_rate(uhd, 30.72e6);
@ -329,38 +336,39 @@ int main(int argc, char **argv) {
printf("Tunning TX receiver to %.3f MHz\n", (double ) prog_args.uhd_tx_freq/1000000);
#ifdef kk
ret = cuhd_search_and_decode_mib(uhd, &cell_detect_config, prog_args.force_N_id_2, &cell);
if (ret < 0) {
fprintf(stderr, "Error searching for cell\n");
exit(-1);
} else if (ret == 0) {
printf("Cell not found\n");
uint32_t ntrial=0;
do {
ret = cuhd_search_and_decode_mib(uhd, &cell_detect_config, prog_args.force_N_id_2, &cell);
if (ret < 0) {
fprintf(stderr, "Error searching for cell\n");
exit(-1);
} else if (ret == 0 && !go_exit) {
printf("Cell not found after %d trials. Trying again (Press Ctrl+C to exit)\n", ntrial++);
}
} while (ret == 0 && !go_exit);
if (go_exit) {
exit(0);
}
#endif
cell.nof_prb = 50;
cell.id = 1;
cell.nof_ports = 1;
/* set sampling frequency */
int srate = srslte_sampling_freq_hz(cell.nof_prb);
if (srate != -1) {
if (srate < 10e6) {
cuhd_set_master_clock_rate(uhd, 4*srate);
} else {
cuhd_set_master_clock_rate(uhd, srate);
}
printf("Setting sampling rate %.2f MHz\n", (float) srate/1000000);
float srate_uhd = cuhd_set_rx_srate(uhd, (double) srate);
if (srate_uhd != srate) {
fprintf(stderr, "Could not set sampling rate\n");
exit(-1);
}
int srate = srslte_sampling_freq_hz(cell.nof_prb);
if (srate != -1) {
if (srate < 10e6) {
cuhd_set_master_clock_rate(uhd, 4*srate);
} else {
fprintf(stderr, "Invalid number of PRB %d\n", cell.nof_prb);
cuhd_set_master_clock_rate(uhd, srate);
}
printf("Setting sampling rate %.2f MHz\n", (float) srate/1000000);
float srate_uhd = cuhd_set_rx_srate(uhd, (double) srate);
if (srate_uhd != srate) {
fprintf(stderr, "Could not set sampling rate\n");
exit(-1);
}
} else {
fprintf(stderr, "Invalid number of PRB %d\n", cell.nof_prb);
exit(-1);
}
INFO("Stopping UHD and flushing buffer...\r",0);
cuhd_stop_rx_stream(uhd);
@ -429,8 +437,7 @@ cell.nof_ports = 1;
uint16_t ra_rnti;
uint32_t conn_setup_trial = 0;
uint32_t ul_sf_idx = 0;
// Register Ctrl+C handler
signal(SIGINT, sig_int_handler);
state = DECODE_MIB;
/* Main loop */

@ -124,6 +124,11 @@ int main(int argc, char **argv) {
}
cuhd_set_master_clock_rate(uhd, 30.72e6);
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
printf("Set RX freq: %.6f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000);
printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_gain));
printf("Set RX rate: %.6f MHz\n", cuhd_set_rx_srate(uhd, uhd_rate*1e6) / 1000000);

@ -125,6 +125,11 @@ int main(int argc, char **argv) {
}
cuhd_set_master_clock_rate(uhd, 30.72e6);
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
printf("Set RX freq: %.6f MHz\n", cuhd_set_rx_freq(uhd, uhd_freq) / 1000000);
printf("Set RX gain: %.1f dB\n", cuhd_set_rx_gain(uhd, uhd_gain));
printf("Set RX rate: %.6f MHz\n", cuhd_set_rx_srate(uhd, srslte_sampling_freq_hz(nof_prb)) / 1000000);

Loading…
Cancel
Save