Skip to content

Commit

Permalink
Merge pull request #367 from mavlink/pr-update-proto
Browse files Browse the repository at this point in the history
Update proto, mavsdk_server v0.41.0
  • Loading branch information
julianoes authored Jul 23, 2021
2 parents 831f68b + 9a93ffc commit 0b3d8ab
Show file tree
Hide file tree
Showing 37 changed files with 10,264 additions and 416 deletions.
2 changes: 1 addition & 1 deletion MAVSDK_SERVER_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.40.0
v0.41.0
10 changes: 9 additions & 1 deletion mavsdk/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,17 @@ class Result(Enum):
Camera denied the command
ERROR
An error has occured while executing the command
An error has occurred while executing the command
TIMEOUT
Command timed out
WRONG_ARGUMENT
Command has wrong argument(s)
NO_SYSTEM
No system connected
"""


Expand All @@ -143,6 +146,7 @@ class Result(Enum):
ERROR = 5
TIMEOUT = 6
WRONG_ARGUMENT = 7
NO_SYSTEM = 8

def translate_to_rpc(self):
if self == CameraResult.Result.UNKNOWN:
Expand All @@ -161,6 +165,8 @@ def translate_to_rpc(self):
return camera_pb2.CameraResult.RESULT_TIMEOUT
if self == CameraResult.Result.WRONG_ARGUMENT:
return camera_pb2.CameraResult.RESULT_WRONG_ARGUMENT
if self == CameraResult.Result.NO_SYSTEM:
return camera_pb2.CameraResult.RESULT_NO_SYSTEM

@staticmethod
def translate_from_rpc(rpc_enum_value):
Expand All @@ -181,6 +187,8 @@ def translate_from_rpc(rpc_enum_value):
return CameraResult.Result.TIMEOUT
if rpc_enum_value == camera_pb2.CameraResult.RESULT_WRONG_ARGUMENT:
return CameraResult.Result.WRONG_ARGUMENT
if rpc_enum_value == camera_pb2.CameraResult.RESULT_NO_SYSTEM:
return CameraResult.Result.NO_SYSTEM

def __str__(self):
return self.name
Expand Down
79 changes: 42 additions & 37 deletions mavsdk/camera_pb2.py

Large diffs are not rendered by default.

123 changes: 16 additions & 107 deletions mavsdk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,101 +64,11 @@ def translate_to_rpc(self, rpcConnectionState):



class PluginInfo:
"""
Plugin info type.
Parameters
----------
name : std::string
Name of the plugin
address : std::string
Address where the plugin is running
port : int32_t
Port where the plugin is running
"""



def __init__(
self,
name,
address,
port):
""" Initializes the PluginInfo object """
self.name = name
self.address = address
self.port = port

def __equals__(self, to_compare):
""" Checks if two PluginInfo are the same """
try:
# Try to compare - this likely fails when it is compared to a non
# PluginInfo object
return \
(self.name == to_compare.name) and \
(self.address == to_compare.address) and \
(self.port == to_compare.port)

except AttributeError:
return False

def __str__(self):
""" PluginInfo in string representation """
struct_repr = ", ".join([
"name: " + str(self.name),
"address: " + str(self.address),
"port: " + str(self.port)
])

return f"PluginInfo: [{struct_repr}]"

@staticmethod
def translate_from_rpc(rpcPluginInfo):
""" Translates a gRPC struct to the SDK equivalent """
return PluginInfo(

rpcPluginInfo.name,


rpcPluginInfo.address,


rpcPluginInfo.port
)

def translate_to_rpc(self, rpcPluginInfo):
""" Translates this SDK object into its gRPC equivalent """




rpcPluginInfo.name = self.name





rpcPluginInfo.address = self.address





rpcPluginInfo.port = self.port







class Core(AsyncBase):
"""
Access to the connection state and running plugins.
Access to the connection state and core configurations
Generated by dcsdkgen - MAVSDK Core API
"""
Expand Down Expand Up @@ -196,26 +106,25 @@ async def connection_state(self):
finally:
connection_state_stream.cancel()

async def list_running_plugins(self):
async def set_mavlink_timeout(self, timeout_s):
"""
Get a list of currently running plugins.
Set timeout of MAVLink transfers.
Returns
-------
plugin_info : [PluginInfo]
Plugin info
The default timeout used is generally (0.5 seconds) seconds.
If MAVSDK is used on the same host this timeout can be reduced, while
if MAVSDK has to communicate over links with high latency it might
need to be increased to prevent timeouts.
Parameters
----------
timeout_s : double
Timeout in seconds
"""

request = core_pb2.ListRunningPluginsRequest()
response = await self._stub.ListRunningPlugins(request)



plugin_info = []
for plugin_info_rpc in response.plugin_info:
plugin_info.append(PluginInfo.translate_from_rpc(plugin_info_rpc))
request = core_pb2.SetMavlinkTimeoutRequest()
request.timeout_s = timeout_s
response = await self._stub.SetMavlinkTimeout(request)

return plugin_info


Loading

0 comments on commit 0b3d8ab

Please sign in to comment.