Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small Fix for Reloading Tree from #61 #96

Merged
merged 6 commits into from
Sep 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 48 additions & 48 deletions bt_editor/sidepanel_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,60 +48,60 @@ void SidepanelMonitor::on_timer()

const uint32_t header_size = flatbuffers::ReadScalar<uint32_t>( buffer );
const uint32_t num_transitions = flatbuffers::ReadScalar<uint32_t>( &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<uint16_t>(&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<uint16_t>(&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<uint16_t>(&buffer[offset]);
const uint16_t index = _uid_to_index.at(uid);
AbstractTreeNode* node = _loaded_tree.node( index );
node->status = convert(flatbuffers::ReadScalar<Serialization::NodeStatus>(&buffer[offset+2] ));
}


std::vector<std::pair<int, NodeStatus>> 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<uint16_t>(&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<uint16_t>(&buffer[offset+8]);
_uid_to_index.at(uid);
}

//qDebug() << "--------";
for(size_t t=0; t < num_transitions; t++)
{
size_t offset = 8 + header_size + 12*t;
for(size_t offset = 4; offset < header_size +4; offset +=3 )
{
const uint16_t uid = flatbuffers::ReadScalar<uint16_t>(&buffer[offset]);
const uint16_t index = _uid_to_index.at(uid);
AbstractTreeNode* node = _loaded_tree.node( index );
node->status = convert(flatbuffers::ReadScalar<Serialization::NodeStatus>(&buffer[offset+2] ));
}

// const double t_sec = flatbuffers::ReadScalar<uint32_t>( &buffer[offset] );
// const double t_usec = flatbuffers::ReadScalar<uint32_t>( &buffer[offset+4] );
// double timestamp = t_sec + t_usec* 0.000001;
const uint16_t uid = flatbuffers::ReadScalar<uint16_t>(&buffer[offset+8]);
const uint16_t index = _uid_to_index.at(uid);
// NodeStatus prev_status = convert(flatbuffers::ReadScalar<Serialization::NodeStatus>(&buffer[index+10] ));
NodeStatus status = convert(flatbuffers::ReadScalar<Serialization::NodeStatus>(&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<uint32_t>( &buffer[offset] );
// const double t_usec = flatbuffers::ReadScalar<uint32_t>( &buffer[offset+4] );
// double timestamp = t_sec + t_usec* 0.000001;
const uint16_t uid = flatbuffers::ReadScalar<uint16_t>(&buffer[offset+8]);
const uint16_t index = _uid_to_index.at(uid);
// NodeStatus prev_status = convert(flatbuffers::ReadScalar<Serialization::NodeStatus>(&buffer[index+10] ));
NodeStatus status = convert(flatbuffers::ReadScalar<Serialization::NodeStatus>(&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 );
}
Expand Down