From: Lars Op den Kamp Date: Sat, 8 Oct 2011 09:29:52 +0000 (+0200) Subject: cec: fix GetTimeMs() on linux. add time in ms since startup to log messages X-Git-Tag: upstream/2.2.0~1^2~274 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=403398523c7fbae86cbc527473ea54d78bb3d763;p=deb_libcec.git cec: fix GetTimeMs() on linux. add time in ms since startup to log messages --- diff --git a/include/CECExports.h b/include/CECExports.h index d1a7414..47dcdff 100644 --- a/include/CECExports.h +++ b/include/CECExports.h @@ -243,6 +243,7 @@ namespace CEC { { char message[1024]; cec_log_level level; + int64_t time; } cec_log_message; typedef struct cec_keypress diff --git a/src/lib/AdapterCommunication.cpp b/src/lib/AdapterCommunication.cpp index 68f31a4..8ddeaa6 100644 --- a/src/lib/AdapterCommunication.cpp +++ b/src/lib/AdapterCommunication.cpp @@ -193,7 +193,7 @@ bool CAdapterCommunication::Write(const cec_frame &data) m_controller->AddLog(CEC_LOG_DEBUG, "command sent"); - CCondition::Sleep((uint32_t) data.size * (uint32_t)24 /*data*/ + (uint32_t)5 /*start bit (4.5 ms)*/ + (uint32_t)50 /* to be on the safe side */); + CCondition::Sleep((uint32_t) data.size * (uint32_t)24 /*data*/ + (uint32_t)5 /*start bit (4.5 ms)*/); } return true; diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 0f88470..2f76815 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -42,6 +42,7 @@ using namespace std; using namespace CEC; CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) : + m_iStartTime(GetTimeMs()), m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN), m_buttontime(0) { @@ -183,6 +184,7 @@ void CLibCEC::AddLog(cec_log_level level, const string &strMessage) { cec_log_message message; message.level = level; + message.time = GetTimeMs() - m_iStartTime; snprintf(message.message, sizeof(message.message), "%s", strMessage.c_str()); m_logBuffer.Push(message); } diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index 2a84952..013288e 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -80,6 +80,7 @@ namespace CEC virtual void SetCurrentButton(cec_user_control_code iButtonCode); protected: + int64_t m_iStartTime; cec_user_control_code m_iCurrentButton; int64_t m_buttontime; CCECProcessor *m_cec; diff --git a/src/lib/platform/timeutils.h b/src/lib/platform/timeutils.h index c414020..20b6eff 100644 --- a/src/lib/platform/timeutils.h +++ b/src/lib/platform/timeutils.h @@ -19,7 +19,7 @@ */ #include -#include +#include namespace CEC { @@ -38,10 +38,9 @@ namespace CEC } return -1; #else - struct timespec time; - clock_gettime(CLOCK_MONOTONIC, &time); - - return ((int64_t)time.tv_sec * (int64_t)1000) + (int64_t)time.tv_nsec / (int64_t)1000; + timeval time; + gettimeofday(&time, NULL); + return (int64_t) (time.tv_sec * 1000 + time.tv_usec / 1000); #endif } diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index c239d3b..4156d05 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -105,18 +105,22 @@ void flush_log(ICECAdapter *cecParser) switch (message.level) { case CEC_LOG_ERROR: - cout << "ERROR: " << message.message << endl; + cout << "ERROR: "; break; case CEC_LOG_WARNING: - cout << "WARNING: " << message.message << endl; + cout << "WARNING: "; break; case CEC_LOG_NOTICE: - cout << "NOTICE: " << message.message << endl; + cout << "NOTICE: "; break; case CEC_LOG_DEBUG: - cout << "DEBUG: " << message.message << endl; + cout << "DEBUG: "; break; } + + CStdString strMessageTmp; + strMessageTmp.Format("[%16lld]\t%s", message.time, message.message); + cout << strMessageTmp.c_str() << endl; } }