Skip to content

Commit

Permalink
Merge pull request #2060 from mavlink/pr-split-ftp
Browse files Browse the repository at this point in the history
Split Ftp plugin into Ftp and FtpServer
  • Loading branch information
julianoes authored Nov 2, 2023
2 parents b545332 + 62874de commit 578ec76
Show file tree
Hide file tree
Showing 67 changed files with 7,807 additions and 6,956 deletions.
66 changes: 26 additions & 40 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y lcov python3-future
- name: configure
run: cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=Coverage -DASAN=ON -DWERROR=OFF -Bbuild -H.
run: cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=Coverage -DASAN=ON -DWERROR=OFF -DENABLE_CPPTRACE=On -Bbuild -H.
- name: build
run: cmake --build build -j2
- name: unit tests
Expand Down Expand Up @@ -64,13 +64,13 @@ jobs:
cmake -Bthird_party/mavlink/build -Sthird_party/mavlink
sudo cmake --build third_party/mavlink/build
- name: configure
run: cmake -DCMAKE_BUILD_TYPE=Release -DSUPERBUILD=OFF -DWERROR=OFF -Bbuild/release -H.
run: cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DSUPERBUILD=OFF -DWERROR=OFF -DENABLE_CPPTRACE=On -Bbuild/release -H.
- name: build
run: cmake --build build/release -j2
- name: unit tests
run: ./build/release/src/unit_tests/unit_tests_runner
- name: system tests
run: ./build/release/src/system_tests/system_tests_runner
#- name: system tests
# run: ./build/release/src/system_tests/system_tests_runner

ubuntu-superbuild:
name: ${{ matrix.ubuntu_image }} (mavsdk_server, superbuild)
Expand All @@ -91,7 +91,7 @@ jobs:
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: configure
run: cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=Release -DBUILD_MAVSDK_SERVER=ON -DWERROR=OFF -Bbuild/release -H.
run: cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_MAVSDK_SERVER=ON -DWERROR=OFF -DENABLE_CPPTRACE=On -Bbuild/release -H.
- name: build
run: cmake --build build/release -j2
- name: install
Expand All @@ -104,13 +104,13 @@ jobs:
- name: install examples dependencies
run: sudo apt-get install libsdl2-dev
- name: configure examples
run: cmake -DCMAKE_PREFIX_PATH=$(pwd)/build/release/third_party/install -DCMAKE_BUILD_TYPE=Release -DWERROR=OFF -Bexamples/build -Hexamples
run: cmake -DCMAKE_PREFIX_PATH=$(pwd)/build/release/third_party/install -DCMAKE_BUILD_TYPE=RelWithDebInfo -DWERROR=OFF -Bexamples/build -Hexamples
- name: build examples
run: cmake --build examples/build -j2
- name: unit tests
run: ./build/release/src/unit_tests/unit_tests_runner
- name: system tests
run: ./build/release/src/system_tests/system_tests_runner
# - name: system tests
# run: ./build/release/src/system_tests/system_tests_runner
- name: test (mavsdk_server)
run: ./build/release/src/mavsdk_server/test/unit_tests_mavsdk_server

Expand All @@ -125,22 +125,22 @@ jobs:
id: cache
with:
path: ~/.hunter
key: ${{ github.job }}-${{ hashFiles('~/.hunter/**') }}
key: ${{ github.job }}-${{ hashFiles('~/.hunter/**') }}-2
- name: install mavlink on the system
run: |
cmake -Bthird_party/mavlink/build -Sthird_party/mavlink
sudo cmake --build third_party/mavlink/build
- name: configure
run: cmake -DSUPERBUILD=OFF -DHUNTER_ENABLED=ON -DCMAKE_TOOLCHAIN_FILE=$(pwd)/src/cmake/fpic_toolchain.cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_MAVSDK_SERVER=OFF -DBUILD_SHARED_LIBS=OFF -Bbuild -H.
run: cmake -DSUPERBUILD=OFF -DHUNTER_ENABLED=ON -DCMAKE_TOOLCHAIN_FILE=$(pwd)/src/cmake/fpic_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_MAVSDK_SERVER=OFF -DBUILD_SHARED_LIBS=OFF -DENABLE_CPPTRACE=On -Bbuild -H.
- name: build
run: cmake --build build -j2
- name: unit tests
run: ./build/src/unit_tests/unit_tests_runner
- name: system tests
run: ./build/src/system_tests/system_tests_runner
#- name: system tests
# run: ./build/src/system_tests/system_tests_runner

ubuntu20-proto-check:
name: ubuntu-22.04 (proto check)
ubuntu22-style-and-proto-check:
name: ubuntu-22.04 (style and proto check)
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
Expand All @@ -157,28 +157,14 @@ jobs:
if: steps.cache.outputs.cache-hit == 'true'
run: echo "superbuild=-DSUPERBUILD=OFF" >> $GITHUB_ENV && echo "cmake_prefix_path=-DCMAKE_PREFIX_PATH=$(pwd)/build/default/third_party/install" >> $GITHUB_ENV
- name: build necessary protoc tooling
run: cmake $superbuild $cmake_prefix_path -DBUILD_MAVSDK_SERVER=ON -Bbuild/default -H.
run: cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=Debug -DBUILD_MAVSDK_SERVER=ON -DENABLE_CPPTRACE=On -Bbuild/default -H.
- name: generate code from protos
run: PATH="$PATH:$HOME/.local/bin" tools/generate_from_protos.sh
- name: fix style
run: tools/fix_style.sh . || true
- name: check for diff
run: git diff --exit-code

ubuntu20-check-style:
name: ubuntu-22.04 (check style and docs)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: install dependencies
run: sudo apt-get update && sudo apt-get install -y doxygen clang-format-12
- name: check style
run: ./tools/fix_style.sh .
- name: check docs
run: tools/generate_docs.sh

deb-package:
name: ${{ matrix.container_name }} (package, non-mavsdk_server)
runs-on: ubuntu-20.04
Expand All @@ -195,7 +181,7 @@ jobs:
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config --global --add safe.directory /github/workspace
- name: configure
run: cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_MAVSDK_SERVER=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=install -DWERROR=OFF -Bbuild/release -H.
run: cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_MAVSDK_SERVER=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=install -DWERROR=OFF -Bbuild/release -H.
- name: build
run: cmake --build build/release --target install -- -j2
- name: Package
Expand Down Expand Up @@ -251,7 +237,7 @@ jobs:
if: steps.cache.outputs.cache-hit == 'true'
run: echo "superbuild=-DSUPERBUILD=OFF" >> $GITHUB_ENV && echo "cmake_prefix_path=-DCMAKE_PREFIX_PATH=/work/build/linux-${{ matrix.arch_name }}/third_party/install" >> $GITHUB_ENV
- name: configure
run: ./dockcross-linux-${{ matrix.arch_name }}-custom /bin/bash -c "cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=build/linux-${{ matrix.arch_name }}/install -DBUILD_MAVSDK_SERVER=OFF -DBUILD_SHARED_LIBS=ON -DWERROR=OFF -Bbuild/linux-${{ matrix.arch_name }} -H."
run: ./dockcross-linux-${{ matrix.arch_name }}-custom /bin/bash -c "cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=build/linux-${{ matrix.arch_name }}/install -DBUILD_MAVSDK_SERVER=OFF -DBUILD_SHARED_LIBS=ON -DWERROR=OFF -Bbuild/linux-${{ matrix.arch_name }} -H."
- name: build
run: ./dockcross-linux-${{ matrix.arch_name }}-custom cmake --build build/linux-${{ matrix.arch_name }} -j2 --target install
- name: create deb packages
Expand Down Expand Up @@ -289,13 +275,13 @@ jobs:
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: configure
run: cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=Release -DBUILD_MAVSDK_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_MAVSDK_SERVER=ON -DCMAKE_INSTALL_PREFIX=install -DWERROR=OFF -Bbuild/release -H.
run: cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_MAVSDK_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_MAVSDK_SERVER=ON -DCMAKE_INSTALL_PREFIX=install -DWERROR=OFF -DENABLE_CPPTRACE=On -Bbuild/release -H.
- name: build
run: cmake --build build/release --target install -- -j2
- name: unit tests
run: ./build/release/src/unit_tests/unit_tests_runner
- name: system tests
run: ./build/release/src/system_tests/system_tests_runner
# - name: system tests
# run: ./build/release/src/system_tests/system_tests_runner
- name: test (mavsdk_server)
run: ./build/release/src/mavsdk_server/test/unit_tests_mavsdk_server
- name: Upload as artefact
Expand Down Expand Up @@ -335,7 +321,7 @@ jobs:
if: steps.cache.outputs.cache-hit == 'true'
run: echo "superbuild=-DSUPERBUILD=OFF" >> $GITHUB_ENV && echo "cmake_prefix_path=-DCMAKE_PREFIX_PATH=/work/build/${{ matrix.arch_name }}/third_party/install" >> $GITHUB_ENV
- name: configure
run: ./dockcross-${{ matrix.arch_name }} /bin/bash -c "cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=build/${{ matrix.arch_name }}/install -DBUILD_MAVSDK_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_MAVSDK_SERVER=ON -DWERROR=OFF -Bbuild/${{ matrix.arch_name }} -H."
run: ./dockcross-${{ matrix.arch_name }} /bin/bash -c "cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=build/${{ matrix.arch_name }}/install -DBUILD_MAVSDK_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_MAVSDK_SERVER=ON -DWERROR=OFF -Bbuild/${{ matrix.arch_name }} -H."
- name: build
run: ./dockcross-${{ matrix.arch_name }} cmake --build build/${{ matrix.arch_name }} -j2 --target install
- name: Publish artefacts
Expand Down Expand Up @@ -377,7 +363,7 @@ jobs:
if: steps.cache.outputs.cache-hit == 'true'
run: echo "superbuild=-DSUPERBUILD=OFF" >> $GITHUB_ENV && echo "cmake_prefix_path=-DCMAKE_PREFIX_PATH=/work/build/${{ matrix.name }}/third_party/install" >> $GITHUB_ENV
- name: configure
run: ./dockcross-${{ matrix.name }} /bin/bash -c "cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=build/${{ matrix.name }}/install -DBUILD_MAVSDK_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DWERROR=OFF -Bbuild/${{ matrix.name }} -H."
run: ./dockcross-${{ matrix.name }} /bin/bash -c "cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=build/${{ matrix.name }}/install -DBUILD_MAVSDK_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DWERROR=OFF -Bbuild/${{ matrix.name }} -H."
- name: build
run: ./dockcross-${{ matrix.name }} cmake --build build/${{ matrix.name }} -j2 --target install
- name: create tar with header and library
Expand Down Expand Up @@ -418,7 +404,7 @@ jobs:
- name: set SDKROOT value
run: echo "SDKROOT=$(xcrun --sdk macosx --show-sdk-path)" >> $GITHUB_ENV
- name: configure
run: cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=build/macos/install -DBUILD_MAVSDK_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DMACOS_FRAMEWORK=${{ matrix.build-framework }} -DWERROR=OFF -Bbuild/macos -H.
run: cmake $superbuild $cmake_prefix_path -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=build/macos/install -DBUILD_MAVSDK_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DMACOS_FRAMEWORK=${{ matrix.build-framework }} -DWERROR=OFF -DENABLE_CPPTRACE=On -Bbuild/macos -H.
- name: build
run: cmake --build build/macos -j2 --target install
- name: unit tests
Expand Down Expand Up @@ -478,7 +464,7 @@ jobs:
python3 -m pip install wheel
python3 -m pip install future
- name: configure
run: cmake $superbuild $cmake_prefix_path -DENABLE_STRICT_TRY_COMPILE=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$(pwd)/tools/ios.toolchain.cmake -DENABLE_BITCODE=Off -DPLATFORM=${{ matrix.platform }} -DDEPLOYMENT_TARGET=14.0 -DBUILD_MAVSDK_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DWERROR=OFF -Bbuild/${{ matrix.name }} -H.
run: cmake $superbuild $cmake_prefix_path -DENABLE_STRICT_TRY_COMPILE=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=$(pwd)/tools/ios.toolchain.cmake -DENABLE_BITCODE=Off -DPLATFORM=${{ matrix.platform }} -DDEPLOYMENT_TARGET=14.0 -DBUILD_MAVSDK_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DWERROR=OFF -Bbuild/${{ matrix.name }} -H.
- name: build
run: cmake --build build/${{ matrix.name }} -j2
- uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -555,9 +541,9 @@ jobs:
choco install nasm
echo "C:\Program Files\NASM" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: configure
run: cmake -G "Visual Studio 17 2022" $env:superbuild $env:cmake_prefix_path -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=build/release/install -DBUILD_MAVSDK_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DWERROR=OFF -Bbuild/release -S.
run: cmake -G "Visual Studio 17 2022" $env:superbuild $env:cmake_prefix_path -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=build/release/install -DBUILD_MAVSDK_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DWERROR=OFF -Bbuild/release -S.
- name: build
run: cmake --build build/release -j2 --config Release --target install
run: cmake --build build/release -j2 --config RelWithDebInfo --target install
- name: Create zip file mavsdk libraries
if: startsWith(github.ref, 'refs/tags/v')
run: cd build/release/install && 7z.exe a -tzip ../../../mavsdk-windows-x64-release.zip . && cd ../../..
Expand Down
34 changes: 11 additions & 23 deletions examples/ftp_client/ftp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ void usage(const std::string& bin_name)
<< " 3 : Files are different (cmp command)\n";
}

Ftp::Result reset_server(Ftp& ftp)
{
auto prom = std::promise<Ftp::Result>{};
auto future_result = prom.get_future();
ftp.reset_async([&prom](Ftp::Result result) { prom.set_value(result); });
return future_result.get();
}

Ftp::Result create_directory(Ftp& ftp, const std::string& path)
{
std::cerr << "Creating directory: " << path << '\n';
Expand Down Expand Up @@ -131,7 +123,10 @@ download_file(Ftp& ftp, const std::string& remote_file_path, const std::string&
auto prom = std::promise<Ftp::Result>{};
auto future_result = prom.get_future();
ftp.download_async(
remote_file_path, local_path, [&prom](Ftp::Result result, Ftp::ProgressData progress) {
remote_file_path,
local_path,
false,
[&prom](Ftp::Result result, Ftp::ProgressData progress) {
if (result == Ftp::Result::Next) {
int percentage = progress.total_bytes > 0 ?
progress.bytes_transferred * 100 / progress.total_bytes :
Expand Down Expand Up @@ -215,21 +210,14 @@ int main(int argc, char** argv)
return 1;
}

Ftp::Result res;
res = reset_server(ftp);
if (res != Ftp::Result::Success) {
std::cerr << "Reset server error: " << res << '\n';
return 1;
}

std::string command = argv[3];

if (command == "put") {
if (argc < 6) {
usage(argv[0]);
return 1;
}
res = upload_file(ftp, argv[4], argv[5]);
auto res = upload_file(ftp, argv[4], argv[5]);
if (res == Ftp::Result::Success) {
std::cerr << "File uploaded.\n";
} else {
Expand All @@ -241,7 +229,7 @@ int main(int argc, char** argv)
usage(argv[0]);
return 1;
}
res = download_file(ftp, argv[4], (argc == 6) ? argv[5] : ".");
auto res = download_file(ftp, argv[4], (argc == 6) ? argv[5] : ".");
if (res == Ftp::Result::Success) {
std::cerr << "File downloaded.\n";
} else {
Expand All @@ -253,7 +241,7 @@ int main(int argc, char** argv)
usage(argv[0]);
return 1;
}
res = rename_file(ftp, argv[4], argv[5]);
auto res = rename_file(ftp, argv[4], argv[5]);
if (res == Ftp::Result::Success) {
std::cerr << "File renamed.\n";
} else {
Expand All @@ -265,7 +253,7 @@ int main(int argc, char** argv)
usage(argv[0]);
return 1;
}
res = create_directory(ftp, argv[4]);
auto res = create_directory(ftp, argv[4]);
if (res == Ftp::Result::Success) {
std::cerr << "Directory created.\n";
} else if (res == Ftp::Result::FileExists) {
Expand All @@ -289,7 +277,7 @@ int main(int argc, char** argv)
recursive = true;
}
}
res = remove_directory(ftp, path, recursive);
auto res = remove_directory(ftp, path, recursive);
if (res == Ftp::Result::Success) {
std::cerr << "Directory removed.\n";
} else if (res == Ftp::Result::FileDoesNotExist) {
Expand All @@ -304,7 +292,7 @@ int main(int argc, char** argv)
usage(argv[0]);
return 1;
}
res = list_directory(ftp, argv[4]);
auto res = list_directory(ftp, argv[4]);
if (res == Ftp::Result::Success) {
std::cerr << "Directory listed.\n";
} else if (res == Ftp::Result::FileDoesNotExist) {
Expand All @@ -319,7 +307,7 @@ int main(int argc, char** argv)
usage(argv[0]);
return 1;
}
res = remove_file(ftp, argv[4]);
auto res = remove_file(ftp, argv[4]);
if (res == Ftp::Result::Success) {
std::cerr << "File deleted.\n";
} else if (res == Ftp::Result::FileDoesNotExist) {
Expand Down
12 changes: 6 additions & 6 deletions examples/ftp_server/ftp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

#include <mavsdk/mavsdk.h>
#include <mavsdk/plugins/ftp/ftp.h>
#include <mavsdk/plugins/ftp_server/ftp_server.h>

#include <chrono>
#include <iostream>
Expand Down Expand Up @@ -37,15 +37,15 @@ int main(int argc, char** argv)
return 1;
}

auto system_cc = mavsdk.systems().at(0);

auto ftp_server = Ftp{system_cc};
ftp_server.set_root_directory(argv[3]);
auto component =
mavsdk.server_component_by_type(mavsdk::Mavsdk::ServerComponentType::CompanionComputer);
auto ftp_server = FtpServer{component};
ftp_server.set_root_dir(argv[3]);

std::cout << "Mavlink FTP server running.\n"
<< '\n'
<< "Remote: " << argv[1] << ":" << argv[2] << '\n'
<< "Component ID: " << static_cast<int>(ftp_server.get_our_compid()) << '\n';
<< "Component ID: " << std::to_string(component->component_id()) << '\n';

while (true) {
std::this_thread::sleep_for(std::chrono::seconds(1));
Expand Down
2 changes: 1 addition & 1 deletion proto
1 change: 0 additions & 1 deletion src/integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ add_executable(integration_tests_runner
offboard_attitude.cpp
#logging.cpp # Not fully implemented
log_files.cpp
ftp.cpp
mission_cancellation.cpp
mission_change_speed.cpp
mission.cpp
Expand Down
Loading

0 comments on commit 578ec76

Please sign in to comment.