Fixposition SDK 0.0.0-heads/main-0-g75e6614
Collection of c++ libraries and apps for use with Fixposition products on Linux
Loading...
Searching...
No Matches
fpsdk::common::ros1::BagWriter Class Reference

ROS1 bag (rosbag) writer. More...

#include <ros1.hpp>

Public Member Functions

 BagWriter (const BagWriter &)=delete
 No copy.
BagWriter & operator= (const BagWriter &)=delete
 No copy.
bool Open (const std::string &path, const int compress=0)
 Open bag for writing.
void Close ()
 Close bag.
template<typename T>
bool WriteMessage (const T &msg, const std::string &topic, const time::RosTime &time={})
 Write a message to the bag.
template<typename T>
bool WriteMessage (const T &msg, const std::string &topic, const ros::Time &time)
 Write a message to the bag.
void AddMsgDef (const fpl::RosMsgDef &rosmsgdef)
 Add ROS message definition from .fpl.
bool WriteMessage (const fpl::RosMsgBin &rosmsgbin)
 Write message from .fpl.

Detailed Description

ROS1 bag (rosbag) writer.

This writes ROS1 bag files (rosbag format version 2.0). Unlike the rosbag library from ROS1 this does not need ROS and therefore it works in all builds of the SDK (with ROS1, with ROS2, and without any ROS). Messages can either be given as ROS1 message objects (see WriteMessage()) or as already serialised data from a .fpl logfile (see AddMsgDef() and WriteMessage()).

Compared to the original rosbag library this implementation has some limitations:

  • Only "bz2" chunk compression is available (and only if compiled with BZip2, see Dependencies)
  • No encryption
  • Only one connection per topic
  • Write only (no reading, no appending to existing bags)

The resulting bags are valid rosbag version 2.0 files and can be read by any ROS1 tool (rosbag info, rosbag play, rqt_bag, ...) as well as other tools that understand the format.

Definition at line 175 of file ros1.hpp.

Member Function Documentation

◆ Open()

bool fpsdk::common::ros1::BagWriter::Open ( const std::string & path,
const int compress = 0 )

Open bag for writing.

Parameters
[in]pathPath/filename of the bag file (an existing file is overwritten)
[in]compressCompress bag, 0 = no compression, 1+ = BZ2 (if compiled in)
Returns
true if bag was sucessfully opened, false otherwise (bad path, compression requested but bz2 support not compiled in, ...)

◆ Close()

void fpsdk::common::ros1::BagWriter::Close ( )

Close bag.

Note
Failing to close the bag (for example, by not destroying the object) leaves an unusable (unindexed) file behind. The index is only written on close.

◆ WriteMessage() [1/3]

template<typename T>
bool fpsdk::common::ros1::BagWriter::WriteMessage ( const T & msg,
const std::string & topic,
const time::RosTime & time = {} )
inline

Write a message to the bag.

Template Parameters
TROS message type
Parameters
[in]msgThe message
[in]topicTopic name
[in]timeBag record time
Returns
true if message was added, false otherwise (bag not open, write error)

Definition at line 214 of file ros1.hpp.

Referenced by WriteMessage().

◆ WriteMessage() [2/3]

template<typename T>
bool fpsdk::common::ros1::BagWriter::WriteMessage ( const T & msg,
const std::string & topic,
const ros::Time & time )
inline

Write a message to the bag.

Template Parameters
TROS message type
Parameters
[in]msgThe message
[in]topicTopic name
[in]timeBag record time
Returns
true if message was added, false otherwise (bag not open, write error)

Definition at line 237 of file ros1.hpp.

References WriteMessage().

◆ AddMsgDef()

void fpsdk::common::ros1::BagWriter::AddMsgDef ( const fpl::RosMsgDef & rosmsgdef)

Add ROS message definition from .fpl.

Note
No checks on the provided data are done!
Parameters
[in]rosmsgdefThe message definition

◆ WriteMessage() [3/3]

bool fpsdk::common::ros1::BagWriter::WriteMessage ( const fpl::RosMsgBin & rosmsgbin)

Write message from .fpl.

Note
No checks on the provided data are done!
Parameters
[in]rosmsgbinThe recorded message
Returns
true if message was added, false otherwise (message definition missing, bag not open, write error)

The documentation for this class was generated from the following file:
  • fpsdk_common/include/fpsdk_common/ros1.hpp