Skip to content
This repository was archived by the owner on Feb 19, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 27 additions & 0 deletions pc_ble_driver_py/ble_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,26 @@ def to_c(self):
char_md.p_sccd_md = self.sccd_md.to_c()
return char_md

class BLEGattsValue(object):
def __init__(self, value=None, offset=0):
if value == None:
value = [0]
Comment on lines +1471 to +1473
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for why you want the default value to be a list with 0 elements?

Also, do you support the functionality for when p_value is set to NULL(https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v5.0.0/structble__gatts__value__t.html)?

Copy link
Contributor

Choose a reason for hiding this comment

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

One version of the underlying c-function can be found at
ble_gatts_value_set

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 @@ -2546,6 +2566,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
6 changes: 6 additions & 0 deletions tests/test_pc_ble_driver_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,9 @@ def test_adv_start(ble_tester):
ble_tester.driver.ble_gap_adv_data_set(adv_data)
ble_tester.driver.ble_gap_adv_start(tag=1)
time.sleep(2)

def test_ble_gatts_value(ble_tester):
gatts_value = BLEGattsValue()
gatts_value.value = [1,2,3,4]
gatts_value.offset = 2