Skip to content
This repository was archived by the owner on Feb 19, 2024. It is now read-only.
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions pc_ble_driver_py/ble_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,24 @@ def to_c(self):
char_md.p_sccd_md = self.sccd_md.to_c()
return char_md

class BLEGattsValue(object):
def __init__(self, value=[0], offset=0):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having lists can as the default parameters to functions can often be risky, since any change the list will persist between function calls. It is often safer to do:

f(arg=None):
    if arg == None:
        arg = [0]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! That was new to me. Updating with None as default parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, about writing tests: I'm not sure how to write a test involving ble_gatts_value_set() as I need a conn_handle and a handle for it?

self.offset = offset
self.value = value

def __str__(self):
return str(self.__dict__)

def to_c(self):
self.value_array = util.list_to_uint8_array(self.value)
p_value = self.value_array.cast()

ble_gatts_value = driver.ble_gatts_value_t()
ble_gatts_value.len = len(self.value)
ble_gatts_value.offset = self.offset
ble_gatts_value.p_value = p_value
return ble_gatts_value


class BLEGapPhys(object):
def __init__(self, tx_phys, rx_phys):
Expand Down Expand Up @@ -2540,6 +2558,13 @@ def ble_gatts_hvx(self, conn_handle, hvx_params):
assert isinstance(hvx_params, BLEGattsHVXParams), "Invalid argument type"
hvx_params = hvx_params.to_c()
return driver.sd_ble_gatts_hvx(self.rpc_adapter, conn_handle, hvx_params)

@NordicSemiErrorCheck
@wrapt.synchronized(api_lock)
def ble_gatts_value_set(self, conn_handle, handle, value):
assert isinstance(value, BLEGattsValue), "Invalid argument type"
p_value = value.to_c()
return driver.sd_ble_gatts_value_set(self.rpc_adapter, conn_handle, handle, p_value)

def ble_gatts_sys_attr_set(self, conn_handle, sys_attr_data, length, flags):
return driver.sd_ble_gatts_sys_attr_set(self.rpc_adapter, conn_handle,
Expand Down