Skip to content

Commit

Permalink
Add function for getting any telemetry message
Browse files Browse the repository at this point in the history
Need to import annotations to support the |-operator in python <3.10
  • Loading branch information
sindrehan committed Jun 21, 2023
1 parent eea1119 commit 25d090e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions blueye/sdk/drone.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
from __future__ import annotations

import time
from json import JSONDecodeError
from typing import Callable, Dict, List, Optional
Expand Down Expand Up @@ -108,6 +110,32 @@ def remove_msg_callback(self, callback_id: str) -> Optional[str]:
"""
self._parent_drone._telemetry_watcher.remove_callback(callback_id)

def get(
self, msg_type: proto.message.Message, deserialize=True
) -> Optional[proto.message.Message | bytes]:
"""Get the latest telemetry message of the specified type
*Arguments*:
* msg_type: The message type to get. Eg. blueye.protocol.DepthTel
* deserialize: If True, the message will be deserialized before being returned. If False,
the raw bytes will be returned.
*Returns*:
* The latest message of the specified type, or None if no message has been received yet
"""
try:
msg = self._parent_drone._telemetry_watcher.get(msg_type)
except KeyError:
return None
if deserialize:
return msg_type.deserialize(msg)
else:
return msg


class Drone:
"""A class providing an interface to a Blueye drone's functions
Expand Down

0 comments on commit 25d090e

Please sign in to comment.