Skip to content

Commit e6462b2

Browse files
committed
softdevice: fix writing to a characteristic
This seems to have been broken since #192, I suspect it's a problem with the struct calling convention (which most certainly is a TinyGo CGo bug, but at least this works around the problem).
1 parent 0124318 commit e6462b2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

gatts_sd.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ static inline uint32_t sd_ble_gatts_hvx_noescape(uint16_t conn_handle, uint16_t
1212
return sd_ble_gatts_hvx(conn_handle, &p_hvx_params);
1313
}
1414
15-
static inline uint32_t sd_ble_gatts_value_set_noescape(uint16_t conn_handle, uint16_t handle, ble_gatts_value_t p_value) {
15+
static inline uint32_t sd_ble_gatts_value_set_noescape(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t *value) {
16+
ble_gatts_value_t p_value = {
17+
.len = len,
18+
.offset = 0,
19+
.p_value = value,
20+
};
1621
return sd_ble_gatts_value_set(conn_handle, handle, &p_value);
1722
}
1823
*/
@@ -145,10 +150,7 @@ func (c *Characteristic) Write(p []byte) (n int, err error) {
145150
}
146151
}
147152

148-
errCode := C.sd_ble_gatts_value_set_noescape(C.BLE_CONN_HANDLE_INVALID, c.handle, C.ble_gatts_value_t{
149-
len: C.uint16_t(len(p)),
150-
p_value: (*C.uint8_t)(unsafe.Pointer(&p[0])),
151-
})
153+
errCode := C.sd_ble_gatts_value_set_noescape(C.BLE_CONN_HANDLE_INVALID, c.handle, C.uint16_t(len(p)), unsafe.SliceData(p))
152154
if errCode != 0 {
153155
return 0, Error(errCode)
154156
}

0 commit comments

Comments
 (0)