Skip to content

Commit

Permalink
Bugfix: Connection status only reported as false when the flight cont…
Browse files Browse the repository at this point in the history
…roller disconnects (#19)

* Changed heartbeats to only disable when all other systems have timed out.

* Changed MAVSDK server to only report connection status of primary system.

* Corrected behaviour to pass unit tests.

* Added Github workflow to build mavsdk_server and create a release.
  • Loading branch information
KierDugan authored Apr 24, 2024
1 parent 315cd76 commit aaabffb
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/sees.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build Sees Release

on:
push:
branches:
- 'main'
tags:
- 'v*'
pull_request:
branches:
- '*'

jobs:
ubuntu22-superbuild:
name: ubuntu-22.04 (mavsdk_server, superbuild)
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: actions/cache@v2
id: cache
with:
path: ./build/release/third_party/install
key: ${{ github.job }}-${{ hashFiles('./third_party/**') }}
- name: disable superbuild on cache hit
if: steps.cache.outputs.cache-hit == 'true'
run: echo "superbuild=-DSUPERBUILD=OFF" >> $GITHUB_ENV && echo "cmake_prefix_path=-DCMAKE_PREFIX_PATH=$(pwd)/build/release/third_party/install" >> $GITHUB_ENV
- name: install pymavlink dependencies
run: sudo apt-get update && sudo apt-get install -y python3-future build-essential cmake
- name: configure
run: cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=Release -DBUILD_MAVSDK_SERVER=ON -DWERROR=OFF -Bbuild/release -H.
- name: build
run: cmake --build build/release -j2
- name: install
run: sudo cmake --build build/release --target install
- name: install examples dependencies
run: sudo apt-get install -y libsdl2-dev
- name: configure examples
run: (cd examples && cmake -DCMAKE_BUILD_TYPE=Release -DWERROR=OFF -Bbuild -H.)
- name: build examples
run: (cd examples && cmake --build build -j2)
- name: test
run: ./build/release/src/unit_tests_runner
- name: test (mavsdk_server)
run: ./build/release/src/mavsdk_server/test/unit_tests_mavsdk_server
- name: test FTP server
run: ./build/release/src/integration_tests/integration_tests_runner --gtest_filter="FtpTest.TestServer"
- name: Upload release binaries
uses: actions/upload-artifact@v3
with:
name: mavsdk_server_sees_x86_64
path: ./install/bin/mavsdk_server
- name: Create Release
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: gh release create --verify-tag --draft --generate-notes $TAG install/bin/mavsdk_server
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ github.ref_name }}
8 changes: 8 additions & 0 deletions src/mavsdk/core/mavsdk_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ void MavsdkImpl::notify_on_discover()
auto temp_callback = _new_system_callback;
call_user_callback([temp_callback]() { temp_callback(); });
}

// Start sending heartbeats now that it's certain there are other systems to receive them.
start_sending_heartbeats();
}

void MavsdkImpl::notify_on_timeout()
Expand All @@ -520,6 +523,11 @@ void MavsdkImpl::notify_on_timeout()
auto temp_callback = _new_system_callback;
call_user_callback([temp_callback]() { temp_callback(); });
}

// Only stop sending heartbeats if **all** systems have timed out.
if (!is_any_system_connected()) {
stop_sending_heartbeats();
}
}

void MavsdkImpl::subscribe_on_new_system(const Mavsdk::NewSystemCallback& callback)
Expand Down
5 changes: 0 additions & 5 deletions src/mavsdk/core/system_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,6 @@ void SystemImpl::set_connected()
_parent.notify_on_discover();
}

// Send a heartbeat back immediately.
_parent.start_sending_heartbeats();

if (!_always_connected) {
register_timeout_handler(
[this] { heartbeats_timed_out(); },
Expand Down Expand Up @@ -641,8 +638,6 @@ void SystemImpl::set_disconnected()
}
}

_parent.stop_sending_heartbeats();

{
std::lock_guard<std::mutex> lock(_plugin_impls_mutex);
for (auto plugin_impl : _plugin_impls) {
Expand Down
9 changes: 7 additions & 2 deletions src/mavsdk_server/src/core/core_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ class CoreServiceImpl final : public mavsdk::rpc::core::CoreService::Service {
{
auto systems = _mavsdk.systems();

for (auto system : systems) {
// Don't publish anything until we have at least one system.
if (systems.size() >= 1) {
// System at index 0 is always the flight controller.
const bool is_connected = systems[0]->is_connected();

// Send just a single message instead of iterating over all systems.
const auto rpc_connection_state_response =
createRpcConnectionStateResponse(system->is_connected());
createRpcConnectionStateResponse(is_connected);

std::lock_guard<std::mutex> lock(connection_state_mutex);
writer->Write(rpc_connection_state_response);
Expand Down

0 comments on commit aaabffb

Please sign in to comment.