Skip to content

Commit

Permalink
ros2GH-21 Wire rosbag play into CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
greimela-si authored and Martin-Idel-SI committed Sep 14, 2018
1 parent 4da3aab commit 1703b5b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ros2bag/ros2bag/verb/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from ros2bag.verb import VerbExtension

from rosbag2_transport import rosbag_transport_py


class PlayVerb(VerbExtension):
"""ros2 bag play."""
Expand All @@ -24,4 +26,4 @@ def add_arguments(self, parser, cli_name): # noqa: D102

def main(self, *, args): # noqa: D102
bag_file = args.bag_file
print('calling ros2 bag play on', bag_file)
rosbag_transport_py.play_bag(bag_file)
23 changes: 23 additions & 0 deletions rosbag2_transport/src/rosbag2_transport/_rosbag2_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,35 @@ rosbag2_transport_record_topics(PyObject * Py_UNUSED(self), PyObject * args)
Py_RETURN_NONE;
}

static PyObject *
rosbag2_transport_play(PyObject * Py_UNUSED(self), PyObject * args)
{
char * file_name;
if (!PyArg_ParseTuple(args, "s", &file_name)) {
return nullptr;
}

rosbag2::Rosbag2PlayOptions options{};
options.queue_buffer_length_ = 1000;

rosbag2_transport::Rosbag2Transport transport;
transport.init();
transport.play(file_name, options);
transport.shutdown();

Py_RETURN_NONE;
}

/// Define the public methods of this module
static PyMethodDef rosbag2_transport_methods[] = {
{
"record_topics", rosbag2_transport_record_topics, METH_VARARGS,
"Record topics"
},
{
"play_bag", rosbag2_transport_play, METH_VARARGS,
"Play bag"
},
{nullptr, nullptr, 0, nullptr} /* sentinel */
};

Expand Down

0 comments on commit 1703b5b

Please sign in to comment.