Aggiunte funzioni di lettura di Startup/Heartbeat

funzioni aggiunte nelle callback mqtt che segnalano il cambiamento con
l'emit di commonStatusChange
This commit is contained in:
2019-11-04 15:40:22 +01:00
parent 9483e265f3
commit 29db06e3c4
5 changed files with 44 additions and 1 deletions

View File

@@ -20,6 +20,29 @@ void mqtt_callback::message_arrived(mqtt::const_message_ptr msg) {
msg->get_topic(), msg->to_string());
if(msg->get_topic() == mem_->comSettings.subMap.find("interface")->second) {
log_->debug("MQTT: Interface Message: {}", msg->get_payload().c_str());
// Gestione dei messaggi di interfaccia
std::vector<std::string> intMsg;
boost::split(intMsg, static_cast<const std::string>(msg->to_string()), boost::is_any_of(":"));
if (!intMsg[mem_->comSettings.TYPE].compare("STARTUP") ||
!intMsg[mem_->comSettings.TYPE].compare("HB")){
// Received Startup Message
log_->debug("Startup/Heartbeat from node, ts: {},[{}]",
intMsg[mem_->comSettings.NODE].c_str(),
intMsg[mem_->comSettings.TS]);
if (!intMsg[mem_->comSettings.NODE].compare(mem_->comSettings.nodeNames["relay"])){
mem_->commonStatus.relayRunning = true;
mem_->commonStatus.relayLast = std::stod(intMsg[mem_->comSettings.TS]);
} else if (!intMsg[mem_->comSettings.NODE].compare(mem_->comSettings.nodeNames["follower"])) {
mem_->commonStatus.followerRunning = true;
mem_->commonStatus.followerLast = std::stod(intMsg[mem_->comSettings.TS]);
} else if (!intMsg[mem_->comSettings.NODE].compare(mem_->comSettings.nodeNames["recorder"])) {
mem_->commonStatus.recorderRunning = true;
mem_->commonStatus.recorderLast = std::stod(intMsg[mem_->comSettings.TS]);
} else {
log_->error("Node {} unknown", intMsg[mem_->comSettings.NODE].c_str());
}
emit mem_->commonStatusChange();
}
} else if (msg->get_topic() == mem_->comSettings.subMap.find("state")->second){
log_->debug("MQTT: State Message: {}", msg->get_payload().c_str());
} else if (msg->get_topic() == mem_->comSettings.subMap.find("commands")->second){