This commit is contained in:
Jakob Gegeniger committed 2026-10-13 22:10:06 +02:00
1 parent e7393389b8
commit c1e8f2a7a4
4 files changed
+121 -60

No files matched your search

+13 -7
View File
@@ -10,6 +10,7 @@ class MqttChannel {
Logger(log),
runTopic(cfg.StationPath + "run"),
cfgTopic(cfg.StationPath + "cfg"),
setTopic(cfg.StationPath + "set"),
verTopic(cfg.StationPath + "ver"),
eventTopic(cfg.StationPath + "event"),
statTopic(cfg.StationPath + "stat"),
@@ -34,11 +35,13 @@ class MqttChannel {
{"volume", ServiceCommands_e::SetConfigVolume},
{"promoDelay", ServiceCommands_e::SetConfigPromoDelay},
}),
subTopics{{runTopic, cfgTopic, resetTopic}},
subTopics{{runTopic, setTopic, cfgTopic, resetTopic}},
client(name, cfg.BrockerUrl, subTopics,
{cfg.MqttUser, cfg.MqttPassword}) {
fmt::println("MQTT: Starting task:");
mqttCall = [this](string topic, string payload) {
fmt::print("MQTT: Got T:'{}' M:'{}'\n", topic, payload);
if (topic == resetTopic ||
topic == cfgTopic) {
auto mq = std::make_unique<MqttQe>(topic, payload);
@@ -86,7 +89,8 @@ class MqttChannel {
static void runMasterService(Thread::Context& ctx, MqttChannel& instance, function<void()> resetCall, CurrMon& mon) {
while (true) {
auto serMsg = instance.MasterQueue.dequeue();
auto serMsg = instance.MasterQueue.tryDequeueFor(500ms);
instance.sendStatusMessage();
if (!serMsg) {
continue;
}
@@ -147,10 +151,10 @@ class MqttChannel {
MediaPlayer::playWavFile(instance.Config.SoundPromo);
} break;
case ServiceCommands_e::PlaySoundDeny: {
MediaPlayer::playWavFile(instance.Config.SoundDeny);
MediaPlayer::playWavFile(instance.Config.getNextDeny());
} break;
case ServiceCommands_e::PlaySoundChosen: {
MediaPlayer::playWavFile(instance.Config.SoundAllow);
MediaPlayer::playWavFile(instance.Config.getNextAllow());
} break;
}
}
@@ -158,11 +162,11 @@ class MqttChannel {
resetCall();
}
void sendStatusMessage(OpMode mode) {
void sendStatusMessage() {
try {
auto& s = IoStat;
client.send(statTopic, fmt::format("M:{}, snd:{}, sS:{},sE:{},sP:{},lE:{},v:{},pD:{}",
(int)mode,
client.send(statTopic, fmt::format("M:{},snd:{},sS:{},sE:{},sP:{},lE:{},v:{},pD:{}",
(int)IoStat.Mode,
!s.Mute,
s.SwordEntry.get(),
s.SwordEnd.get(),
@@ -177,6 +181,7 @@ class MqttChannel {
void sendEvent(std::string event) {
try {
auto& s = IoStat;
fmt::println("Sending Event: {}",event);
client.send(eventTopic, fmt::format("{}", event));
} catch (const exception& exc) {
fmt::println(stderr, "\nERROR: Unable to connect to Setup bridge: {}", exc.what());
@@ -193,6 +198,7 @@ class MqttChannel {
DeviceIoState& IoStat;
SeqLogger& Logger;
const string runTopic;
const string setTopic;
const string cfgTopic;
const string verTopic;
const string eventTopic;