mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
fix(nimble): Fix issues found in review for nimble examples
This commit is contained in:
@@ -245,7 +245,20 @@ gatt_svr_chr_access_sc_control_point(uint16_t conn_handle,
|
||||
break;
|
||||
}
|
||||
|
||||
/* Append response value */
|
||||
/* Append Response Op Code, Request Op Code, and Response Value */
|
||||
uint8_t rsp_op = SC_CP_OP_RESPONSE;
|
||||
rc = os_mbuf_append(om_indication, &rsp_op, sizeof(rsp_op));
|
||||
if (rc != 0) {
|
||||
os_mbuf_free_chain(om_indication);
|
||||
return BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
|
||||
rc = os_mbuf_append(om_indication, &op_code, sizeof(op_code));
|
||||
if (rc != 0) {
|
||||
os_mbuf_free_chain(om_indication);
|
||||
return BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
|
||||
rc = os_mbuf_append(om_indication, &response, sizeof(response));
|
||||
|
||||
if (rc != 0){
|
||||
@@ -267,14 +280,7 @@ gatt_svr_chr_access_sc_control_point(uint16_t conn_handle,
|
||||
|
||||
rc = ble_gatts_indicate_custom(conn_handle, csc_control_point_handle,
|
||||
om_indication);
|
||||
if (rc != 0) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
||||
done:
|
||||
os_mbuf_free_chain(om_indication);
|
||||
/* om_indication is consumed (freed) by ble_gatts_indicate_custom regardless of result */
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -328,6 +334,9 @@ gatt_svr_chr_notify_csc_measurement(uint16_t conn_handle)
|
||||
#endif
|
||||
|
||||
om = ble_hs_mbuf_from_flat(data_buf, data_offset);
|
||||
if (om == NULL) {
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
rc = ble_gatts_notify_custom(conn_handle, csc_measurement_handle, om);
|
||||
return rc;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "console/console.h"
|
||||
#include "nimble/ble.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/util/util.h"
|
||||
#include "services/gap/ble_svc_gap.h"
|
||||
#include "blecsc_sens.h"
|
||||
#include "nimble/nimble_port.h"
|
||||
@@ -198,14 +199,16 @@ blecsc_measurement(struct ble_npl_event *ev)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = ble_npl_callout_reset(&blecsc_measure_timer, portTICK_PERIOD_MS * 10);
|
||||
rc = ble_npl_callout_reset(&blecsc_measure_timer, ble_npl_time_ms_to_ticks32(1000));
|
||||
assert(rc == 0);
|
||||
|
||||
blecsc_simulate_speed_and_cadence();
|
||||
|
||||
if (notify_state) {
|
||||
rc = gatt_svr_chr_notify_csc_measurement(conn_handle);
|
||||
assert(rc == 0);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(WARN, "gatt_svr_chr_notify_csc_measurement failed; rc=%d\n", rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,6 +235,8 @@ blecsc_gap_event(struct ble_gap_event *event, void *arg)
|
||||
case BLE_GAP_EVENT_DISCONNECT:
|
||||
MODLOG_DFLT(INFO, "disconnect; reason=%d\n", event->disconnect.reason);
|
||||
conn_handle = 0;
|
||||
notify_state = false;
|
||||
gatt_svr_set_cp_indicate(0);
|
||||
/* Connection terminated; resume advertising */
|
||||
blecsc_advertise();
|
||||
break;
|
||||
@@ -272,6 +277,9 @@ blecsc_on_sync(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = ble_hs_util_ensure_addr(0);
|
||||
assert(rc == 0);
|
||||
|
||||
/* Figure out address to use while advertising (no privacy) */
|
||||
rc = ble_hs_id_infer_auto(0, &blecsc_addr_type);
|
||||
assert(rc == 0);
|
||||
@@ -321,7 +329,7 @@ app_main(void)
|
||||
/* Initialize measurement and notification timer */
|
||||
ble_npl_callout_init(&blecsc_measure_timer, nimble_port_get_dflt_eventq(),
|
||||
blecsc_measurement, NULL);
|
||||
rc = ble_npl_callout_reset(&blecsc_measure_timer, portTICK_PERIOD_MS * 100);
|
||||
rc = ble_npl_callout_reset(&blecsc_measure_timer, ble_npl_time_ms_to_ticks32(1000));
|
||||
assert(rc == 0);
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS)
|
||||
|
||||
Reference in New Issue
Block a user