From dbe482655c495731fada00b9ce6f4df066cdaa40 Mon Sep 17 00:00:00 2001 From: Jakob Gegeniger Date: Fri, 16 Oct 2026 23:55:31 +0200 Subject: [PATCH] step: version-return --- makefile | 5 +++- src/sword/defines.hpp | 1 + src/sword/mqttChannel.hpp | 12 +++++++++- src/sword/swordMain.cpp | 48 +++++++++++++++++++++++++++------------ 4 files changed, 49 insertions(+), 17 deletions(-) diff --git a/makefile b/makefile index 162fb4c..dd39ed8 100644 --- a/makefile +++ b/makefile @@ -12,4 +12,7 @@ pack_sword: cp_sword: @mkdir -p deploy/sword - @cp build/src/sword/SwordMain deploy/sword \ No newline at end of file + @cp build/src/sword/SwordMain deploy/sword + +cpexe_toServ: + scp build/src/sword/SwordMain gustice@excaliburs-erben.de:SwordMain \ No newline at end of file diff --git a/src/sword/defines.hpp b/src/sword/defines.hpp index 513edb9..8bf30e2 100644 --- a/src/sword/defines.hpp +++ b/src/sword/defines.hpp @@ -15,6 +15,7 @@ enum ServiceCommands_e { PlaySoundPromo, PlaySoundDeny, PlaySoundChosen, + SetMaintanence, }; enum GameModeCommands_e { diff --git a/src/sword/mqttChannel.hpp b/src/sword/mqttChannel.hpp index cf50ec5..cd1baec 100644 --- a/src/sword/mqttChannel.hpp +++ b/src/sword/mqttChannel.hpp @@ -4,8 +4,11 @@ class MqttChannel { public: + static constexpr array Modes = {"Undefined", "Maintanance", "Production"}; + MqttChannel(string name, string version, SwordConfig cfg, DeviceIoState& ioStat, SeqLogger& log) - : Config(cfg), + : Version(version), + Config(cfg), IoStat(ioStat), Logger(log), cfgTopic(cfg.StationPath + "cfg"), @@ -24,6 +27,7 @@ class MqttChannel { {"playSound:Promo", ServiceCommands_e::PlaySoundPromo}, {"playSound:Deny", ServiceCommands_e::PlaySoundDeny}, {"playSound:Chosen", ServiceCommands_e::PlaySoundChosen}, + {"setMaintanance", ServiceCommands_e::SetMaintanence}, }), setCommands({ // cfg-topic @@ -102,6 +106,11 @@ class MqttChannel { if (serMsg->Topic == instance.resetTopic) { return; } + if (serMsg->Payload == "setMaintanance") { + std::string m{Modes[static_cast(instance.IoStat.Mode)]}; + instance.client.send(instance.verTopic, fmt::format("{}", instance.Version)); + continue; + } auto payload = serMsg->Payload; if (payload == "mute") { @@ -204,6 +213,7 @@ class MqttChannel { const std::map& getSerCommands() { return serviceCommands; } private: + std::string Version; SwordConfig Config; Queue MasterQueue; Queue MqttQueue; diff --git a/src/sword/swordMain.cpp b/src/sword/swordMain.cpp index 50cc8e9..4f95c6e 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.9.2"; +const string Version = "V 0.9.3"; unique_ptr SwordCfg; unique_ptr IoStat; @@ -87,8 +87,7 @@ int main(int argc, char* argv[]) { } else { fmt::println("unknown {}", modeArg); } - constexpr array modes = {"Undefined", "Maintanance", "PromoMode", "Production"}; - log.sendBootUp(Version, modes[static_cast(IoStat->Mode)]); + log.sendBootUp(Version, MqttChannel::Modes[static_cast(IoStat->Mode)]); MqttChannel mqtt(appName, Version, *SwordCfg, *IoStat, log); auto resetCall = [&]() { @@ -209,6 +208,7 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) { fmt::println("Got GameStarted"); log.sendEvent("Req", "GameStarted"); IoStat->GameRunning = true; + // system("pinctrl set 6 ip pd"); } break; case GameModeCommands_e::GameFinished: { @@ -227,7 +227,7 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) { // say: You are not the one mqtt.sendEvent("pull"); MediaPlayer::playWavFileSync(SwordCfg->getNextDeny()); - log.sendEvent("Req", "Pulled"); + log.sendEvent("Game", "Pulled"); mqtt.sendEvent("pull-denied"); break; } @@ -243,8 +243,14 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) { IoStat->SwordLatch.moveIn(); while (!abort) { IoStat->SwordEnd.sample(); - if (IoStat->SwordEnd.getState() == pal::InputBiDebounced::State::Passive) { - fmt::println("pulling sword"); + IoStat->SwordEntry.sample(); + if ((!IoStat->SwordEnd.isActive()) || (!IoStat->SwordEntry.isActive())) { + fmt::println("..pulling sword"); + if ((!IoStat->SwordEntry.isActive()) && IoStat->SwordEnd.isActive()) { + // Unplausible state + fmt::println("!Sensor Error"); + log.sendEvent("Err", "Stuck sensor"); + } break; } auto abortMsg = mqtt.tryDequeueFor(10ms); @@ -252,45 +258,57 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) { } while (!abort) { IoStat->SwordEntry.sample(); - if (IoStat->SwordEntry.getState() == pal::InputBiDebounced::State::Passive) { - fmt::println("sword pulled"); + if (!IoStat->SwordEntry.isActive()) { + fmt::println("..sword pulled"); break; } auto abortMsg = mqtt.tryDequeueFor(10ms); abort = abortMsg && abortMsg->Payload == "abortTry"; } if (abort) { + fmt::println("..abort"); + log.sendEvent("Req", "Aborted Start"); break; } + + IoStat->SwordEnd.sample(); // still stuck? + bool stuckSensor = (!IoStat->SwordEntry.isActive()) && (IoStat->SwordEnd.isActive()); + mqtt.sendEvent("pulled-out"); - log.sendEvent("Req", "Pulled Out"); + log.sendEvent("Game", "Pulled Out"); // say: You ARE the one MediaPlayer::playWavFileSync(SwordCfg->getNextAllow()); - log.sendEvent("Req", "Ceremony"); + log.sendEvent("Game", "Ceremony"); mqtt.sendEvent("ceremonyDone"); while (!abort) { IoStat->SwordEntry.sample(); - if (IoStat->SwordEntry.getState() == pal::InputBiDebounced::State::Active) { - fmt::println("returning sword"); + if (IoStat->SwordEntry.isActive()) { + fmt::println("..returning sword"); break; } auto abortMsg = mqtt.tryDequeueFor(10ms); abort = abortMsg && abortMsg->Payload == "abortTry"; } + if (stuckSensor) { + fmt::println("..extra wait due to stuck sensor"); + Thread::sleep(3s); + } while (!abort) { IoStat->SwordEnd.sample(); - if (IoStat->SwordEnd.getState() == pal::InputBiDebounced::State::Active) { - fmt::println("sword returned"); + if (IoStat->SwordEnd.isActive()) { + fmt::println("..sword returned"); break; } auto abortMsg = mqtt.tryDequeueFor(10ms); abort = abortMsg && abortMsg->Payload == "abortTry"; } if (abort) { + fmt::println("..abortEnd"); + log.sendEvent("Req", "Aborted End"); break; } - log.sendEvent("Req", "Put Back"); + log.sendEvent("Game", "Put Back"); mqtt.sendEvent("put-in"); IoStat->SwordLatch.moveOut(); // Lock Thread::sleep(3s);