From 5aacbeaecc42ffd66802ffa142d2384df105b2bd Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Sat, 11 Feb 2023 20:39:41 +1100 Subject: [PATCH] Add unqiue id to BLE name --- source/Core/BSP/Pinecilv2/ble_peripheral.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/source/Core/BSP/Pinecilv2/ble_peripheral.c b/source/Core/BSP/Pinecilv2/ble_peripheral.c index 35cbdcee..d223fa97 100644 --- a/source/Core/BSP/Pinecilv2/ble_peripheral.c +++ b/source/Core/BSP/Pinecilv2/ble_peripheral.c @@ -26,9 +26,9 @@ NOTES #include "log.h" #include "uuid.h" +#include "BSP.h" #include "ble_characteristics.h" #include "ble_handlers.h" - bool pds_start; static void ble_device_connected(struct bt_conn *conn, u8_t err); @@ -250,14 +250,10 @@ static struct bt_gatt_attr attrs[] = { NAME get_attr */ -struct bt_gatt_attr *get_attr(u8_t index) { - return &attrs[index]; -} +struct bt_gatt_attr *get_attr(u8_t index) { return &attrs[index]; } static struct bt_gatt_service ble_tp_server = BT_GATT_SERVICE(attrs); -const char *DEVICE_BLE_NAME = "Pinecil"; - // Start advertising with expected default values int ble_start_adv(void) { MSG("BLE Starting advertising\n"); @@ -267,18 +263,15 @@ int ble_start_adv(void) { .interval_min = BT_GAP_ADV_FAST_INT_MIN_3, .interval_max = BT_GAP_ADV_FAST_INT_MAX_3, }; + char nameBuffer[16]; + int nameLen = snprintf(nameBuffer, 16, "Pinecil-%03d", (int)(getDeviceID() & 0xFFFF)); // scan and response data must each stay < 31 bytes - struct bt_data adv_data[2] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_NO_BREDR | BT_LE_AD_GENERAL)), - BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_BLE_NAME, strlen(DEVICE_BLE_NAME)) - }; + struct bt_data adv_data[2] = {BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_NO_BREDR | BT_LE_AD_GENERAL)), BT_DATA(BT_DATA_NAME_COMPLETE, nameBuffer, nameLen)}; - struct bt_data scan_response_data[1] = { - BT_DATA(BT_DATA_UUID128_SOME, ((struct bt_uuid_128 *)BT_UUID_SVC_BULK_DATA)->val, 16) - }; + struct bt_data scan_response_data[1] = {BT_DATA(BT_DATA_UUID128_SOME, ((struct bt_uuid_128 *)BT_UUID_SVC_BULK_DATA)->val, 16)}; - return bt_le_adv_start(&adv_param, adv_data, ARRAY_SIZE(adv_data), scan_response_data, ARRAY_SIZE(scan_response_data)); + return bt_le_adv_start(&adv_param, adv_data, ARRAY_SIZE(adv_data), scan_response_data, ARRAY_SIZE(scan_response_data)); } // Callback that the ble stack will call once it has been kicked off running