From a72dbbf7a414b19b5de9fba9acda1645967ba0dc Mon Sep 17 00:00:00 2001 From: tpu Date: Wed, 7 May 2025 22:01:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AEMAC=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E7=94=9F=E6=88=90=E8=AE=BE=E5=A4=87=E5=90=8D?= =?UTF-8?q?=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Keil_5/ble_app_peripheral.uvoptx | 2 +- src/config/user_config.h | 2 +- src/user_peripheral.c | 33 +++++++++++++++++++++++--------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Keil_5/ble_app_peripheral.uvoptx b/Keil_5/ble_app_peripheral.uvoptx index 345475b..9c4936f 100644 --- a/Keil_5/ble_app_peripheral.uvoptx +++ b/Keil_5/ble_app_peripheral.uvoptx @@ -120,7 +120,7 @@ 0 DLGUARM - d + 0 diff --git a/src/config/user_config.h b/src/config/user_config.h index baaa9d9..02a3e3f 100644 --- a/src/config/user_config.h +++ b/src/config/user_config.h @@ -213,7 +213,7 @@ static const struct advertise_configuration user_adv_conf = { **************************************************************************************** */ /// Device name -#define USER_DEVICE_NAME "DLG-CLOCK" +#define USER_DEVICE_NAME "" /// Device name length #define USER_DEVICE_NAME_LEN (sizeof(USER_DEVICE_NAME)-1) diff --git a/src/user_peripheral.c b/src/user_peripheral.c index 3ce6527..6630ef8 100644 --- a/src/user_peripheral.c +++ b/src/user_peripheral.c @@ -292,21 +292,36 @@ void user_app_on_db_init_complete( void ) void user_app_adv_start(void) { - // Schedule the next advertising data update - //app_adv_data_update_timer_used = app_easy_timer(APP_ADV_DATA_UPDATE_TO, adv_data_update_timer_cb); - - struct gapm_start_advertise_cmd* cmd; - cmd = app_easy_gap_undirected_advertise_get_active(); - - // Add manufacturer data to initial advertising or scan response data, if there is enough space - app_add_ad_struct(cmd, &mnf_data, sizeof(struct mnf_specific_data_ad_structure), 1); + u32 ba0 = *(volatile u32*)(0x40000024); + u32 ba1 = *(volatile u32*)(0x40000028); + char adv_name[20]; + + ba1 = (ba1<<8)|(ba0>>24); + ba0 &= 0x00ffffff; + ba0 ^= ba1; + + u8 *ba = (u8*)&ba0; + sprintf(adv_name+2, "DLG-CLOCK-%02x%02x%02x", ba[2], ba[1], ba[0]); + int name_len = strlen(adv_name+2); + + if(device_info.dev_name.length==0){ + device_info.dev_name.length = name_len; + memcpy(device_info.dev_name.name, adv_name+2, name_len); + } + + adv_name[0] = name_len+1; + adv_name[1] = GAP_AD_TYPE_COMPLETE_NAME; + + struct gapm_start_advertise_cmd* cmd = app_easy_gap_undirected_advertise_get_active(); + app_add_ad_struct(cmd, adv_name, name_len+2, 1); //default_advertise_operation(); //app_easy_gap_undirected_advertise_start(); app_easy_gap_undirected_advertise_with_timeout_start(user_default_hnd_conf.advertise_period, NULL); - printk("\nuser_app_adv_start!\n"); + printk("\nuser_app_adv_start! %s\n", adv_name+2); } + void user_app_connection(uint8_t connection_idx, struct gapc_connection_req_ind const *param) { printk("user_app_connection: %d\n", connection_idx);