Skip to content

Commit 1b1efab

Browse files
sgbihuSidLeung
authored andcommitted
Jira 794 Inconsistent writeInt() result with different Peripherals, git 385
Root cause: - The function, BLECharacteristicImp::write(), did not check the characteristic property to determine if the caller requires a response. It just treats all calls do not require a response. Modifications: 1. libraries/CurieBLE/src/internal/BLECallbacks.cpp: - Added fake write response CB for write with no response call. 2. libraries/CurieBLE/src/internal/BLECallbacks.h: - Function definition added. 3. libraries/CurieBLE/src/internal/BLECharacteristicImp.cpp: - In function write(), check the characteristic property to determine whether the call requires a response.
1 parent 29daefb commit 1b1efab

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

libraries/CurieBLE/src/internal/BLECallbacks.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,8 @@ void ble_central_device_found(const bt_addr_le_t *addr,
223223
ad, len);
224224
}
225225

226+
void ble_on_write_no_rsp_complete(struct bt_conn *conn, uint8_t err,
227+
const void *data)
228+
{
229+
}
226230

libraries/CurieBLE/src/internal/BLECallbacks.h

+3
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,8 @@ uint8_t profile_service_read_rsp_process(bt_conn_t *conn,
7474
const void *data,
7575
uint16_t length);
7676

77+
void ble_on_write_no_rsp_complete(struct bt_conn *conn, uint8_t err,
78+
const void *data);
79+
7780
#endif
7881

libraries/CurieBLE/src/internal/BLECharacteristicImp.cpp

+19-6
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,25 @@ bool BLECharacteristicImp::write(const unsigned char value[],
655655
return false;
656656
}
657657

658-
// Send read request
659-
retval = bt_gatt_write_without_response(conn,
660-
_value_handle,
661-
value,
662-
length,
663-
false);
658+
// Send write request
659+
if (_gatt_chrc.properties | BT_GATT_CHRC_WRITE_WITHOUT_RESP)
660+
{
661+
retval = bt_gatt_write_without_response(conn,
662+
_value_handle,
663+
value,
664+
length,
665+
false);
666+
}
667+
else if (_gatt_chrc.properties | BT_GATT_CHRC_WRITE)
668+
{
669+
retval = bt_gatt_write(conn,
670+
_value_handle,
671+
0,
672+
value,
673+
length,
674+
ble_on_write_no_rsp_complete);
675+
676+
}
664677
bt_conn_unref(conn);
665678
return (0 == retval);
666679
}

0 commit comments

Comments
 (0)