PX4 Firmware
PX4 Autopilot Software http://px4.io
|
Parses an ULog file and replays it in 'real-time'. More...
#include <Replay.hpp>
Classes | |
class | CompatBase |
class | CompatSensorCombinedDtType |
struct | Subscription |
Public Member Functions | |
Replay ()=default | |
virtual | ~Replay () |
void | run () override |
Static Public Member Functions | |
static int | task_spawn (int argc, char *argv[]) |
static Replay * | instantiate (int argc, char *argv[]) |
static int | custom_command (int argc, char *argv[]) |
static int | print_usage (const char *reason=nullptr) |
static int | applyParams (bool quiet) |
Apply the parameters from the log. More... | |
static void | setupReplayFile (const char *file_name) |
Tell the replay module that we want to use replay mode. More... | |
static bool | isSetup () |
Protected Member Functions | |
bool | publishTopic (Subscription &sub, void *data) |
publish an orb topic More... | |
virtual void | onEnterMainLoop () |
called when entering the main replay loop More... | |
virtual void | onExitMainLoop () |
called when exiting the main replay loop More... | |
virtual void | onSubscriptionAdded (Subscription &sub, uint16_t msg_id) |
called when a new subscription is added More... | |
virtual uint64_t | handleTopicDelay (uint64_t next_file_time, uint64_t timestamp_offset) |
handle delay until topic can be published. More... | |
virtual bool | handleTopicUpdate (Subscription &sub, void *data, std::ifstream &replay_file) |
handle the publication of a topic update More... | |
void | readTopicDataToBuffer (const Subscription &sub, std::ifstream &replay_file) |
read a topic from the file (offset given by the subscription) into _read_buffer More... | |
bool | nextDataMessage (std::ifstream &file, Subscription &subscription, int msg_id) |
Find next data message for this subscription, starting with the stored file offset. More... | |
Static Protected Member Functions | |
static bool | findFieldOffset (const std::string &format, const std::string &field_name, int &offset, int &field_size) |
Find the offset & field size in bytes for a given field name. More... | |
Protected Attributes | |
std::vector< Subscription * > | _subscriptions |
std::vector< uint8_t > | _read_buffer |
Private Member Functions | |
bool | readFileHeader (std::ifstream &file) |
bool | readFileDefinitions (std::ifstream &file) |
Read definitions section: check formats, apply parameters and store the start of the data section. More... | |
bool | readFormat (std::ifstream &file, uint16_t msg_size) |
file parsing methods. They return false, when further parsing should be aborted. More... | |
bool | readAndAddSubscription (std::ifstream &file, uint16_t msg_size) |
bool | readFlagBits (std::ifstream &file, uint16_t msg_size) |
bool | readDefinitionsAndApplyParams (std::ifstream &file) |
Read the file header and definitions sections. More... | |
bool | readAndHandleAdditionalMessages (std::ifstream &file, std::streampos end_position) |
Read and handle additional messages starting at current file position, while position < end_position. More... | |
bool | readDropout (std::ifstream &file, uint16_t msg_size) |
bool | readAndApplyParameter (std::ifstream &file, uint16_t msg_size) |
void | setUserParams (const char *filename) |
Static Private Member Functions | |
static const orb_metadata * | findTopic (const std::string &name) |
static std::string | extractArraySize (const std::string &type_name_full, int &array_size) |
get the array size from a type. More... | |
static size_t | sizeOfType (const std::string &type_name) |
get the size of a type that is not an array More... | |
static size_t | sizeOfFullType (const std::string &type_name_full) |
get the size of a type that can be an array More... | |
Private Attributes | |
std::set< std::string > | _overridden_params |
std::map< std::string, std::string > | _file_formats |
all formats we read from the file More... | |
uint64_t | _file_start_time |
uint64_t | _replay_start_time |
std::streampos | _data_section_start |
first ADD_LOGGED_MSG message More... | |
std::streampos | _subscription_file_pos = 0 |
keep track of file position to avoid adding a subscription multiple times. More... | |
int64_t | _read_until_file_position = 1ULL << 60 |
read limit if log contains appended data More... | |
Static Private Attributes | |
static char * | _replay_file = nullptr |
Parses an ULog file and replays it in 'real-time'.
The timestamp of each replayed message is offset to match the starting time of replay. It keeps a stream for each subscription to find the next message to replay. This is necessary because data messages from different subscriptions don't need to be in monotonic increasing order.
Definition at line 58 of file Replay.hpp.
|
default |
|
virtual |
Definition at line 87 of file Replay.cpp.
References _subscriptions.
|
static |
Apply the parameters from the log.
quiet | do not print an error if true and no log file given via ENV |
Definition at line 986 of file Replay.cpp.
References _replay_file, isSetup(), readDefinitionsAndApplyParams(), and Replay().
Referenced by custom_command().
|
static |
Definition at line 944 of file Replay.cpp.
References applyParams(), print_usage(), and task_spawn().
|
staticprivate |
get the array size from a type.
eg. float[3] -> return float
Definition at line 656 of file Replay.cpp.
Referenced by sizeOfFullType().
|
staticprotected |
Find the offset & field size in bytes for a given field name.
format | format string, as specified by ULog |
field_name | search for this field |
offset | returned offset |
field_size | returned field size |
Definition at line 441 of file Replay.cpp.
References sizeOfFullType().
Referenced by readAndAddSubscription().
|
staticprivate |
Definition at line 642 of file Replay.cpp.
References orb_get_topics(), and orb_topics_count().
Referenced by readAndAddSubscription(), and sizeOfType().
|
protectedvirtual |
handle delay until topic can be published.
next_file_timestamp | timestamp of next message to publish |
timestamp_offset | offset between file start time and replay start time |
Reimplemented in px4::ReplayEkf2.
Definition at line 878 of file Replay.cpp.
References _file_start_time, and hrt_absolute_time().
Referenced by onSubscriptionAdded(), and run().
|
protectedvirtual |
handle the publication of a topic update
Reimplemented in px4::ReplayEkf2.
Definition at line 872 of file Replay.cpp.
References publishTopic().
Referenced by onSubscriptionAdded(), and run().
|
static |
Definition at line 1017 of file Replay.cpp.
References ll40ls::instance, and Replay().
|
inlinestatic |
Definition at line 94 of file Replay.hpp.
References _replay_file.
Referenced by applyParams(), replay_main(), and task_spawn().
|
protected |
Find next data message for this subscription, starting with the stored file offset.
Skip the first message, and if found, read the timestamp and store the new file offset. This also takes care of new subscriptions and parameter updates. When reaching EOF, the subscription is set to invalid. File seek position is arbitrary after this call.
Definition at line 557 of file Replay.cpp.
References _read_until_file_position, ADD_LOGGED_MSG, DATA, DROPOUT, INFO, INFO_MULTIPLE, LOGGING, px4::Replay::Subscription::next_read_pos, px4::Replay::Subscription::next_timestamp, orb_metadata::o_name, orb_metadata::o_size_no_padding, px4::Replay::Subscription::orb_meta, PARAMETER, readAndAddSubscription(), REMOVE_LOGGED_MSG, SYNC, px4::Replay::Subscription::timestamp_offset, and ULOG_MSG_HEADER_LEN.
Referenced by px4::ReplayEkf2::findTimestampAndPublish(), onSubscriptionAdded(), readAndAddSubscription(), and run().
|
inlineprotectedvirtual |
called when entering the main replay loop
Reimplemented in px4::ReplayEkf2.
Definition at line 168 of file Replay.hpp.
Referenced by run().
|
inlineprotectedvirtual |
called when exiting the main replay loop
Reimplemented in px4::ReplayEkf2.
Definition at line 173 of file Replay.hpp.
Referenced by run().
|
inlineprotectedvirtual |
called when a new subscription is added
Reimplemented in px4::ReplayEkf2.
Definition at line 178 of file Replay.hpp.
References data, file, handleTopicDelay(), handleTopicUpdate(), nextDataMessage(), and readTopicDataToBuffer().
Referenced by readAndAddSubscription().
|
static |
Definition at line 1036 of file Replay.cpp.
Referenced by custom_command().
|
protected |
publish an orb topic
sub | |
data |
Definition at line 894 of file Replay.cpp.
References _subscriptions, px4::Replay::CompatBase::apply(), px4::Replay::Subscription::compat, ll40ls::instance, px4::Replay::Subscription::multi_id, orb_metadata::o_name, px4::Replay::Subscription::orb_advert, orb_advertise(), orb_advertise_multi(), px4::Replay::Subscription::orb_meta, ORB_PRIO_DEFAULT, orb_publish(), and px4::Replay::Subscription::publication_counter.
Referenced by px4::ReplayEkf2::findTimestampAndPublish(), px4::ReplayEkf2::handleTopicUpdate(), handleTopicUpdate(), and px4::ReplayEkf2::publishEkf2Topics().
|
private |
Definition at line 324 of file Replay.cpp.
References _file_formats, _read_buffer, _subscription_file_pos, _subscriptions, px4::Replay::Subscription::compat, px4::Replay::CompatSensorCombinedDtType::CompatSensorCombinedDtType(), findFieldOffset(), findTopic(), px4::Replay::Subscription::multi_id, px4::Replay::Subscription::next_read_pos, nextDataMessage(), orb_metadata::o_fields, orb_metadata::o_name, onSubscriptionAdded(), px4::Replay::Subscription::orb_meta, px4::Replay::Subscription::timestamp_offset, and ULOG_MSG_HEADER_LEN.
Referenced by nextDataMessage(), and run().
|
private |
Definition at line 505 of file Replay.cpp.
References _overridden_params, _read_buffer, param_find(), PARAM_INVALID, param_name(), and param_set().
Referenced by readAndHandleAdditionalMessages(), and readFileDefinitions().
|
private |
Read and handle additional messages starting at current file position, while position < end_position.
This handles dropout and parameter update messages. We need to handle these separately, because they have no timestamp. We look at the file position instead.
Definition at line 472 of file Replay.cpp.
References DROPOUT, PARAMETER, readAndApplyParameter(), readDropout(), and ULOG_MSG_HEADER_LEN.
Referenced by run().
|
private |
Read the file header and definitions sections.
Apply the parameters from this section and apply user-defined overridden parameters.
Definition at line 714 of file Replay.cpp.
References PARAMS_OVERRIDE_FILE, readFileDefinitions(), readFileHeader(), and setUserParams().
Referenced by applyParams(), and run().
|
private |
Definition at line 547 of file Replay.cpp.
Referenced by readAndHandleAdditionalMessages().
|
private |
Read definitions section: check formats, apply parameters and store the start of the data section.
Definition at line 194 of file Replay.cpp.
References _data_section_start, ADD_LOGGED_MSG, FLAG_BITS, FORMAT, INFO, INFO_MULTIPLE, PARAMETER, readAndApplyParameter(), readFlagBits(), readFormat(), and ULOG_MSG_HEADER_LEN.
Referenced by readDefinitionsAndApplyParams().
|
private |
Definition at line 170 of file Replay.cpp.
References _file_start_time.
Referenced by readDefinitionsAndApplyParams().
|
private |
Definition at line 251 of file Replay.cpp.
References _read_buffer, _read_until_file_position, and ULOG_INCOMPAT_FLAG0_DATA_APPENDED_MASK.
Referenced by readFileDefinitions().
|
private |
file parsing methods. They return false, when further parsing should be aborted.
Definition at line 298 of file Replay.cpp.
References _file_formats, _read_buffer, and name.
Referenced by readFileDefinitions().
|
protected |
read a topic from the file (offset given by the subscription) into _read_buffer
Definition at line 862 of file Replay.cpp.
References _read_buffer, px4::Replay::Subscription::next_read_pos, orb_metadata::o_size, orb_metadata::o_size_no_padding, px4::Replay::Subscription::orb_meta, and ULOG_MSG_HEADER_LEN.
Referenced by px4::ReplayEkf2::findTimestampAndPublish(), onSubscriptionAdded(), px4::ReplayEkf2::publishEkf2Topics(), and run().
|
override |
Definition at line 745 of file Replay.cpp.
References _data_section_start, _file_start_time, _read_buffer, _replay_file, _replay_start_time, _subscriptions, handleTopicDelay(), handleTopicUpdate(), hrt_absolute_time(), hrt_elapsed_time(), px4::Replay::Subscription::ignored, px4::Replay::Subscription::next_read_pos, px4::Replay::Subscription::next_timestamp, nextDataMessage(), onEnterMainLoop(), onExitMainLoop(), px4::Replay::Subscription::orb_meta, orb_unadvertise(), readAndAddSubscription(), readAndHandleAdditionalMessages(), readDefinitionsAndApplyParams(), readTopicDataToBuffer(), px4::Replay::Subscription::timestamp_offset, and ULOG_MSG_HEADER_LEN.
|
static |
Tell the replay module that we want to use replay mode.
After that, only 'replay start' must be executed (typically the last step after startup).
file_name | file name of the used log replay file. Will be copied. |
Definition at line 118 of file Replay.cpp.
References _replay_file.
Referenced by replay_main().
|
private |
Definition at line 128 of file Replay.cpp.
References _overridden_params, param_find(), param_name(), param_set(), param_type(), PARAM_TYPE_FLOAT, and PARAM_TYPE_INT32.
Referenced by readDefinitionsAndApplyParams().
|
staticprivate |
get the size of a type that can be an array
Definition at line 706 of file Replay.cpp.
References extractArraySize(), and sizeOfType().
Referenced by findFieldOffset().
|
staticprivate |
get the size of a type that is not an array
Definition at line 671 of file Replay.cpp.
References findTopic(), and orb_metadata::o_size.
Referenced by sizeOfFullType().
|
static |
Definition at line 958 of file Replay.cpp.
References isSetup().
Referenced by custom_command().
|
private |
first ADD_LOGGED_MSG message
Definition at line 218 of file Replay.hpp.
Referenced by readFileDefinitions(), and run().
|
private |
all formats we read from the file
Definition at line 214 of file Replay.hpp.
Referenced by readAndAddSubscription(), and readFormat().
|
private |
Definition at line 216 of file Replay.hpp.
Referenced by handleTopicDelay(), readFileHeader(), and run().
|
private |
Definition at line 213 of file Replay.hpp.
Referenced by readAndApplyParameter(), and setUserParams().
|
protected |
Definition at line 210 of file Replay.hpp.
Referenced by px4::ReplayEkf2::findTimestampAndPublish(), px4::ReplayEkf2::publishEkf2Topics(), readAndAddSubscription(), readAndApplyParameter(), readFlagBits(), readFormat(), readTopicDataToBuffer(), and run().
|
private |
read limit if log contains appended data
Definition at line 223 of file Replay.hpp.
Referenced by nextDataMessage(), and readFlagBits().
|
staticprivate |
Definition at line 269 of file Replay.hpp.
Referenced by applyParams(), isSetup(), run(), and setupReplayFile().
|
private |
Definition at line 217 of file Replay.hpp.
Referenced by run().
|
private |
keep track of file position to avoid adding a subscription multiple times.
Definition at line 221 of file Replay.hpp.
Referenced by readAndAddSubscription().
|
protected |
Definition at line 209 of file Replay.hpp.
Referenced by px4::ReplayEkf2::findTimestampAndPublish(), px4::ReplayEkf2::onExitMainLoop(), px4::ReplayEkf2::publishEkf2Topics(), publishTopic(), readAndAddSubscription(), run(), and ~Replay().