diff options
-rw-r--r-- | src/DabMod.cpp | 45 | ||||
-rw-r--r-- | src/DabModulator.cpp | 5 | ||||
-rw-r--r-- | src/DabModulator.h | 4 | ||||
-rw-r--r-- | src/EtiReader.cpp | 10 | ||||
-rw-r--r-- | src/EtiReader.h | 35 | ||||
-rw-r--r-- | src/Log.cpp | 22 | ||||
-rw-r--r-- | src/Log.h | 83 | ||||
-rw-r--r-- | src/OutputUHD.cpp | 58 | ||||
-rw-r--r-- | src/TimestampDecoder.cpp | 18 | ||||
-rw-r--r-- | src/TimestampDecoder.h | 19 |
10 files changed, 173 insertions, 126 deletions
diff --git a/src/DabMod.cpp b/src/DabMod.cpp index 0a83120..1974e33 100644 --- a/src/DabMod.cpp +++ b/src/DabMod.cpp @@ -258,7 +258,7 @@ int main(int argc, char* argv[]) goto END_MAIN; } modconf.use_offset_file = true; - modconf.offset_filename = optarg; + modconf.offset_filename = std::string(optarg); outputuhd_conf.enableSync = true; break; case 'm': @@ -440,7 +440,7 @@ int main(int argc, char* argv[]) modconf.use_offset_fixed = true; } else if (delay_mgmt == "dynamic") { - modconf.offset_filename = pt.get<std::string>("delaymanagement.dynamicoffsetfile").c_str(); + modconf.offset_filename = pt.get<std::string>("delaymanagement.dynamicoffsetfile"); modconf.use_offset_file = true; } else { @@ -455,14 +455,14 @@ int main(int argc, char* argv[]) } } - logger(info, "starting up"); + logger.level(info) << "starting up"; // When using offset, enable frame muting outputuhd_conf.muteNoTimestamps = (modconf.use_offset_file || modconf.use_offset_fixed); if (!(modconf.use_offset_file || modconf.use_offset_fixed)) { fprintf(stderr, "No Modulator offset defined, setting to 0\n"); - logger(debug, "No Modulator offset defined, setting to 0"); + logger.level(debug) << "No Modulator offset defined, setting to 0"; modconf.use_offset_fixed = true; modconf.offset_fixed = 0; } @@ -491,12 +491,12 @@ int main(int argc, char* argv[]) fprintf(stderr, "\n"); printUsage(argv[0]); ret = -1; - logger(error, "Received invalid command line arguments"); + logger.level(error) << "Received invalid command line arguments"; goto END_MAIN; } if (!useFileOutput && !useUHDOutput) { - logger(error, "Output not specified"); + logger.level(error) << "Output not specified"; fprintf(stderr, "Must specify output !"); goto END_MAIN; } @@ -526,7 +526,7 @@ int main(int argc, char* argv[]) inputFile = fopen(inputName.c_str(), "r"); if (inputFile == NULL) { fprintf(stderr, "Unable to open input file!\n"); - logger(error, "Unable to open input file!"); + logger.level(error) << "Unable to open input file!"; perror(inputName.c_str()); ret = -1; goto END_MAIN; @@ -548,8 +548,7 @@ int main(int argc, char* argv[]) ((OutputUHD*)output)->enrol_at(*rc); } catch (std::exception& e) { - logger(error, "UHD initialisation failed:"); - logger(error, e.what()); + logger.level(error) << "UHD initialisation failed:" << e.what(); goto END_MAIN; } @@ -558,7 +557,7 @@ int main(int argc, char* argv[]) flowgraph = new Flowgraph(); data.setLength(6144); input = new InputMemory(&data); - modulator = new DabModulator(modconf, rc, outputRate, clockRate, + modulator = new DabModulator(modconf, rc, logger, outputRate, clockRate, dabMode, gainMode, amplitude, filterTapsFilename); flowgraph->connect(input, modulator); flowgraph->connect(modulator, output); @@ -583,7 +582,7 @@ int main(int argc, char* argv[]) if (fread(&sync, sizeof(sync), 1, inputFile) != 1) { fprintf(stderr, "Unable to read sync in input file!\n"); - logger(error, "Unable to read sync in input file!"); + logger.level(error) << "Unable to read sync in input file!"; perror(inputName.c_str()); ret = -1; goto END_MAIN; @@ -599,7 +598,7 @@ int main(int argc, char* argv[]) if (fread(data.getData(), 6144 - sizeof(sync), 1, inputFile) != 1) { fprintf(stderr, "Unable to seek in input file!\n"); - logger(error, "Unable to seek in input file!"); + logger.level(error) << "Unable to seek in input file!"; ret = -1; goto END_MAIN; } @@ -610,7 +609,7 @@ int main(int argc, char* argv[]) nbFrames = sync; if (fread(&frameSize, sizeof(frameSize), 1, inputFile) != 1) { fprintf(stderr, "Unable to read frame size in input file!\n"); - logger(error, "Unable to read frame size in input file!"); + logger.level(error) << "Unable to read frame size in input file!"; perror(inputName.c_str()); ret = -1; goto END_MAIN; @@ -631,7 +630,7 @@ int main(int argc, char* argv[]) if (fread(data.getData(), frameSize - 4, 1, inputFile) != 1) { fprintf(stderr, "Unable to seek in input file!\n"); - logger(error, "Unable to seek in input file!"); + logger.level(error) << "Unable to seek in input file!"; ret = -1; goto END_MAIN; } @@ -641,7 +640,7 @@ int main(int argc, char* argv[]) if (fread(&sync, sizeof(sync), 1, inputFile) != 1) { fprintf(stderr, "Unable to read nb frame in input file!\n"); - logger(error, "Unable to read nb frame in input file!"); + logger.level(error) << "Unable to read nb frame in input file!"; perror(inputName.c_str()); ret = -1; goto END_MAIN; @@ -652,7 +651,7 @@ int main(int argc, char* argv[]) if (fread(data.getData(), frameSize - 4, 1, inputFile) != 1) { fprintf(stderr, "Unable to seek in input file!\n"); - logger(error, "Unable to seek in input file!"); + logger.level(error) << "Unable to seek in input file!"; ret = -1; goto END_MAIN; } @@ -665,7 +664,7 @@ int main(int argc, char* argv[]) sync &= 0xffffff; if (fread((uint8_t*)&sync + 3, 1, 1, inputFile) != 1) { fprintf(stderr, "Unable to read from input file!\n"); - logger(error, "Unable to read from input file!"); + logger.level(error) << "Unable to read from input file!"; ret = 1; goto END_MAIN; } @@ -680,7 +679,7 @@ int main(int argc, char* argv[]) if (fread(data.getData(), 6144 - sizeof(sync), 1, inputFile) != 1) { fprintf(stderr, "Unable to seek in input file!\n"); - logger(error, "Unable to seek in input file!"); + logger.level(error) << "Unable to seek in input file!"; ret = -1; goto END_MAIN; } @@ -690,7 +689,7 @@ int main(int argc, char* argv[]) } fprintf(stderr, "Bad input file format!\n"); - logger(error, "Bad input file format!"); + logger.level(error) << "Bad input file format!"; ret = -1; goto END_MAIN; @@ -708,7 +707,7 @@ START: break; default: fprintf(stderr, "unknown\n"); - logger(error, "Input file format unknown!"); + logger.level(error) << "Input file format unknown!"; ret = -1; goto END_MAIN; } @@ -730,7 +729,7 @@ START: if (fread(&frameSize, sizeof(frameSize), 1, inputFile) != 1) { PDEBUG("End of file!\n"); - logger(error, "Reached end of file!"); + logger.level(error) << "Reached end of file!"; goto END_MAIN; } } @@ -742,7 +741,7 @@ START: frameSize); perror(inputName.c_str()); ret = -1; - logger(error, "Unable to read from input file!"); + logger.level(error) << "Unable to read from input file!"; goto END_MAIN; } memset(&((uint8_t*)data.getData())[frameSize], 0x55, 6144 - frameSize); @@ -785,7 +784,7 @@ END_MAIN: fclose(inputFile); } - logger(info, "Terminating"); + logger.level(info) << "Terminating"; return ret; } diff --git a/src/DabModulator.cpp b/src/DabModulator.cpp index 14c6d3d..662f98a 100644 --- a/src/DabModulator.cpp +++ b/src/DabModulator.cpp @@ -48,22 +48,25 @@ #include "TimeInterleaver.h" #include "TimestampDecoder.h" #include "RemoteControl.h" +#include "Log.h" DabModulator::DabModulator( struct modulator_offset_config& modconf, BaseRemoteController* rc, + Logger& logger, unsigned outputRate, unsigned clockRate, unsigned dabMode, GainMode gainMode, float factor, std::string filterTapsFilename ) : ModCodec(ModFormat(1), ModFormat(0)), + myLogger(logger), myOutputRate(outputRate), myClockRate(clockRate), myDabMode(dabMode), myGainMode(gainMode), myFactor(factor), - myEtiReader(EtiReader(modconf)), + myEtiReader(EtiReader(modconf, myLogger)), myFlowgraph(NULL), myFilterTapsFilename(filterTapsFilename), myRC(rc) diff --git a/src/DabModulator.h b/src/DabModulator.h index e91507c..bc93345 100644 --- a/src/DabModulator.h +++ b/src/DabModulator.h @@ -39,6 +39,7 @@ #include "GainControl.h" #include "OutputMemory.h" #include "RemoteControl.h" +#include "Log.h" class DabModulator : public ModCodec @@ -47,6 +48,7 @@ public: DabModulator( struct modulator_offset_config& modconf, BaseRemoteController* rc, + Logger& logger, unsigned outputRate = 2048000, unsigned clockRate = 0, unsigned dabMode = 0, GainMode gainMode = GAIN_VAR, float factor = 1.0, std::string filterTapsFilename = ""); @@ -60,6 +62,8 @@ public: EtiReader* getEtiReader() { return &myEtiReader; } protected: + Logger& myLogger; + void setMode(unsigned mode); unsigned myOutputRate; diff --git a/src/EtiReader.cpp b/src/EtiReader.cpp index 7e7d4af..fcc0125 100644 --- a/src/EtiReader.cpp +++ b/src/EtiReader.cpp @@ -23,6 +23,7 @@ */ #include "EtiReader.h" +#include "Log.h" #include "PcDebug.h" #include "TimestampDecoder.h" @@ -47,13 +48,16 @@ enum ETI_READER_STATE { }; -EtiReader::EtiReader(struct modulator_offset_config& modconf) : - state(EtiReaderStateSync), myFicSource(NULL) +EtiReader::EtiReader(struct modulator_offset_config& modconf, + Logger& logger) : + myLogger(logger), + state(EtiReaderStateSync), + myFicSource(NULL) { PDEBUG("EtiReader::EtiReader()\n"); myCurrentFrame = 0; - myTimestampDecoder = new TimestampDecoder(modconf); + myTimestampDecoder = new TimestampDecoder(modconf, myLogger); } EtiReader::~EtiReader() diff --git a/src/EtiReader.h b/src/EtiReader.h index 5f4897b..5833a25 100644 --- a/src/EtiReader.h +++ b/src/EtiReader.h @@ -31,6 +31,7 @@ #include "Eti.h" +#include "Log.h" #include "FicSource.h" #include "SubchannelSource.h" #include "TimestampDecoder.h" @@ -42,23 +43,8 @@ class EtiReader { -protected: - void sync(); - int state; - uint32_t nb_frames; - uint16_t framesize; - eti_SYNC eti_sync; - eti_FC eti_fc; - std::vector<eti_STC> eti_stc; - eti_EOH eti_eoh; - eti_EOF eti_eof; - eti_TIST eti_tist; - FicSource* myFicSource; - std::vector<SubchannelSource*> mySources; - TimestampDecoder* myTimestampDecoder; - public: - EtiReader(struct modulator_offset_config& modconf); + EtiReader(struct modulator_offset_config& modconf, Logger& logger); virtual ~EtiReader(); EtiReader(const EtiReader&); EtiReader& operator=(const EtiReader&); @@ -81,9 +67,26 @@ public: bool sourceContainsTimestamp(); protected: + /* Main program logger */ + Logger& myLogger; + /* Transform the ETI TIST to a PPS offset in ms */ double getPPSOffset(); + void sync(); + int state; + uint32_t nb_frames; + uint16_t framesize; + eti_SYNC eti_sync; + eti_FC eti_fc; + std::vector<eti_STC> eti_stc; + eti_EOH eti_eoh; + eti_EOF eti_eof; + eti_TIST eti_tist; + FicSource* myFicSource; + std::vector<SubchannelSource*> mySources; + TimestampDecoder* myTimestampDecoder; + private: size_t myCurrentFrame; bool time_ext_enabled; diff --git a/src/Log.cpp b/src/Log.cpp index 8d04c58..2c4de21 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -24,7 +24,6 @@ */ #include <list> -#include <stdarg.h> #include "Log.h" #include "porting.h" @@ -39,24 +38,17 @@ Logger::register_backend(LogBackend* backend) { //log(info, "Registered new logger " + backend->get_name()); } -void -Logger::operator()(log_level_t level, const char* fmt, ...) { - va_list arg_ptr; - va_start(arg_ptr, fmt); +void +Logger::log(log_level_t level, std::string message) { for (std::list<LogBackend*>::iterator it = backends.begin(); it != backends.end(); it++) { - (*it)->log(level, fmt, arg_ptr); + (*it)->log(level, message); } - va_end(arg_ptr); } -void -Logger::log(log_level_t level, const char* fmt, ...) { - va_list arg_ptr; - va_start(arg_ptr, fmt); - for (std::list<LogBackend*>::iterator it = backends.begin(); it != backends.end(); it++) { - (*it)->log(level, fmt, arg_ptr); - } - va_end(arg_ptr); +LogLine +Logger::level(log_level_t level) +{ + return LogLine(this, level); } @@ -30,14 +30,14 @@ # include "config.h" #endif -#include <string> +#include <stdio.h> #include <syslog.h> -#include <iostream> #include <fstream> +#include <sstream> +#include <iostream> #include <list> #include <stdexcept> - -#include <stdarg.h> +#include <string> #include "porting.h" @@ -46,12 +46,14 @@ enum log_level_t {debug = 0, info, warn, error, alert, emerg}; +/** Abstract class all backends must inherit from */ class LogBackend { public: - virtual void log(log_level_t level, const char* fmt, ...) = 0; + virtual void log(log_level_t level, std::string message) = 0; virtual std::string get_name() = 0; }; +/** A Logging backend for Syslog */ class LogToSyslog : public LogBackend { public: LogToSyslog() { @@ -63,8 +65,7 @@ class LogToSyslog : public LogBackend { closelog(); } - void log(log_level_t level, const char* fmt, ...) { - va_list arg_ptr; + void log(log_level_t level, std::string message) { int syslog_level = LOG_EMERG; switch (level) { @@ -76,9 +77,7 @@ class LogToSyslog : public LogBackend { case emerg: syslog_level = LOG_EMERG; break; } - va_start(arg_ptr, fmt); - syslog(level, fmt, arg_ptr); - va_end(arg_ptr); + syslog(level, SYSLOG_IDENT " %s", message.c_str()); } std::string get_name() { return name; }; @@ -91,55 +90,79 @@ class LogToFile : public LogBackend { public: LogToFile(std::string filename) { name = "FILE"; - log_filename = filename; - log_stream.open(filename.c_str(), std::ios::out | std::ios::app); - if (!log_stream.is_open()) { + log_file = fopen(filename.c_str(), "a"); + if (log_file == NULL) { throw new std::runtime_error("Cannot open log file !"); } } ~LogToFile() { - if (log_stream.is_open()) { - log_stream.close(); + if (log_file != NULL) { + fclose(log_file); } } - void log(log_level_t level, const char* fmt, ...) { - va_list arg_ptr; - char message[200]; + void log(log_level_t level, std::string message) { const char* log_level_text[] = {"DEBUG", "INFO", "WARN", "ERROR", "ALERT", "EMERG"}; - - va_start(arg_ptr, fmt); - snprintf(message, 200, fmt, arg_ptr); - log_stream << "CRC-DABMOD: " << log_level_text[(size_t)level] << ": " << message << std::endl; - log_stream.flush(); - va_end(arg_ptr); + + // fprintf is thread-safe + fprintf(log_file, "CRC-DABMOD: %s: %s\n", log_level_text[(size_t)level], message.c_str()); + fflush(log_file); } std::string get_name() { return name; }; private: std::string name; - std::string log_filename; - std::ofstream log_stream; + FILE* log_file; }; +class LogLine; + class Logger { public: Logger(); void register_backend(LogBackend* backend); - void log(log_level_t level, std::string message) { operator()(level, "%s", message.c_str()); } - void log(log_level_t level, const char* fmt, ...); - - void operator()(log_level_t level, const char* fmt, ...); + /* The LogLevel will call this when a line is complete */ + void log(log_level_t level, std::string message); + /* Return a LogLine for the given level */ + LogLine level(log_level_t level); + private: std::list<LogBackend*> backends; }; +// Accumulate a line of logs, using same syntax as stringstream +class LogLine { + public: + LogLine(const LogLine& logline); + LogLine(Logger* logger, log_level_t level) : + logger_(logger) + { + level_ = level; + } + + template <typename T> + LogLine& operator<<(T s) { + os << s; + return *this; + } + + ~LogLine() + { + logger_->log(level_, os.str()); + } + + private: + std::ostringstream os; + log_level_t level_; + Logger* logger_; +}; + #endif diff --git a/src/OutputUHD.cpp b/src/OutputUHD.cpp index 0f8139d..d750771 100644 --- a/src/OutputUHD.cpp +++ b/src/OutputUHD.cpp @@ -100,16 +100,16 @@ OutputUHD::OutputUHD( MDEBUG("OutputUHD:Actual TX Gain: %f ...\n", myUsrp->get_tx_gain()); if (enable_sync && (config.pps_src == "none")) { - myLogger(warn, "OutputUHD: WARNING: you are using synchronous transmission without PPS input!"); + myLogger.level(warn) << "OutputUHD: WARNING: you are using synchronous transmission without PPS input!"; struct timespec now; if (clock_gettime(CLOCK_REALTIME, &now)) { perror("OutputUHD:Error: could not get time: "); - myLogger(error, "OutputUHD: could not get time"); + myLogger.level(error) << "OutputUHD: could not get time"; } else { myUsrp->set_time_now(uhd::time_spec_t(now.tv_sec)); - myLogger(info, "OutputUHD: Setting USRP time to %f", - uhd::time_spec_t(now.tv_sec).get_real_secs()); + myLogger.level(info) << "OutputUHD: Setting USRP time to " << + uhd::time_spec_t(now.tv_sec).get_real_secs(); } } @@ -120,7 +120,7 @@ OutputUHD::OutputUHD( time_t seconds; if (clock_gettime(CLOCK_REALTIME, &now)) { perror("OutputUHD:Error: could not get time: "); - myLogger(error, "OutputUHD: could not get time"); + myLogger.level(error) << "OutputUHD: could not get time"; } else { seconds = now.tv_sec; @@ -131,7 +131,7 @@ OutputUHD::OutputUHD( if (clock_gettime(CLOCK_REALTIME, &now)) { fprintf(stderr, "errno: %d\n", errno); perror("OutputUHD:Error: could not get time: "); - myLogger(error, "OutputUHD: could not get time"); + myLogger.level(error) << "OutputUHD: could not get time"; break; } } @@ -140,8 +140,8 @@ OutputUHD::OutputUHD( usleep(200000); // 200ms, we want the PPS to be later myUsrp->set_time_unknown_pps(uhd::time_spec_t(seconds + 2)); - myLogger(info, "OutputUHD: Setting USRP time next pps to %f\n", - uhd::time_spec_t(seconds + 2).get_real_secs()); + myLogger.level(info) << "OutputUHD: Setting USRP time next pps to " << + uhd::time_spec_t(seconds + 2).get_real_secs(); } usleep(1e6); @@ -154,7 +154,7 @@ OutputUHD::OutputUHD( uwd.myUsrp = myUsrp; #else fprintf(stderr, "OutputUHD: UHD initialisation disabled at compile-time\n"); - myLogger(error, "OutputUHD: UHD initialisation disabled at compile-time"); + myLogger.level(error) << "OutputUHD: UHD initialisation disabled at compile-time"; #endif uwd.frame0.ts.timestamp_valid = false; @@ -198,7 +198,7 @@ int OutputUHD::process(Buffer* dataIn, Buffer* dataOut) // OutputUHD::process if (first_run) { fprintf(stderr, "OutUHD.process:Initialising...\n"); - myLogger(debug, "OutputUHD: UHD initialising..."); + myLogger.level(debug) << "OutputUHD: UHD initialising..."; uwd.bufsize = dataIn->getLength(); uwd.frame0.buf = malloc(uwd.bufsize); @@ -218,7 +218,7 @@ int OutputUHD::process(Buffer* dataIn, Buffer* dataOut) lastLen = uwd.bufsize; first_run = false; fprintf(stderr, "OutUHD.process:Initialising complete.\n"); - myLogger(debug, "OutputUHD: UHD initialising complete"); + myLogger.level(debug) << "OutputUHD: UHD initialising complete"; } else { @@ -227,7 +227,7 @@ int OutputUHD::process(Buffer* dataIn, Buffer* dataOut) fprintf(stderr, "OutUHD.process:AAAAH PANIC input length changed from %zu to %zu !\n", lastLen, dataIn->getLength()); - myLogger(emerg, "OutputUHD: Fatal error, input length changed !"); + myLogger.level(emerg) << "OutputUHD: Fatal error, input length changed !"; throw std::runtime_error("Non-constant input length!"); } //fprintf(stderr, "OutUHD.process:Waiting for barrier\n"); @@ -284,6 +284,7 @@ void UHDWorker::process(struct UHDWorkerData *uwd) size_t bufsize = myTxStream->get_max_num_samps(); #endif + bool check_refclk_loss = true; const complexf* in; uhd::tx_metadata_t md; @@ -323,11 +324,20 @@ void UHDWorker::process(struct UHDWorkerData *uwd) #if ENABLE_UHD // Check for ref_lock - if (! uwd->myUsrp->get_mboard_sensor("ref_locked", 0).to_bool()) { - fprintf(stderr, "UHDWorker: RefLock lost !\n"); - uwd->logger->log(alert, "OutputUHD: External reference clock lock lost !"); - if (uwd->refclk_lock_loss_behaviour == CRASH) { - throw std::runtime_error("OutputUHD: External reference clock lock lost."); + if (check_refclk_loss) + { + try { + if (! uwd->myUsrp->get_mboard_sensor("ref_locked", 0).to_bool()) { + fprintf(stderr, "UHDWorker: RefLock lost !\n"); + uwd->logger->log(alert, "OutputUHD: External reference clock lock lost !"); + if (uwd->refclk_lock_loss_behaviour == CRASH) { + throw std::runtime_error("OutputUHD: External reference clock lock lost."); + } + } + } + catch (uhd::lookup_error &e) { + check_refclk_loss = false; + uwd->logger->log(warn, "OutputUHD: This USRP does not have mboard sensor for ext clock loss. Check disabled."); } } @@ -343,8 +353,8 @@ void UHDWorker::process(struct UHDWorkerData *uwd) */ fprintf(stderr, "UHDOut: Throwing sample %d away: incomplete timestamp %zu + %f\n", frame->fct, tx_second, pps_offset); - uwd->logger->log(info, "OutputUHD: Throwing sample %d away: incomplete timestamp %zu + %f", - frame->fct, tx_second, pps_offset); + uwd->logger->level(info) << "OutputUHD: Throwing sample " << + frame->fct << " away: incomplete timestamp " << tx_second << " + " << pps_offset; usleep(20000); //TODO should this be TM-dependant ? goto loopend; } @@ -402,7 +412,6 @@ void UHDWorker::process(struct UHDWorkerData *uwd) PDEBUG("UHDWorker::process:max_num_samps: %zu.\n", myTxStream->get_max_num_samps()); - uwd->logger->log(alert, "TX %d: ", frame->fct); /* size_t num_tx_samps = myTxStream->send( dataIn, sizeIn, md, timeout); @@ -494,12 +503,9 @@ void UHDWorker::process(struct UHDWorkerData *uwd) } if (failure) { - fprintf(stderr, "Near frame %d: Received Async UHD Message '%s'\n", - frame->fct, - uhd_async_message); - uwd->logger->log(alert, "Near frame %d: Received Async UHD Message '%s'", - frame->fct, - uhd_async_message); + uwd->logger->level(alert) << "Near frame " << + frame->fct << ": Received Async UHD Message '" << + uhd_async_message << "'"; } } diff --git a/src/TimestampDecoder.cpp b/src/TimestampDecoder.cpp index eb70a56..a0c457a 100644 --- a/src/TimestampDecoder.cpp +++ b/src/TimestampDecoder.cpp @@ -31,6 +31,7 @@ #include "PcDebug.h" #include "TimestampDecoder.h" #include "Eti.h" +#include "Log.h" //#define MDEBUG(fmt, args...) fprintf (LOG, fmt , ## args) #define MDEBUG(fmt, args...) PDEBUG(fmt, ## args) @@ -90,8 +91,8 @@ void TimestampDecoder::calculateTimestamp(struct frame_timestamp& ts) modconfig.delay_calculation_pipeline_stages); if (queue_timestamps.size() > modconfig.delay_calculation_pipeline_stages) { - fprintf(stderr, "Error: Timestamp queue is too large : size %zu ! This should not happen !\n", - queue_timestamps.size()); + myLogger.level(error) << "Error: Timestamp queue is too large : size " << + queue_timestamps.size() << "! This should not happen !"; } //ts.print("calc2 "); @@ -197,7 +198,7 @@ bool TimestampDecoder::updateModulatorOffset() if (modconfig.use_offset_fixed) { timestamp_offset = modconfig.offset_fixed; - PDEBUG("Setting timestamp offset to %f\n", timestamp_offset); + myLogger.level(info) << "Setting fixed offset to " << timestamp_offset; return true; } else if (modconfig.use_offset_file) @@ -210,7 +211,7 @@ bool TimestampDecoder::updateModulatorOffset() try { - filestream.open(modconfig.offset_filename); + filestream.open(modconfig.offset_filename.c_str()); if (!filestream.eof()) { getline(filestream, filedata); @@ -221,20 +222,20 @@ bool TimestampDecoder::updateModulatorOffset() } catch (bad_lexical_cast& e) { - fprintf(stderr, "Error parsing timestamp offset from file\n"); + myLogger.level(error) << "Error parsing timestamp offset from file '" << modconfig.offset_filename << "'"; r = false; } } else { - fprintf(stderr, "Error reading from timestamp offset file: eof reached\n"); + myLogger.level(error) << "Error reading from timestamp offset file: eof reached\n"; r = false; } filestream.close(); } catch (exception& e) { - fprintf(stderr, "Error opening timestamp offset file\n"); + myLogger.level(error) << "Error opening timestamp offset file\n"; r = false; } @@ -244,8 +245,7 @@ bool TimestampDecoder::updateModulatorOffset() if (timestamp_offset != newoffset) { timestamp_offset = newoffset; - fprintf(stderr, "TimestampDecoder::updateTimestampOffset:" \ - "new offset is %f\n", timestamp_offset); + myLogger.level(info) << "TimestampDecoder::updateTimestampOffset: new offset is " << timestamp_offset; offset_changed = true; } diff --git a/src/TimestampDecoder.h b/src/TimestampDecoder.h index f55813f..dcc162e 100644 --- a/src/TimestampDecoder.h +++ b/src/TimestampDecoder.h @@ -26,10 +26,12 @@ #define TIMESTAMP_DECODER_H #include <queue> +#include <string> #include <time.h> #include <math.h> #include <stdio.h> #include "Eti.h" +#include "Log.h" struct modulator_offset_config { @@ -38,7 +40,7 @@ struct modulator_offset_config /* These two fields are used when the modulator is run with a fixed offset */ bool use_offset_file; - const char* offset_filename; + std::string offset_filename; /* These two fields are used when the modulator reads the offset from a file */ unsigned delay_calculation_pipeline_stages; @@ -103,8 +105,10 @@ struct frame_timestamp class TimestampDecoder { public: - TimestampDecoder(struct modulator_offset_config& config): - modconfig(config) + TimestampDecoder( + struct modulator_offset_config& config, + Logger& logger): + myLogger(logger), modconfig(config) { inhibit_second_update = 0; time_pps = 0.0; @@ -113,6 +117,12 @@ class TimestampDecoder full_timestamp_received_mnsc = false; gmtime_r(0, &temp_time); offset_changed = false; + + myLogger.level(info) << "Setting up timestamp decoder with " << + (modconfig.use_offset_fixed ? "fixed" : + (modconfig.use_offset_file ? "dynamic" : "none")) << + " offset"; + }; /* Calculate the timestamp for the current frame. */ @@ -126,6 +136,9 @@ class TimestampDecoder bool updateModulatorOffset(); protected: + /* Main program logger */ + Logger& myLogger; + /* Push a new MNSC field into the decoder */ void pushMNSCData(int framephase, uint16_t mnsc); |