Skip to content
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

Implement component metadata protocol #2272

Merged
merged 15 commits into from
Apr 26, 2024
Merged

Conversation

bkueng
Copy link
Member

@bkueng bkueng commented Apr 5, 2024

This implements the MAVLink component metadata protocol.
Details:

  • Allows users to retrieve the JSON metadata. The idea is to then build on top of that to handle the specific component types (e.g. parameters or events)
  • Implementation for both client + server (with system test)
  • File caching based on CRC
  • Support for mftp + http (if curl is enabled)
  • translation is not implemented

Client example usage:

auto component_metadata = ComponentMetadata{system.value()};
component_metadata.register_notification_callback([] (ComponentMetadata::MetadataType type, uint32_t compid, const std::string& json_data) {
	std::cout << "Got metadata: type: " << (int)type << " compid: " << compid << std::endl;
});

TODO:

  • To support https, curl with openssl needs to be enabled (I tested this already)
  • For XZ decompression, the xz-embedded submodule is added. liblzma could be used instead.
  • Are plugins required to stop ongoing mftp/http downloads when PluginImplBase::disable is called?

Requires PX4/PX4-Autopilot#22980

Tested with PX4 (SITL + Pixhawk, mftp + https links)

Copy link
Collaborator

@julianoes julianoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! Thanks so much for the split commits, makes the review much easier.

I left a bunch of comments. I might do a more in-depth review once I try out some of the pieces.

What's missing is the proto pull request. I want to make sure I understand the user interface.

src/mavsdk/core/locked_queue.h Outdated Show resolved Hide resolved
src/mavsdk/core/mavlink_ftp_client.h Outdated Show resolved Hide resolved
src/mavsdk/core/mavlink_ftp_client.cpp Show resolved Hide resolved
.gitmodules Outdated
Comment on lines 7 to 9
[submodule "src/third_party/xz-embedded/submodule"]
path = src/third_party/xz-embedded/submodule
url = https://github.com/tukaani-project/xz-embedded.git
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to get the dependency in the same way like all others (except gtest):

https://github.com/mavlink/MAVSDK/blob/main/third_party/CMakeLists.txt
E.g. https://github.com/mavlink/MAVSDK/blob/main/third_party/jsoncpp/CMakeLists.txt

Which library is up to you.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I changed to the system lib liblzma in 5175884

src/mavsdk/core/fs_utils.cpp Show resolved Hide resolved
}
_tmp_path = *tmp_option;

LogDebug() << "Storing metadata under " << _tmp_path;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, I would probably add a _debugging bool like other plugins have it which can be enabled using export MAVSDK_COMPONENT_METADATA_DEBUGGING=1, and then you can make it quite verbose in that case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a725299

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

Comment on lines 215 to 226
for (int i = 0; i < 100 && (!received_events || !received_parameters); ++i) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't want to do this one with std::future and std::promise?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it's not worth the extra complexity given it's a test and we need to wait for multiple things.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I wonder what the canonical way is to wait for two futures.

Comment on lines +212 to +213
start_timer(3.0);
LogDebug() << "No session available, retrying...";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, nice.

{
_system_impl.unregister_timeout_handler(_timeout_cookie);
_system_impl.register_timeout_handler(
[this]() { timeout(); }, _system_impl.timeout_s(), &_timeout_cookie);
[this]() { timeout(); }, duration_s.value_or(_system_impl.timeout_s()), &_timeout_cookie);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't know value_or, that's nice.

@bkueng
Copy link
Member Author

bkueng commented Apr 11, 2024

Thanks for the review @julianoes! Here's the proto changes: mavlink/MAVSDK-Proto#338
I'll amend the commits after things settle.

@bkueng bkueng force-pushed the component_metadata branch 3 times, most recently from 8cd8a6e to c1883f4 Compare April 25, 2024 11:46
@bkueng
Copy link
Member Author

bkueng commented Apr 25, 2024

CI is passing now, except for the proto submodule not being updated yet.
I also had to update the re2 dependency (c1883f4). I'm not sure why that problem shows up here, but not on main.

julianoes
julianoes previously approved these changes Apr 26, 2024
Copy link
Collaborator

@julianoes julianoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine to be merged once we have proto merged!

@@ -0,0 +1,20 @@
#pragma once
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably merge this file with https://github.com/mavlink/MAVSDK/blob/main/src/system_tests/fs_helpers.h but it can happen after this PR.

bkueng and others added 15 commits April 26, 2024 13:28
Otherwise there might still be data in the buffer.

All other places already close the stream.
This version (5.4.5) is not affected by the recently discovered backdoor
(https://tukaani.org/xz-backdoor/)
instead of calling the callback directly.

Otherwise if the callback tries to trigger a new request, it would block
indefinitely when trying to add a work item to _work_queue, which is already
locked by this:
LockedQueue<Work>::Guard work_queue_guard(_work_queue);
To include this commit:
google/re2@9ebe4a2

Which should fix the CI error:
CMake Error at /home/runner/work/MAVSDK/MAVSDK/build/release/third_party/install/lib/cmake/re2/re2Config.cmake:15 (message):
  File or directory /include referenced by variable re2_INCLUDE_DIR does not
  exist !
Brings component metadata plugins.

Signed-off-by: Julian Oes <[email protected]>
Copy link

sonarcloud bot commented Apr 26, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots
E Reliability Rating on New Code (required ≥ A)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@julianoes julianoes merged commit d68204a into mavlink:main Apr 26, 2024
27 of 28 checks passed
@julianoes
Copy link
Collaborator

Thanks a lot @bkueng!

@bkueng bkueng deleted the component_metadata branch April 26, 2024 06:28
@bkueng bkueng mentioned this pull request Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants