Merge branch 'bugfix/add_event_cb_for_pcl_v5.1' into 'release/v5.1'

Nimble: Add support to send power control event in registered callback (v5.1)

See merge request espressif/esp-idf!23583
This commit is contained in:
Rahul Tank 2023-07-04 18:18:59 +08:00
commit 40bf1ed65e
2 changed files with 42 additions and 78 deletions

View File

@ -44,10 +44,6 @@ static uint8_t peer_addr[6];
void ble_store_config_init(void); void ble_store_config_init(void);
#if MYNEWT_VAL(BLE_POWER_CONTROL)
static struct ble_gap_event_listener power_control_event_listener;
#endif
/** /**
* Application Callback. Called when the custom subscribable chatacteristic * Application Callback. Called when the custom subscribable chatacteristic
* in the remote GATT server is read. * in the remote GATT server is read.
@ -615,36 +611,6 @@ static void blecent_power_control(uint16_t conn_handle)
rc = ble_gap_set_path_loss_reporting_enable(conn_handle, 0x01); rc = ble_gap_set_path_loss_reporting_enable(conn_handle, 0x01);
assert (rc == 0); assert (rc == 0);
} }
static int
blecent_gap_power_event(struct ble_gap_event *event, void *arg)
{
switch(event->type) {
case BLE_GAP_EVENT_TRANSMIT_POWER:
MODLOG_DFLT(INFO, "Transmit power event : status=%d conn_handle=%d reason=%d "
"phy=%d power_level=%x power_level_flag=%d delta=%d",
event->transmit_power.status,
event->transmit_power.conn_handle,
event->transmit_power.reason,
event->transmit_power.phy,
event->transmit_power.transmit_power_level,
event->transmit_power.transmit_power_level_flag,
event->transmit_power.delta);
return 0;
case BLE_GAP_EVENT_PATHLOSS_THRESHOLD:
MODLOG_DFLT(INFO, "Pathloss threshold event : conn_handle=%d current path loss=%d "
"zone_entered =%d",
event->pathloss_threshold.conn_handle,
event->pathloss_threshold.current_path_loss,
event->pathloss_threshold.zone_entered);
return 0;
default:
return 0;
}
}
#endif #endif
/** /**
@ -703,9 +669,6 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
#if MYNEWT_VAL(BLE_POWER_CONTROL) #if MYNEWT_VAL(BLE_POWER_CONTROL)
blecent_power_control(event->connect.conn_handle); blecent_power_control(event->connect.conn_handle);
ble_gap_event_listener_register(&power_control_event_listener,
blecent_gap_power_event, NULL);
#endif #endif
#if CONFIG_EXAMPLE_ENCRYPTION #if CONFIG_EXAMPLE_ENCRYPTION
@ -824,6 +787,27 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
return 0; return 0;
#endif #endif
#if MYNEWT_VAL(BLE_POWER_CONTROL)
case BLE_GAP_EVENT_TRANSMIT_POWER:
MODLOG_DFLT(INFO, "Transmit power event : status=%d conn_handle=%d reason=%d "
"phy=%d power_level=%x power_level_flag=%d delta=%d",
event->transmit_power.status,
event->transmit_power.conn_handle,
event->transmit_power.reason,
event->transmit_power.phy,
event->transmit_power.transmit_power_level,
event->transmit_power.transmit_power_level_flag,
event->transmit_power.delta);
return 0;
case BLE_GAP_EVENT_PATHLOSS_THRESHOLD:
MODLOG_DFLT(INFO, "Pathloss threshold event : conn_handle=%d current path loss=%d "
"zone_entered =%d",
event->pathloss_threshold.conn_handle,
event->pathloss_threshold.current_path_loss,
event->pathloss_threshold.zone_entered);
return 0;
#endif
default: default:
return 0; return 0;
} }

View File

@ -47,10 +47,6 @@ static uint8_t own_addr_type;
void ble_store_config_init(void); void ble_store_config_init(void);
#if MYNEWT_VAL(BLE_POWER_CONTROL)
static struct ble_gap_event_listener power_control_event_listener;
#endif
/** /**
* Logs information about a connection to the console. * Logs information about a connection to the console.
*/ */
@ -217,40 +213,6 @@ static void bleprph_power_control(uint16_t conn_handle)
} }
#endif #endif
#if MYNEWT_VAL(BLE_POWER_CONTROL)
static int
bleprph_gap_power_event(struct ble_gap_event *event, void *arg)
{
switch(event->type) {
case BLE_GAP_EVENT_TRANSMIT_POWER:
MODLOG_DFLT(INFO, "Transmit power event : status=%d conn_handle=%d reason=%d "
"phy=%d power_level=%x power_level_flag=%d delta=%d",
event->transmit_power.status,
event->transmit_power.conn_handle,
event->transmit_power.reason,
event->transmit_power.phy,
event->transmit_power.transmit_power_level,
event->transmit_power.transmit_power_level_flag,
event->transmit_power.delta);
return 0;
case BLE_GAP_EVENT_PATHLOSS_THRESHOLD:
MODLOG_DFLT(INFO, "Pathloss threshold event : conn_handle=%d current path loss=%d "
"zone_entered =%d",
event->pathloss_threshold.conn_handle,
event->pathloss_threshold.current_path_loss,
event->pathloss_threshold.zone_entered);
return 0;
default:
return 0;
}
}
#endif
/** /**
* The nimble host executes this callback when a GAP event occurs. The * The nimble host executes this callback when a GAP event occurs. The
* application associates a GAP event callback with each connection that forms. * application associates a GAP event callback with each connection that forms.
@ -296,9 +258,6 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg)
#if MYNEWT_VAL(BLE_POWER_CONTROL) #if MYNEWT_VAL(BLE_POWER_CONTROL)
bleprph_power_control(event->connect.conn_handle); bleprph_power_control(event->connect.conn_handle);
ble_gap_event_listener_register(&power_control_event_listener,
bleprph_gap_power_event, NULL);
#endif #endif
return 0; return 0;
@ -434,6 +393,27 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg)
} }
return 0; return 0;
#if MYNEWT_VAL(BLE_POWER_CONTROL)
case BLE_GAP_EVENT_TRANSMIT_POWER:
MODLOG_DFLT(INFO, "Transmit power event : status=%d conn_handle=%d reason=%d "
"phy=%d power_level=%x power_level_flag=%d delta=%d",
event->transmit_power.status,
event->transmit_power.conn_handle,
event->transmit_power.reason,
event->transmit_power.phy,
event->transmit_power.transmit_power_level,
event->transmit_power.transmit_power_level_flag,
event->transmit_power.delta);
return 0;
case BLE_GAP_EVENT_PATHLOSS_THRESHOLD:
MODLOG_DFLT(INFO, "Pathloss threshold event : conn_handle=%d current path loss=%d "
"zone_entered =%d",
event->pathloss_threshold.conn_handle,
event->pathloss_threshold.current_path_loss,
event->pathloss_threshold.zone_entered);
return 0;
#endif
} }
return 0; return 0;