-
-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
log_streaming: make it robust to message drops #2290
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,28 +178,45 @@ void LogStreamingImpl::process_logging_data(const mavlink_message_t& message) | |
} | ||
|
||
std::lock_guard<std::mutex> lock(_mutex); | ||
check_sequence(logging_data.sequence); | ||
|
||
if (logging_data.first_message_offset == std::numeric_limits<uint8_t>::max()) { | ||
_ulog_data.insert( | ||
_ulog_data.end(), logging_data.data, logging_data.data + logging_data.length); | ||
} else { | ||
if (logging_data.first_message_offset > sizeof(logging_data.data)) { | ||
LogWarn() << "Invalid first_message_offset"; | ||
return; | ||
} | ||
|
||
_ulog_data.insert( | ||
_ulog_data.end(), | ||
logging_data.data, | ||
logging_data.data + logging_data.first_message_offset); | ||
process_message(); | ||
_ulog_data.clear(); | ||
|
||
_ulog_data.insert( | ||
_ulog_data.end(), | ||
logging_data.data + logging_data.first_message_offset, | ||
logging_data.data + logging_data.length); | ||
auto drop_state = check_sequence(logging_data.sequence); | ||
|
||
switch (drop_state) { | ||
case DropState::Ok: | ||
if (logging_data.first_message_offset == std::numeric_limits<uint8_t>::max()) { | ||
_ulog_data.insert( | ||
_ulog_data.end(), logging_data.data, logging_data.data + logging_data.length); | ||
|
||
} else { | ||
if (logging_data.first_message_offset > sizeof(logging_data.data)) { | ||
LogWarn() << "Invalid first_message_offset"; | ||
return; | ||
} | ||
|
||
_ulog_data.insert( | ||
_ulog_data.end(), | ||
logging_data.data, | ||
logging_data.data + logging_data.first_message_offset); | ||
process_message(); | ||
|
||
_ulog_data.clear(); | ||
_ulog_data.insert( | ||
_ulog_data.end(), | ||
logging_data.data + logging_data.first_message_offset, | ||
logging_data.data + logging_data.length); | ||
} | ||
break; | ||
|
||
case DropState::Dropped: | ||
_ulog_data.clear(); | ||
_ulog_data.insert( | ||
_ulog_data.end(), | ||
logging_data.data + logging_data.first_message_offset, | ||
logging_data.data + logging_data.length); | ||
break; | ||
|
||
case DropState::Duplicate: | ||
// Ignore. | ||
break; | ||
} | ||
} | ||
|
||
|
@@ -254,46 +271,62 @@ void LogStreamingImpl::process_logging_data_acked(const mavlink_message_t& messa | |
} | ||
|
||
std::lock_guard<std::mutex> lock(_mutex); | ||
check_sequence(logging_data_acked.sequence); | ||
|
||
if (logging_data_acked.first_message_offset == std::numeric_limits<uint8_t>::max()) { | ||
_ulog_data.insert( | ||
_ulog_data.end(), | ||
logging_data_acked.data, | ||
logging_data_acked.data + logging_data_acked.length); | ||
} else { | ||
if (logging_data_acked.first_message_offset > sizeof(logging_data_acked.data)) { | ||
LogWarn() << "Invalid first_message_offset"; | ||
return; | ||
} | ||
|
||
_ulog_data.insert( | ||
_ulog_data.end(), | ||
logging_data_acked.data, | ||
logging_data_acked.data + logging_data_acked.first_message_offset); | ||
process_message(); | ||
_ulog_data.clear(); | ||
|
||
_ulog_data.insert( | ||
_ulog_data.end(), | ||
logging_data_acked.data + logging_data_acked.first_message_offset, | ||
logging_data_acked.data + logging_data_acked.length); | ||
auto drop_state = check_sequence(logging_data_acked.sequence); | ||
|
||
switch (drop_state) { | ||
case DropState::Ok: | ||
if (logging_data_acked.first_message_offset == std::numeric_limits<uint8_t>::max()) { | ||
_ulog_data.insert( | ||
_ulog_data.end(), | ||
logging_data_acked.data, | ||
logging_data_acked.data + logging_data_acked.length); | ||
} else { | ||
if (logging_data_acked.first_message_offset > sizeof(logging_data_acked.data)) { | ||
LogWarn() << "Invalid first_message_offset"; | ||
return; | ||
} | ||
|
||
_ulog_data.insert( | ||
_ulog_data.end(), | ||
logging_data_acked.data, | ||
logging_data_acked.data + logging_data_acked.first_message_offset); | ||
process_message(); | ||
_ulog_data.clear(); | ||
|
||
_ulog_data.insert( | ||
_ulog_data.end(), | ||
logging_data_acked.data + logging_data_acked.first_message_offset, | ||
logging_data_acked.data + logging_data_acked.length); | ||
} | ||
break; | ||
|
||
case DropState::Dropped: | ||
_ulog_data.clear(); | ||
_ulog_data.insert( | ||
_ulog_data.end(), | ||
logging_data_acked.data + logging_data_acked.first_message_offset, | ||
logging_data_acked.data + logging_data_acked.length); | ||
Comment on lines
+305
to
+308
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you must only insert if there's a valid offset: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, right! |
||
break; | ||
|
||
case DropState::Duplicate: | ||
// Ignore. | ||
break; | ||
} | ||
} | ||
|
||
void LogStreamingImpl::check_sequence(uint16_t sequence) | ||
LogStreamingImpl::DropState LogStreamingImpl::check_sequence(uint16_t sequence) | ||
{ | ||
// Assume we have lock. | ||
|
||
if (!_maybe_current_sequence) { | ||
// This is the first time we use the sequence. | ||
_maybe_current_sequence = sequence; | ||
return; | ||
return DropState::Ok; | ||
} | ||
|
||
if (_maybe_current_sequence.value() == sequence) { | ||
// Duplicate | ||
return; | ||
return DropState::Duplicate; | ||
} | ||
|
||
if (sequence > _maybe_current_sequence.value()) { | ||
|
@@ -303,6 +336,10 @@ void LogStreamingImpl::check_sequence(uint16_t sequence) | |
if (drop > 0 && _debugging) { | ||
LogDebug() << "Dropped: " << drop << " (no wrap around), overall: " << _drops; | ||
} | ||
|
||
_maybe_current_sequence = sequence; | ||
return drop > 0 ? DropState::Dropped : DropState::Ok; | ||
|
||
} else { | ||
// Wrap around! | ||
uint16_t drop = | ||
|
@@ -311,9 +348,10 @@ void LogStreamingImpl::check_sequence(uint16_t sequence) | |
if (drop > 0 && _debugging) { | ||
LogDebug() << "Dropped: " << drop << " (with wrap around), overall: " << _drops; | ||
} | ||
} | ||
|
||
_maybe_current_sequence = sequence; | ||
_maybe_current_sequence = sequence; | ||
return drop > 0 ? DropState::Dropped : DropState::Ok; | ||
} | ||
} | ||
|
||
void LogStreamingImpl::process_message() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a dropout you must first wait for a valid
logging_data_acked.first_message_offset
before inserting in_ulog_data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. So I need to keep track of the previous state. Or rather set if there was a valid one.