From fa8a75b61f8dcdc76f0f763c5cc53ca06fc89a11 Mon Sep 17 00:00:00 2001 From: Florian Gramss Date: Sat, 19 Sep 2020 14:35:07 +0200 Subject: [PATCH 1/6] Add missing err:out_of_range code-sections + intent fixes --- bt_editor/sidepanel_monitor.cpp | 118 ++++++++++++++------------------ 1 file changed, 50 insertions(+), 68 deletions(-) diff --git a/bt_editor/sidepanel_monitor.cpp b/bt_editor/sidepanel_monitor.cpp index 28372a77..c24e5bb2 100644 --- a/bt_editor/sidepanel_monitor.cpp +++ b/bt_editor/sidepanel_monitor.cpp @@ -45,62 +45,62 @@ void SidepanelMonitor::on_timer() ui->labelCount->setText( QString("Messages received: %1").arg(_msg_count) ); const char* buffer = reinterpret_cast(msg.data()); - + const uint32_t header_size = flatbuffers::ReadScalar( buffer ); const uint32_t num_transitions = flatbuffers::ReadScalar( &buffer[4+header_size] ); - // check uid in the index, if failed load tree from server - try { - for(size_t offset = 4; offset < header_size +4; offset +=3 ) - { - const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset]); - _uid_to_index.at(uid); - } - - for(size_t t=0; t < num_transitions; t++) - { - size_t offset = 8 + header_size + 12*t; - const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset+8]); - _uid_to_index.at(uid); - } - } - catch( std::out_of_range& err) { - qDebug() << "Reload tree from server"; - if( !getTreeFromServer() ) { - _connected = false; - ui->lineEdit->setDisabled(false); - _timer->stop(); - connectionUpdate(false); - return; - } - } - - for(size_t offset = 4; offset < header_size +4; offset +=3 ) - { - const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset]); - const uint16_t index = _uid_to_index.at(uid); - AbstractTreeNode* node = _loaded_tree.node( index ); - node->status = convert(flatbuffers::ReadScalar(&buffer[offset+2] )); - } - std::vector> node_status; - //qDebug() << "--------"; - for(size_t t=0; t < num_transitions; t++) - { - size_t offset = 8 + header_size + 12*t; + // check uid in the index, if failed load tree from server + try { + for(size_t offset = 4; offset < header_size +4; offset +=3 ) + { + const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset]); + _uid_to_index.at(uid); + } + + for(size_t t=0; t < num_transitions; t++) + { + size_t offset = 8 + header_size + 12*t; + const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset+8]); + _uid_to_index.at(uid); + } + for(size_t offset = 4; offset < header_size +4; offset +=3 ) + { + const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset]); + const uint16_t index = _uid_to_index.at(uid); + AbstractTreeNode* node = _loaded_tree.node( index ); + node->status = convert(flatbuffers::ReadScalar(&buffer[offset+2] )); + } + - // const double t_sec = flatbuffers::ReadScalar( &buffer[offset] ); - // const double t_usec = flatbuffers::ReadScalar( &buffer[offset+4] ); - // double timestamp = t_sec + t_usec* 0.000001; - const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset+8]); - const uint16_t index = _uid_to_index.at(uid); - // NodeStatus prev_status = convert(flatbuffers::ReadScalar(&buffer[index+10] )); - NodeStatus status = convert(flatbuffers::ReadScalar(&buffer[offset+11] )); + //qDebug() << "--------"; + for(size_t t=0; t < num_transitions; t++) + { + size_t offset = 8 + header_size + 12*t; + + // const double t_sec = flatbuffers::ReadScalar( &buffer[offset] ); + // const double t_usec = flatbuffers::ReadScalar( &buffer[offset+4] ); + // double timestamp = t_sec + t_usec* 0.000001; + const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset+8]); + const uint16_t index = _uid_to_index.at(uid); + // NodeStatus prev_status = convert(flatbuffers::ReadScalar(&buffer[index+10] )); + NodeStatus status = convert(flatbuffers::ReadScalar(&buffer[offset+11] )); - _loaded_tree.node(index)->status = status; - node_status.push_back( {index, status} ); + _loaded_tree.node(index)->status = status; + node_status.push_back( {index, status} ); + } + } + catch( std::out_of_range& err) { + qDebug() << "Reload tree from server"; + if( !getTreeFromServer() ) { + _connected = false; + ui->lineEdit->setDisabled(false); + _timer->stop(); + connectionUpdate(false); + return; + } } // update the graphic part emit changeNodeStyle( "BehaviorTree", node_status ); @@ -189,27 +189,11 @@ void SidepanelMonitor::on_Connect() address = ui->lineEdit->placeholderText(); ui->lineEdit->setText(address); } - - QString publisher_port = ui->lineEdit_publisher->text(); - if( publisher_port.isEmpty() ) - { - publisher_port = ui->lineEdit_publisher->placeholderText(); - ui->lineEdit_publisher->setText(publisher_port); - } - - QString server_port = ui->lineEdit_server->text(); - if( server_port.isEmpty() ) - { - publisher_port = ui->lineEdit_server->placeholderText(); - ui->lineEdit_server->setText(publisher_port); - } - bool failed = false; if( !address.isEmpty() ) { - _connection_address_pub = "tcp://" + address.toStdString() + ":" + publisher_port.toStdString(); - _connection_address_req = "tcp://" + address.toStdString() + ":" + server_port.toStdString(); - + _connection_address_pub = "tcp://" + address.toStdString() + std::string(":1666"); + _connection_address_req = "tcp://" + address.toStdString() + std::string(":1667"); try{ _zmq_subscriber.connect( _connection_address_pub.c_str() ); @@ -236,7 +220,6 @@ void SidepanelMonitor::on_Connect() { _connected = true; ui->lineEdit->setDisabled(true); - ui->lineEdit_publisher->setDisabled(true); _timer->start(20); connectionUpdate(true); } @@ -250,7 +233,6 @@ void SidepanelMonitor::on_Connect() else{ _connected = false; ui->lineEdit->setDisabled(false); - ui->lineEdit_publisher->setDisabled(false); _timer->stop(); connectionUpdate(false); From 67b6181da60a64dc75367ea9adc8a97e12e0961e Mon Sep 17 00:00:00 2001 From: Florian Gramss Date: Sat, 19 Sep 2020 14:35:07 +0200 Subject: [PATCH 2/6] Revert "Add missing err:out_of_range code-sections + intent fixes" This reverts commit fa8a75b61f8dcdc76f0f763c5cc53ca06fc89a11. --- bt_editor/sidepanel_monitor.cpp | 118 ++++++++++++++++++-------------- 1 file changed, 68 insertions(+), 50 deletions(-) diff --git a/bt_editor/sidepanel_monitor.cpp b/bt_editor/sidepanel_monitor.cpp index c24e5bb2..28372a77 100644 --- a/bt_editor/sidepanel_monitor.cpp +++ b/bt_editor/sidepanel_monitor.cpp @@ -45,62 +45,62 @@ void SidepanelMonitor::on_timer() ui->labelCount->setText( QString("Messages received: %1").arg(_msg_count) ); const char* buffer = reinterpret_cast(msg.data()); - + const uint32_t header_size = flatbuffers::ReadScalar( buffer ); const uint32_t num_transitions = flatbuffers::ReadScalar( &buffer[4+header_size] ); - std::vector> node_status; - // check uid in the index, if failed load tree from server - try { - for(size_t offset = 4; offset < header_size +4; offset +=3 ) - { - const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset]); - _uid_to_index.at(uid); - } - - for(size_t t=0; t < num_transitions; t++) - { - size_t offset = 8 + header_size + 12*t; - const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset+8]); - _uid_to_index.at(uid); - } - for(size_t offset = 4; offset < header_size +4; offset +=3 ) - { - const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset]); - const uint16_t index = _uid_to_index.at(uid); - AbstractTreeNode* node = _loaded_tree.node( index ); - node->status = convert(flatbuffers::ReadScalar(&buffer[offset+2] )); - } - + try { + for(size_t offset = 4; offset < header_size +4; offset +=3 ) + { + const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset]); + _uid_to_index.at(uid); + } + + for(size_t t=0; t < num_transitions; t++) + { + size_t offset = 8 + header_size + 12*t; + const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset+8]); + _uid_to_index.at(uid); + } + } + catch( std::out_of_range& err) { + qDebug() << "Reload tree from server"; + if( !getTreeFromServer() ) { + _connected = false; + ui->lineEdit->setDisabled(false); + _timer->stop(); + connectionUpdate(false); + return; + } + } + + for(size_t offset = 4; offset < header_size +4; offset +=3 ) + { + const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset]); + const uint16_t index = _uid_to_index.at(uid); + AbstractTreeNode* node = _loaded_tree.node( index ); + node->status = convert(flatbuffers::ReadScalar(&buffer[offset+2] )); + } - //qDebug() << "--------"; - for(size_t t=0; t < num_transitions; t++) - { - size_t offset = 8 + header_size + 12*t; + std::vector> node_status; - // const double t_sec = flatbuffers::ReadScalar( &buffer[offset] ); - // const double t_usec = flatbuffers::ReadScalar( &buffer[offset+4] ); - // double timestamp = t_sec + t_usec* 0.000001; - const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset+8]); - const uint16_t index = _uid_to_index.at(uid); - // NodeStatus prev_status = convert(flatbuffers::ReadScalar(&buffer[index+10] )); - NodeStatus status = convert(flatbuffers::ReadScalar(&buffer[offset+11] )); + //qDebug() << "--------"; + for(size_t t=0; t < num_transitions; t++) + { + size_t offset = 8 + header_size + 12*t; - _loaded_tree.node(index)->status = status; - node_status.push_back( {index, status} ); + // const double t_sec = flatbuffers::ReadScalar( &buffer[offset] ); + // const double t_usec = flatbuffers::ReadScalar( &buffer[offset+4] ); + // double timestamp = t_sec + t_usec* 0.000001; + const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset+8]); + const uint16_t index = _uid_to_index.at(uid); + // NodeStatus prev_status = convert(flatbuffers::ReadScalar(&buffer[index+10] )); + NodeStatus status = convert(flatbuffers::ReadScalar(&buffer[offset+11] )); + + _loaded_tree.node(index)->status = status; + node_status.push_back( {index, status} ); - } - } - catch( std::out_of_range& err) { - qDebug() << "Reload tree from server"; - if( !getTreeFromServer() ) { - _connected = false; - ui->lineEdit->setDisabled(false); - _timer->stop(); - connectionUpdate(false); - return; - } } // update the graphic part emit changeNodeStyle( "BehaviorTree", node_status ); @@ -189,11 +189,27 @@ void SidepanelMonitor::on_Connect() address = ui->lineEdit->placeholderText(); ui->lineEdit->setText(address); } + + QString publisher_port = ui->lineEdit_publisher->text(); + if( publisher_port.isEmpty() ) + { + publisher_port = ui->lineEdit_publisher->placeholderText(); + ui->lineEdit_publisher->setText(publisher_port); + } + + QString server_port = ui->lineEdit_server->text(); + if( server_port.isEmpty() ) + { + publisher_port = ui->lineEdit_server->placeholderText(); + ui->lineEdit_server->setText(publisher_port); + } + bool failed = false; if( !address.isEmpty() ) { - _connection_address_pub = "tcp://" + address.toStdString() + std::string(":1666"); - _connection_address_req = "tcp://" + address.toStdString() + std::string(":1667"); + _connection_address_pub = "tcp://" + address.toStdString() + ":" + publisher_port.toStdString(); + _connection_address_req = "tcp://" + address.toStdString() + ":" + server_port.toStdString(); + try{ _zmq_subscriber.connect( _connection_address_pub.c_str() ); @@ -220,6 +236,7 @@ void SidepanelMonitor::on_Connect() { _connected = true; ui->lineEdit->setDisabled(true); + ui->lineEdit_publisher->setDisabled(true); _timer->start(20); connectionUpdate(true); } @@ -233,6 +250,7 @@ void SidepanelMonitor::on_Connect() else{ _connected = false; ui->lineEdit->setDisabled(false); + ui->lineEdit_publisher->setDisabled(false); _timer->stop(); connectionUpdate(false); From c80693b2d1a51ce70deef6d9829149a57445af01 Mon Sep 17 00:00:00 2001 From: Florian Gramss Date: Sat, 19 Sep 2020 15:12:17 +0200 Subject: [PATCH 3/6] indentation fixes --- bt_editor/sidepanel_monitor.cpp | 50 ++++++++++++++++----------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/bt_editor/sidepanel_monitor.cpp b/bt_editor/sidepanel_monitor.cpp index 28372a77..d99a5cca 100644 --- a/bt_editor/sidepanel_monitor.cpp +++ b/bt_editor/sidepanel_monitor.cpp @@ -48,31 +48,31 @@ void SidepanelMonitor::on_timer() const uint32_t header_size = flatbuffers::ReadScalar( buffer ); const uint32_t num_transitions = flatbuffers::ReadScalar( &buffer[4+header_size] ); - - // check uid in the index, if failed load tree from server - try { - for(size_t offset = 4; offset < header_size +4; offset +=3 ) - { - const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset]); - _uid_to_index.at(uid); - } - - for(size_t t=0; t < num_transitions; t++) - { - size_t offset = 8 + header_size + 12*t; - const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset+8]); - _uid_to_index.at(uid); - } - } - catch( std::out_of_range& err) { - qDebug() << "Reload tree from server"; - if( !getTreeFromServer() ) { - _connected = false; - ui->lineEdit->setDisabled(false); - _timer->stop(); - connectionUpdate(false); - return; - } + + // check uid in the index, if failed load tree from server + try{ + for(size_t offset = 4; offset < header_size +4; offset +=3 ) + { + const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset]); + _uid_to_index.at(uid); + } + + for(size_t t=0; t < num_transitions; t++) + { + size_t offset = 8 + header_size + 12*t; + const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset+8]); + _uid_to_index.at(uid); + } + } + catch( std::out_of_range& err) { + qDebug() << "Reload tree from server"; + if( !getTreeFromServer() ) { + _connected = false; + ui->lineEdit->setDisabled(false); + _timer->stop(); + connectionUpdate(false); + return; + } } for(size_t offset = 4; offset < header_size +4; offset +=3 ) From a2d8f185ec1f602161be8dc24a2400a25c2024d4 Mon Sep 17 00:00:00 2001 From: Florian Gramss Date: Sat, 19 Sep 2020 15:13:45 +0200 Subject: [PATCH 4/6] indentation fixes - again --- bt_editor/sidepanel_monitor.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bt_editor/sidepanel_monitor.cpp b/bt_editor/sidepanel_monitor.cpp index d99a5cca..240f2e2d 100644 --- a/bt_editor/sidepanel_monitor.cpp +++ b/bt_editor/sidepanel_monitor.cpp @@ -65,15 +65,15 @@ void SidepanelMonitor::on_timer() } } catch( std::out_of_range& err) { - qDebug() << "Reload tree from server"; - if( !getTreeFromServer() ) { - _connected = false; - ui->lineEdit->setDisabled(false); - _timer->stop(); - connectionUpdate(false); - return; + qDebug() << "Reload tree from server"; + if( !getTreeFromServer() ) { + _connected = false; + ui->lineEdit->setDisabled(false); + _timer->stop(); + connectionUpdate(false); + return; + } } - } for(size_t offset = 4; offset < header_size +4; offset +=3 ) { From dc6afc6f19cdac326b8d9e94b782ba3bcad50a2c Mon Sep 17 00:00:00 2001 From: Florian Gramss Date: Sat, 19 Sep 2020 15:14:52 +0200 Subject: [PATCH 5/6] get node status out of try/catch for compiler --- bt_editor/sidepanel_monitor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bt_editor/sidepanel_monitor.cpp b/bt_editor/sidepanel_monitor.cpp index 240f2e2d..c995d463 100644 --- a/bt_editor/sidepanel_monitor.cpp +++ b/bt_editor/sidepanel_monitor.cpp @@ -49,6 +49,7 @@ void SidepanelMonitor::on_timer() const uint32_t header_size = flatbuffers::ReadScalar( buffer ); const uint32_t num_transitions = flatbuffers::ReadScalar( &buffer[4+header_size] ); + std::vector> node_status; // check uid in the index, if failed load tree from server try{ for(size_t offset = 4; offset < header_size +4; offset +=3 ) @@ -83,7 +84,7 @@ void SidepanelMonitor::on_timer() node->status = convert(flatbuffers::ReadScalar(&buffer[offset+2] )); } - std::vector> node_status; + //qDebug() << "--------"; for(size_t t=0; t < num_transitions; t++) From 49d34c1a540e11f7f2faa923f9ad3826a1599eb3 Mon Sep 17 00:00:00 2001 From: Florian Gramss Date: Sat, 19 Sep 2020 15:18:32 +0200 Subject: [PATCH 6/6] main thing: move rest of uid-based logic in try/catch for reload --- bt_editor/sidepanel_monitor.cpp | 53 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/bt_editor/sidepanel_monitor.cpp b/bt_editor/sidepanel_monitor.cpp index c995d463..de3514be 100644 --- a/bt_editor/sidepanel_monitor.cpp +++ b/bt_editor/sidepanel_monitor.cpp @@ -64,6 +64,32 @@ void SidepanelMonitor::on_timer() const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset+8]); _uid_to_index.at(uid); } + + for(size_t offset = 4; offset < header_size +4; offset +=3 ) + { + const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset]); + const uint16_t index = _uid_to_index.at(uid); + AbstractTreeNode* node = _loaded_tree.node( index ); + node->status = convert(flatbuffers::ReadScalar(&buffer[offset+2] )); + } + + //qDebug() << "--------"; + for(size_t t=0; t < num_transitions; t++) + { + size_t offset = 8 + header_size + 12*t; + + // const double t_sec = flatbuffers::ReadScalar( &buffer[offset] ); + // const double t_usec = flatbuffers::ReadScalar( &buffer[offset+4] ); + // double timestamp = t_sec + t_usec* 0.000001; + const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset+8]); + const uint16_t index = _uid_to_index.at(uid); + // NodeStatus prev_status = convert(flatbuffers::ReadScalar(&buffer[index+10] )); + NodeStatus status = convert(flatbuffers::ReadScalar(&buffer[offset+11] )); + + _loaded_tree.node(index)->status = status; + node_status.push_back( {index, status} ); + + } } catch( std::out_of_range& err) { qDebug() << "Reload tree from server"; @@ -76,33 +102,6 @@ void SidepanelMonitor::on_timer() } } - for(size_t offset = 4; offset < header_size +4; offset +=3 ) - { - const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset]); - const uint16_t index = _uid_to_index.at(uid); - AbstractTreeNode* node = _loaded_tree.node( index ); - node->status = convert(flatbuffers::ReadScalar(&buffer[offset+2] )); - } - - - - //qDebug() << "--------"; - for(size_t t=0; t < num_transitions; t++) - { - size_t offset = 8 + header_size + 12*t; - - // const double t_sec = flatbuffers::ReadScalar( &buffer[offset] ); - // const double t_usec = flatbuffers::ReadScalar( &buffer[offset+4] ); - // double timestamp = t_sec + t_usec* 0.000001; - const uint16_t uid = flatbuffers::ReadScalar(&buffer[offset+8]); - const uint16_t index = _uid_to_index.at(uid); - // NodeStatus prev_status = convert(flatbuffers::ReadScalar(&buffer[index+10] )); - NodeStatus status = convert(flatbuffers::ReadScalar(&buffer[offset+11] )); - - _loaded_tree.node(index)->status = status; - node_status.push_back( {index, status} ); - - } // update the graphic part emit changeNodeStyle( "BehaviorTree", node_status ); }