/** * @brief Initialize the BlueNRG * * @param None * @retval None */ void BlueNRG_Init(void) { tBleStatus ret = BLE_STATUS_SUCCESS; uint16_t service_handle, dev_name_char_handle, appearance_char_handle; uint8_t SERVER_BDADDR[] = { MAC_ADDRESS }; uint8_t hwVersion; uint16_t fwVersion; uint8_t bnrg_expansion_board = IDB04A1; /* at startup, suppose the X-NUCLEO-IDB04A1 is used */ /* get the BlueNRG HW and FW versions */ getBlueNRGVersion(&hwVersion, &fwVersion); if (hwVersion > 0x30) { /* X-NUCLEO-IDB05A1 expansion board is used */ bnrg_expansion_board = IDB05A1; } ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, SERVER_BDADDR); if (ret != BLE_STATUS_SUCCESS) { __asm("nop"); } ret = aci_gatt_init(); if (ret != BLE_STATUS_SUCCESS) { __asm("nop"); } if (bnrg_expansion_board == IDB05A1) { ret = aci_gap_init_IDB05A1(GAP_PERIPHERAL_ROLE_IDB05A1, 0, 0x07, &service_handle, &dev_name_char_handle, &appearance_char_handle); } else { ret = aci_gap_init_IDB04A1(GAP_PERIPHERAL_ROLE_IDB04A1, &service_handle, &dev_name_char_handle, &appearance_char_handle); } if (ret != BLE_STATUS_SUCCESS) { __asm("nop"); } ret = aci_hal_set_tx_power_level(1,4); if (ret != BLE_STATUS_SUCCESS) { __asm("nop"); } } tBleStatus Beacon_Init(void) { tBleStatus ret = BLE_STATUS_SUCCESS; /* Disable scan response. */ hci_le_set_scan_resp_data(0, NULL); uint16_t AdvertisingInterval = (10 * 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. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 0x00, /*< Reserved. */ 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; } tBleStatus UpdateAdv(uint8_t * buff,uint8_t len) { tBleStatus ret = BLE_STATUS_SUCCESS; uint8_t service_data[] = { 23, /*< Length. */ AD_TYPE_SERVICE_DATA, /*< Service Data data type value. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; memcpy(&service_data[2],buff,len); memset(&service_data[2+len],0,22-len); /* Update the service data. */ ret = aci_gap_update_adv_data(sizeof(service_data), service_data); if (ret != BLE_STATUS_SUCCESS) { return ret; } return ret; } |