From 4fe05999880d0c6118b7b0a17456afcfc0a340ca Mon Sep 17 00:00:00 2001 From: Jakob Gegeniger Date: Tue, 3 Nov 2026 00:37:12 +0100 Subject: [PATCH] step: less noise --- platform | 2 +- src/sword/mqttChannel.hpp | 51 +++++++++++++++++++++------ src/sword/swordMain.cpp | 26 +++++++------- src/throne/throneMain.cpp | 7 ---- src/throneBridge/throneBridgeMain.cpp | 7 ---- 5 files changed, 56 insertions(+), 37 deletions(-) diff --git a/platform b/platform index dd23ecf..b74f37d 160000 --- a/platform +++ b/platform @@ -1 +1 @@ -Subproject commit dd23ecf4a703a6f45d91b7f2d0b9fbe22c9be8ff +Subproject commit b74f37d99987a7c5aecdc85c8d31e3049f861d3e diff --git a/src/sword/mqttChannel.hpp b/src/sword/mqttChannel.hpp index 98dc191..7587a0f 100644 --- a/src/sword/mqttChannel.hpp +++ b/src/sword/mqttChannel.hpp @@ -17,6 +17,7 @@ class MqttChannel { eventTopic(cfg.StationPath + "event"), statTopic(cfg.StationPath + "stat"), resetTopic(cfg.StationPath + "reset"), + sendTimeout(std::chrono::seconds{10}), serviceCommands({ // cfg-topic @@ -99,7 +100,7 @@ class MqttChannel { static void runMasterService(Thread::Context& ctx, MqttChannel& instance, function resetCall) { while (true) { - auto serMsg = instance.MasterQueue.tryDequeueFor(500ms); + auto serMsg = instance.MasterQueue.tryDequeueFor(50ms); // only resetTopic and cfgTopic arrive here instance.sendStatusMessage(); if (!serMsg) { @@ -174,18 +175,46 @@ class MqttChannel { resetCall(); } + union IoState { + uint32_t raw{}; + struct { + uint32_t mode : 2; + uint32_t mute : 1; + uint32_t sS : 1; + uint32_t sE : 1; + uint32_t sP : 1; + uint32_t lE : 1; + uint32_t v : 3; + uint32_t pD : 4; + } state; + }; + void sendStatusMessage() { try { auto& s = IoStat; - client.send(statTopic, fmt::format("M:{},snd:{},sS:{},sE:{},sP:{},lE:{},v:{},pD:{}", - (int)IoStat.Mode, - !s.Mute, - s.SwordEntry.get(), - s.SwordEnd.get(), - s.SwordPulled.get(), - s.SwordLatch.isLocked(), - s.Volume, - s.PromoDelay)); + IoState ss; + ss.state.mode = (int)IoStat.Mode; + ss.state.mute = s.Mute; + ss.state.sS = s.SwordEntry.get(); + ss.state.sE = s.SwordEnd.get(); + ss.state.sP = s.SwordPulled.get(); + ss.state.lE = s.SwordLatch.isLocked(); + ss.state.v = s.Volume; + ss.state.pD = s.PromoDelay.count(); + + if ((ss.raw != lastState.raw) || sendTimeout.tick()) { + client.send(statTopic, fmt::format("M:{},snd:{},sS:{},sE:{},sP:{},lE:{},v:{},pD:{}", + (int)IoStat.Mode, + !s.Mute, + s.SwordEntry.get(), + s.SwordEnd.get(), + s.SwordPulled.get(), + s.SwordLatch.isLocked(), + s.Volume, + s.PromoDelay)); + sendTimeout.reset(); + } + lastState.raw = ss.raw; } catch (const exception& exc) { fmt::println(stderr, "\nERROR: Unable to connect to Setup bridge: {}", exc.what()); } @@ -217,6 +246,8 @@ class MqttChannel { const string eventTopic; const string statTopic; const string resetTopic; + IoState lastState{}; + Tick sendTimeout; const std::map gameCommands; const std::map serviceCommands; diff --git a/src/sword/swordMain.cpp b/src/sword/swordMain.cpp index 77ecb76..4b559e6 100644 --- a/src/sword/swordMain.cpp +++ b/src/sword/swordMain.cpp @@ -8,7 +8,7 @@ using namespace std::literals::string_view_literals; using namespace std::literals::chrono_literals; using namespace std; -const string Version = "V 0.10.0"; +const string Version = "V 0.10.1"; unique_ptr SwordCfg; unique_ptr IoStat; @@ -47,6 +47,15 @@ int main(int argc, char* argv[]) { fmt::println("## Starting Sword Station {}", Version); + OpMode mode{OpMode::Maintanance}; + fmt::println("{}", app.get_description()); + if (modeArg == "game") { + fmt::println("starting with game"); + mode = OpMode::GamingMode; + } else { + fmt::println("unknown {}", modeArg); + } + CLI11_PARSE(app, argc, argv); std::ostringstream cmdline; for (int i = 0; i < argc; ++i) { @@ -78,14 +87,14 @@ int main(int argc, char* argv[]) { InputTransAware SwordEnd(sePort); InputTransAware SwordPulled(spPort); - log.sendBootUp(Version, MqttChannel::Modes[static_cast(IoStat->Mode)]); + log.sendBootUp(Version, MqttChannel::Modes[static_cast(mode)]); ICurrentMon* pMon = nullptr; try { static I2cMaster i2cDev(II2cMaster::ClockRate::_400k); static AdcAds1115 adc(i2cDev, AdcAds1115::I2CAddress::Gnd); // Check if the ADC is connected if (!adc.isConnected()) { - fmt::println("Failed to connect ot Sensor {}", modeArg); + fmt::println("Failed to connect ot Sensor"); } static CurrMon mon(adc); pMon = &mon; @@ -98,14 +107,7 @@ int main(int argc, char* argv[]) { } LinMot SwordLatch(mOut1, mOut2, *pMon, saveFile); IoStat = make_unique(SwordEntry, SwordEnd, SwordPulled, SwordLatch); - - fmt::println("{}", app.get_description()); - if (modeArg == "game") { - fmt::println("starting with game"); - IoStat->Mode = OpMode::GamingMode; - } else { - fmt::println("unknown {}", modeArg); - } + IoStat->Mode = mode; MqttChannel mqtt(appName, Version, *SwordCfg, *IoStat, log); auto resetCall = [&]() { @@ -148,7 +150,7 @@ void processPromo(MqttChannel& mqtt, SeqLogger& log) { if (IoStat->SwordPulled.isPosEdge()) { if (!IoStat->Mute) { if (dP.tick(IoStat->PromoDelay)) { - log.sendEvent("Pull", "Start Audio"); + log.sendEvent("Promo-Pull", "Start Audio"); if (tsf.tick()) { MediaPlayer::playWavFileAsync(SwordCfg->SoundPromo); diff --git a/src/throne/throneMain.cpp b/src/throne/throneMain.cpp index 2c586cc..bab65d3 100644 --- a/src/throne/throneMain.cpp +++ b/src/throne/throneMain.cpp @@ -279,7 +279,6 @@ void processMaintanence(MqttChannel& mqtt) { } } IoStat->tick(); - mqtt.sendStatusMessage(Mode); } } @@ -304,7 +303,6 @@ void processPromo(MqttChannel& mqtt, SeqLogger& log) { } if (chrono::steady_clock::now() > (tn + 1s)) { tn = chrono::steady_clock::now(); - mqtt.sendStatusMessage(Mode); } } } @@ -341,7 +339,6 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) { while (true) { IoStat->SwordPulled.sample(); if (IoStat->SwordPulled.isPosEdge()) { - mqtt.sendStatusMessage(Mode); // say: You are not the one MediaPlayer::playWavFile(SwordCfg.getSoundDeny()); Thread::sleep(15s); @@ -358,14 +355,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) { while (true) { IoStat->SwordEnd.sample(); if (IoStat->SwordEnd.isNegEdge()) { - mqtt.sendStatusMessage(Mode); break; } } while (true) { IoStat->SwordEntry.sample(); if (IoStat->SwordEntry.isNegEdge()) { - mqtt.sendStatusMessage(Mode); break; } } @@ -379,14 +374,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) { while (true) { IoStat->SwordEnd.sample(); if (IoStat->SwordEnd.isNegEdge()) { - mqtt.sendStatusMessage(Mode); break; } } while (true) { IoStat->SwordEntry.sample(); if (IoStat->SwordEntry.isNegEdge()) { - mqtt.sendStatusMessage(Mode); break; } } diff --git a/src/throneBridge/throneBridgeMain.cpp b/src/throneBridge/throneBridgeMain.cpp index 2e52de6..289e84a 100644 --- a/src/throneBridge/throneBridgeMain.cpp +++ b/src/throneBridge/throneBridgeMain.cpp @@ -282,7 +282,6 @@ void processMaintanence(MqttChannel& mqtt) { } } IoStat->tick(); - mqtt.sendStatusMessage(Mode); } } @@ -307,7 +306,6 @@ void processPromo(MqttChannel& mqtt, SeqLogger& log) { } if (chrono::steady_clock::now() > (tn + 1s)) { tn = chrono::steady_clock::now(); - mqtt.sendStatusMessage(Mode); } } } @@ -344,7 +342,6 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) { while (true) { IoStat->SwordPulled.sample(); if (IoStat->SwordPulled.isPosEdge()) { - mqtt.sendStatusMessage(Mode); // say: You are not the one MediaPlayer::playWavFile(SwordCfg.getSoundDeny()); Thread::sleep(15s); @@ -361,14 +358,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) { while (true) { IoStat->SwordEnd.sample(); if (IoStat->SwordEnd.isNegEdge()) { - mqtt.sendStatusMessage(Mode); break; } } while (true) { IoStat->SwordEntry.sample(); if (IoStat->SwordEntry.isNegEdge()) { - mqtt.sendStatusMessage(Mode); break; } } @@ -382,14 +377,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) { while (true) { IoStat->SwordEnd.sample(); if (IoStat->SwordEnd.isNegEdge()) { - mqtt.sendStatusMessage(Mode); break; } } while (true) { IoStat->SwordEntry.sample(); if (IoStat->SwordEntry.isNegEdge()) { - mqtt.sendStatusMessage(Mode); break; } }