step: Consistent abort msg, live signal and last Will
This commit is contained in:
1 parent
dbe482655c
commit
6443089dc1
5 files changed
+52
-25
No files matched your search
@@ -29,4 +29,18 @@ sudo crontab -e
|
||||
```
|
||||
```txt
|
||||
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
|
||||
```
|
||||
+1
-1
Submodule platform updated: b998471c3f...ef888d8811.
@@ -23,7 +23,8 @@ enum GameModeCommands_e {
|
||||
GameFinished, // The Game is finished (resume to Promo mode)
|
||||
GameNextTryLocked, // Lock 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 {
|
||||
|
||||
@@ -41,10 +41,12 @@ class MqttChannel {
|
||||
{"stayLocked", GameModeCommands_e::GameNextTryLocked},
|
||||
{"releaseLock", GameModeCommands_e::GameNextTryRelease},
|
||||
{"abortTry", GameModeCommands_e::GameAbortTry},
|
||||
{"forceAbort", GameModeCommands_e::GameAbortTry},
|
||||
}),
|
||||
subTopics{{setTopic, cfgTopic, resetTopic}},
|
||||
client(name, cfg.BrockerUrl, subTopics,
|
||||
{cfg.MqttUser, cfg.MqttPassword}) {
|
||||
{cfg.MqttUser, cfg.MqttPassword},
|
||||
MqttClient::LastWill{eventTopic, "offline", 1, false}) {
|
||||
fmt::println("MQTT: Starting task:");
|
||||
mqttCall = [this](string topic, string payload) {
|
||||
fmt::print("MQTT: Got T:'{}' M:'{}'\n", topic, payload);
|
||||
@@ -64,6 +66,7 @@ class MqttChannel {
|
||||
client.registerCallback(mqttCall);
|
||||
|
||||
client.send(verTopic, fmt::format("{}", version));
|
||||
client.send(eventTopic, "online");
|
||||
}
|
||||
|
||||
std::unique_ptr<MqttQe> tryDeque() {
|
||||
|
||||
+31
-22
@@ -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.3";
|
||||
const string Version = "V 0.10.0";
|
||||
|
||||
unique_ptr<SwordConfig> SwordCfg;
|
||||
unique_ptr<DeviceIoState> IoStat;
|
||||
@@ -185,6 +185,23 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
auto& gameCmds = mqtt.getGameCommands();
|
||||
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) {
|
||||
auto msg = mqtt.tryDequeueFor(10ms);
|
||||
IoStat->tick();
|
||||
@@ -208,13 +225,14 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
fmt::println("Got GameStarted");
|
||||
log.sendEvent("Req", "GameStarted");
|
||||
IoStat->GameRunning = true;
|
||||
// system("pinctrl set 6 ip pd");
|
||||
// todo abort all running tests
|
||||
} break;
|
||||
|
||||
case GameModeCommands_e::GameFinished: {
|
||||
fmt::println("Got GameFinished");
|
||||
log.sendEvent("Req", "GameFinished");
|
||||
IoStat->GameRunning = false;
|
||||
// todo abort all running tests
|
||||
} break;
|
||||
|
||||
case GameModeCommands_e::GameNextTryLocked: {
|
||||
@@ -231,9 +249,9 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
mqtt.sendEvent("pull-denied");
|
||||
break;
|
||||
}
|
||||
auto abortMsg = mqtt.tryDequeueFor(10ms);
|
||||
abort = abortMsg && abortMsg->Payload == "abortTry";
|
||||
abort = testAbortCondition(mqtt, "abortTry");
|
||||
}
|
||||
sendLogIfAborted(abort);
|
||||
} break;
|
||||
|
||||
case GameModeCommands_e::GameNextTryRelease: {
|
||||
@@ -253,8 +271,7 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
auto abortMsg = mqtt.tryDequeueFor(10ms);
|
||||
abort = abortMsg && abortMsg->Payload == "abortTry";
|
||||
abort = testAbortCondition(mqtt, "abortTry");
|
||||
}
|
||||
while (!abort) {
|
||||
IoStat->SwordEntry.sample();
|
||||
@@ -262,14 +279,10 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
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;
|
||||
abort = testAbortCondition(mqtt, "abortTry");
|
||||
}
|
||||
sendLogIfAborted(abort);
|
||||
if (abort) break;
|
||||
|
||||
IoStat->SwordEnd.sample(); // still stuck?
|
||||
bool stuckSensor = (!IoStat->SwordEntry.isActive()) && (IoStat->SwordEnd.isActive());
|
||||
@@ -287,8 +300,7 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
fmt::println("..returning sword");
|
||||
break;
|
||||
}
|
||||
auto abortMsg = mqtt.tryDequeueFor(10ms);
|
||||
abort = abortMsg && abortMsg->Payload == "abortTry";
|
||||
abort = testAbortCondition(mqtt, "forceAbort");
|
||||
}
|
||||
if (stuckSensor) {
|
||||
fmt::println("..extra wait due to stuck sensor");
|
||||
@@ -300,14 +312,11 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
||||
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;
|
||||
abort = testAbortCondition(mqtt, "forceAbort");
|
||||
}
|
||||
sendLogIfAborted(abort);
|
||||
if (abort) break;
|
||||
|
||||
log.sendEvent("Game", "Put Back");
|
||||
mqtt.sendEvent("put-in");
|
||||
IoStat->SwordLatch.moveOut(); // Lock
|
||||
|
||||
Reference in new issue
Block a user