Corretta gestione Heartbeat

This commit is contained in:
2019-11-05 16:47:55 +01:00
parent 64a4b9b122
commit bf368d6ac6
6 changed files with 22 additions and 12 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.8.2, 2019-11-04T15:40:48. -->
<!-- Written by QtCreator 4.8.2, 2019-11-05T16:47:40. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@@ -31,17 +31,20 @@ void mqtt_callback::message_arrived(mqtt::const_message_ptr msg) {
intMsg[mem_->comSettings.TS]);
if (!intMsg[mem_->comSettings.NODE].compare(mem_->comSettings.nodeNames["relay"])){
mem_->commonStatus.relayRunning = true;
mem_->commonStatus.relayLast = fabs(mem_->commonStatus.relayLast - std::stod(intMsg[mem_->comSettings.TS]));
mem_->commonStatus.relayLast = std::stod(intMsg[mem_->comSettings.TS]);
log_->trace("HB RELAY time: [{}]", mem_->commonStatus.relayLast);
} else if (!intMsg[mem_->comSettings.NODE].compare(mem_->comSettings.nodeNames["follower"])) {
mem_->commonStatus.followerRunning = true;
mem_->commonStatus.followerLast = fabs(mem_->commonStatus.followerLast - std::stod(intMsg[mem_->comSettings.TS]));
mem_->commonStatus.followerLast = std::stod(intMsg[mem_->comSettings.TS]);
log_->trace("HB FOLLOWER time: [{}]", mem_->commonStatus.followerLast);
} else if (!intMsg[mem_->comSettings.NODE].compare(mem_->comSettings.nodeNames["recorder"])) {
mem_->commonStatus.recorderRunning = true;
mem_->commonStatus.recorderLast = fabs(mem_->commonStatus.recorderLast - std::stod(intMsg[mem_->comSettings.TS]));
mem_->commonStatus.recorderLast = std::stod(intMsg[mem_->comSettings.TS]);
log_->trace("HB RECORDER time: [{}]", mem_->commonStatus.recorderLast);
} else {
log_->error("Node {} unknown", intMsg[mem_->comSettings.NODE].c_str());
}
emit mem_->commonStatusChange();
//emit mem_->commonStatusChange();
}
} else if (msg->get_topic() == mem_->comSettings.subMap.find("state")->second){
log_->debug("MQTT: State Message: {}", msg->get_payload().c_str());

View File

@@ -6,7 +6,7 @@ RoboGlue_COM::RoboGlue_COM (RoboGlue_SHARED *mem): m(mem) {
liblog = spdlog::stdout_logger_mt("URcom_liblog");
modlog = spdlog::stdout_logger_mt("RoboGlue_comlog");
liblog->set_level(spdlog::level::warn);
modlog->set_level(spdlog::level::info);
modlog->set_level(spdlog::level::trace);
///////// INITIALIZE TCP SERVER ///////////
server = new QTcpServer(this);

View File

@@ -92,13 +92,13 @@ void RoboGlue_GUI::disableLockAxes(){
void RoboGlue_GUI::on_commonStatusChange() {
modlog->trace("on_commonStatusChange Received");
// TODO: aggiungere e interpretare le flag per capire se i nodi ros sono tutti vivi dall'heartbeat
this->ui->lbl_relay->setText(QString().fromStdString(std::to_string(m->commonStatus.relayLast)));
this->ui->lbl_follower->setText(QString().fromStdString(std::to_string(m->commonStatus.followerLast)));
this->ui->lbl_recorder->setText(QString().fromStdString(std::to_string(m->commonStatus.recorderLast)));
this->ui->lbl_relay->setText(QString().fromStdString(std::to_string(m->commonStatus.relayTime)));
this->ui->lbl_follower->setText(QString().fromStdString(std::to_string(m->commonStatus.followerTime)));
this->ui->lbl_recorder->setText(QString().fromStdString(std::to_string(m->commonStatus.recorderTime)));
if(m->commonStatus.relayLast > m->comSettings.deadTime ||
m->commonStatus.followerLast > m->comSettings.deadTime ||
m->commonStatus.recorderLast > m->comSettings.deadTime) {
if(m->commonStatus.relayTime > m->comSettings.deadTime ||
m->commonStatus.followerTime > m->comSettings.deadTime ||
m->commonStatus.recorderTime > m->comSettings.deadTime) {
this->ui->lbl_relay->setStyleSheet("QLabel { background-color : red; color : white; }");
this->ui->lbl_follower->setStyleSheet("QLabel { background-color : red; color : white; }");
this->ui->lbl_recorder->setStyleSheet("QLabel { background-color : red; color : white; }");

View File

@@ -15,6 +15,10 @@ RoboGlue_SHARED::~RoboGlue_SHARED(){
}
void RoboGlue_SHARED::on_statusTimer(void){
double curTime = static_cast<double>(std::time(NULL));
commonStatus.relayTime = fabs(commonStatus.relayLast - curTime);
commonStatus.followerTime = fabs(commonStatus.followerLast - curTime);
commonStatus.recorderTime = fabs(commonStatus.recorderLast - curTime);
emit this->commonStatusChange();
}
////////////////////////////////////////////////////////////////

View File

@@ -59,6 +59,9 @@ public:
double relayLast = 0.0;
double followerLast = 0.0;
double recorderLast = 0.0;
double relayTime = 0.0;
double followerTime = 0.0;
double recorderTime = 0.0;
} commonStatus;
/////////// PERMANENT SETTINGS VARIABLES /////////