adding support for phy(C level) logging to file

master
yagoda 7 years ago
parent 754a657285
commit 1b1301101c

@ -700,7 +700,7 @@ int main(int argc, char **argv) {
uint32_t sfn;
srslte_refsignal_t csr_refs;
srslte_refsignal_t mbsfn_refs;
srslte_is_example = 1;
srslte_debug_handle_crash(argc, argv);
#ifdef DISABLE_RF

@ -352,7 +352,7 @@ int main(int argc, char **argv) {
uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
int sfn_offset;
float cfo = 0;
srslte_is_example = 1;
srslte_debug_handle_crash(argc, argv);
parse_args(&prog_args, argc, argv);

@ -0,0 +1,59 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2015 Software Radio Systems Limited
*
* \section LICENSE
*
* This file is part of the srsUE library.
*
* srsUE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* srsUE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
/******************************************************************************
* File: phy_logger.h
* Description: Interface for logging output
*****************************************************************************/
#ifndef PHY_LOGGER_H
#define PHY_LOGGER_H
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
typedef enum {LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_ERROR} phy_logger_level_t;
typedef void (*phy_log_handler_t)(phy_logger_level_t log_level, void *ctx, char *str);
void srslte_phy_log_register_handler(void *ctx, phy_log_handler_t handler);
void srslte_phy_log_print(phy_logger_level_t log_level, const char *format, ...);
#ifdef __cplusplus
}
#endif // C++
#endif // LOGGER_H

@ -37,7 +37,7 @@
#include <stdio.h>
#include "srslte/config.h"
#include "srslte/srslte.h"
#define SRSLTE_VERBOSE_DEBUG 2
#define SRSLTE_VERBOSE_INFO 1
#define SRSLTE_VERBOSE_NONE 0
@ -48,6 +48,7 @@ SRSLTE_API void get_time_interval(struct timeval * tdata);
#define SRSLTE_DEBUG_ENABLED 1
SRSLTE_API extern int srslte_verbose;
SRSLTE_API extern int srslte_is_example;
#define SRSLTE_VERBOSE_ISINFO() (srslte_verbose>=SRSLTE_VERBOSE_INFO)
#define SRSLTE_VERBOSE_ISDEBUG() (srslte_verbose>=SRSLTE_VERBOSE_DEBUG)
@ -57,17 +58,23 @@ SRSLTE_API extern int srslte_verbose;
#define PRINT_INFO srslte_verbose=SRSLTE_VERBOSE_INFO
#define PRINT_NONE srslte_verbose=SRSLTE_VERBOSE_NONE
#define DEBUG(_fmt, ...) if (SRSLTE_DEBUG_ENABLED && srslte_verbose >= SRSLTE_VERBOSE_DEBUG) \
fprintf(stdout, "[DEBUG]: " _fmt, ##__VA_ARGS__)
#define DEBUG(_fmt, ...) if (SRSLTE_DEBUG_ENABLED && srslte_verbose >= SRSLTE_VERBOSE_DEBUG && srslte_is_example)\
{ fprintf(stdout, "[DEBUG]: " _fmt, ##__VA_ARGS__); }\
else{ srslte_phy_log_print(LOG_LEVEL_DEBUG, _fmt, ##__VA_ARGS__); }
#define INFO(_fmt, ...) if (SRSLTE_DEBUG_ENABLED && srslte_verbose >= SRSLTE_VERBOSE_INFO) \
fprintf(stdout, "[INFO]: " _fmt, ##__VA_ARGS__)
#define INFO(_fmt, ...) if (SRSLTE_DEBUG_ENABLED && ((srslte_verbose >= SRSLTE_VERBOSE_INFO)) && srslte_is_example)\
{ fprintf(stdout, "[INFO]: " _fmt, ##__VA_ARGS__); }\
else{ srslte_phy_log_print(LOG_LEVEL_INFO, _fmt, ##__VA_ARGS__); }
#if CMAKE_BUILD_TYPE==Debug
/* In debug mode, it prints out the */
#define ERROR(_fmt, ...) fprintf(stderr, "\e[31m%s.%d: " _fmt "\e[0m\n", __FILE__, __LINE__, ##__VA_ARGS__)
#define ERROR(_fmt, ...) if (srslte_is_example)\
{ fprintf(stderr, "\e[31m%s.%d: " _fmt "\e[0m\n", __FILE__, __LINE__, ##__VA_ARGS__);}\
else {srslte_phy_log_print(LOG_LEVEL_ERROR, _fmt, ##__VA_ARGS__);} //
#else
#define ERROR(_fmt, ...) fprintf(stderr, "[ERROR in %s]:" _fmt "\n", __FUNCTION__, ##__VA_ARGS__)
#define ERROR(_fmt, ...) if (srslte_is_example)\
{ fprintf(stderr, "[ERROR in %s]:" _fmt "\n", __FUNCTION__, ##__VA_ARGS__);}\
else{srslte_phy_log_print(LOG_LEVEL_ERROR, _fmt, ##__VA_ARGS__);} //
#endif /* CMAKE_BUILD_TYPE==Debug */
void srslte_debug_handle_crash(int argc, char **argv);

@ -48,6 +48,7 @@
#include "srslte/phy/common/timestamp.h"
#include "srslte/phy/common/sequence.h"
#include "srslte/phy/common/phy_common.h"
#include "srslte/phy/common/phy_logger.h"
#include "srslte/phy/ch_estimation/chest_ul.h"
#include "srslte/phy/ch_estimation/chest_dl.h"

@ -0,0 +1,59 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2015 Software Radio Systems Limited
*
* \section LICENSE
*
* This file is part of the srsUE library.
*
* srsUE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* srsUE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#include <stdarg.h>
#include "srslte/phy/common/phy_logger.h"
/*********************************************************************
Functions for external logging
*********************************************************************/
static phy_log_handler_t phy_log_handler;
static void *callback_ctx = NULL;
void srslte_phy_log_register_handler(void *ctx, phy_log_handler_t handler) {
phy_log_handler = handler;
callback_ctx = ctx;
}
void srslte_phy_log_print(phy_logger_level_t log_level, const char *format, ...) {
va_list args;
va_start(args, format);
if (phy_log_handler) {
char *args_msg = NULL;
if(vasprintf(&args_msg, format, args) > 0) {
phy_log_handler(log_level, callback_ctx, args_msg);
}
if (args_msg) {
free(args_msg);
}
}
va_end(args);
}

@ -34,6 +34,7 @@
#include "srslte/version.h"
int srslte_verbose = 0;
int srslte_is_example = 0;
void get_time_interval(struct timeval * tdata) {

@ -58,7 +58,7 @@ public:
void set_earfcn(std::vector<uint32_t> earfcn);
void force_freq(float dl_freq, float ul_freq);
void srslte_phy_logger(phy_logger_level_t log_level, char *str);
void reset_sync();
void cell_search_start();
void cell_search_stop();

@ -46,6 +46,30 @@ double callback_set_rx_gain(void *h, double gain) {
return ((phch_recv*) h)->set_rx_gain(gain);
}
static void srslte_phy_handler(phy_logger_level_t log_level, void *ctx, char *str) {
phch_recv *r = (phch_recv *) ctx;
r->srslte_phy_logger(log_level, str);
}
void phch_recv::srslte_phy_logger(phy_logger_level_t log_level, char *str) {
if (log_h) {
switch(log_level){
case LOG_LEVEL_INFO:
log_h->info("[PHY_LAYER]: %s", str);
break;
case LOG_LEVEL_DEBUG:
log_h->debug("[PHY_LAYER]: %s", str);
break;
case LOG_LEVEL_ERROR:
log_h->error("[PHY_LAYER]: %s", str);
break;
default:
break;
}
} else {
printf("[PHY_LAYER]: %s\n", str);
}
}
phch_recv::phch_recv() {
dl_freq = -1;
@ -94,7 +118,7 @@ void phch_recv::init(srslte::radio_multi *_radio_handler, mac_interface_phy *_ma
intra_freq_meas.init(worker_com, rrc, log_h);
reset();
srslte_phy_log_register_handler(this, srslte_phy_handler);
// Start main thread
if (sync_cpu_affinity < 0) {
start(prio);

Loading…
Cancel
Save