diff --git a/src/controller/python/BUILD.gn b/src/controller/python/BUILD.gn index e1d91001e728c4..d7756997cd6dec 100644 --- a/src/controller/python/BUILD.gn +++ b/src/controller/python/BUILD.gn @@ -174,7 +174,9 @@ chip_python_wheel_action("chip-core") { "chip/ChipStack.py", "chip/FabricAdmin.py", "chip/__init__.py", + "chip/bdx/__init__.py", "chip/bdx/Bdx.py", + "chip/bdx/BdxTransfer.py", "chip/ble/__init__.py", "chip/ble/commissioning/__init__.py", "chip/ble/get_adapters.py", @@ -244,6 +246,7 @@ chip_python_wheel_action("chip-core") { py_packages = [ "chip", + "chip.bdx", "chip.ble", "chip.ble.commissioning", "chip.configuration", diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index fec30ce7e3f062..59be39c88330e2 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -48,6 +48,7 @@ from . import FabricAdmin from . import clusters as Clusters from . import discovery +from .bdx import Bdx from .clusters import Attribute as ClusterAttribute from .clusters import ClusterObjects as ClusterObjects from .clusters import Command as ClusterCommand diff --git a/src/controller/python/chip/bdx/Bdx.py b/src/controller/python/chip/bdx/Bdx.py index abaed8c92f60fb..75b9bde9316bbd 100644 --- a/src/controller/python/chip/bdx/Bdx.py +++ b/src/controller/python/chip/bdx/Bdx.py @@ -15,8 +15,18 @@ # limitations under the License. # +import builtins import ctypes -from ctypes import CFUNCTYPE, POINTER, c_bool, c_char_p, c_size_t, c_uint8, c_uint16, c_uint32, c_void_p, cast, py_object +from asyncio.futures import Future +from ctypes import CFUNCTYPE, POINTER, c_char_p, c_size_t, c_uint8, c_uint16, c_uint64, c_void_p, py_object + +import chip +from chip.native import PyChipError + +from . import BdxTransfer + + +c_uint8_p = POINTER(c_uint8) _OnTransferObtainedCallbackFunct = CFUNCTYPE( @@ -35,7 +45,7 @@ def _OnTransferObtainedCallback(future: Future, result: PyChipError, bdxTransfer fileDesignatorData = ctypes.string_at(fileDesignator, fileDesignatorLength) metadataData = ctypes.string_at(metadata, metadataLength) - initMessage = InitMessage() + initMessage = BdxTransfer.InitMessage() initMessage.TransferControlFlags = transferControlFlags initMessage.MaxBlockSize = maxBlockSize initMessage.StartOffset = startOffset @@ -67,7 +77,7 @@ def __init__(self, future, data=None): self._future = future self._data = data - def handleTransfer(self, bdxTransfer, initMessage: InitMessage): + def handleTransfer(self, bdxTransfer, initMessage: BdxTransfer.InitMessage): transfer = BdxTransfer(bdx_transfer=bdxTransfer, init_message=initMessage, data=self._data) self._future.set_result(transfer) diff --git a/src/controller/python/chip/bdx/BdxTransfer.py b/src/controller/python/chip/bdx/BdxTransfer.py index d331a8361d07b3..4af6a282460262 100644 --- a/src/controller/python/chip/bdx/BdxTransfer.py +++ b/src/controller/python/chip/bdx/BdxTransfer.py @@ -15,17 +15,24 @@ # limitations under the License. # +import asyncio +import ctypes +from ctypes import c_void_p +from dataclasses import dataclass + +from . import Bdx + @dataclass class InitMessage: TransferControlFlags: int MaxBlockSize: int StartOffset: int Length: int - FileDesignator - Metadata + FileDesignator: bytes + Metadata: bytes class BdxTransfer: - __init__(self, bdx_transfer: c_void_p, init_message: InitMessage, data = None): + def __init__(self, bdx_transfer: c_void_p, init_message: InitMessage, data = None): self.init_message = init_message self._bdx_transfer = bdx_transfer self._data = data @@ -48,4 +55,4 @@ async def accept(self): async def reject(self): res = await Bdx.RejectTransfer(self._bdx_transfer) res.raise_on_error() - return res \ No newline at end of file + return res diff --git a/src/controller/python/chip/bdx/__init__.py b/src/controller/python/chip/bdx/__init__.py new file mode 100644 index 00000000000000..23b3bb5b5e567e --- /dev/null +++ b/src/controller/python/chip/bdx/__init__.py @@ -0,0 +1,27 @@ +# +# Copyright (c) 2024 Project CHIP Authors +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# @file +# Provides Python APIs for CHIP. +# + +"""Provides Python APIs for CHIP.""" + +from . import Bdx, BdxTransfer + +__all__ = [Bdx, BdxTransfer]