From 1b971290d41883a61ea190aeb6fa6829a4d0fcce Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=83=A1=E4=BC=A0=E5=86=9B?= <1224667075@qq.com> Date: Sat, 29 Jun 2024 10:09:03 +0000 Subject: [PATCH] Merge #416 into sdk602patch0521 from refs/changes/416/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 胡传军 * refs/changes/416/head: (8 commits squashed) - 修复表盘协议BUG - Merge branch 'sdk602patch0521' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521 - 低电量修改 - Merge branch 'sdk602patch0521' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521 - 优化低电量关机 - Merge branch 'sdk602patch0521' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521 - 更改低电量报警 - ble扫描过滤去除,ble read属性更新 Signed-off-by: aliyun8003852482 <1224667075@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/416 --- .../nativeui/bluetooth/src/BluetoothModel.cpp | 30 +++-- .../ble_service/bleservice/bleService.c | 108 +++++++++++++++++- .../msg_center/src/msg_center_customer.cpp | 32 ++++-- .../src/notify/charge_notification.cpp | 57 ++++++--- 4 files changed, 189 insertions(+), 38 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp index 2dd3fc9d7..df0c44139 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -601,8 +601,8 @@ void BtGapPairConfirmedCallback(const bd_addr_t *bdAddr, int req_type, int numbe void BtGapDiscoveryResultCallback(const bd_addr_t *bdAddr) { if ((gap_get_device_class(bdAddr) & 0x200) != 0) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtGapDiscoveryResultCallback: Mobile Phone Device"); - return; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BtGapDiscoveryResultCallback: Mobile Phone Device"); + //return; } if (bdAddr == nullptr) { @@ -795,12 +795,12 @@ void BluetoothModel::BtGapAclStateChangedHandle(gap_acl_state_t state, unsigned // 回调:ACL连接状态上报 void GapAclStateChangedCallback(const bd_addr_t *bdAddr, gap_acl_state_t state, unsigned int reason) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bt GapAclStateChangedCallback state %d, reason %x succ or err", state, reason); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "addr: %02x%02x%02x%02x%02x%02x", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bt GapAclStateChangedCallback state %d, reason %x succ or err", state, reason); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addr: %02x%02x%02x%02x%02x%02x", bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* mac下标 0 1 2 3 4 5 */ bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* mac下标 0 1 2 3 4 5 */ if ((gap_get_device_class(bdAddr) & 0x200) != 0) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GapAclStateChangedCallback: Mobile Phone Device"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GapAclStateChangedCallback: Mobile Phone Device"); return; } GraphicService::GetInstance()->PostGraphicEvent( @@ -971,6 +971,22 @@ static void BtGattsRequestWriteCallback(uint8_t serverId, uint16_t connId, gatts WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BtGattsRequestWriteCallback"); } +/* 与设备建立A2DP连接 */ +static int wstp_a2dp_snk_connect(const bd_addr_t *bd_addr) +{ + int ret = a2dp_snk_connect(bd_addr); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP,"a2dp_snk_connect ret(int): %x\n", ret); + return ret; +} + +/* 与设备断开A2DP连接 */ +static int wstp_a2dp_snk_disconnect(const bd_addr_t *bd_addr) +{ + int ret = a2dp_snk_disconnect(bd_addr); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP,"a2dp_snk_disconnect ret(int): %x\n", ret); + return ret; +} + static void BtA2dpSnkAcceptTimerStop(void) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "stop timer\n"); @@ -1045,6 +1061,7 @@ static void BtA2dpSnkConnectStateChangedCb(bd_addr_t *bd_addr, int conn_state) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x conn_state: %x\n", bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0], conn_state); /* 3 2 1 0 idx */ + } static void BtA2dpSnkStartStreamReqCb(bd_addr_t *bd_addr) @@ -1129,9 +1146,6 @@ void BtA2dpInit(void) void BtA2dpDeInit(void) { - - - a2dp_src_deregister_callbacks(&g_a2dpSrcCallbacks); a2dp_snk_deregister_callbacks(&g_a2dp_snk_callbacks); diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c index 402d075cb..25ed5dd10 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -38,7 +38,7 @@ extern "C" { #include "build_version.h" #include "custom_runtime.h" #include "custom_utils.h" - +#include "bletest.h" // extern void bts_data_to_uuid_len2(uint16_t uuid_data, bt_uuid_t *out_uuid); @@ -108,6 +108,7 @@ uint16_t ble_nus_max_data_len = SDK_BLE_MTU_MIN - 3; uint16_t data2ae3Cmd = 0;//2ae3短指令特征值 uint16_t data2ae4Cmd = 0; uint16_t data2ae5Cmd = 0; +uint16_t data2ae2Cmd = 0;//read uint16_t data2ae1Cmd = 0;//安卓消息来电 uint16_t data2ae0Cmd = 0;//OTA @@ -122,7 +123,7 @@ enum{ BLE_CHARACTERISTIC_SNED_LONG_ID_PROPERTIES = GATT_CHARACTER_PROPERTY_BIT_WRITE|GATT_CHARACTER_PROPERTY_BIT_WRITE_NO_RSP, BLE_CHARACTERISTIC_SNED_OTA_ID_PROPERTIES = GATT_CHARACTER_PROPERTY_BIT_WRITE|GATT_CHARACTER_PROPERTY_BIT_WRITE_NO_RSP, BLE_CHARACTERISTIC_SNED_ANDRIOD_ID_PROPERTIES = GATT_CHARACTER_PROPERTY_BIT_WRITE|GATT_CHARACTER_PROPERTY_BIT_WRITE_NO_RSP, - BLE_CHARACTERISTIC_READ_BATTERY_ID_PROPERTIES = GATT_CHARACTER_PROPERTY_BIT_READ, + BLE_CHARACTERISTIC_READ_BATTERY_ID_PROPERTIES = GATT_CHARACTER_PROPERTY_BIT_READ|GATT_CHARACTER_PROPERTY_BIT_NOTIFY, }; static uint8_t ble_adv_falg = 0; void svr_ble_adv_stop(void) @@ -876,6 +877,9 @@ static void svr_ble_bt_gatts_characteristic_add_cb(uint8_t server_id, bt_uuid_t { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "2ae2 result->value_handle6 %d\r\n",result->value_handle); // shortCmdChara = result->value_handle; + if(data2ae2Cmd == 0){ + data2ae2Cmd = result->value_handle; + } } if(ble_gatts_cmp_uuid(uuid, &chara_uuid_data_2ae4)) { @@ -984,13 +988,111 @@ errcode_t svr_ble_bt_gatts_noyify(uint8_t *data, uint16_t data_len)//这里是 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "gatts_notify_indicate ret:0x%x. serverid:%u,conn_id:%u,handle:%u.data_len:%d", ret, g_ble_server_id, g_ble_conn_id, g_ble_server_handle,data_len); - return ret; + return ret; +} + +errcode_t svr_ble_read_data_value_updata_noyify(void)//2ae2 +{ + gatts_ntf_ind_t data_info; + data_info.attr_handle = data2ae2Cmd; + static uint8_t battery_point_val[20] = {0}; + // 获取电池电压值 + float voltage = 0.0F; + uint8_t power = 0; + power =battery_get_voltage(&voltage); + battery_point_val[0] +=1;//power ;//power;//电量90 + uint16_t dial = ble_get_dial_id(); + memcpy_s(&battery_point_val[1],2,&dial,2); + + uint8_t _major,_mid,_minor; + uapi_get_fw_version(&_major,&_mid,&_minor); + + battery_point_val[3] = _major;//固件版本号 + battery_point_val[4] = _mid; + battery_point_val[5] = _minor; + + bd_addr_t addr_info; + errcode_t ret = gap_ble_get_local_addr(&addr_info); + battery_point_val[6] = addr_info.addr[5]; + battery_point_val[7] = addr_info.addr[4]; + battery_point_val[8] = addr_info.addr[3]; + battery_point_val[9] = addr_info.addr[2]; + battery_point_val[10] = addr_info.addr[1]; + battery_point_val[11] = addr_info.addr[0]; + + battery_point_val[12] = 0;//消息推送开关 默认是关闭 0 + battery_point_val[13] = 0;//多媒体开关 + battery_point_val[14] = 5;//客户编号 + battery_point_val[15] = 5;//产品编号 + + battery_point_val[16] = 0;//硬件版本号 + battery_point_val[17] = 1; + + battery_point_val[18] = 0;//ble版本号 + battery_point_val[19] = 1; + + + data_info.value = battery_point_val; + data_info.value_len = 20; + ret = gatts_notify_indicate(g_ble_server_id, g_ble_conn_id, &data_info); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "gatts_notify_indicate ret:0x%x. serverid:%u,conn_id:%u,handle:%u.data_len:%d", ret, g_ble_server_id, + g_ble_conn_id, g_ble_server_handle,20); + return ret; } + + static void svr_ble_bt_gatts_req_read_cb(uint8_t server_id, uint16_t conn_id, gatts_req_read_cb_t *read_cb_para, errcode_t status) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "svr_ble_bt_gatts_req_read_cb ret:is_long:%d",read_cb_para->is_long); + + //WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "svr_ble_bt_gatts_req_read_cb ret:is_long:%d 2ae2 %d read_cb_para->handle :%d",read_cb_para->is_long,data2ae2Cmd,read_cb_para->handle); + if(read_cb_para->handle!=data2ae2Cmd) + return; + + static uint8_t battery_point_val[20] = {0}; + // 获取电池电压值 + float voltage = 0.0F; + uint8_t power = 0; + power =battery_get_voltage(&voltage); + battery_point_val[0] =power;//power ;//power;//电量90 + uint16_t dial = ble_get_dial_id(); + memcpy_s(&battery_point_val[1],2,&dial,2); + + uint8_t _major,_mid,_minor; + uapi_get_fw_version(&_major,&_mid,&_minor); + + battery_point_val[3] = _major;//固件版本号 + battery_point_val[4] = _mid; + battery_point_val[5] = _minor; + + bd_addr_t addr_info; + errcode_t ret = gap_ble_get_local_addr(&addr_info); + battery_point_val[6] = addr_info.addr[5]; + battery_point_val[7] = addr_info.addr[4]; + battery_point_val[8] = addr_info.addr[3]; + battery_point_val[9] = addr_info.addr[2]; + battery_point_val[10] = addr_info.addr[1]; + battery_point_val[11] = addr_info.addr[0]; + + battery_point_val[12] = 0;//消息推送开关 默认是关闭 0 + battery_point_val[13] = 0;//多媒体开关 + battery_point_val[14] = 5;//客户编号 + battery_point_val[15] = 5;//产品编号 + + battery_point_val[16] = 0;//硬件版本号 + battery_point_val[17] = 1; + + battery_point_val[18] = 0;//ble版本号 + battery_point_val[19] = 1; + + static gatts_ntf_ind_t gatts_ntf_ind; + gatts_ntf_ind.attr_handle=read_cb_para->handle; + gatts_ntf_ind.value=battery_point_val; + gatts_ntf_ind.value_len=20; + //read_cb_para->need_rsp=0; + gatts_notify_indicate(server_id,conn_id,&gatts_ntf_ind); } diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index 952555216..820e8d355 100644 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -363,31 +363,43 @@ void MsgCenterNotifyLowPowerAlarmProc(const Topic topic, Request* req) //if(req->data); uint8 *x= (uint8 *)(req->data); const power_display_svr_api_t *display_api = power_display_svr_get_api(); - if (display_api->get_screen_state() != SCREEN_ON) - { - display_api->turn_on_screen(); - } - display_api->set_screen_set_keepon_timeout(1000*5); + if(*x==3) { + if (display_api->get_screen_state() != SCREEN_ON) + { + display_api->turn_on_screen(); + } + display_api->set_screen_set_keepon_timeout(1000*5); //倒计时结束后,直接执行关机动画 low_power_play(); } else if(*x==0) { //提醒低电充电 + if (display_api->get_screen_state() != SCREEN_ON) + { + display_api->turn_on_screen(); + } + display_api->set_screen_set_keepon_timeout(1000*5); + set_lowpower_falg(0); - // if (NotificationManager::GetInstance()->HasNotifyShowing()) - // NotificationManager::GetInstance()->StopNotify(); - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE); + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true); } else { //电量过低,直接提醒关机 + if (display_api->get_screen_state() != SCREEN_ON) + { + display_api->turn_on_screen(); + } + display_api->set_screen_set_keepon_timeout(1000*10); + set_lowpower_falg(1); - // if (NotificationManager::GetInstance()->HasNotifyShowing()) - // NotificationManager::GetInstance()->StopNotify(); + if (NotificationManager::GetInstance()->HasNotifyShowing()) + NotificationManager::GetInstance()->StopNotify(); + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE); NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true); diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp index 5fe43358b..5bb1d33ca 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp @@ -9,6 +9,8 @@ #include "battery_service.h" #include "NativeAbility.h" #include "custom_utils.h" +#include "cmsis_os2.h" +#include "linux/delay.h" namespace OHOS { UIImageView *imageCharge = nullptr; @@ -19,15 +21,15 @@ namespace OHOS UIViewGroup *group=nullptr; UIImageAnimatorView *ShutDownImageAnimatorView=nullptr; static constexpr char *ShutDownPaths = "/user/res/RebootAndShutDown/ShutDown/"; //关机图片路径 - static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 30; // 图片帧数 - static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_TIME = 150; // 图片更新间隔 - ImageAnimatorInfo ShutDownImageInfo[SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; // 关机图像的信息 + #define SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES 30 // 图片帧数 + static int16_t SHUTDOWN_IMAGE_ANIMATOR_TIME = 130; // 图片更新间隔 + static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_X = 0; static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_Y = 0; static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_W = 466; static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_H = 466; const char **ShutDownPathsArray{nullptr}; // 关机图片路径数组 - + ImageAnimatorInfo ShutDownImageInfo[SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; // 关机图像的信息 #define LOW_POWER_BUTTON "LOW_POWER_BUTTON" // UIViewGroup *ChargingStatuShow() // { @@ -52,6 +54,17 @@ namespace OHOS // imageCharge->SetVisible(true); // } // } + + static void FreeImagePathsArray(const char **imagePaths, const int numImages) + { + for (int i = 0; i < numImages; i++) + { + // ImageCacheManager::GetInstance().UnloadSingleRes(imagePaths[i]); + delete imagePaths[i]; + imagePaths[i] = nullptr; + } + } + static const char ** CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages) { const char **imagePaths = new const char *[numImages]; @@ -65,15 +78,15 @@ namespace OHOS return imagePaths; } - UIViewGroup * ShowUpShutDownAnimatorView() + void ShowUpShutDownAnimatorView() { group = new UIViewGroup(); if (group == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); - return nullptr; + return ; } - group->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group->SetPosition(0, 0, 466, 466); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShutDownAnimatorView::ShowUpShutDownAnimatorView"); ShutDownPathsArray = CreateImagePathsArray(ShutDownPaths, "bin", SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); @@ -84,8 +97,9 @@ namespace OHOS if (ShutDownImageAnimatorView == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView new ShutDownImageAnimatorView fail"); - return NULL; + return ; } + for (uint8_t i = 0; i < SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++) { ShutDownImageInfo[i].imagePath = (ShutDownPathsArray[i]); @@ -98,16 +112,24 @@ namespace OHOS ShutDownImageAnimatorView->SetPosition(SHUTDOWN_IMAGE_ANIMATOR_VIEW_X, SHUTDOWN_IMAGE_ANIMATOR_VIEW_Y, SHUTDOWN_IMAGE_ANIMATOR_VIEW_W, SHUTDOWN_IMAGE_ANIMATOR_VIEW_H); ShutDownImageAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); ShutDownImageAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - ShutDownImageAnimatorView->SetImageAnimatorSrc(ShutDownImageInfo, SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, 100); + ShutDownImageAnimatorView->SetImageAnimatorSrc(ShutDownImageInfo, SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, SHUTDOWN_IMAGE_ANIMATOR_TIME); ShutDownImageAnimatorView->SetRepeat(false); ShutDownImageAnimatorView->SetRepeatTimes(1); } + UIImageAnimatorView::AnimatorStopListener *stoplistener = static_cast(lowppowrAnimatorStopListener::GetInstance()); + ShutDownImageAnimatorView->SetAnimatorStopListener(stoplistener); + if (stoplistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to Create stoplistener!!"); + return; + } + ShutDownImageAnimatorView->SetVisible(true); //ShutDownImageAnimatorView->Start(); group->SetVisible(false); group->Add(ShutDownImageAnimatorView); - return group; + return ; } static uint8_t battery_falg=0; @@ -140,6 +162,7 @@ namespace OHOS if(group) { group->RemoveAll(); + ShutDownImageAnimatorView->Stop(); if(ShutDownImageAnimatorView) { delete ShutDownImageAnimatorView; @@ -149,6 +172,7 @@ namespace OHOS group = nullptr; } + FreeImagePathsArray(ShutDownPathsArray,SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); RootView::GetInstance()->Remove(UIViewGroup_lowpower); delete UIViewGroup_lowpower; @@ -292,13 +316,6 @@ namespace OHOS if(battery_falg>=3) { group->SetVisible(true); - UIImageAnimatorView::AnimatorStopListener *stoplistener = static_cast(lowppowrAnimatorStopListener::GetInstance()); - ShutDownImageAnimatorView->SetAnimatorStopListener(stoplistener); - if (stoplistener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to Create stoplistener!!"); - return NULL; - } ShutDownImageAnimatorView->Start(); } return UIViewGroup_lowpower; @@ -344,11 +361,17 @@ namespace OHOS void lowppowrAnimatorStopListener::OnAnimatorStop(UIView &view) { //UNUSED(view); + NotificationManager::GetInstance()->StopNotify(); + msleep(500); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "xxxxxxxxxxxxxxxxxxxxOnAnimatorStop"); + if(battery_falg==4) uapi_reboot_device(); else uapi_poweroff_device(); // 关机 + + + //NotificationManager::GetInstance()->StopNotify(); // // if(strcmp(view.GetViewId(),LOW_POWER_BUTTON)!=0) -- 2.17.1