step: Consistent abort msg, live signal and last Will

This commit is contained in:
Jakob Gegeniger committed 2026-10-22 21:56:50 +02:00
1 parent dbe482655c
commit 6443089dc1
5 files changed
+54 -27

No files matched your search

+15 -1
View File
@@ -29,4 +29,18 @@ sudo crontab -e
``` ```
```txt ```txt
0 3 * * * /sbin/reboot 0 3 * * * /sbin/reboot
``` 0 23 * * * /sbin/reboot
0 6 * * * /sbin/reboot
*/5 * * * * ping -c 4 8.8.8.8 > /dev/null 2>&1
```
## PowerSavings
```sh
sudo nano /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
```
```ini
[connection]
wifi.powersave = 2
```
Submodule platform updated: b998471c3f...ef888d8811.
+2 -1
View File
@@ -23,7 +23,8 @@ enum GameModeCommands_e {
GameFinished, // The Game is finished (resume to Promo mode) GameFinished, // The Game is finished (resume to Promo mode)
GameNextTryLocked, // Lock sword on next try GameNextTryLocked, // Lock sword on next try
GameNextTryRelease, // Release sword on next try GameNextTryRelease, // Release sword on next try
GameAbortTry // Abort this try GameAbortTry, // Abort this try
GameForceAbort // Abort current state
}; };
enum OutgoingCommands_e { enum OutgoingCommands_e {
+4 -1
View File
@@ -41,10 +41,12 @@ class MqttChannel {
{"stayLocked", GameModeCommands_e::GameNextTryLocked}, {"stayLocked", GameModeCommands_e::GameNextTryLocked},
{"releaseLock", GameModeCommands_e::GameNextTryRelease}, {"releaseLock", GameModeCommands_e::GameNextTryRelease},
{"abortTry", GameModeCommands_e::GameAbortTry}, {"abortTry", GameModeCommands_e::GameAbortTry},
{"forceAbort", GameModeCommands_e::GameAbortTry},
}), }),
subTopics{{setTopic, cfgTopic, resetTopic}}, subTopics{{setTopic, cfgTopic, resetTopic}},
client(name, cfg.BrockerUrl, subTopics, client(name, cfg.BrockerUrl, subTopics,
{cfg.MqttUser, cfg.MqttPassword}) { {cfg.MqttUser, cfg.MqttPassword},
MqttClient::LastWill{eventTopic, "offline", 1, false}) {
fmt::println("MQTT: Starting task:"); fmt::println("MQTT: Starting task:");
mqttCall = [this](string topic, string payload) { mqttCall = [this](string topic, string payload) {
fmt::print("MQTT: Got T:'{}' M:'{}'\n", topic, payload); fmt::print("MQTT: Got T:'{}' M:'{}'\n", topic, payload);
@@ -64,6 +66,7 @@ class MqttChannel {
client.registerCallback(mqttCall); client.registerCallback(mqttCall);
client.send(verTopic, fmt::format("{}", version)); client.send(verTopic, fmt::format("{}", version));
client.send(eventTopic, "online");
} }
std::unique_ptr<MqttQe> tryDeque() { std::unique_ptr<MqttQe> tryDeque() {
+32 -23
View File
@@ -8,7 +8,7 @@ using namespace std::literals::string_view_literals;
using namespace std::literals::chrono_literals; using namespace std::literals::chrono_literals;
using namespace std; using namespace std;
const string Version = "V 0.9.3"; const string Version = "V 0.10.0";
unique_ptr<SwordConfig> SwordCfg; unique_ptr<SwordConfig> SwordCfg;
unique_ptr<DeviceIoState> IoStat; unique_ptr<DeviceIoState> IoStat;
@@ -185,6 +185,23 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
auto& gameCmds = mqtt.getGameCommands(); auto& gameCmds = mqtt.getGameCommands();
static Tick tSend(500ms); static Tick tSend(500ms);
auto sendLogIfAborted = [&log, &mqtt](bool abort) {
if (abort) {
fmt::println("..abort");
log.sendEvent("Req", "Aborted");
mqtt.sendEvent("aborted");
}
};
auto testAbortCondition = [](MqttChannel& mqtt, string cond) -> bool {
auto abortMsg = mqtt.tryDequeueFor(10ms);
return (abortMsg && abortMsg->Payload == cond);
};
auto isDone = [](decltype(std::chrono::steady_clock::now()) until) -> bool {
return std::chrono::steady_clock::now() > until;
};
while (true) { while (true) {
auto msg = mqtt.tryDequeueFor(10ms); auto msg = mqtt.tryDequeueFor(10ms);
IoStat->tick(); IoStat->tick();
@@ -208,13 +225,14 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
fmt::println("Got GameStarted"); fmt::println("Got GameStarted");
log.sendEvent("Req", "GameStarted"); log.sendEvent("Req", "GameStarted");
IoStat->GameRunning = true; IoStat->GameRunning = true;
// system("pinctrl set 6 ip pd"); // todo abort all running tests
} break; } break;
case GameModeCommands_e::GameFinished: { case GameModeCommands_e::GameFinished: {
fmt::println("Got GameFinished"); fmt::println("Got GameFinished");
log.sendEvent("Req", "GameFinished"); log.sendEvent("Req", "GameFinished");
IoStat->GameRunning = false; IoStat->GameRunning = false;
// todo abort all running tests
} break; } break;
case GameModeCommands_e::GameNextTryLocked: { case GameModeCommands_e::GameNextTryLocked: {
@@ -231,9 +249,9 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
mqtt.sendEvent("pull-denied"); mqtt.sendEvent("pull-denied");
break; break;
} }
auto abortMsg = mqtt.tryDequeueFor(10ms); abort = testAbortCondition(mqtt, "abortTry");
abort = abortMsg && abortMsg->Payload == "abortTry";
} }
sendLogIfAborted(abort);
} break; } break;
case GameModeCommands_e::GameNextTryRelease: { case GameModeCommands_e::GameNextTryRelease: {
@@ -253,8 +271,7 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
} }
break; break;
} }
auto abortMsg = mqtt.tryDequeueFor(10ms); abort = testAbortCondition(mqtt, "abortTry");
abort = abortMsg && abortMsg->Payload == "abortTry";
} }
while (!abort) { while (!abort) {
IoStat->SwordEntry.sample(); IoStat->SwordEntry.sample();
@@ -262,16 +279,12 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
fmt::println("..sword pulled"); fmt::println("..sword pulled");
break; break;
} }
auto abortMsg = mqtt.tryDequeueFor(10ms); abort = testAbortCondition(mqtt, "abortTry");
abort = abortMsg && abortMsg->Payload == "abortTry";
}
if (abort) {
fmt::println("..abort");
log.sendEvent("Req", "Aborted Start");
break;
} }
sendLogIfAborted(abort);
if (abort) break;
IoStat->SwordEnd.sample(); // still stuck? IoStat->SwordEnd.sample(); // still stuck?
bool stuckSensor = (!IoStat->SwordEntry.isActive()) && (IoStat->SwordEnd.isActive()); bool stuckSensor = (!IoStat->SwordEntry.isActive()) && (IoStat->SwordEnd.isActive());
mqtt.sendEvent("pulled-out"); mqtt.sendEvent("pulled-out");
@@ -287,8 +300,7 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
fmt::println("..returning sword"); fmt::println("..returning sword");
break; break;
} }
auto abortMsg = mqtt.tryDequeueFor(10ms); abort = testAbortCondition(mqtt, "forceAbort");
abort = abortMsg && abortMsg->Payload == "abortTry";
} }
if (stuckSensor) { if (stuckSensor) {
fmt::println("..extra wait due to stuck sensor"); fmt::println("..extra wait due to stuck sensor");
@@ -300,14 +312,11 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
fmt::println("..sword returned"); fmt::println("..sword returned");
break; break;
} }
auto abortMsg = mqtt.tryDequeueFor(10ms); abort = testAbortCondition(mqtt, "forceAbort");
abort = abortMsg && abortMsg->Payload == "abortTry";
}
if (abort) {
fmt::println("..abortEnd");
log.sendEvent("Req", "Aborted End");
break;
} }
sendLogIfAborted(abort);
if (abort) break;
log.sendEvent("Game", "Put Back"); log.sendEvent("Game", "Put Back");
mqtt.sendEvent("put-in"); mqtt.sendEvent("put-in");
IoStat->SwordLatch.moveOut(); // Lock IoStat->SwordLatch.moveOut(); // Lock