From e21e2be04ec3c2a03e4d1695f0c8a9be68c6767f Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Tue, 9 Jul 2024 12:09:42 +0800 Subject: [PATCH] =?utf8?q?ANCS=E6=8F=90=E4=BA=A4=EF=BC=88=E8=BF=98?= =?utf8?q?=E6=9C=89bug=EF=BC=8C=E5=BE=85=E6=B5=8B=E8=AF=95=EF=BC=8C?= =?utf8?q?=E6=9C=AA=E6=89=93=E5=BC=80=E7=9B=AE=E5=89=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../ble_service/bleservice/CMakeLists.txt | 15 +- .../service/ble_service/bleservice/bleANCS.c | 483 ++++++++++++++++++ .../service/ble_service/bleservice/bleANCS.h | 33 ++ .../service/ble_service/bleservice/bleEvent.c | 12 +- .../ble_service/bleservice/bleService.c | 43 +- 5 files changed, 575 insertions(+), 11 deletions(-) create mode 100644 code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c create mode 100644 code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.h diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/CMakeLists.txt b/code/sdk/application/wearable/service/ble_service/bleservice/CMakeLists.txt index 53daf6184..874190416 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/CMakeLists.txt +++ b/code/sdk/application/wearable/service/ble_service/bleservice/CMakeLists.txt @@ -4,14 +4,25 @@ set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR} ) - - +#/home/hcj/FD230/code/sdk/protocol/bt/host/bt/bts/bt_sample/ble_profile/profiles/include/ble_ancs_client.h +#/home/hcj/FD230/code/sdk/protocol/bt/host/bt/bts/bg_common/include/sdk_common +#/home/hcj/FD230/code/sdk/protocol/bt/host/bt/bts/host/inc/product_bth.h +#code/sdk/protocol/bt/host/bt/bts/bg_common/include/log/bt_acore_log.h +#/home/hcj/FD230/code/sdk/protocol/bt/host/bt/bts/bg_common/include/gdk_common/custdefs.h set(PRIVATE_HEADER + ${ROOT_DIR}/protocol/bt/host/bt/bts/bt_sample/ble_profile/profiles/include + ${ROOT_DIR}/protocol/bt/host/bt/bts/bg_common/include/sdk_common + ${ROOT_DIR}/protocol/bt/host/bt/bts/host/inc + ${ROOT_DIR}/protocol/bt/host/bt/bts/bg_common/include + ${ROOT_DIR}/protocol/bt/host/bt/bts/bg_common/include/log + ${ROOT_DIR}/protocol/bt/host/bt/bts/bg_common/include/gdk_common #${CMAKE_CURRENT_SOURCE_DIR}/../../fd230app/nativeui/weather/include ) set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/bleService.c ${CMAKE_CURRENT_SOURCE_DIR}/bleEvent.c + ${CMAKE_CURRENT_SOURCE_DIR}/bleANCS.c + ) set(COMPONENT_PUBLIC_CCFLAGS diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c new file mode 100644 index 000000000..eea310f74 --- /dev/null +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c @@ -0,0 +1,483 @@ +/* + * Copyright (c) CompanyNameMagicTag 2024. All rights reserved. + * Description: This module include test function of ANCS Client module. + */ +#include +#include +#include +#include "common_def.h" +#include "bts_def.h" +#include "bts_gatt_stru.h" +#include "bts_a2dp_source.h" +#include "bts_gatt_server.h" +#include "bts_le_gap.h" +#include "osal_task.h" +#include "securec.h" +#include "wearable_log.h" +#include +#include +#include "stdbool.h" + +#include "bts_le_gap.h" +#include "bts_br_gap.h" +#include "battery_hal.h" +#include "bleService.h" +#include "alipay_feature.h" +#include "alipay_bluetooth.h" +#include "bts_a2dp_sink.h" +#include "osal_timer.h" +#include "bleEvent.h" +#include "hidService.h" +#include "factorytestService.h" +#include "ppgBleService.h" +#include "build_version.h" +#include "custom_runtime.h" +#include "custom_utils.h" +#include "bletest.h" +#ifdef SUPPORT_AT_OHOSFWK +#include "BluetoothWrapper.h" +#endif + +#include "ble_ancs_client.h" +#include "bleANCS.h" +#include "ble_gatts_callbacks.h" +#include "bleEvent.h" + +#define TEN 10 +#define ANCS_ATT_BYTE_LENGTH 6 +#define ANCS_DEC_CHAR_COUNT 2 +#define BYTE_BIT_COUNT 8 + +/* ANCS客户端接口命令id */ +typedef enum { + BLE_SAMPLE_ANCS_CLIENT_REGISTER_CBK = 1, /* 1 注册ANCS客户端回调函数 */ + BLE_SAMPLE_ANCS_CLIENT_SETUP, /* 2 ANCS客户端连接服务端 */ + BLE_SAMPLE_ANCS_CLIENT_SUBSCRIBE_NOTITY, /* 3 订阅通知 */ + BLE_SAMPLE_ANCS_CLIENT_SUBSCRIBE_DATA, /* 4 订阅数据 */ + BLE_SAMPLE_ANCS_CLIENT_PERFORM_ACTION, /* 5 执行操作 */ + BLE_SAMPLE_ANCS_CLIENT_NOTIFY_ATT_GET, /* 6 执行操作 */ + BLE_SAMPLE_ANCS_CLIENT_APP_ATT_GET /* 7 执行操作 */ +} ble_ancs_client_at_cmd_id_t; + + +static uint8_t g_client_id=0; +/* 命令处理函数接口 */ + + +/* 获取通知属性 */ +static uint8_t ble_ancs_client_at_cmd_get_notify_att(uint16_t conn_id,uint32_t notify_uid) +{ + + /* 获取来电通知属性 */ + ble_ancs_notification_attr_req_t *notify_attr_req = bt_os_new( + sizeof(ble_ancs_notification_attr_req_t) + (5 * sizeof(ble_ancs_attr_req_t))); + notify_attr_req->att_num = 5; + notify_attr_req->notification_uid = notify_uid; + + (notify_attr_req->attr)->att_id=0x00; + (notify_attr_req->attr)->att_max_length=2; + + (notify_attr_req->attr+1)->att_id=0x01; + (notify_attr_req->attr+1)->att_max_length=256; + + (notify_attr_req->attr+2)->att_id=0x03; + (notify_attr_req->attr+2)->att_max_length=256; + + (notify_attr_req->attr+3)->att_id=0x05; + (notify_attr_req->attr+3)->att_max_length=64; + + (notify_attr_req->attr+4)->att_id=0x06; + (notify_attr_req->attr+4)->att_max_length=10; + + //decode_att_req_from_str(argv[BT_INDEX_4], notify_attr_req->attr); + errcode_t ret = ble_ancs_client_send_get_notify_att_cmd(g_client_id, conn_id, notify_attr_req); + bt_os_free(notify_attr_req); + printf("ble ancs client notify att get ret:0x%x\r\n", ret); + return 0; +} + + + +/* 执行消息行为(积极或消极行为) */ +static uint8_t ble_ancs_client_at_cmd_perform_action(uint16_t conn_id,uint32_t notify_uid,uint8_t action_id) +{ + ble_ancs_notification_action_req_t action_cmd = {0}; + action_cmd.notification_uid = notify_uid; + action_cmd.action_id = action_id; + errcode_t ret = ble_ancs_client_send_perform_notify_action_cmd(g_client_id, conn_id, &action_cmd); + printf("ble ancs client perform action ret:0x%x\r\n", ret); + return 0; +} + +//过滤掉之前的通知,只接收后发的 +static uint32_t subscribe_notify_creationTime=0; +/* ANCS服务建立结果回调 */ +static void ble_ancs_client_setup_result_cbk(uint8_t client_id, uint16_t conn_id, errcode_t status) +{ + printf("[ANCSClientSetupCBK]conn_id:%d status:0x%x\r\n", conn_id, status); + + + int ret = uapi_get_timestampe_ss(&subscribe_notify_creationTime); + + ble_ancs_client_subscribe_notify(conn_id,1); + + + + //if(status==ERRCODE_BT_SUCCESS) + +} + +/* ANCS服务订阅结果回调 */ +static void ble_ancs_client_subscribe_result_cbk(uint8_t client_id, uint16_t conn_id, + ancs_client_subscribe_type_t type, gatt_status_t status) +{ + printf("[ANCSClientSubscribeResultCBK]conn_id:%d type:%d status:0x%x\r\n", conn_id, type, status); + if(type==ANCS_CLIENT_SUBSCRIBE_NOTIFY) + ble_ancs_client_subscribe_data(conn_id,1); +} + +/* ANCS服务命令执行结果回调 */ +static void ble_ancs_client_write_result_cbk(uint8_t client_id, uint16_t conn_id, gatt_status_t status) +{ + printf("[ANCSClientCMDResultCBK]conn_id:%d status:0x%x\r\n", conn_id, status); + +} + +/* ANCS服务消息通知回调 */ +static void ble_ancs_client_notify_source_cbk(uint8_t client_id, uint16_t conn_id, + ble_ancs_notification_src_t *notify_src, errcode_t status) +{ + if (status == ERRCODE_BT_SUCCESS) { + printf( + "[ANCSClientNotifySRCCBK]conn_id:%d status:0x%x notify_id:%lu " + "eventId:%d eventFlags:0x%x category_id:%d\r\n", + conn_id, status, + notify_src->notification_uid, + notify_src->event_id, + notify_src->event_flags, + notify_src->category_id); + //ble_ancs_client_at_cmd_perform_action(conn_id,notify_src->notification_uid,ANCS_ACTION_POSITIVE); + + + uint32_t creationTime=0; + int ret = uapi_get_timestampe_ss(&creationTime); + //当前时间戳减去订阅通知时间戳10s以上的通知,才要求数据(过滤ios将所有未查看消息发过来) + if(creationTime-subscribe_notify_creationTime>=10) + ble_ancs_client_at_cmd_get_notify_att(conn_id, notify_src->notification_uid); + // + + } else { + printf("[ANCSClientNotifySRCCBK]conn_id:%d status:0x%x.\r\n", + conn_id, status); + } +} +static char old_time_buf[64]={0}; + +//"20240709T093253" +/* ANCS服务通知属性响应结果回调 */ +static void ble_ancs_client_notification_attr_rsp_cbk(uint8_t client_id, uint16_t conn_id, + ble_ancs_notification_attr_rsp_t *notify_attr_rsp, errcode_t status) +{ + if (status == ERRCODE_BT_SUCCESS) { + printf("[ANCSClientNotifyATTRSPCBK]conn_id:%d status:0x%x notify_uid:%lu\r\n", + conn_id, status, notify_attr_rsp->notification_uid); + + ble_ancs_attr_rsp_t *node = (ble_ancs_attr_rsp_t *)notify_attr_rsp->attr_rsp_lst.head; + uint16_t att_num = 1; + char title_buf[256]={0}; + char msg_buf[256]={0}; + char new_msg_buf[64]={0}; + while (node != NULL) { + if (node != NULL) { + printf("[ANCSClientNotifyATTRSPCBK]att id:%d length:%lu att_value:%s\r\n", + node->att_id, node->att_length, node->att); + if( node->att_id==1) + { + sprintf_s(title_buf,256,"%s",node->att); + } + if(node->att_id==3) + { + sprintf_s(msg_buf,256,"%s",node->att); + } + if(node->att_id==5) + { + sprintf_s(new_msg_buf,64,"%s",node->att); + } + } + node = lnext(node); + if (att_num == notify_attr_rsp->att_num) { + break; + } + att_num = att_num + 1; + } + + printf("ble_ancs_client_notification_attr_rsp_cbk test\r\n"); + + + if(strcmp(old_time_buf,new_msg_buf)!=0) + { + memset(old_time_buf,0,64); + memcpy_s(old_time_buf,64,new_msg_buf,64); + + printf("ble_ancs_client_notification_attr_rsp_cbk test 2\r\n"); + message_data(notify_attr_rsp->notification_uid,0,title_buf,msg_buf,0); + //CustomEventPublish_TOPIC_EVENT_MESSAGENOTE(); + + + } + + } else { + printf("[ANCSClientNotifyATTRSPCBK]conn_id:%d status:0x%x.\r\n", + conn_id, status); + } +} + +/* ANCS服务应用属性响应结果回调 */ +static void ble_ancs_client_app_attr_rsp_cbk(uint8_t client_id, uint16_t conn_id, + ble_ancs_app_attr_rsp_t *app_attr_rsp, errcode_t status) +{ + printf("[ANCSClientAPPATTRSPCBK]conn_id:%d status:0x%x\r\n", conn_id, status); + if (status == ERRCODE_BT_SUCCESS) { + ble_ancs_attr_rsp_t *node = (ble_ancs_attr_rsp_t *)app_attr_rsp->attr_rsp_lst.head; + uint16_t att_num = 1; + while (node != NULL) { + if (node != NULL && node->att_id == ANCS_APP_ATT_DISPLAY_NAME) { + printf("[ANCSClientAPPATTRSPCBK]app id:%s length:%lu app name:%s\r\n", + app_attr_rsp->app_id.id, node->att_length, node->att); + } + node = lnext(node); + if (att_num == app_attr_rsp->att_num) { + break; + } + att_num = att_num + 1; + } + } else { + printf("[ANCSClientAPPATTRSPCBK]conn_id:%d status:0x%x.\r\n", + conn_id, status); + } +} + + + + + +/* 注册ancs服务回调 */ +static uint8_t ble_ancs_client_at_cmd_register_cbk() +{ + ble_ancs_client_callbacks_t cbk = {0}; + cbk.setup_cb = ble_ancs_client_setup_result_cbk; + cbk.subscribe_cb = ble_ancs_client_subscribe_result_cbk; + cbk.write_result_cb = ble_ancs_client_write_result_cbk; + cbk.notify_source_cb = ble_ancs_client_notify_source_cbk; + cbk.notify_attr_cb = ble_ancs_client_notification_attr_rsp_cbk; + cbk.app_attr_cb = ble_ancs_client_app_attr_rsp_cbk; + + errcode_t ret = ble_ancs_client_register_callbacks(&cbk); + printf("ble ancs client register cbk ret:0x%x\r\n", ret); + return 0; +} + +/*注册客户端,初始化ANCS服务*/ +void gattc_reg_id(void) +{ + ble_client_register_gatt_callbacks(); + + ble_ancs_client_at_cmd_register_cbk(); + bt_uuid_t uuid={0}; + uuid.uuid[0]=0; + uuid.uuid[1]=1; + + uuid.uuid_len=2; + + uint8_t client_id; + errcode_t ret = gattc_register_client(&uuid, &client_id); + + g_client_id=client_id; + printf("[GATTClient]gattc_register ret(errcode_t): %x client_id:%u\n", ret, client_id); +} + + + + +/* ANCS服务建立 */ +static uint8_t ble_ancs_client_at_cmd_setup(uint16_t conn_id) +{ + errcode_t ret = ble_ancs_client_setup_service(g_client_id, conn_id); + printf("ble ancs client setup ret:0x%x %d\r\n", ret,conn_id); + return 0; +} + +/* 订阅数据 */ +static uint8_t ble_ancs_client_at_cmd_subscribe_data(uint16_t conn_id,uint8_t sub_flag) +{ + + errcode_t ret = ble_ancs_client_subscribe_data_source(g_client_id, conn_id, sub_flag); + printf("ble ancs client sub data ret:0x%x %d\r\n", ret,sub_flag); + return 0; +} + +/* 订阅 */ +uint8_t ble_ancs_client_subscribe_notify(uint16_t conn_id,uint8_t sub_flag) +{ + + errcode_t ret = ble_ancs_client_subscribe_notification_source(g_client_id, conn_id, sub_flag); + printf("ble ancs client sub notify ret:0x%x %d\r\n", ret,sub_flag); + + + return 0; +} + +uint8_t ble_ancs_client_subscribe_data(uint16_t conn_id,uint8_t sub_flag) +{ + + errcode_t ret = ble_ancs_client_subscribe_data_source(g_client_id, conn_id, sub_flag); + printf("ble ancs client sub data ret:0x%x %d\r\n", ret,sub_flag); + return 0; +} + + + +uint8_t ble_ancs_client_cmd_setup_and_subscribe(uint16_t conn_id) +{ + ble_ancs_client_at_cmd_setup(conn_id); + return 0; +} + + + + +/* 十六进制字符转数值 */ +static uint8_t char_2_num(int8_t c) +{ + if (c >= '0' && c <= '9') { + return (uint8_t)(c - '0'); + } else if (c >= 'A' && c <= 'F') { + return (uint8_t)(c - 'A' + TEN); + } else if (c >= 'a' && c <= 'f') { + return (uint8_t)(c - 'a' + TEN); + } else { + return TD_U8_MAX; + } +} + +/* 十六进制字符转数值 */ +static uint8_t str_2_byte(const char *str) +{ + return ((char_2_num(str[0]) << TD_U4_BITS) + char_2_num(str[1])); +} + +/* 十六进制字符转属性请求参数结构体 */ +static void decode_att_req_from_str(const char *str, ble_ancs_attr_req_t *nums) +{ + uint32_t len = strlen(str); + uint32_t cnt = 0; + char *ptr_str = NULL; + uint16_t length_big_byte = 0; + uint16_t length_little_byte = 0; + ptr_str = str; + for (uint32_t i = 0; i < len - 1; i += ANCS_ATT_BYTE_LENGTH) { /* 6个字符为1组,2个字符为一个字节 */ + nums[cnt].att_id = str_2_byte(ptr_str); + ptr_str += ANCS_DEC_CHAR_COUNT; + length_big_byte = (((uint16_t)str_2_byte(ptr_str)) << BYTE_BIT_COUNT); + ptr_str += ANCS_DEC_CHAR_COUNT; + length_little_byte = ((uint16_t)str_2_byte(ptr_str)); + nums[cnt].att_max_length = (uint16_t)(length_big_byte | length_little_byte); + ptr_str += ANCS_DEC_CHAR_COUNT; + cnt++; + } +} + + + +/* 解析应用属性参数 */ +static uint8_t parse_app_att_req_param(ble_ancs_app_attr_req_t *app_attr_req, + uint16_t app_id_len, uint16_t att_num, char **argv) +{ + // app_attr_req->att_num = att_num; + // app_attr_req->app_id.len = app_id_len + 1; + // uint8_t *id = bt_os_new(app_attr_req->app_id.len); + // if (id == NULL) { + // bts_error("[ANCSClientSample]app id memnew error!\r\n"); + // app_attr_req->app_id.id = NULL; + // return MPC_BT_FAIL; + // } + // if (memcpy_s(id, app_attr_req->app_id.len, (uint8_t *)argv[BT_INDEX_2], app_id_len) != EOK) { + // bts_error("[ANCSClientSample]app id memcpy error!\r\n"); + // bt_os_free(id); + // app_attr_req->app_id.id = NULL; + // return MPC_BT_FAIL; + // } + // *(id + app_id_len) = 0; /* This string is NULL-terminated */ + // app_attr_req->app_id.id = id; + + // /* 解析应用属性参数 */ + // decode_att_req_from_str(argv[BT_INDEX_4], app_attr_req->attr_id); + return 0; +} + +/* 获取应用属性 */ +static uint8_t ble_ancs_client_at_cmd_get_app_att(uint8_t argc, char **argv) +{ + //if (argc != BT_AT_PARAM_LEN5) { + // bts_error("ble ancs client argc num invalid :%u\r\n", argc); + // return MPC_BT_FAIL; + // } + + // uint8_t client_id = 0; + // uint16_t conn_id = 0; + // uint8_t att_num = 0; + // uint16_t app_id_len = 0; + // client_id = (uint8_t)atoi(argv[BT_INDEX_0]); + // conn_id = (uint16_t)atoi(argv[BT_INDEX_1]); + // app_id_len = strlen(argv[BT_INDEX_2]); + // att_num = (uint8_t)atoi(argv[BT_INDEX_3]); + // if (att_num == 0) { + // bts_error("ble ancs client notify att req att num is zero!\r\n"); + // return MPC_BT_FAIL; + // } + // uint32_t len = strlen(argv[BT_INDEX_4]); + // if ((att_num * ANCS_ATT_BYTE_LENGTH) != len) { + // bts_error("ble ancs client notify att req att num is wrong!\r\n"); + // return MPC_BT_FAIL; + // } + + // /* 获取应用属性 */ + // ble_ancs_app_attr_req_t *app_attr_req = bt_os_new(sizeof(ble_ancs_app_attr_req_t) + (att_num * sizeof(uint8_t))); + // uint8_t result = parse_app_att_req_param(app_attr_req, app_id_len, att_num, argv); + // if (result != MPC_BT_SUCC) { + // if (app_attr_req->app_id.id != NULL) { + // bt_os_free(app_attr_req->app_id.id); + // } + // bt_os_free(app_attr_req); + // return result; + // } + // errcode_t ret = ble_ancs_client_send_get_app_att_cmd(client_id, conn_id, app_attr_req); + // printf("ble ancs client app att get ret:0x%x\r\n", ret); + // bt_os_free(app_attr_req->app_id.id); + // bt_os_free(app_attr_req); + return 0; +} + +/* ANCS客户端AT命令与接口对应关系 */ +// static ble_ancs_client_at_hdl_info_t g_ble_ancs_client_at_hdl[] = { +// { BLE_SAMPLE_ANCS_CLIENT_REGISTER_CBK, ble_ancs_client_at_cmd_register_cbk }, +// { BLE_SAMPLE_ANCS_CLIENT_SETUP, ble_ancs_client_at_cmd_setup }, +// { BLE_SAMPLE_ANCS_CLIENT_SUBSCRIBE_NOTITY, ble_ancs_client_at_cmd_subscribe_notify }, +// { BLE_SAMPLE_ANCS_CLIENT_SUBSCRIBE_DATA, ble_ancs_client_at_cmd_subscribe_data }, +// { BLE_SAMPLE_ANCS_CLIENT_NOTIFY_ATT_GET, ble_ancs_client_at_cmd_get_notify_att }, +// { BLE_SAMPLE_ANCS_CLIENT_APP_ATT_GET, ble_ancs_client_at_cmd_get_app_att }, +// { BLE_SAMPLE_ANCS_CLIENT_PERFORM_ACTION, ble_ancs_client_at_cmd_perform_action }, +// }; + +// void ble_ancs_client_at_cmd(uint8_t cmd_id, char **params, uint8_t params_cnt) +// { +// size_t hdl_cnt = sizeof(g_ble_ancs_client_at_hdl) / sizeof(ble_ancs_client_at_hdl_info_t); +// for (uint8_t i = 0; i < hdl_cnt; i++) { +// if (g_ble_ancs_client_at_hdl[i].id == cmd_id && g_ble_ancs_client_at_hdl[i].func != NULL) { +// (void)g_ble_ancs_client_at_hdl[i].func(params_cnt, params); +// return; +// } +// } +// } + + diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.h b/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.h new file mode 100644 index 000000000..b587f1d1c --- /dev/null +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) CompanyNameMagicTag 2024. All rights reserved. + * + * Description: ANCS Client Test module. + */ +/** + * @defgroup bluetooth_sample_ble_ancs ANCS TEST API + * @ingroup bluetooth + * @{ + */ + +#ifndef SAMPLE_BLE_ANCS_H +#define SAMPLE_BLE_ANCS_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +//void ble_ancs_client_at_cmd(uint8_t cmd_id, char **params, uint8_t params_cnt); + +void gattc_reg_id(void); +uint8_t ble_ancs_client_cmd_setup_and_subscribe(uint16_t conn_id); +uint8_t ble_ancs_client_subscribe_notify(uint16_t conn_id,uint8_t sub_flag); +uint8_t ble_ancs_client_subscribe_data(uint16_t conn_id,uint8_t sub_flag); +/** + * @} + */ +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c index 67a155547..9e22d05ea 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -5088,6 +5088,7 @@ void message_data(int uid,int appid,char *title,char *msg,int hasCode) uint8_t buf_size = 0; FILE *jsfile = fopen(ANCS_DATA_CJSON_PATH, "r"); cJSON *data_root; + if (jsfile != NULL) { printf("succes opening file\n"); fseek(jsfile, 0, SEEK_END); @@ -5176,9 +5177,17 @@ void message_data(int uid,int appid,char *title,char *msg,int hasCode) FILE *fp = fopen(ANCS_DATA_CJSON_PATH, "wb"); if (fp) { - fwrite(jsonString, 1, strlen(jsonString), fp); + int ret=fwrite(jsonString, 1, strlen(jsonString), fp); + + if(ret!=strlen(jsonString)) + printf("message_data write fail\r\n"); + fclose(fp); } + else + { + printf("fopen fail\r\n"); + } cJSON_free(jsonString); cJSON_Delete(data_root); read_message_data(); @@ -6198,6 +6207,7 @@ errcode_t handle_recv_file(ble_read_data *buffer_handle,uint8_t *data, uint16_t printf("handle_recv_file received_size %d\n",buffer_handle->file_recv_stat.received_size); OTA_FILE_value= ((float) buffer_handle->file_recv_stat.received_size / (float)buffer_handle->file_recv_stat.file_size) *100; + }else{ printf("handle_recv_file write file failed! ret %d != %d\n",writtensize,event_size); return ERRCODE_FAIL; 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 fc1daa00f..5ccfc42be 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -304,6 +304,11 @@ void svr_ble_connstate_change_cb(unsigned short conn_id, bd_addr_t *addr, gap_bl svr_ble_adv_stop(); } set_phone_info(addr); + + //扫描ios的ANCS服务,扫描到服务后会自动建立连接,并订阅服务 + // if(get_notify_switch()) + // ble_ancs_client_cmd_setup_and_subscribe(g_ble_conn_id); + Bleconnect = GAP_BLE_STATE_CONNECTED;//蓝牙已连接 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GAP_BLE_STATE_CONNECTED!!! 0x%x\r\n",pair_state); @@ -991,7 +996,7 @@ errcode_t svr_ble_read_data_value_updata_noyify(void)//2ae2 return ret; } - +//static uint8_t flag=1; 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) { @@ -1000,6 +1005,21 @@ static void svr_ble_bt_gatts_req_read_cb(uint8_t server_id, uint16_t conn_id, ga //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; + + // if(flag==0) + // ble_ancs_client_cmd_setup_and_subscribe(g_ble_conn_id); + // else if(flag==1) + // ble_ancs_client_subscribe_notify(g_ble_conn_id,1); + // else if(flag==2) + // ble_ancs_client_subscribe_data(g_ble_conn_id,1); + // else if (flag==3) + // ble_ancs_client_subscribe_notify(g_ble_conn_id,0); + + // flag++; + // if(flag==4) + // { + // flag=1; + // } static uint8_t battery_point_val[20] = {0}; // 获取电池电压值 @@ -1163,7 +1183,7 @@ static void svr_ble_register_service(void) WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "wrapper_gatts_add_service ret: 0x%x", ret); #endif - svr_alipay_bluetooth_init(serverId); + return; } @@ -1223,11 +1243,16 @@ void svr_ble_bluetooth_init(void) #ifdef SUPPORT_HID_SERVICE // ble_hid_server_init(); #endif + svr_alipay_bluetooth_init(g_ble_server_id); ble_factory_server_init(g_ble_server_id); ble_ppgtest_server_init(g_ble_server_id); + gattc_reg_id(); + + + g_custom_ble_init_flag = true; return; } @@ -1383,13 +1408,15 @@ static void blesrv_service_check_task(void const *arg) else if (server_handle == get_factory_ota_write_handl()) { factory_recv_ota_data(p_msgbuf,msg_len,server_handle); - }else if(server_handle == alipay_handle) - { - printf("alipay wirte!!!!!"); - // svr_alipay_bt_gatts_noyify(buf,5); - errcode_t ret = svr_alipay_msg_write(ALIPAY_MSG_BT, p_msgbuf, msg_len, false); + } + // else if(server_handle == alipay_handle) + // { + // printf("alipay wirte!!!!!"); + // // // svr_alipay_bt_gatts_noyify(buf,5); + // // errcode_t ret = svr_alipay_msg_write(ALIPAY_MSG_BT, p_msgbuf, msg_len, false); - }else{ + // } + else{ revBleOldData(p_msgbuf,msg_len,server_handle); } #endif -- 2.17.1