@@ -5,6 +5,16 @@ package bluetooth
5
5
/*
6
6
#include "ble_gap.h"
7
7
#include "ble_gatts.h"
8
+
9
+ // Workaround wrapper functions which prevent pointer arguments escaping to heap
10
+ static inline uint32_t sd_ble_gatts_hvx_noescape(uint16_t conn_handle, uint16_t handle, uint8_t type, uint16_t offset, uint16_t len, uint8_t *p_data) {
11
+ ble_gatts_hvx_params_t p_hvx_params = {handle, type, offset, &len, p_data};
12
+ return sd_ble_gatts_hvx(conn_handle, &p_hvx_params);
13
+ }
14
+
15
+ static inline uint32_t sd_ble_gatts_value_set_noescape(uint16_t conn_handle, uint16_t handle, ble_gatts_value_t p_value) {
16
+ return sd_ble_gatts_value_set(conn_handle, handle, &p_value);
17
+ }
8
18
*/
9
19
import "C"
10
20
@@ -110,12 +120,13 @@ func (c *Characteristic) Write(p []byte) (n int, err error) {
110
120
if connHandle != C .BLE_CONN_HANDLE_INVALID {
111
121
// There is a connected central.
112
122
p_len := uint16 (len (p ))
113
- errCode := C .sd_ble_gatts_hvx (connHandle , & C.ble_gatts_hvx_params_t {
114
- handle : c .handle ,
115
- _type : C .BLE_GATT_HVX_NOTIFICATION ,
116
- p_len : & p_len ,
117
- p_data : & p [0 ],
118
- })
123
+ errCode := C .sd_ble_gatts_hvx_noescape (connHandle ,
124
+ c .handle ,
125
+ C .BLE_GATT_HVX_NOTIFICATION ,
126
+ 0 ,
127
+ p_len ,
128
+ & p [0 ],
129
+ )
119
130
120
131
// Check for some expected errors. Don't report them as errors, but
121
132
// instead fall through and do a normal characteristic value update.
@@ -133,7 +144,7 @@ func (c *Characteristic) Write(p []byte) (n int, err error) {
133
144
}
134
145
}
135
146
136
- errCode := C .sd_ble_gatts_value_set (C .BLE_CONN_HANDLE_INVALID , c .handle , & C.ble_gatts_value_t {
147
+ errCode := C .sd_ble_gatts_value_set_noescape (C .BLE_CONN_HANDLE_INVALID , c .handle , C.ble_gatts_value_t {
137
148
len : uint16 (len (p )),
138
149
p_value : & p [0 ],
139
150
})
0 commit comments