Skip to content

Commit 8dedd43

Browse files
add status to start and stop events
1 parent e99741d commit 8dedd43

File tree

2 files changed

+25
-54
lines changed

2 files changed

+25
-54
lines changed

connectivity/FEATURE_BLE/include/ble/Gap.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -341,18 +341,6 @@ class Gap {
341341
{
342342
}
343343

344-
/**
345-
* Called when an asynchronous advertising command fails.
346-
*
347-
* @param event Advertising command failed event.
348-
*
349-
* @see startAdvertising()
350-
* @see stopAdvertising()
351-
*/
352-
virtual void onAdvertisingCommandFailed(const AdvertisingCommandFailedEvent &event)
353-
{
354-
}
355-
356344
/**
357345
* Called when a scanner receives an advertising or a scan response packet.
358346
*
@@ -761,7 +749,7 @@ class Gap {
761749
* @param maxEvents Max number of events produced during advertising - 0 means no limit.
762750
* @return BLE_ERROR_NONE on success. This does not guarantee the set has started if
763751
* extended advertising is enabled. Register an event handler and wait for onAdvertisingStart
764-
* event. An (unlikely) failed start will emit an onAdvertisingCommandFailed instead.
752+
* event. An (unlikely) failed start the status of the event will contain an error.
765753
*
766754
* @see EventHandler::onAdvertisingStart when the advertising starts.
767755
* @see EventHandler::onScanRequestReceived when a scan request is received.
@@ -781,7 +769,7 @@ class Gap {
781769
* @param handle Advertising set handle.
782770
* @return BLE_ERROR_NONE on success. For extented advertising this does not guarantee
783771
* the set is stopped if. Register an event handler and wait for onAdvertisingEnd event.
784-
* An (unlikely) failed stop will emit an onAdvertisingCommandFailed instead.
772+
* An (unlikely) failed stop the event status will contain the error code.
785773
*/
786774
ble_error_t stopAdvertising(advertising_handle_t handle);
787775

connectivity/FEATURE_BLE/include/ble/gap/Events.h

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,10 @@ struct AdvertisingStartEvent {
586586
/** Create an advertising start event.
587587
*
588588
* @param advHandle Advertising set handle.
589+
* @param status Advertising set start command status.
589590
*/
590-
AdvertisingStartEvent(advertising_handle_t advHandle) :
591-
advHandle(advHandle)
591+
AdvertisingStartEvent(advertising_handle_t advHandle, ble_error_t status = BLE_ERROR_NONE) :
592+
advHandle(advHandle), status(status)
592593
{
593594
}
594595

@@ -600,43 +601,12 @@ struct AdvertisingStartEvent {
600601
return advHandle;
601602
}
602603

603-
private:
604-
advertising_handle_t advHandle;
605-
};
606-
607-
/**
608-
* Event produced when an async advertising command fails.
609-
*
610-
* @see ble::Gap::EventHandler::onAdvertisingCommandFailed().
611-
*/
612-
struct AdvertisingCommandFailedEvent {
613-
#if !defined(DOXYGEN_ONLY)
614-
/** Create an extended advertising command failed event.
615-
*
616-
* @param advHandle Advertising set handle.
617-
* @param status Error code.
618-
*/
619-
AdvertisingCommandFailedEvent(
620-
advertising_handle_t advHandle,
621-
ble_error_t status
622-
) :
623-
advHandle(advHandle),
624-
status(status)
625-
{
626-
}
627-
628-
#endif
629-
/** Get advertising handle. */
630-
advertising_handle_t getAdvHandle() const
631-
{
632-
return advHandle;
633-
}
634-
635-
/** Error code that caused the event. */
636-
uint8_t getStatus() const
604+
/** Get status of operation. */
605+
ble_error_t getStatus() const
637606
{
638607
return status;
639608
}
609+
640610
private:
641611
advertising_handle_t advHandle;
642612
ble_error_t status;
@@ -648,7 +618,8 @@ struct AdvertisingCommandFailedEvent {
648618
* @see ble::Gap::EventHandler::onAdvertisingEnd().
649619
*
650620
* @note The connection handle, connected flag and completed_event fields are
651-
* valid if the flag legacy is not set to true.
621+
* valid if the flag legacy is not set to true. If status is different from BLE_ERROR_NONE
622+
* the completed_events field is not valid and the set may still be active.
652623
*/
653624
struct AdvertisingEndEvent {
654625
#if !defined(DOXYGEN_ONLY)
@@ -659,18 +630,21 @@ struct AdvertisingEndEvent {
659630
* @param connection Connection handle.
660631
* @param completed_events Number of events created during before advertising end.
661632
* @param connected True if connection has been established.
633+
* @param status Error code if stop command failed.
662634
*/
663635
AdvertisingEndEvent(
664636
advertising_handle_t advHandle,
665637
connection_handle_t connection,
666638
uint8_t completed_events,
667-
bool connected
639+
bool connected,
640+
ble_error_t status = BLE_ERROR_NONE
668641
) :
669642
advHandle(advHandle),
670643
connection(connection),
671644
completed_events(completed_events),
672645
connected(connected),
673-
legacy(false)
646+
legacy(false),
647+
status(status)
674648
{
675649
}
676650

@@ -681,7 +655,8 @@ struct AdvertisingEndEvent {
681655
connection(),
682656
completed_events(0),
683657
connected(false),
684-
legacy(true)
658+
legacy(true),
659+
status(BLE_ERROR_NONE)
685660
{
686661
}
687662

@@ -721,12 +696,20 @@ struct AdvertisingEndEvent {
721696
return legacy;
722697
}
723698

699+
/** Get the result of the stop advertising event. If the status is not BLE_ERROR_NONE the set
700+
* may still be active. */
701+
ble_error_t getStatus() const
702+
{
703+
return status;
704+
}
705+
724706
private:
725707
advertising_handle_t advHandle;
726708
connection_handle_t connection;
727709
uint8_t completed_events;
728710
bool connected;
729711
bool legacy;
712+
ble_error_t status;
730713
};
731714

732715
/**

0 commit comments

Comments
 (0)