这是eddystone_beacon.c里的一段代码你可以参考下
discoverable和service_data可按照你的需要做些调整
- /**
- * [url=home.php?mod=space&uid=159083]@brief[/url] This function initializes the Eddystone UID Bluetooth services
- * @param EddystoneUID_Init pointer to initialization structure
- * @retval None
- */
- tBleStatus EddystoneUID_Init(EddystoneUID_InitTypeDef *EddystoneUID_Init)
- {
- tBleStatus ret = BLE_STATUS_SUCCESS;
- /* Disable scan response. */
- hci_le_set_scan_resp_data(0, NULL);
- uint16_t AdvertisingInterval = (EddystoneUID_Init->AdvertisingInterval * ADVERTISING_INTERVAL_INCREMENT / 10);
- /* Put the device in a non-connectable mode. */
- ret = aci_gap_set_discoverable(ADV_NONCONN_IND, /*< Advertise as non-connectable, undirected. */
- AdvertisingInterval, AdvertisingInterval, /*< Set the advertising interval as 700 ms (0.625 us increment). */
- PUBLIC_ADDR, NO_WHITE_LIST_USE, /*< Use the public address, with no white list. */
- 0, NULL, /*< Do not use a local name. */
- 0, NULL, /*< Do not include the service UUID list. */
- 0, 0); /*< Do not set a slave connection interval. */
- if (ret != BLE_STATUS_SUCCESS)
- {
- return ret;
- }
- /* Remove the TX power level advertisement (this is done to decrease the packet size). */
- ret = aci_gap_delete_ad_type(AD_TYPE_TX_POWER_LEVEL);
- if (ret != BLE_STATUS_SUCCESS)
- {
- return ret;
- }
- uint8_t service_data[] =
- {
- 23, /*< Length. */
- AD_TYPE_SERVICE_DATA, /*< Service Data data type value. */
- 0xAA, 0xFE, /*< 16-bit Eddystone UUID. */
- 0x00, /*< UID frame type. */
- EddystoneUID_Init->CalibratedTxPower, /*< Ranging data. */
- EddystoneUID_Init->NamespaceID[0], /*< 10-byte ID Namespace. */
- EddystoneUID_Init->NamespaceID[1],
- EddystoneUID_Init->NamespaceID[2],
- EddystoneUID_Init->NamespaceID[3],
- EddystoneUID_Init->NamespaceID[4],
- EddystoneUID_Init->NamespaceID[5],
- EddystoneUID_Init->NamespaceID[6],
- EddystoneUID_Init->NamespaceID[7],
- EddystoneUID_Init->NamespaceID[8],
- EddystoneUID_Init->NamespaceID[9],
- EddystoneUID_Init->BeaconID[0], /*< 6-byte ID Instance. */
- EddystoneUID_Init->BeaconID[1],
- EddystoneUID_Init->BeaconID[2],
- EddystoneUID_Init->BeaconID[3],
- EddystoneUID_Init->BeaconID[4],
- EddystoneUID_Init->BeaconID[5],
- 0x00, /*< Reserved. */
- 0x00 /*< Reserved. */
- };
- uint8_t service_uuid_list[] =
- {
- 3, /*< Length. */
- AD_TYPE_16_BIT_SERV_UUID_CMPLT_LIST, /*< Complete list of 16-bit Service UUIDs data type value. */
- 0xAA, 0xFE /*< 16-bit Eddystone UUID. */
- };
- uint8_t flags[] =
- {
- 2, /*< Length. */
- AD_TYPE_FLAGS, /*< Flags data type value. */
- (FLAG_BIT_LE_GENERAL_DISCOVERABLE_MODE | FLAG_BIT_BR_EDR_NOT_SUPPORTED) /*< BLE general discoverable, without BR/EDR support. */
- };
- /* Update the service data. */
- ret = aci_gap_update_adv_data(sizeof(service_data), service_data);
- if (ret != BLE_STATUS_SUCCESS)
- {
- return ret;
- }
- /* Update the service UUID list. */
- ret = aci_gap_update_adv_data(sizeof(service_uuid_list), service_uuid_list);
- if (ret != BLE_STATUS_SUCCESS)
- {
- return ret;
- }
- /* Update the adverstising flags. */
- ret = aci_gap_update_adv_data(sizeof(flags), flags);
- if (ret != BLE_STATUS_SUCCESS)
- {
- return ret;
- }
- return ret;
- }
相关宏定义在link_layer.h里