-
Notifications
You must be signed in to change notification settings - Fork 73
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
Add MAVLinkServer #2930
Merged
joaoantoniocardoso
merged 3 commits into
bluerobotics:master
from
patrickelectric:mavlink-server
Sep 30, 2024
Merged
Add MAVLinkServer #2930
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
69 changes: 69 additions & 0 deletions
69
core/services/ardupilot_manager/mavlink_proxy/MAVLinkServer.py
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import re | ||
import subprocess | ||
from typing import Optional | ||
|
||
from mavlink_proxy.AbstractRouter import AbstractRouter | ||
from mavlink_proxy.Endpoint import Endpoint | ||
from typedefs import EndpointType | ||
|
||
|
||
class MAVLinkServer(AbstractRouter): | ||
def __init__(self) -> None: | ||
super().__init__() | ||
|
||
def _get_version(self) -> Optional[str]: | ||
binary = self.binary() | ||
assert binary is not None | ||
for line in subprocess.check_output([binary, "--version"]).decode("utf-8").split("\n"): | ||
regex = re.search(r"mavlink-server (?P<version>\S+)\b", line) | ||
if regex: | ||
return regex.group("version") | ||
|
||
return None | ||
|
||
def assemble_command(self, master_endpoint: Endpoint) -> str: | ||
# Convert endpoint format to mavlink-router format | ||
def convert_endpoint(endpoint: Endpoint) -> str: | ||
if endpoint.connection_type == EndpointType.Serial: | ||
return f"serial:{endpoint.place}:{endpoint.argument}" | ||
if endpoint.connection_type == EndpointType.TCPServer: | ||
return f"tcps:{endpoint.place}:{endpoint.argument}" | ||
if endpoint.connection_type == EndpointType.TCPClient: | ||
return f"tcpc:{endpoint.place}:{endpoint.argument}" | ||
if endpoint.connection_type == EndpointType.UDPServer: | ||
return f"udps:{endpoint.place}:{endpoint.argument}" | ||
if endpoint.connection_type == EndpointType.UDPClient: | ||
return f"udpc:{endpoint.place}:{endpoint.argument}" | ||
raise ValueError(f"Endpoint of type {endpoint.connection_type} not supported on MAVLink-Server.") | ||
|
||
endpoints = " ".join([convert_endpoint(endpoint) for endpoint in [master_endpoint, *self.endpoints()]]) | ||
|
||
return f"{self.binary()} {endpoints}" | ||
|
||
@staticmethod | ||
def name() -> str: | ||
return "MAVLink-Server" | ||
|
||
@staticmethod | ||
def binary_name() -> str: | ||
return "mavlink-server" | ||
|
||
@staticmethod | ||
def _validate_endpoint(endpoint: Endpoint) -> None: | ||
valid_connection_types = [ | ||
EndpointType.UDPClient, | ||
EndpointType.UDPServer, | ||
EndpointType.TCPServer, | ||
EndpointType.TCPClient, | ||
EndpointType.Serial, | ||
] | ||
if endpoint.connection_type not in valid_connection_types: | ||
raise ValueError(f"Connection_type '{endpoint.connection_type}' not supported by {MAVLinkServer.name()}.") | ||
|
||
@staticmethod | ||
def is_ok() -> bool: | ||
try: | ||
router = MAVLinkServer() | ||
return router.binary() is not None and router.version() is not None | ||
except Exception as _: | ||
return False |
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ TOOLS=( | |
machineid | ||
mavlink2rest | ||
mavlink_router | ||
mavlink_server | ||
mavp2p | ||
ttyd | ||
) | ||
|
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Immediately exit on errors | ||
set -e | ||
|
||
VERSION="master" | ||
PROJECT_NAME="mavlink-server" | ||
REPOSITORY_ORG="bluerobotics" | ||
REPOSITORY_NAME="$PROJECT_NAME" | ||
REPOSITORY_URL="https://github.com/$REPOSITORY_ORG/$REPOSITORY_NAME" | ||
|
||
echo "Installing project $PROJECT_NAME version $VERSION" | ||
|
||
# Step 1: Prepare the download URL | ||
|
||
ARCH="$(uname -m)" | ||
case "$ARCH" in | ||
x86_64 | amd64) | ||
BUILD_NAME="x86_64-unknown-linux-musl" | ||
;; | ||
armv7l | armhf) | ||
BUILD_NAME="armv7-unknown-linux-musleabihf" | ||
;; | ||
aarch64 | arm64) | ||
BUILD_NAME="aarch64-unknown-linux-musl" | ||
;; | ||
*) | ||
echo "Architecture: $ARCH is unsupported, please create a new issue on https://github.com/bluerobotics/BlueOS/issues" | ||
exit 1 | ||
;; | ||
esac | ||
ARTIFACT_NAME="$PROJECT_NAME-$BUILD_NAME" | ||
echo "For architecture $ARCH, using build $BUILD_NAME" | ||
|
||
REMOTE_URL="$REPOSITORY_URL/releases/download/$VERSION/$ARTIFACT_NAME" | ||
echo "Remote URL is $REMOTE_URL" | ||
|
||
# Step 2: Prepare the installation path | ||
|
||
if [ -n "$VIRTUAL_ENV" ]; then | ||
BIN_DIR="$VIRTUAL_ENV/bin" | ||
else | ||
BIN_DIR="/usr/bin" | ||
fi | ||
mkdir -p "$BIN_DIR" | ||
|
||
BINARY_PATH="$BIN_DIR/$PROJECT_NAME" | ||
echo "Installing to $BINARY_PATH" | ||
|
||
# Step 3: Download and install | ||
|
||
wget -q "$REMOTE_URL" -O "$BINARY_PATH" | ||
chmod +x "$BINARY_PATH" | ||
|
||
echo "Installed binary type: $(file "$(which "$BINARY_PATH")")" | ||
|
||
echo "Finished installing $PROJECT_NAME" |
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.
just a reminder to fixate a version once we validate it