Hi Dialog Team,
I am customising the ble_app_barebone to implement the following requirement.
1) Device should scan for BLE packets in the GAP_OBSERVER_SCA mode.
2) Upon reception of the first BLE packet, the packet has to be retransmitted 3 times by the device as soon as possible.
3) After retransmission of the packet, the device should switch back to scanning mode.
这是实现如下:
1. When scan is started, a systick timer of 2ms is initiated.
2. In the scan callback when a packet is received, a flag is set.
3. In the systick timer callback, if the flag is set, scanning is stopped.
4. In the scan complete callback function, gap reset is invoked.
5. In the reset gap callback, a custom function is called to set the role to GAP_BROADCASTER_ADV.
6. In the device configuration complete callback, advertisement is started. A flag is set to denote advertisement has started.
7. In the timer callback, if the flag for advertisement start is set, advertisement is stopped. The flag is reset.
8. During the next 2ms timer callback, since the flag is reset, advertisement is started again. The advertisement start callback is set. Steps 7-8 is repeated thrice to send 3 packets consecutively.
9. The third time, after advertisement is stopped, gap reset is invoked.
10. In the gap reset callback, the role is set to GAP_OBSERVER_SCA.
11. In the device configuration complete callback, scanning is started.
12. Thus steps 1-11 gets repeated.
在this implementation, packets are captured in the scan callback. However, the packet is not getting transmitted.
Should there be any delay between scanning and advertisement switching / advertisement start and stop? Kindly advise.
Thanks
Wisilica

Hi wisilica,
The system requires sometime in order to reset the stack and configure a new role in order to start advertising, but this is a matter of few milliseconds in a fully hosted project. If you are not able to see any advertising messages then the most probable cause is that there is something wrong with the advertising string or you ve set the interval of the advertising in a large value, larger than the timer that counts until the next role switch. So perhaps the device transmits one advertising string and before transmits the second the device has allreay switched role. Anyhow if there is something wrong with the advertising message or if for any reason the device fails to transmit an advertising message when you send a advertising command you should get the advertising complete callback with a corresponding error, for example if any invalid data in the string you should get GAP_ERR_ADV_DATA_INVALID status, so this is a good place to start looking.
Thanks MT_dialog
Hi Dialog Team,
Thank you for the prompt reply. I am getting the error GAP_ERR_NOT_SUPPORTED in the callback of app_on_adv_nonconn_complete event.
Please mention the cases of occurence of this error and the ways to rectify those.
Thanks
Wisilica
Hi wisilica,
You are trying to execute a command and your role doesn't support it, for example you are trying to advertise while you are a central, or you try to advertise as a broadcaster but the mode that you are using is general discoverable instead of broadcaster mode. Check in the user_adv_conf structure the mode member and make sure that this is set to GAP_OBSERVER_MODE in case you are operating in the observer role.
Thanks MT_dialog