Skip to content

Commit

Permalink
Add hotfix for connecting to Blunux >=3.0 (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
sindrehan authored Jan 19, 2023
2 parents 1d22dd0 + e79d5d3 commit ddca534
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
18 changes: 16 additions & 2 deletions blueye/sdk/drone.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

import requests
from blueye.protocol import TcpClient, UdpClient
from blueye.protocol.exceptions import MismatchedReply, NoConnectionToDrone, ResponseTimeout
from blueye.protocol.exceptions import (
MismatchedReply,
NoConnectionToDrone,
ResponseTimeout,
)
from packaging import version

from .camera import Camera
Expand Down Expand Up @@ -244,6 +248,12 @@ def _start_state_watcher_thread(self):
# Ignore multiple starts
pass

def _create_temporary_tcp_client(self):
temp_tcp_client = TcpClient()
temp_tcp_client.connect()
temp_tcp_client.stop()
temp_tcp_client._sock.close()

def connect(self, timeout: float = None):
"""Start receiving telemetry info from the drone, and publishing watchdog messages
Expand All @@ -253,8 +263,12 @@ def connect(self, timeout: float = None):
- *timeout* (float): Seconds to wait for connection
"""

self._wait_for_udp_communication(timeout, self._ip)
self._update_drone_info()
if version.parse(self.software_version_short) >= version.parse("3.0"):
# Blunux 3.0 requires a TCP message before enabling UDP communication
self._create_temporary_tcp_client()

self._wait_for_udp_communication(timeout, self._ip)
self._start_state_watcher_thread()
if self._slave_mode_enabled:
# No need to touch the TCP stuff if we're in slave mode so we return early
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "blueye.sdk"
version = "1.0.1"
version = "1.0.2"
description = "SDK for controlling a Blueye underwater drone"
authors = ["Sindre Hansen <[email protected]>",
"Johannes Schrimpf <[email protected]>",
Expand Down
16 changes: 13 additions & 3 deletions tests/test_sdk.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from time import time
from unittest.mock import PropertyMock
from unittest.mock import Mock, PropertyMock

import blueye.sdk
import pytest
import requests
from blueye.sdk import Drone
from freezegun import freeze_time

import blueye.sdk
from blueye.sdk import Drone


class TestLights:
def test_lights_returns_value(self, mocked_drone):
Expand Down Expand Up @@ -92,6 +93,15 @@ def test_verify_sw_version_raises_connection_error_when_not_connected(mocked_dro
mocked_drone._verify_required_blunux_version("1.4.7")


def test_if_blunux_newer_than_3_create_tcp_first(mocked_drone: Drone):
mocked_drone.software_version_short = "3.0"
mocked_drone._create_temporary_tcp_client = Mock()
mocked_drone._update_drone_info = Mock() # To avoid overwriting the version number
mocked_drone.connect()

mocked_drone._create_temporary_tcp_client.assert_called_once()


def test_depth_reading(mocked_drone):
depth = 10000
mocked_drone._state_watcher._general_state = {"depth": depth}
Expand Down

0 comments on commit ddca534

Please sign in to comment.