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 <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#include <signal.h>
#include "srslte/srslte.h" #include "srslte/srslte.h"
#include "srslte/cuhd/cuhd.h" #include "srslte/cuhd/cuhd.h"
#include "srslte/cuhd/cuhd_utils.h" #include "srslte/cuhd/cuhd_utils.h"
#define B210_DEFAULT_GAIN_CORREC 100.0
cell_search_cfg_t cell_detect_config = { cell_search_cfg_t cell_detect_config = {
5000, // maximum number of frames to receive for MIB decoding 5000, // maximum number of frames to receive for MIB decoding
50, // maximum number of frames to receive for PSS correlation 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 */ /* 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) { int cuhd_recv_wrapper(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *q) {
DEBUG(" ---- Receive %d samples ---- \n", nsamples); DEBUG(" ---- Receive %d samples ---- \n", nsamples);
@ -167,6 +175,12 @@ int main(int argc, char **argv) {
cuhd_set_rx_gain(uhd, 50); 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); cuhd_set_master_clock_rate(uhd, 30.72e6);
/* set receiver frequency */ /* set receiver frequency */
@ -174,12 +188,18 @@ int main(int argc, char **argv) {
cuhd_rx_wait_lo_locked(uhd); cuhd_rx_wait_lo_locked(uhd);
printf("Tunning receiver to %.3f MHz\n", (double ) prog_args.uhd_freq/1000000); printf("Tunning receiver to %.3f MHz\n", (double ) prog_args.uhd_freq/1000000);
uint32_t ntrial=0;
do {
ret = cuhd_search_and_decode_mib(uhd, &cell_detect_config, prog_args.force_N_id_2, &cell); ret = cuhd_search_and_decode_mib(uhd, &cell_detect_config, prog_args.force_N_id_2, &cell);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "Error searching cell\n"); fprintf(stderr, "Error searching for cell\n");
return -1; exit(-1);
} else if (ret == 0) { } else if (ret == 0 && !go_exit) {
printf("Cell not found\n"); 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); exit(0);
} }
@ -247,7 +267,7 @@ int main(int argc, char **argv) {
float rx_gain_offset = 0; float rx_gain_offset = 0;
/* Main loop */ /* 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); ret = srslte_ue_sync_get_buffer(&ue_sync, &sf_buffer);
if (ret < 0) { if (ret < 0) {

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

@ -33,6 +33,7 @@
#include <sys/select.h> #include <sys/select.h>
#include <pthread.h> #include <pthread.h>
#include <semaphore.h> #include <semaphore.h>
#include <signal.h>
#include "srslte/srslte.h" #include "srslte/srslte.h"
@ -98,6 +99,7 @@ srslte_netsink_t net_sink;
int prbset_num = 1, last_prbset_num = 1; int prbset_num = 1, last_prbset_num = 1;
int prbset_orig = 0; int prbset_orig = 0;
void usage(char *prog) { void usage(char *prog) {
printf("Usage: %s [agmfoncvpu]\n", prog); printf("Usage: %s [agmfoncvpu]\n", prog);
#ifndef DISABLE_UHD #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 unsigned int
reverse(register unsigned int x) reverse(register unsigned int x)
{ {
@ -491,6 +505,12 @@ int main(int argc, char **argv) {
#ifndef DISABLE_UHD #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); cuhd_set_master_clock_rate(uhd, 30.72e6);
if (!output_file_name) { if (!output_file_name) {
@ -525,7 +545,7 @@ int main(int argc, char **argv) {
bool start_of_burst = true; bool start_of_burst = true;
srslte_softbuffer_tx_reset(&softbuffer); 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++) { 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); 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]; uint8_t data[20000];
bool go_exit = false; bool go_exit = false;
void sig_int_handler(int signo) void sig_int_handler(int signo)
{ {
printf("SIGINT received. Exiting...\n");
if (signo == SIGINT) { if (signo == SIGINT) {
go_exit = true; go_exit = true;
} }
@ -305,6 +305,12 @@ int main(int argc, char **argv) {
cell_detect_config.init_agc = 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); cuhd_set_master_clock_rate(uhd, 30.72e6);
/* set receiver frequency */ /* set receiver frequency */
@ -318,11 +324,14 @@ int main(int argc, char **argv) {
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "Error searching for cell\n"); fprintf(stderr, "Error searching for cell\n");
exit(-1); 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++); 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 */ /* set sampling frequency */
int srate = srslte_sampling_freq_hz(cell.nof_prb); int srate = srslte_sampling_freq_hz(cell.nof_prb);
if (srate != -1) { 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 */ /* TODO: Do something with the output data */
uint8_t data_rx[20000]; 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) { int cuhd_recv_wrapper_timed(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *uhd_time) {
DEBUG(" ---- Receive %d samples ---- \n", nsamples); 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); 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 rar_unpack(uint8_t *buffer, rar_msg_t *msg)
{ {
int ret = SRSLTE_ERROR; int ret = SRSLTE_ERROR;
@ -312,6 +313,12 @@ int main(int argc, char **argv) {
exit(-1); 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); cuhd_set_master_clock_rate(uhd, 30.72e6);
/* Set receiver gain */ /* Set receiver gain */
@ -329,19 +336,20 @@ int main(int argc, char **argv) {
printf("Tunning TX receiver to %.3f MHz\n", (double ) prog_args.uhd_tx_freq/1000000); printf("Tunning TX receiver to %.3f MHz\n", (double ) prog_args.uhd_tx_freq/1000000);
#ifdef kk uint32_t ntrial=0;
do {
ret = cuhd_search_and_decode_mib(uhd, &cell_detect_config, prog_args.force_N_id_2, &cell); ret = cuhd_search_and_decode_mib(uhd, &cell_detect_config, prog_args.force_N_id_2, &cell);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "Error searching for cell\n"); fprintf(stderr, "Error searching for cell\n");
exit(-1); exit(-1);
} else if (ret == 0) { } else if (ret == 0 && !go_exit) {
printf("Cell not found\n"); 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); exit(0);
} }
#endif
cell.nof_prb = 50;
cell.id = 1;
cell.nof_ports = 1;
/* set sampling frequency */ /* set sampling frequency */
int srate = srslte_sampling_freq_hz(cell.nof_prb); int srate = srslte_sampling_freq_hz(cell.nof_prb);
@ -429,8 +437,7 @@ cell.nof_ports = 1;
uint16_t ra_rnti; uint16_t ra_rnti;
uint32_t conn_setup_trial = 0; uint32_t conn_setup_trial = 0;
uint32_t ul_sf_idx = 0; uint32_t ul_sf_idx = 0;
// Register Ctrl+C handler
signal(SIGINT, sig_int_handler);
state = DECODE_MIB; state = DECODE_MIB;
/* Main loop */ /* Main loop */

@ -124,6 +124,11 @@ int main(int argc, char **argv) {
} }
cuhd_set_master_clock_rate(uhd, 30.72e6); 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 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 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); 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); 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 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 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); printf("Set RX rate: %.6f MHz\n", cuhd_set_rx_srate(uhd, srslte_sampling_freq_hz(nof_prb)) / 1000000);

Loading…
Cancel
Save