mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-22 01:12:31 +00:00
refactor replay: split timestamp offset into separate method
This commit is contained in:
@@ -112,6 +112,16 @@ protected:
|
|||||||
int publication_counter = 0;
|
int publication_counter = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the offset & field size in bytes for a given field name
|
||||||
|
* @param format format string, as specified by ULog
|
||||||
|
* @param field_name search for this field
|
||||||
|
* @param offset returned offset
|
||||||
|
* @param field_size returned field size
|
||||||
|
* @return true if found, false otherwise
|
||||||
|
*/
|
||||||
|
static bool findFieldOffset(const std::string &format, const std::string &field_name, int &offset, int &field_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* publish an orb topic
|
* publish an orb topic
|
||||||
* @param sub
|
* @param sub
|
||||||
|
|||||||
@@ -332,42 +332,18 @@ bool Replay::readAndAddSubscription(std::ifstream &file, uint16_t msg_size)
|
|||||||
subscription.multi_id = multi_id;
|
subscription.multi_id = multi_id;
|
||||||
|
|
||||||
|
|
||||||
//find the timestamp offset (not necessarily the first field)
|
//find the timestamp offset
|
||||||
string fields = orb_meta->o_fields;
|
int field_size;
|
||||||
size_t prev_field_end = 0;
|
bool timestamp_found = findFieldOffset(orb_meta->o_fields, "timestamp", subscription.timestamp_offset, field_size);
|
||||||
size_t field_end = fields.find(';');
|
|
||||||
bool timestamp_found = false;
|
|
||||||
subscription.timestamp_offset = 0;
|
|
||||||
|
|
||||||
while (field_end != string::npos && !timestamp_found) {
|
|
||||||
size_t space_pos = fields.find(' ', prev_field_end);
|
|
||||||
|
|
||||||
if (space_pos != string::npos) {
|
|
||||||
string type_name_full = fields.substr(prev_field_end, space_pos - prev_field_end);
|
|
||||||
string field_name = fields.substr(space_pos + 1, field_end - space_pos - 1);
|
|
||||||
|
|
||||||
if (field_name == "timestamp") {
|
|
||||||
timestamp_found = true;
|
|
||||||
|
|
||||||
if (type_name_full != "uint64_t") {
|
|
||||||
PX4_ERR("Unsupported timestamp type %s, ignoring the topic %s", type_name_full.c_str(),
|
|
||||||
orb_meta->o_name);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
subscription.timestamp_offset += sizeOfFullType(type_name_full);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
prev_field_end = field_end + 1;
|
|
||||||
field_end = fields.find(';', prev_field_end);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!timestamp_found) {
|
if (!timestamp_found) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (field_size != 8) {
|
||||||
|
PX4_ERR("Unsupported timestamp with size %i, ignoring the topic %s", field_size, orb_meta->o_name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//find first data message (and the timestamp)
|
//find first data message (and the timestamp)
|
||||||
streampos cur_pos = file.tellg();
|
streampos cur_pos = file.tellg();
|
||||||
@@ -398,6 +374,37 @@ bool Replay::readAndAddSubscription(std::ifstream &file, uint16_t msg_size)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Replay::findFieldOffset(const string &format, const string &field_name, int &offset, int &field_size)
|
||||||
|
{
|
||||||
|
size_t prev_field_end = 0;
|
||||||
|
size_t field_end = format.find(';');
|
||||||
|
offset = 0;
|
||||||
|
field_size = 0;
|
||||||
|
|
||||||
|
while (field_end != string::npos) {
|
||||||
|
size_t space_pos = format.find(' ', prev_field_end);
|
||||||
|
|
||||||
|
if (space_pos != string::npos) {
|
||||||
|
string type_name_full = format.substr(prev_field_end, space_pos - prev_field_end);
|
||||||
|
string cur_field_name = format.substr(space_pos + 1, field_end - space_pos - 1);
|
||||||
|
|
||||||
|
if (cur_field_name == field_name) {
|
||||||
|
field_size = sizeOfFullType(type_name_full);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
offset += sizeOfFullType(type_name_full);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prev_field_end = field_end + 1;
|
||||||
|
field_end = format.find(';', prev_field_end);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Replay::readAndHandleAdditionalMessages(std::ifstream &file, std::streampos end_position)
|
bool Replay::readAndHandleAdditionalMessages(std::ifstream &file, std::streampos end_position)
|
||||||
{
|
{
|
||||||
ulog_message_header_s message_header;
|
ulog_message_header_s message_header;
|
||||||
|
|||||||
Reference in New Issue
Block a user