From dec520bca4cf12e49d08a9f0974f7bc556fe4d1e Mon Sep 17 00:00:00 2001 From: SnickerSun Date: Sun, 3 Mar 2024 15:28:27 +0800 Subject: [PATCH] =?utf8?q?=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE=E6=98=BE?= =?utf8?q?=E7=A4=BA=E6=AD=A3=E7=A1=AEbtaddr?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../system/include/SystemAboutTheWatchView.h | 2 +- .../system/src/SystemAboutTheWatchView.cpp | 81 ++++++++++--------- .../drivers/peripheral/utils/custom_utils.c | 22 +++++ .../drivers/peripheral/utils/custom_utils.h | 2 + 4 files changed, 69 insertions(+), 38 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemAboutTheWatchView.h b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemAboutTheWatchView.h index 03249d47e..09b40efb3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemAboutTheWatchView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemAboutTheWatchView.h @@ -24,7 +24,7 @@ namespace OHOS int16_t height; int16_t fontSize; // 字体大小 int16_t lineHeigh; // 行高 - const char *text; // 文本 + char *text; // 文本 uint8_t lineBreakMode; // 断行模式。 }; UIScrollView *SystemAbouTheWatchtInitIView(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemAboutTheWatchView.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemAboutTheWatchView.cpp index 7f9b49bcf..88f1040d5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemAboutTheWatchView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemAboutTheWatchView.cpp @@ -1,6 +1,7 @@ #include "system/include/SystemAboutTheWatchView.h" #include "system/include/SystemPresenter.h" #include "wearable_log.h" +#include "custom_utils.h" namespace OHOS { @@ -258,6 +259,10 @@ namespace OHOS } SystemAboutTheWatchScrollView->Add(BluetoothAddressTitle); /* -------------------------------------------------------------------------- */ + uint8_t btaddr[64]={0}; + uint32_t len = 64; + uapi_get_btaddr((uint8_t*)btaddr,&len); + Config = { .left = 37, .top = 651, @@ -265,9 +270,11 @@ namespace OHOS .height = 30, .fontSize = 26, .lineHeigh = 30, - .text = "D4:FF:E3:12:00:A4", + .text = (char*)btaddr, .lineBreakMode = UILabel::LINE_BREAK_ELLIPSIS, }; + + BluetoothAddress = InitLabel(Config); if (BluetoothAddress == nullptr) { @@ -277,42 +284,42 @@ namespace OHOS BluetoothAddress->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x87)); SystemAboutTheWatchScrollView->Add(BluetoothAddress); /* -------------------------------------------------------------------------- */ - Config = { - .left = 173, - .top = 740, - .width = 120, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .text = "局域网地址", - .lineBreakMode = UILabel::LINE_BREAK_ADAPT, - }; - LANAddressTitle = InitLabel(Config); - if (LANAddressTitle == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::LANAddressTitle new fail!"); - return nullptr; - } - SystemAboutTheWatchScrollView->Add(LANAddressTitle); - /* -------------------------------------------------------------------------- */ - Config = { - .left = 37, - .top = 796, - .width = 400, - .height = 30, - .fontSize = 26, - .lineHeigh = 30, - .text = "D4:FF:E3:12:00:A4", - .lineBreakMode = UILabel::LINE_BREAK_ELLIPSIS, - }; - LANAddress = InitLabel(Config); - if (LANAddress == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::LANAddress new fail!"); - return nullptr; - } - LANAddress->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x87)); - SystemAboutTheWatchScrollView->Add(LANAddress); + // Config = { + // .left = 173, + // .top = 740, + // .width = 120, + // .height = 35, + // .fontSize = 30, + // .lineHeigh = 35, + // .text = "局域网地址", + // .lineBreakMode = UILabel::LINE_BREAK_ADAPT, + // }; + // LANAddressTitle = InitLabel(Config); + // if (LANAddressTitle == nullptr) + // { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::LANAddressTitle new fail!"); + // return nullptr; + // } + // SystemAboutTheWatchScrollView->Add(LANAddressTitle); + // /* -------------------------------------------------------------------------- */ + // Config = { + // .left = 37, + // .top = 796, + // .width = 400, + // .height = 30, + // .fontSize = 26, + // .lineHeigh = 30, + // .text = "D4:FF:E3:12:00:A4", + // .lineBreakMode = UILabel::LINE_BREAK_ELLIPSIS, + // }; + // LANAddress = InitLabel(Config); + // if (LANAddress == nullptr) + // { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::LANAddress new fail!"); + // return nullptr; + // } + // LANAddress->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x87)); + // SystemAboutTheWatchScrollView->Add(LANAddress); /* -------------------------------------------------------------------------- */ Config = { .left = 173, diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index a7acc5496..6424c1d04 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -283,6 +283,28 @@ errcode_t uapi_set_time_from_cat1(char* cat1time) return ERRCODE_SUCC; } +#include "bts_le_gap.h" + +errcode_t uapi_get_btaddr(uint8_t *buf_btaddr, uint32_t *len_btaddr) +{ + if (buf_btaddr == NULL || len_btaddr == NULL) { + return ERRCODE_FAIL; + } + + bd_addr_t addr_info; + gap_ble_get_local_addr(&addr_info); + char str[18] = {0}; + sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x", addr_info.addr[5], addr_info.addr[4], addr_info.addr[3], + addr_info.addr[2], addr_info.addr[1], addr_info.addr[0]); +#ifdef ALIPAY_CSI_LOG_EXT_ON + MyPrintf("addr:%s\n", str); +#endif + *len_btaddr = strlen(str); + memcpy(buf_btaddr, str, strlen(str)); + + return ERRCODE_SUCC; +} + #if 0 diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 5a6e68b22..8f7fa5add 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -30,6 +30,8 @@ errcode_t uapi_get_timestampe_ms(uint64_t *tm); /**根据cat1获取的时间字串设置时间*/ errcode_t uapi_set_time_from_cat1(char* cat1time); + +errcode_t uapi_get_btaddr(uint8_t *buf_btaddr, uint32_t *len_btaddr); /** * @} */ -- 2.17.1