From 7fc08f780d09c399efad73f46a8c0ec80086e620 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Thu, 23 May 2024 15:17:34 +0000 Subject: [PATCH] Tweaks to telemetry. Load IP/port from config --- src/config.json.sample | 9 ++++++++- src/control.cc | 2 ++ src/stream.cc | 11 ++++++----- src/telem.cc | 26 ++++++++++++++++++-------- src/telem.h | 19 +++++++++++-------- src/videoomx.cc | 8 ++++---- 6 files changed, 49 insertions(+), 26 deletions(-) diff --git a/src/config.json.sample b/src/config.json.sample index e0f9c27..bba00fc 100644 --- a/src/config.json.sample +++ b/src/config.json.sample @@ -42,6 +42,13 @@ "prefer-ipv": 6 }, + "telemetry": + { + /* Enable / disable telemetry with define in telem.h */ + "target_ip": "192.0.2.1", + "target_port": 7777 + }, + "input": { "mod_cec_enabled": true, @@ -60,7 +67,7 @@ // Use these two options: - "lirc_ip": "192.0.2.0", /* Numeric IPv4 or IPv6 */ + "lirc_ip": "192.0.2.1", /* Numeric IPv4 or IPv6 */ "lirc_port": 8765, /* except this, this has a default */ // Or this one: diff --git a/src/control.cc b/src/control.cc index 4a55880..5fe4904 100644 --- a/src/control.cc +++ b/src/control.cc @@ -115,7 +115,9 @@ bool Control::init(bool tcrashed) crashed = tcrashed; logger = LogNT::getInstance(); + #if TELEM_ENABLED == 1 Telemetry::init(); + #endif SkinFactory::InitSkin(0); diff --git a/src/stream.cc b/src/stream.cc index 9af19c7..fc57a0a 100644 --- a/src/stream.cc +++ b/src/stream.cc @@ -109,25 +109,26 @@ int Stream::put(const u1* inbuf, int len, u1 type, unsigned int index) hasdts = true; } - TELEM((localWhich ? 11 : 4), newPacket.pts); - TELEM((localWhich ? 12 : 5), newPacket.dts); + TELEM((localWhich ? 10 : 4), newPacket.pts); + TELEM((localWhich ? 11 : 5), newPacket.dts); //ok we have the pts now convert it to a continously time code in 100ns units if (hasdts && draintarget->dtsTimefix()) newPacket.presentation_time = static_cast(newPacket.dts * 10000LL / 90LL); // Windows only else newPacket.presentation_time = static_cast(newPacket.pts * 10000LL / 90LL); - TELEM((localWhich ? 13 : 6), newPacket.presentation_time); + TELEM((localWhich ? 12 : 6), newPacket.presentation_time); // now PTS & DTS are original, presentation_time is OMX ticks. If it's rolled, it's rolled! //newPacket.presentation_time-=draintarget->SetStartOffset(static_cast(newPacket.pts*10000LL/90LL),&newPacket.disconti); //newPacket.presentation_time -= draintarget->SetStartOffset(static_cast(newPacket.pts * 10000LL / 90LL), &newPacket.disconti); long long returnedStartOffset = draintarget->SetStartOffset(static_cast(newPacket.pts * 10000LL / 90LL), &newPacket.disconti); + TELEM((localWhich ? 13 : 7), returnedStartOffset); + newPacket.presentation_time -= returnedStartOffset; //LogNT::getInstance()->debug("MP", "draintarget {} PTSmod {} disconti {} rso: {}", (void*)draintarget, newPacket.presentation_time, newPacket.disconti, returnedStartOffset); - TELEM((localWhich ? 14 : 7), newPacket.presentation_time); - TELEM((localWhich ? 15 : 8), returnedStartOffset); + TELEM((localWhich ? 14 : 8), newPacket.presentation_time); } } diff --git a/src/telem.cc b/src/telem.cc index 75fb98f..70cb374 100644 --- a/src/telem.cc +++ b/src/telem.cc @@ -17,24 +17,33 @@ along with VOMP. If not, see . */ +#include "telem.h" + +#if TELEM_ENABLED == 1 + + #include #include +#include "config.h" #include "log.h" -#include "telem.h" UDP4 Telemetry::udp; +std::string Telemetry::telemReceiverIP; +const char* Telemetry::ip; +i4 Telemetry::telemPort; void Telemetry::init() { -#if TELEM_ENABLED LogNT::getInstance()->debug("Telem", "Init"); - udp.init(0); - // TODO load target IP / port from config + Config::getInstance()->getString("telemetry", "target_ip", telemReceiverIP); + ip = telemReceiverIP.c_str(); + telemPort = 7777; + Config::getInstance()->getInt("telemetry", "target_port", telemPort); -#endif + udp.init(0); } void Telemetry::message(u4 messageNumber, i4 data) @@ -42,7 +51,7 @@ void Telemetry::message(u4 messageNumber, i4 data) char* buffer; asprintf(&buffer, "%c%c%c%c%i", 1, 1, 1, 1, data); memcpy(buffer, (const void*)&messageNumber, 4); - udp.send("", 7777, buffer, strlen(&buffer[4])+4); + udp.send(ip, telemPort, buffer, strlen(&buffer[4])+4); free(buffer); } @@ -51,7 +60,7 @@ void Telemetry::message(u4 messageNumber, i8 data) char* buffer; asprintf(&buffer, "%c%c%c%c%lli", 1, 1, 1, 1, data); memcpy(buffer, (const void*)&messageNumber, 4); - udp.send("", 7777, buffer, strlen(&buffer[4])+4); + udp.send(ip, telemPort, buffer, strlen(&buffer[4])+4); free(buffer); } @@ -60,7 +69,8 @@ void Telemetry::message(u4 messageNumber, u8 data) char* buffer; asprintf(&buffer, "%c%c%c%c%llu", 1, 1, 1, 1, data); memcpy(buffer, (const void*)&messageNumber, 4); - udp.send("", 7777, buffer, strlen(&buffer[4])+4); + udp.send(ip, telemPort, buffer, strlen(&buffer[4])+4); free(buffer); } +#endif diff --git a/src/telem.h b/src/telem.h index a6b605d..c3e996a 100644 --- a/src/telem.h +++ b/src/telem.h @@ -20,13 +20,18 @@ #ifndef TELEM_H #define TELEM_H -#define TELEM_ENABLED 1 +// Master telemetry enable. If 0 the code isn't included and all +// calls to TELEM() will be deleted by the preprocessor +#define TELEM_ENABLED 0 -#include "defines.h" +#if TELEM_ENABLED == 0 + #define TELEM(x, y) +#else +#include +#include "defines.h" #include "udp4.h" - class Telemetry { public: @@ -37,14 +42,12 @@ class Telemetry private: static UDP4 udp; + static std::string telemReceiverIP; + static const char* ip; + static i4 telemPort; }; -#if TELEM_ENABLED #define TELEM(x, y) Telemetry::message(x, y) -#else - #define TELEM(x, y) #endif - - #endif diff --git a/src/videoomx.cc b/src/videoomx.cc index 8c85707..b83a155 100644 --- a/src/videoomx.cc +++ b/src/videoomx.cc @@ -2798,7 +2798,7 @@ long long VideoOMX::SetStartOffset(long long curreftime, bool* rsync) { rolloveroffset = startoffset; //logger->debug("SSO", "Rollover detected, saving rolloveroffset at {}", rolloveroffset); - TELEM(16, rolloveroffset); + TELEM(9, rolloveroffset); startoffset += curreftime - lastrefvideotime; } @@ -2845,7 +2845,7 @@ long long VideoOMX::SetStartAudioOffset(long long curreftime, bool* rsync) // curreftime, startoffset, rolloveroffset, lastrefaudiotime); rolloveroffset = 0; - TELEM(16, rolloveroffset); + TELEM(9, rolloveroffset); } else { @@ -3217,7 +3217,7 @@ u4 VideoOMX::DeliverMediaPacket(MediaPacket packet, const u1* buffer, u4* sample // logger->debug(TAG, "DMP mark 1"); //logger->debug(TAG, "DeliverMediaPacketOMX time {}", packet.presentation_time); - TELEM(9, packet.presentation_time); + TELEM(15, packet.presentation_time); /*First Check, if we have an video sample*/ if (iframemode) @@ -3337,7 +3337,7 @@ u4 VideoOMX::DeliverMediaPacket(MediaPacket packet, const u1* buffer, u4* sample } lastreftimeOMX = packet.presentation_time; - TELEM(10, lastreftimeOMX); + TELEM(16, lastreftimeOMX); // logger->debug(TAG, "Time code {} pts {}", lastreftimeOMX,packet.pts); lastreftimePTS = packet.pts; cur_input_buf_omx->nTimeStamp = intToOMXTicks(lastreftimeOMX / 10LL); // the clock component is faulty; -- 2.39.5