mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-31 02:16:53 +08:00
replay: do not fail on first ignored topic
This commit is contained in:
@@ -418,7 +418,7 @@ string Replay::getOrbFields(const orb_metadata *meta)
|
|||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
Replay::ReadAndAndAddSubResult
|
||||||
Replay::readAndAddSubscription(std::ifstream &file, uint16_t msg_size)
|
Replay::readAndAddSubscription(std::ifstream &file, uint16_t msg_size)
|
||||||
{
|
{
|
||||||
_read_buffer.reserve(msg_size + 1);
|
_read_buffer.reserve(msg_size + 1);
|
||||||
@@ -428,11 +428,11 @@ Replay::readAndAddSubscription(std::ifstream &file, uint16_t msg_size)
|
|||||||
message[msg_size] = 0;
|
message[msg_size] = 0;
|
||||||
|
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return false;
|
return ReadAndAndAddSubResult::kFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file.tellg() <= _subscription_file_pos) { //already read this subscription
|
if (file.tellg() <= _subscription_file_pos) { //already read this subscription
|
||||||
return true;
|
return ReadAndAndAddSubResult::kIgnoringMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
_subscription_file_pos = file.tellg();
|
_subscription_file_pos = file.tellg();
|
||||||
@@ -444,7 +444,7 @@ Replay::readAndAddSubscription(std::ifstream &file, uint16_t msg_size)
|
|||||||
|
|
||||||
if (!orb_meta) {
|
if (!orb_meta) {
|
||||||
PX4_WARN("Topic %s not found internally. Will ignore it", topic_name.c_str());
|
PX4_WARN("Topic %s not found internally. Will ignore it", topic_name.c_str());
|
||||||
return true;
|
return ReadAndAndAddSubResult::kIgnoringMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatBase *compat = nullptr;
|
CompatBase *compat = nullptr;
|
||||||
@@ -520,7 +520,7 @@ Replay::readAndAddSubscription(std::ifstream &file, uint16_t msg_size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true; // not a fatal error
|
return ReadAndAndAddSubResult::kIgnoringMsg; // not a fatal error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,13 +535,13 @@ Replay::readAndAddSubscription(std::ifstream &file, uint16_t msg_size)
|
|||||||
|
|
||||||
if (!timestamp_found) {
|
if (!timestamp_found) {
|
||||||
delete subscription;
|
delete subscription;
|
||||||
return true;
|
return ReadAndAndAddSubResult::kIgnoringMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (field_size != 8) {
|
if (field_size != 8) {
|
||||||
PX4_ERR("Unsupported timestamp with size %i, ignoring the topic %s", field_size, orb_meta->o_name);
|
PX4_ERR("Unsupported timestamp with size %i, ignoring the topic %s", field_size, orb_meta->o_name);
|
||||||
delete subscription;
|
delete subscription;
|
||||||
return true;
|
return ReadAndAndAddSubResult::kIgnoringMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
//find first data message (and the timestamp)
|
//find first data message (and the timestamp)
|
||||||
@@ -550,7 +550,7 @@ Replay::readAndAddSubscription(std::ifstream &file, uint16_t msg_size)
|
|||||||
|
|
||||||
if (!nextDataMessage(file, *subscription, msg_id)) {
|
if (!nextDataMessage(file, *subscription, msg_id)) {
|
||||||
delete subscription;
|
delete subscription;
|
||||||
return false;
|
return ReadAndAndAddSubResult::kFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.seekg(cur_pos);
|
file.seekg(cur_pos);
|
||||||
@@ -558,7 +558,7 @@ Replay::readAndAddSubscription(std::ifstream &file, uint16_t msg_size)
|
|||||||
if (!subscription->orb_meta) {
|
if (!subscription->orb_meta) {
|
||||||
//no message found. This is not a fatal error
|
//no message found. This is not a fatal error
|
||||||
delete subscription;
|
delete subscription;
|
||||||
return true;
|
return ReadAndAndAddSubResult::kIgnoringMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
PX4_DEBUG("adding subscription for %s (msg_id %i)", subscription->orb_meta->o_name, msg_id);
|
PX4_DEBUG("adding subscription for %s (msg_id %i)", subscription->orb_meta->o_name, msg_id);
|
||||||
@@ -572,7 +572,7 @@ Replay::readAndAddSubscription(std::ifstream &file, uint16_t msg_size)
|
|||||||
|
|
||||||
onSubscriptionAdded(*_subscriptions[msg_id], msg_id);
|
onSubscriptionAdded(*_subscriptions[msg_id], msg_id);
|
||||||
|
|
||||||
return true;
|
return ReadAndAndAddSubResult::kSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -908,13 +908,19 @@ Replay::run()
|
|||||||
replay_file.seekg(_data_section_start);
|
replay_file.seekg(_data_section_start);
|
||||||
|
|
||||||
//we know the next message must be an ADD_LOGGED_MSG
|
//we know the next message must be an ADD_LOGGED_MSG
|
||||||
replay_file.read((char *)&message_header, ULOG_MSG_HEADER_LEN);
|
ReadAndAndAddSubResult res;
|
||||||
|
|
||||||
if (!readAndAddSubscription(replay_file, message_header.msg_size)) {
|
do {
|
||||||
|
replay_file.read((char *)&message_header, ULOG_MSG_HEADER_LEN);
|
||||||
|
res = readAndAddSubscription(replay_file, message_header.msg_size);
|
||||||
|
|
||||||
|
if (res == ReadAndAndAddSubResult::kFailure) {
|
||||||
PX4_ERR("Failed to read subscription");
|
PX4_ERR("Failed to read subscription");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} while (res != ReadAndAndAddSubResult::kSuccess);
|
||||||
|
|
||||||
const uint64_t timestamp_offset = getTimestampOffset();
|
const uint64_t timestamp_offset = getTimestampOffset();
|
||||||
uint32_t nr_published_messages = 0;
|
uint32_t nr_published_messages = 0;
|
||||||
streampos last_additional_message_pos = _data_section_start;
|
streampos last_additional_message_pos = _data_section_start;
|
||||||
|
|||||||
@@ -262,7 +262,9 @@ private:
|
|||||||
|
|
||||||
///file parsing methods. They return false, when further parsing should be aborted.
|
///file parsing methods. They return false, when further parsing should be aborted.
|
||||||
bool readFormat(std::ifstream &file, uint16_t msg_size);
|
bool readFormat(std::ifstream &file, uint16_t msg_size);
|
||||||
bool readAndAddSubscription(std::ifstream &file, uint16_t msg_size);
|
|
||||||
|
enum class ReadAndAndAddSubResult : uint8_t { kSuccess, kIgnoringMsg, kFailure };
|
||||||
|
ReadAndAndAddSubResult readAndAddSubscription(std::ifstream &file, uint16_t msg_size);
|
||||||
bool readFlagBits(std::ifstream &file, uint16_t msg_size);
|
bool readFlagBits(std::ifstream &file, uint16_t msg_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user