Hi TI experts,
I am trying to update one part(actually rear part with 5 bytes long) of the AdvData array at any time when needed by using GapAdv_prepareLoadByHandle & GapAdv_loadByHandle.
As usual, it works well, but sometimes, the AdvData has a little bit what I didn't mean, that is, the rear part of the AdvData has garbage data I didn't update.
This case happened where 125Kbps PHY packet is being used, while 1Mbps PHY packet didn't.
case GAP_EVT_ADV_START:
//Display_printf(dispHandle, SP_ROW_ADVSTATE, 0, "GAP_EVT_ADV_START");
static uint8 button_pressed = KEYFOB_NO_BUTTON;
if ( (which_button_pressed > KEYFOB_NO_BUTTON) && (button_pressed != which_button_pressed) )
button_pressed = which_button_pressed;
which_button_pressed = KEYFOB_NO_BUTTON;
if ( button_pressed )
{
if (++block_count > 12)
{
block_count = 0;
button_pressed = KEYFOB_NO_BUTTON;
//Display_printf(dispHandle, SP_ROW_STATUS_1, 0, "advertising data for #1 is stopped");
}
advertData[19] = button_pressed;
advertData[20] = block_count;
Display_print2(dispHandle, 0, 0, "button value: %d updated to AdvData: %d", button_pressed, block_count);
bStatus_t status = FAILURE;
status = GapAdv_prepareLoadByHandle(advHandleLongRange, GAP_ADV_FREE_OPTION_DONT_FREE);
//Display_print1(dispHandle, 0, 0, "GapAdv_prepareLoadByHandle: %x", status); ==> showed 0.
HUFPERIPHERAL_ASSERT(status == SUCCESS);
//Display_printf(dispHandle, SP_ROW_STATUS_1, 0, "advertising data for #1 is freed");
// Load advertising data for set #2 that is statically allocated by the app
status = GapAdv_loadByHandle(advHandleLongRange, GAP_ADV_DATA_TYPE_ADV,
sizeof(advertData), advertData);
//Display_print1(dispHandle, 0, 0, "GapAdv_loadByHandle: %x", status); ==> showed 0
HUFPERIPHERAL_ASSERT(status == SUCCESS);
//Display_printf(dispHandle, SP_ROW_STATUS_1, 0, "advertising data for #1 is updated");
}
The below log is what I captured when a button is pushed.
Initialized
Set legacy scannable only advertising mode to #0
Set extended advertising parameters command to #1
loadByHandle advertising data for #1
Adv Set 0 enabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 1(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 2(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 3(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 4(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 5(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 6(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 7(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 8(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 9(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 10(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 11(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 1 updated to AdvData: 12(block count)
Adv Set 1 disabled
Adv Set 1 enabled
button value: 0 updated to AdvData: 0(block count)
Adv Set 1 disabled
Adv Set 1 enabled
The below shows a wrong case I didn't want.
The below shows the normal case I expect.
// Advertisement data
static uint8_t advertData[] =
{
// Flags: this field sets the device to use general discoverable
// mode (advertises indefinitely) instead of general
// discoverable mode (advertise for 30 seconds at a time)
0x02, // length of this data
GAP_ADTYPE_FLAGS,
DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,
// service UUID, to notify central devices what services are included
// in this peripheral
0x03, // length of this data
GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all
LO_UINT16(XXXPROFILE_SERV_UUID),
HI_UINT16(XXXPROFILE_SERV_UUID),
// service UUID, to notify central devices what services are included
// in this peripheral
0x03, // length of this data
GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all
LO_UINT16(THROUGHPUT_SERVICE_SERV_UUID),
HI_UINT16(THROUGHPUT_SERVICE_SERV_UUID),
0x03, // length of this data
GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all
LO_UINT16(TEMPERATURE_SERVICE_SERV_UUID),
HI_UINT16(TEMPERATURE_SERVICE_SERV_UUID),
0x05, // length of this data
GAP_ADTYPE_MANUFACTURER_SPECIFIC,
0xFF,
0xFF,
0x00, // which_button_pressed adverData[19]
0x00 // count (0 to 12) adverData[20]
};
BR,
Ji Won Lee