From 8370b97cba3c28d9d2c3e670916142de52d6d0d7 Mon Sep 17 00:00:00 2001 From: alek Date: Fri, 8 Jan 2021 19:14:42 +0100 Subject: [PATCH] [EGD-5155] Change Timers debug functionality Enhanced Timers debug functionality. --- module-gui/gui/core/Timer.hpp | 2 +- module-sys/Service/Timer.cpp | 46 ++++++++++++++++++++--------------- module-sys/Service/Timer.hpp | 2 +- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/module-gui/gui/core/Timer.hpp b/module-gui/gui/core/Timer.hpp index 334e32e0a8d467375a94e3f3f11f41168510d1f6..f6231ca623f4892026a17311445f708ab22bd143 100644 --- a/module-gui/gui/core/Timer.hpp +++ b/module-gui/gui/core/Timer.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once diff --git a/module-sys/Service/Timer.cpp b/module-sys/Service/Timer.cpp index b9e88a5a804c4b89b2f5a79fbbd671543a4e95d8..11ebd53af4f77becaeade684431b1f15d78f99da 100644 --- a/module-sys/Service/Timer.cpp +++ b/module-sys/Service/Timer.cpp @@ -2,21 +2,24 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "Timer.hpp" -#include "Service.hpp" // for Service, Service::Timers -#include "Service/TimerMessage.hpp" // for TimerMessage -#include "log/log.hpp" // for LOG_ERROR -#include "projdefs.h" -#include // for Bus -#include // for numeric_limits -#include // for make_shared -#include // for uint32_t +#include "Service.hpp" +#include "TimerMessage.hpp" +#include "Service/Bus.hpp" +#include +#include +#include +#include +#include #if DEBUG_TIMER == 1 -#define log_timers(...) LOG_DEBUG(__VA_ARGS__) +#define log(...) LOG_DEBUG(__VA_ARGS__) #else -#define log_timers(...) +#define log_debug(...) #endif +#define log_error(...) LOG_ERROR(__VA_ARGS__) +#define log_warn(...) LOG_WARN(__VA_ARGS__) + namespace sys { @@ -36,10 +39,10 @@ namespace sys service->getTimers().attach(this); } else { - LOG_ERROR("Bad timer creation!"); + log_error("Bad timer creation!"); } ++timer_id; - log_timers("Timer %s created %s", name.c_str(), type == Type::Periodic ? "periodic" : "singleshot"); + log_debug("Timer %s created %s", name.c_str(), type == Type::Periodic ? "periodic" : "singleshot"); } Timer::Timer(Service *parent, ms interval, Type type) : Timer("Timer", parent, interval, type) @@ -55,18 +58,18 @@ namespace sys { auto msg = std::make_shared(this); if (parent == nullptr) { - LOG_ERROR("Timer %s error: no parent service", name.c_str()); + log_error("Timer %s error: no parent service", name.c_str()); return; } if (!Bus::SendUnicast(msg, parent->GetName(), parent)) { - LOG_ERROR("Timer %s error: bus error", name.c_str()); + log_error("Timer %s error: bus error", name.c_str()); return; } } void Timer::start() { - log_timers("Timer %s start!", name.c_str()); + log_debug("Timer %s start!", name.c_str()); isActive = true; Start(0); } @@ -78,14 +81,14 @@ namespace sys interval = from_time; SetPeriod(pdMS_TO_TICKS(interval)); } - log_timers("Timer %s reload!", name.c_str()); + log_debug("Timer %s reload!", name.c_str()); isActive = true; Start(0); // start with no waittime } void Timer::stop() { - log_timers("Timer %s stop!", name.c_str()); + log_debug("Timer %s stop!", name.c_str()); // make sure callback is not called even if it is already in the queue isActive = false; Stop(0); @@ -93,17 +96,20 @@ namespace sys void Timer::setInterval(ms new_interval) { - log_timers("Timer %s set interval to: %d ms!", name.c_str(), static_cast(interval)); + log_debug("Timer %s set interval to: %d ms!", name.c_str(), static_cast(interval)); interval = new_interval; SetPeriod(pdMS_TO_TICKS(new_interval), 0); } void Timer::onTimeout() { - log_timers("Timer %s tick", name.c_str()); + log_debug("Timer %s tick", name.c_str()); if (callback != nullptr && isActive) { - log_timers("Timer %s callback run!", name.c_str()); + log_debug("Timer %s callback run!", name.c_str()); callback(*this); + return; } + log_warn( + "callback from %s non valid - %d, or not active - %d", name.c_str(), callback == nullptr, isActive != true); } } // namespace sys diff --git a/module-sys/Service/Timer.hpp b/module-sys/Service/Timer.hpp index d44c27371068d9564e53505669a59ae7cbbff2da..0430bcca66bfdc63d9efce66b8fa8c222c68f35e 100644 --- a/module-sys/Service/Timer.hpp +++ b/module-sys/Service/Timer.hpp @@ -19,7 +19,7 @@ namespace sys using ms = unsigned int; /// Base timer for all coarse timers in system - class Timer : public cpp_freertos::Timer + class Timer : private cpp_freertos::Timer { public: static const ms timeout_infinite;