Skip to content

Commit

Permalink
Merged in resstore_log_playback (pull request #288)
Browse files Browse the repository at this point in the history
Resstore log playback

Approved-by: Mabel Zhang <[email protected]>
  • Loading branch information
nkoenig committed Apr 25, 2019
2 parents 53c7682 + 3b86a37 commit d7c9481
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions src/systems/log/LogPlayback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,27 +185,41 @@ bool LogPlaybackPrivate::Start(const std::string &_logPath,

// Append file name
std::string dbPath = common::joinPaths(_logPath, "state.tlog");
ignmsg << "Loading log file [" + dbPath + "]\n";
if (!common::exists(dbPath))
{
ignerr << "Log path invalid. File [" << dbPath << "] "
<< "does not exist. Nothing to play.\n";
return false;
}

// Temporary. Name of recorded SDF file
std::string sdfPath = common::joinPaths(_logPath, "state.sdf");
// Call Log.hh directly to load a .tlog file
auto log = std::make_unique<transport::log::Log>();
if (!log->Open(dbPath))
{
ignerr << "Failed to open log file [" << dbPath << "]" << std::endl;
}

if (!common::exists(dbPath) ||
!common::exists(sdfPath))
// Find SDF string in .tlog file
transport::log::TopicList sdfOpts("/" + common::basename(_logPath) + "/sdf");
transport::log::Batch sdfBatch = log->QueryMessages(sdfOpts);
transport::log::MsgIter sdfIter = sdfBatch.begin();
if (sdfIter == sdfBatch.end())
{
ignerr << "Log path invalid. File(s) [" << dbPath << "] / [" << sdfPath
<< "] do not exist. Nothing to play.\n";
ignerr << "No SDF found in log file [" << dbPath << "]" << std::endl;
return false;
}

ignmsg << "Loading log files:" << std::endl
<< "* " << dbPath << std::endl
<< "* " << sdfPath << std::endl;
// Parse SDF message
msgs::StringMsg sdfMsg;
sdfMsg.ParseFromString(sdfIter->Data());

// Load recorded SDF file
sdf::Root root;
if (root.Load(sdfPath).size() != 0 || root.WorldCount() <= 0)
if (root.LoadSdfString(sdfMsg.data()).size() != 0 || root.WorldCount() <= 0)
{
ignerr << "Error loading SDF file [" << sdfPath << "]" << std::endl;
ignerr << "Error loading SDF string logged in file [" << dbPath << "]"
<< std::endl;
return false;
}
const sdf::World *sdfWorld = root.WorldByIndex(0);
Expand Down Expand Up @@ -276,13 +290,6 @@ bool LogPlaybackPrivate::Start(const std::string &_logPath,
creator.SetParent(lightEntity, _worldEntity);
}

// Call Log.hh directly to load a .tlog file
auto log = std::make_unique<transport::log::Log>();
if (!log->Open(dbPath))
{
ignerr << "Failed to open log file [" << dbPath << "]" << std::endl;
}

// Access messages in .tlog file
transport::log::TopicList opts("/world/" +
sdfWorld->Element()->GetAttribute("name")->GetAsString() + "/pose/info");
Expand Down

0 comments on commit d7c9481

Please sign in to comment.