-
Notifications
You must be signed in to change notification settings - Fork 115
Implement ble_gatts_value_set() #195
base: master
Are you sure you want to change the base?
Implement ble_gatts_value_set() #195
Conversation
A Python class BLEGattsValue() is also created to feed sd_ble_gatts_value_set()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are missing tests. If you want to add them, you can follow the format of the tests in the tests/ folder.
pc_ble_driver_py/ble_driver.py
Outdated
@@ -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): |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
Not sure how to create a test for ble_gatts_value_set() using the conn_handle and handle arguments
5ff8ff2
to
ae009cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since creating a gatt-database will be so much work, just for a single test, I think it should be fine to skip the test for this one as long as the code looks sound enough.
def __init__(self, value=None, offset=0): | ||
if value == None: | ||
value = [0] |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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
Implement ble_gatts_value_set(). A Python class BLEGattsValue() is also created to feed sd_ble_gatts_value_set()