AP_HAL_SITL: add packet loss and delay to each uart #25775
+419
−10
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.
I need a way to simulate:
(I am working on a redundant link manager plugin for Mission Planner that tries to intelligently select the "best" link to the aircraft.)
Before this, you could only simulate single-byte losses, and the setting applied to all serial ports. This switches to dropping full packets (I may extend this to partial packets at some point, to catch any issues caused by dropped data not aligning with packet boundaries, but I'm trying to figure out how to do that without introducing a million parameters), and it allows you to set the drop rate per serial port. In conjunction with a lua script, this could be used to cause burst losses for multiple seconds or could steadily increase the loss rate as you fly further from home.
I also added two queues to delay packets for a period of time both in and out. This is to simulate, for example, the ping time of a 4G link or satcom. This could even be used with a script that randomly sets this high and then low to simulate a TCP link that locks up for some period of time, then delivers all that data all at once when it comes back.
I have included a simple example script for an RF link, a cell link, and a hypothetical satellite device. Here's a screen of flying this aircraft in Mission Planner with all three links:
Here's a little animation of me testing that the latency works two-ways. Three instances of Mission Planner running on three different links. The left has no delay, and the two on the right have a delay of 500ms both ways. 500ms after I click the button on the right, the status message on the left updates (because the RX latency of the SITL link receiving the AUX function command), and then 500ms after that, the status message on the right updates (because the TX latency of that SITL link)