From d71569b2f5fdec9992fc3880a412a9fac2c1a2ae Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Tue, 21 May 2024 20:14:02 +0000 Subject: [PATCH] Created basic telemetry system --- src/CMakeLists.txt | 2 +- src/control.cc | 3 +++ src/telem.cc | 66 ++++++++++++++++++++++++++++++++++++++++++++++ src/telem.h | 50 +++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/telem.cc create mode 100644 src/telem.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b1f0dda..63115d7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,7 +23,7 @@ set (VOMP_OBJ_COMMON wmovieview.cc wseriesview.cc wtvmedia.cc wpictureview.cc osdvector.cc surfacevector.cc buffer.cc config.cc log.cc playervideorec.cc playervideolive.cc playerradiolive.cc playerradiorec.cc - imageloader.cc image.cc + imageloader.cc image.cc telem.cc ) set (VOMP_OBJ_RASPBERRY diff --git a/src/control.cc b/src/control.cc index 589174d..4a55880 100644 --- a/src/control.cc +++ b/src/control.cc @@ -35,6 +35,7 @@ #include "inputandroid.h" #endif +#include "telem.h" #include "led.h" #include "video.h" #include "audio.h" @@ -114,6 +115,8 @@ bool Control::init(bool tcrashed) crashed = tcrashed; logger = LogNT::getInstance(); + Telemetry::init(); + SkinFactory::InitSkin(0); // FIXME All constructors first which do very little & don't rely on presence of other objects. diff --git a/src/telem.cc b/src/telem.cc new file mode 100644 index 0000000..75fb98f --- /dev/null +++ b/src/telem.cc @@ -0,0 +1,66 @@ +/* + Copyright 2024 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP. If not, see . +*/ + +#include +#include + +#include "log.h" + +#include "telem.h" + +UDP4 Telemetry::udp; + +void Telemetry::init() +{ +#if TELEM_ENABLED + LogNT::getInstance()->debug("Telem", "Init"); + udp.init(0); + + // TODO load target IP / port from config + +#endif +} + +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); + free(buffer); +} + +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); + free(buffer); +} + +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); + free(buffer); +} + diff --git a/src/telem.h b/src/telem.h new file mode 100644 index 0000000..a6b605d --- /dev/null +++ b/src/telem.h @@ -0,0 +1,50 @@ +/* + Copyright 2024 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP. If not, see . +*/ + +#ifndef TELEM_H +#define TELEM_H + +#define TELEM_ENABLED 1 + +#include "defines.h" + +#include "udp4.h" + + +class Telemetry +{ + public: + static void init(); + static void message(u4 messageNumber, i4 data); + static void message(u4 messageNumber, i8 data); + static void message(u4 messageNumber, u8 data); + + private: + static UDP4 udp; +}; + +#if TELEM_ENABLED + #define TELEM(x, y) Telemetry::message(x, y) +#else + #define TELEM(x, y) +#endif + + + +#endif -- 2.39.2