From 6a48ace06f296b1a113890d80ffa5c19f2f4f58c Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sat, 3 Feb 2024 16:45:09 +0100 Subject: [PATCH] timing calc for longer sleep in host program --- solanaceae/zox/ngc_hs.cpp | 14 +++++++++++++- solanaceae/zox/ngc_hs.hpp | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/solanaceae/zox/ngc_hs.cpp b/solanaceae/zox/ngc_hs.cpp index 1af01d4..a217578 100644 --- a/solanaceae/zox/ngc_hs.cpp +++ b/solanaceae/zox/ngc_hs.cpp @@ -27,7 +27,9 @@ ZoxNGCHistorySync::ZoxNGCHistorySync(ToxEventProviderI& tep, ZoxNGCEventProvider subscribeToEvents(); } -void ZoxNGCHistorySync::tick(float delta) { +float ZoxNGCHistorySync::tick(float delta) { + float min_interval {_delay_next_request_min*60.f}; + // send queued requests for (auto it = _request_queue.begin(); it != _request_queue.end();) { it->second.timer += delta; @@ -57,7 +59,11 @@ void ZoxNGCHistorySync::tick(float delta) { // on failure, assume disconnected it = _request_queue.erase(it); } + + // just choose something small, since we expect a response might arrive soon + min_interval = std::min(min_interval, _delay_between_syncs_min); } else { + min_interval = std::min(min_interval, it->second.delay - it->second.timer); it++; } } @@ -66,6 +72,8 @@ void ZoxNGCHistorySync::tick(float delta) { it->second.timer += delta; if (it->second.timer >= it->second.delay) { it->second.timer = 0.f; + // TODO: set min_interval? + Message3 msg_e = it->second.ents.front(); it->second.ents.pop(); @@ -119,10 +127,14 @@ void ZoxNGCHistorySync::tick(float delta) { it = _sync_queue.erase(it); continue; } + } else { + min_interval = std::min(min_interval, it->second.delay - it->second.timer); } it++; } + + return min_interval; } bool ZoxNGCHistorySync::sendRequest( diff --git a/solanaceae/zox/ngc_hs.hpp b/solanaceae/zox/ngc_hs.hpp index 4196244..57ee957 100644 --- a/solanaceae/zox/ngc_hs.hpp +++ b/solanaceae/zox/ngc_hs.hpp @@ -69,7 +69,7 @@ class ZoxNGCHistorySync : public ToxEventI, public ZoxNGCEventI { public: ZoxNGCHistorySync(ToxEventProviderI& tep, ZoxNGCEventProviderI& zngcepi, ToxI& t, Contact3Registry& cr, ToxContactModel2& tcm, RegistryMessageModel& rmm); - void tick(float delta); + float tick(float delta); public: // always private