Skip to content

Commit

Permalink
Python sdk always use extended headers (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcamise-gpsw authored Apr 23, 2024
1 parent 5308bfe commit e2dfea7
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
run: sudo apt-get update && sudo apt install -y graphviz

- name: Set up Python 3.11.4
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.11.4

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/python_sdk_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
os: [windows-latest, macos-12, ubuntu-latest]
python-version: ['3.9', '3.10', '3.11']
include:
- os: ubuntu-latest
path: ~/.cache/pip
- os: macos-latest
- os: macos-12
path: ~/Library/Caches/pip
- os: windows-latest
path: ~\AppData\Local\pip\Cache
Expand All @@ -30,7 +30,7 @@ jobs:
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
5 changes: 3 additions & 2 deletions demos/python/sdk_wireless_camera_control/docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ All notable changes to this project will be documented in this file.
The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`_,
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_.

Unreleased
----------
0.16.1 (April-23-2024)
----------------------

* Always use extended headers
* Add Delete Media HTTP API's
* Add port argument to Preview Stream HTTP API
* Only ask for sudo password when required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ async def read(self, handle: bleak.BleakClient, uuid: BleUUID) -> bytearray:
logger.debug(f'Received response on BleUUID [{uuid}]: {response.hex( ":")}')
return response

async def write(self, handle: bleak.BleakClient, uuid: BleUUID, data: bytearray) -> None:
async def write(self, handle: bleak.BleakClient, uuid: BleUUID, data: bytes) -> None:
"""Write data to a BleUUID.
Args:
handle (bleak.BleakClient): Device to write to
uuid (BleUUID): characteristic BleUUID to write to
data (bytearray): data to write
data (bytes): data to write
"""
logger.debug(f"Writing to {uuid}: {uuid.hex}")
await handle.write_gatt_char(uuid2bleak_string(uuid), data, response=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,23 @@ async def close(self) -> None:
else:
logger.debug("BLE already disconnected")

async def read(self, uuid: BleUUID) -> bytearray:
async def read(self, uuid: BleUUID) -> bytes:
"""Read byte data from a characteristic (identified by BleUUID)
Args:
uuid (BleUUID): characteristic to read
Returns:
bytearray: byte data that was read
bytes: byte data that was read
"""
return await self._controller.read(self._handle, uuid)

async def write(self, uuid: BleUUID, data: bytearray) -> None:
async def write(self, uuid: BleUUID, data: bytes) -> None:
"""Write byte data to a characteristic (identified by BleUUID)
Args:
uuid (BleUUID): characteristic to write to
data (bytearray): byte data to write
data (bytes): byte data to write
"""
await self._controller.write(self._handle, uuid, data)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ def __init__(self, exception_handler: Optional[Callable] = None) -> None:
self._exception_handler = exception_handler

@abstractmethod
async def read(self, handle: BleHandle, uuid: BleUUID) -> bytearray:
async def read(self, handle: BleHandle, uuid: BleUUID) -> bytes:
"""Read a bytestream response from a BleUUID.
Args:
handle (BleHandle): handle to pair to
uuid (BleUUID): BleUUID to read from
Returns:
bytearray: response
bytes: response
"""
raise NotImplementedError

@abstractmethod
async def write(self, handle: BleHandle, uuid: BleUUID, data: bytearray) -> None:
async def write(self, handle: BleHandle, uuid: BleUUID, data: bytes) -> None:
"""Write a bytestream to a BleUUID.
Args:
handle (BleHandle): handle to pair to
uuid (BleUUID): BleUUID to write to
data (bytearray): bytestream to write
data (bytes): bytestream to write
Returns:
bytearray: response
bytes: response
"""
raise NotImplementedError

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,24 +262,19 @@ async def _read_ble_characteristic(

# TODO this should be somewhere else
@classmethod
def _fragment(cls, data: bytearray) -> Generator[bytearray, None, None]:
def _fragment(cls, data: bytes) -> Generator[bytes, None, None]:
"""Fragment data in to MAX_BLE_PKT_LEN length packets
Args:
data (bytearray): data to fragment
data (bytes): data to fragment
Raises:
ValueError: data is too long
Yields:
Generator[bytearray, None, None]: Generator of packets as bytearrays
Generator[bytes, None, None]: Generator of packets as bytes
"""
MAX_BLE_PKT_LEN = 20
general_header = BitStruct(
"continuation" / Const(0, Bit),
"header" / Const(Header.GENERAL.value, BitsInteger(2)),
"length" / BitsInteger(5),
)

extended_13_header = BitStruct(
"continuation" / Const(0, Bit),
Expand All @@ -300,9 +295,7 @@ def _fragment(cls, data: bytearray) -> Generator[bytearray, None, None]:
)

header: Construct
if (data_len := len(data)) < (2**5 - 1):
header = general_header
elif data_len < (2**13 - 1):
if (data_len := len(data)) < (2**13 - 1):
header = extended_13_header
elif data_len < (2**16 - 1):
header = extended_16_header
Expand Down
2 changes: 1 addition & 1 deletion demos/python/sdk_wireless_camera_control/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "open_gopro"
version = "0.16.0"
version = "0.16.1"
description = "Open GoPro API and Examples"
authors = ["Tim Camise <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit e2dfea7

Please sign in to comment.