mirror of https://github.com/PentHertz/srsLTE.git
Added option to log_filter to customize time source
This commit is contained in:
parent
88e19ca19d
commit
845fc87945
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "srslte/phy/common/timestamp.h"
|
||||||
#include "srslte/common/log.h"
|
#include "srslte/common/log.h"
|
||||||
#include "srslte/common/logger.h"
|
#include "srslte/common/logger.h"
|
||||||
#include "srslte/common/logger_stdout.h"
|
#include "srslte/common/logger_stdout.h"
|
||||||
|
@ -71,10 +73,25 @@ public:
|
||||||
void info_line(std::string file, int line, std::string message, ...);
|
void info_line(std::string file, int line, std::string message, ...);
|
||||||
void debug_line(std::string file, int line, std::string message, ...);
|
void debug_line(std::string file, int line, std::string message, ...);
|
||||||
|
|
||||||
|
class time_itf {
|
||||||
|
public:
|
||||||
|
virtual srslte_timestamp_t get_time() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
TIME,
|
||||||
|
EPOCH
|
||||||
|
} time_format_t;
|
||||||
|
|
||||||
|
void set_time_src(time_itf *source, time_format_t format);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
logger *logger_h;
|
logger *logger_h;
|
||||||
bool do_tti;
|
bool do_tti;
|
||||||
|
|
||||||
|
time_itf *time_src;
|
||||||
|
time_format_t time_format;
|
||||||
|
|
||||||
logger_stdout def_logger_stdout;
|
logger_stdout def_logger_stdout;
|
||||||
|
|
||||||
void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg);
|
void all_log(srslte::LOG_LEVEL_ENUM level, uint32_t tti, char *msg);
|
||||||
|
|
|
@ -37,7 +37,9 @@ namespace srslte{
|
||||||
|
|
||||||
log_filter::log_filter()
|
log_filter::log_filter()
|
||||||
{
|
{
|
||||||
do_tti = false;
|
do_tti = false;
|
||||||
|
time_src = NULL;
|
||||||
|
time_format = TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_filter::log_filter(std::string layer)
|
log_filter::log_filter(std::string layer)
|
||||||
|
@ -278,7 +280,10 @@ void log_filter::debug_line(std::string file, int line, std::string message, ...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void log_filter::set_time_src(time_itf *source, time_format_t format) {
|
||||||
|
this->time_src = source;
|
||||||
|
this->time_format = format;
|
||||||
|
}
|
||||||
|
|
||||||
std::string log_filter::now_time()
|
std::string log_filter::now_time()
|
||||||
{
|
{
|
||||||
|
@ -287,13 +292,32 @@ std::string log_filter::now_time()
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
char us[16];
|
char us[16];
|
||||||
|
|
||||||
gettimeofday(&rawtime, NULL);
|
srslte_timestamp_t now;
|
||||||
timeinfo = localtime(&rawtime.tv_sec);
|
uint64_t usec_epoch;
|
||||||
|
|
||||||
strftime(buffer,64,"%H:%M:%S",timeinfo);
|
if (!time_src) {
|
||||||
strcat(buffer,".");
|
gettimeofday(&rawtime, NULL);
|
||||||
snprintf(us,16,"%06ld",rawtime.tv_usec);
|
timeinfo = localtime(&rawtime.tv_sec);
|
||||||
strcat(buffer,us);
|
|
||||||
|
if (time_format == TIME) {
|
||||||
|
strftime(buffer, 64, "%H:%M:%S", timeinfo);
|
||||||
|
strcat(buffer, ".");
|
||||||
|
snprintf(us, 16, "%06ld", rawtime.tv_usec);
|
||||||
|
strcat(buffer, us);
|
||||||
|
} else {
|
||||||
|
usec_epoch = rawtime.tv_sec * 1000000 + rawtime.tv_usec;
|
||||||
|
snprintf(buffer, 64, "%ld", usec_epoch);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
now = time_src->get_time();
|
||||||
|
|
||||||
|
if (time_format == TIME) {
|
||||||
|
snprintf(buffer, 64, "%ld:%06u", now.full_secs, (uint32_t) (now.frac_secs * 1e6));
|
||||||
|
} else {
|
||||||
|
usec_epoch = now.full_secs * 1000000 + (uint32_t) (now.frac_secs * 1e6);
|
||||||
|
snprintf(buffer, 64, "%ld", usec_epoch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return std::string(buffer);
|
return std::string(buffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <boost/concept_check.hpp>
|
|
||||||
|
|
||||||
#include "srslte/srslte.h"
|
#include "srslte/srslte.h"
|
||||||
#include "srslte/common/pdu.h"
|
#include "srslte/common/pdu.h"
|
||||||
|
|
Loading…
Reference in New Issue