Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27a791c4c0 | ||
|
|
dbe482655c |
No files matched your search
+15
-1
@@ -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
|
||||||
|
```
|
||||||
@@ -12,4 +12,7 @@ pack_sword:
|
|||||||
|
|
||||||
cp_sword:
|
cp_sword:
|
||||||
@mkdir -p deploy/sword
|
@mkdir -p deploy/sword
|
||||||
@cp build/src/sword/SwordMain deploy/sword
|
@cp build/src/sword/SwordMain deploy/sword
|
||||||
|
|
||||||
|
cpexe_toServ:
|
||||||
|
scp build/src/sword/SwordMain gustice@excaliburs-erben.de:SwordMain
|
||||||
+1
-1
Submodule platform updated: b998471c3f...387735f701.
@@ -15,6 +15,7 @@ enum ServiceCommands_e {
|
|||||||
PlaySoundPromo,
|
PlaySoundPromo,
|
||||||
PlaySoundDeny,
|
PlaySoundDeny,
|
||||||
PlaySoundChosen,
|
PlaySoundChosen,
|
||||||
|
SetMaintanence,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum GameModeCommands_e {
|
enum GameModeCommands_e {
|
||||||
@@ -22,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,8 +4,11 @@
|
|||||||
|
|
||||||
class MqttChannel {
|
class MqttChannel {
|
||||||
public:
|
public:
|
||||||
|
static constexpr array<const char*, 3> Modes = {"Undefined", "Maintanance", "Production"};
|
||||||
|
|
||||||
MqttChannel(string name, string version, SwordConfig cfg, DeviceIoState& ioStat, SeqLogger& log)
|
MqttChannel(string name, string version, SwordConfig cfg, DeviceIoState& ioStat, SeqLogger& log)
|
||||||
: Config(cfg),
|
: Version(version),
|
||||||
|
Config(cfg),
|
||||||
IoStat(ioStat),
|
IoStat(ioStat),
|
||||||
Logger(log),
|
Logger(log),
|
||||||
cfgTopic(cfg.StationPath + "cfg"),
|
cfgTopic(cfg.StationPath + "cfg"),
|
||||||
@@ -24,6 +27,7 @@ class MqttChannel {
|
|||||||
{"playSound:Promo", ServiceCommands_e::PlaySoundPromo},
|
{"playSound:Promo", ServiceCommands_e::PlaySoundPromo},
|
||||||
{"playSound:Deny", ServiceCommands_e::PlaySoundDeny},
|
{"playSound:Deny", ServiceCommands_e::PlaySoundDeny},
|
||||||
{"playSound:Chosen", ServiceCommands_e::PlaySoundChosen},
|
{"playSound:Chosen", ServiceCommands_e::PlaySoundChosen},
|
||||||
|
{"setMaintanance", ServiceCommands_e::SetMaintanence},
|
||||||
}),
|
}),
|
||||||
setCommands({
|
setCommands({
|
||||||
// cfg-topic
|
// cfg-topic
|
||||||
@@ -37,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);
|
||||||
@@ -60,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() {
|
||||||
@@ -102,6 +109,11 @@ class MqttChannel {
|
|||||||
if (serMsg->Topic == instance.resetTopic) {
|
if (serMsg->Topic == instance.resetTopic) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (serMsg->Payload == "setMaintanance") {
|
||||||
|
std::string m{Modes[static_cast<int>(instance.IoStat.Mode)]};
|
||||||
|
instance.client.send(instance.verTopic, fmt::format("{}", instance.Version));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
auto payload = serMsg->Payload;
|
auto payload = serMsg->Payload;
|
||||||
if (payload == "mute") {
|
if (payload == "mute") {
|
||||||
@@ -204,6 +216,7 @@ class MqttChannel {
|
|||||||
const std::map<string, ServiceCommands_e>& getSerCommands() { return serviceCommands; }
|
const std::map<string, ServiceCommands_e>& getSerCommands() { return serviceCommands; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::string Version;
|
||||||
SwordConfig Config;
|
SwordConfig Config;
|
||||||
Queue<MqttQe> MasterQueue;
|
Queue<MqttQe> MasterQueue;
|
||||||
Queue<MqttQe> MqttQueue;
|
Queue<MqttQe> MqttQueue;
|
||||||
|
|||||||
+58
-31
@@ -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.2";
|
const string Version = "V 0.10.0";
|
||||||
|
|
||||||
unique_ptr<SwordConfig> SwordCfg;
|
unique_ptr<SwordConfig> SwordCfg;
|
||||||
unique_ptr<DeviceIoState> IoStat;
|
unique_ptr<DeviceIoState> IoStat;
|
||||||
@@ -87,8 +87,7 @@ int main(int argc, char* argv[]) {
|
|||||||
} else {
|
} else {
|
||||||
fmt::println("unknown {}", modeArg);
|
fmt::println("unknown {}", modeArg);
|
||||||
}
|
}
|
||||||
constexpr array<const char*, 4> modes = {"Undefined", "Maintanance", "PromoMode", "Production"};
|
log.sendBootUp(Version, MqttChannel::Modes[static_cast<int>(IoStat->Mode)]);
|
||||||
log.sendBootUp(Version, modes[static_cast<int>(IoStat->Mode)]);
|
|
||||||
|
|
||||||
MqttChannel mqtt(appName, Version, *SwordCfg, *IoStat, log);
|
MqttChannel mqtt(appName, Version, *SwordCfg, *IoStat, log);
|
||||||
auto resetCall = [&]() {
|
auto resetCall = [&]() {
|
||||||
@@ -186,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();
|
||||||
@@ -209,12 +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;
|
||||||
|
// 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: {
|
||||||
@@ -227,13 +245,13 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
|||||||
// say: You are not the one
|
// say: You are not the one
|
||||||
mqtt.sendEvent("pull");
|
mqtt.sendEvent("pull");
|
||||||
MediaPlayer::playWavFileSync(SwordCfg->getNextDeny());
|
MediaPlayer::playWavFileSync(SwordCfg->getNextDeny());
|
||||||
log.sendEvent("Req", "Pulled");
|
log.sendEvent("Game", "Pulled");
|
||||||
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: {
|
||||||
@@ -243,54 +261,63 @@ void processProduction(MqttChannel& mqtt, SeqLogger& log) {
|
|||||||
IoStat->SwordLatch.moveIn();
|
IoStat->SwordLatch.moveIn();
|
||||||
while (!abort) {
|
while (!abort) {
|
||||||
IoStat->SwordEnd.sample();
|
IoStat->SwordEnd.sample();
|
||||||
if (IoStat->SwordEnd.getState() == pal::InputBiDebounced::State::Passive) {
|
IoStat->SwordEntry.sample();
|
||||||
fmt::println("pulling sword");
|
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;
|
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();
|
||||||
if (IoStat->SwordEntry.getState() == pal::InputBiDebounced::State::Passive) {
|
if (!IoStat->SwordEntry.isActive()) {
|
||||||
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) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
sendLogIfAborted(abort);
|
||||||
|
if (abort) break;
|
||||||
|
|
||||||
|
IoStat->SwordEnd.sample(); // still stuck?
|
||||||
|
bool stuckSensor = (!IoStat->SwordEntry.isActive()) && (IoStat->SwordEnd.isActive());
|
||||||
|
|
||||||
mqtt.sendEvent("pulled-out");
|
mqtt.sendEvent("pulled-out");
|
||||||
log.sendEvent("Req", "Pulled Out");
|
log.sendEvent("Game", "Pulled Out");
|
||||||
// say: You ARE the one
|
// say: You ARE the one
|
||||||
MediaPlayer::playWavFileSync(SwordCfg->getNextAllow());
|
MediaPlayer::playWavFileSync(SwordCfg->getNextAllow());
|
||||||
log.sendEvent("Req", "Ceremony");
|
log.sendEvent("Game", "Ceremony");
|
||||||
mqtt.sendEvent("ceremonyDone");
|
mqtt.sendEvent("ceremonyDone");
|
||||||
|
|
||||||
while (!abort) {
|
while (!abort) {
|
||||||
IoStat->SwordEntry.sample();
|
IoStat->SwordEntry.sample();
|
||||||
if (IoStat->SwordEntry.getState() == pal::InputBiDebounced::State::Active) {
|
if (IoStat->SwordEntry.isActive()) {
|
||||||
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) {
|
||||||
|
fmt::println("..extra wait due to stuck sensor");
|
||||||
|
Thread::sleep(3s);
|
||||||
}
|
}
|
||||||
while (!abort) {
|
while (!abort) {
|
||||||
IoStat->SwordEnd.sample();
|
IoStat->SwordEnd.sample();
|
||||||
if (IoStat->SwordEnd.getState() == pal::InputBiDebounced::State::Active) {
|
if (IoStat->SwordEnd.isActive()) {
|
||||||
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) {
|
sendLogIfAborted(abort);
|
||||||
break;
|
if (abort) break;
|
||||||
}
|
|
||||||
log.sendEvent("Req", "Put Back");
|
log.sendEvent("Game", "Put Back");
|
||||||
mqtt.sendEvent("put-in");
|
mqtt.sendEvent("put-in");
|
||||||
IoStat->SwordLatch.moveOut(); // Lock
|
IoStat->SwordLatch.moveOut(); // Lock
|
||||||
Thread::sleep(3s);
|
Thread::sleep(3s);
|
||||||
|
|||||||
Reference in new issue
Block a user