Skip to content

blueye.sdk.utils

utils

Classes:

Functions:

UnknownMessageTypeError

UnknownMessageTypeError(type_url: str)

The type URL of an Any message names a type this SDK does not know

The drone logs and publishes every message type its firmware knows, so a newer drone can produce types that an older blueye.protocol package has no class for.

Source code in blueye/sdk/utils.py
104
105
106
def __init__(self, type_url: str):
    super().__init__(f"Unknown message type {type_url}")
    self.type_url = type_url

deprecated_property

deprecated_property(
    fget: str,
    fset: Optional[str] = None,
    doc: Optional[str] = None,
)

Property shim that warns and delegates to the new getter/setter methods.

fget/fset are the names of the replacement methods on the owning class. This is always a data descriptor (it defines __set__) so that assignments to read-only deprecated properties raise an AttributeError instead of silently shadowing the descriptor with an instance attribute.

Source code in blueye/sdk/utils.py
34
35
36
37
def __init__(self, fget: str, fset: Optional[str] = None, doc: Optional[str] = None):
    self.fget = fget
    self.fset = fset
    self.__doc__ = doc

describe_enum

describe_enum(value) -> str

Render a protocol enum value for a log or error message.

A drone running a newer Blunux than the SDK can report an enum value this build does not know, and proto-plus surfaces those as a plain int rather than an enum member. Fall back to UNKNOWN(<number>) so the message still says which value was received.

Source code in blueye/sdk/utils.py
87
88
89
90
91
92
93
94
def describe_enum(value) -> str:
    """Render a protocol enum value for a log or error message.

    A drone running a newer Blunux than the SDK can report an enum value this build does not
    know, and proto-plus surfaces those as a plain int rather than an enum member. Fall back to
    `UNKNOWN(<number>)` so the message still says which value was received.
    """
    return getattr(value, "name", f"UNKNOWN({value})")

deserialize_any_to_message

deserialize_any_to_message(
    msg: Any,
) -> Tuple[type, Message]

Deserialize a protobuf Any message to a concrete message type.

Parameters:

  • msg (Any) –

    The Any message to deserialize. Needs to be a message defined in the blueye.protocol package, a well-known wrapper type (FloatValue, Int32Value, etc) from google.protobuf.wrappers_pb2, or google.protobuf.Empty.

Returns:

  • Tuple[type, Message] –

    A tuple with the message type and the deserialized message. blueye.protocol types come back as proto-plus messages, the google.protobuf types as plain protobuf messages.

Raises:

Source code in blueye/sdk/utils.py
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def deserialize_any_to_message(msg: Any) -> Tuple[type, proto.message.Message]:
    """Deserialize a protobuf Any message to a concrete message type.

    Args:
        msg (Any): The Any message to deserialize. Needs to be a message defined in the
                   blueye.protocol package, a well-known wrapper type (FloatValue, Int32Value,
                   etc) from google.protobuf.wrappers_pb2, or google.protobuf.Empty.

    Returns:
        A tuple with the message type and the deserialized message. blueye.protocol types
        come back as proto-plus messages, the google.protobuf types as plain protobuf messages.

    Raises:
        UnknownMessageTypeError: The type URL names a type this SDK does not have a class for.
    """
    type_url = msg.type_url
    google_prefix = "type.googleapis.com/google.protobuf."
    blueye_prefix = "type.googleapis.com/blueye.protocol."
    if type_url == google_prefix + "Empty":
        return (empty_pb2.Empty, empty_pb2.Empty.FromString(msg.value))
    if type_url.startswith(google_prefix):
        payload_type = getattr(wrappers, type_url[len(google_prefix) :], None)
        if payload_type is None:
            raise UnknownMessageTypeError(type_url)
        return (payload_type, payload_type.FromString(msg.value))
    if type_url.startswith(blueye_prefix):
        payload_type = getattr(bp, type_url[len(blueye_prefix) :], None)
        if payload_type is not None:
            return (payload_type, payload_type.deserialize(msg.value))
    raise UnknownMessageTypeError(type_url)

is_scalar_type

is_scalar_type(msg: Message) -> bool

Check if a message is a scalar type

Parameters:

  • msg (Message) –

    The message to check

Returns:

  • bool –

    True if the message is a scalar type, False otherwise

Source code in blueye/sdk/utils.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
def is_scalar_type(msg: proto.message.Message) -> bool:
    """Check if a message is a scalar type

    Args:
        msg (proto.message.Message): The message to check

    Returns:
        True if the message is a scalar type, False otherwise
    """

    scalar_types = (
        FloatValue,
        Int32Value,
        Int64Value,
        UInt32Value,
        UInt64Value,
        DoubleValue,
        BoolValue,
        StringValue,
        BytesValue,
    )
    return isinstance(msg, scalar_types)

open_local_documentation

open_local_documentation()

Open a pre-built local version of the SDK documentation

Useful when you are connected to the drone wifi, and don't have access to the online version.

Source code in blueye/sdk/utils.py
74
75
76
77
78
79
80
81
82
83
84
def open_local_documentation():
    """Open a pre-built local version of the SDK documentation

    Useful when you are connected to the drone wifi, and don't have access to the online version.
    """
    sdk_path = os.path.dirname(blueye.sdk.__file__)

    # The documentation is located next to the top-level package so we move up a couple of levels
    documentation_path = os.path.abspath(sdk_path + "/../../blueye.sdk_docs/index.html")

    webbrowser.open(documentation_path)