Skip to content

Commit

Permalink
Fix a number of issues preventing the BDX python code from running at…
Browse files Browse the repository at this point in the history
… all.
  • Loading branch information
harimau-qirex committed Aug 22, 2024
1 parent deb4164 commit 5555561
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/controller/python/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -244,6 +246,7 @@ chip_python_wheel_action("chip-core") {

py_packages = [
"chip",
"chip.bdx",
"chip.ble",
"chip.ble.commissioning",
"chip.configuration",
Expand Down
1 change: 1 addition & 0 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/controller/python/chip/bdx/Bdx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
15 changes: 11 additions & 4 deletions src/controller/python/chip/bdx/BdxTransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
return res
27 changes: 27 additions & 0 deletions src/controller/python/chip/bdx/__init__.py
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit 5555561

Please sign in to comment.