From 0bca09ea09e9db3a26a41da55bbe845f46d92337 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Mon, 15 Jul 2024 18:43:05 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0ANCS=E7=9A=84=E6=B6=88?= =?utf8?q?=E6=81=AF=E8=BF=87=E6=BB=A4=E6=9C=BA=E5=88=B6=EF=BC=8C=E4=BB=85?= =?utf8?q?=E8=BF=87=E6=BB=A4ios=EF=BC=8C=E5=AE=89=E5=8D=93=E7=94=B1APP?= =?utf8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/message/src/MessageModel.cpp | 5 + .../service/ble_service/bleservice/bleANCS.c | 135 +++++++++++++++++- .../service/ble_service/bleservice/bleANCS.h | 13 +- .../service/ble_service/bleservice/bleEvent.c | 107 +++++++++++++- .../service/ble_service/bleservice/bleEvent.h | 2 + .../ble_service/bleservice/bleService.c | 2 +- 6 files changed, 252 insertions(+), 12 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp index f417b0bc7..1dda147fe 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp @@ -28,6 +28,7 @@ #include "thread_adapter.h" #include "broadcast_feature.h" #include "broadcast_service.h" +#include "bleANCS.h" #define MESSAGE_JSON_FILE "user/userdata/ancs.json" #define MESSAGE_JSON_DIR "user/userdata/message/" @@ -164,6 +165,8 @@ namespace OHOS // 加载Message文件 bool MessageModel::LoadMessagesFromStorage() { + //加载消息过滤文件 + filtration_file_read(); std::ifstream file(MESSAGE_JSON_FILE); if (!file.is_open()) { @@ -231,6 +234,8 @@ namespace OHOS // 保存Message文件 bool MessageModel::SaveMessagesToStorage() { + //消息过滤文件保存 + filtration_file_save(); if (MessageVector.empty()) { // 清空文件 diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c index 0457b0c39..8f0e986b6 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c @@ -48,6 +48,8 @@ #define ANCS_DEC_CHAR_COUNT 2 #define BYTE_BIT_COUNT 8 +#define ANCS_APP_FILTRATION_PATH "user/userdata/filtration.bin" + /* ANCS客户端接口命令id */ typedef enum { BLE_SAMPLE_ANCS_CLIENT_REGISTER_CBK = 1, /* 1 注册ANCS客户端回调函数 */ @@ -62,6 +64,132 @@ typedef enum { static uint8_t g_client_id=0; /* 命令处理函数接口 */ +#define filtration_data_count 20 +filtration_data filtration_data_T[filtration_data_count]={0}; +//*com.tencent.qqmail +// com.apple.mobilephone +// com.apple.MobileSMS +// com.netease.mailmaster +// com.tencent.xin +// com.tencent.mqq +// com.facebook.Messenger +// com.atebits.Tweetie2 +// net.whatsapp.WhatsAppSMB +// com.linkedin.LinkedIn +// com.burbn.instagram +// com.facebook.Messenger +// com.toyopagroup.picaboo +// jp.naver.line +// com.iwilab.KakaoTalk +// com.viber +// com.skype.skype +// ph.telegra.Telegraph +// com.others +//消息过滤文件保存,在此列的消息未打开,不发消息给手表,不在此列默认开 +void filtration_on_get(char *buf,uint8_t len) +{ + for (size_t i = 0; i < len; i++) + { + if(strlen( filtration_data_T[i].name)!=0 && filtration_data_T[i].on==0) + { + buf[i]=0; + } + else + { + buf[i]=1; + } + } +} +void filtration_file_save(void) +{ + FILE *fp=fopen(ANCS_APP_FILTRATION_PATH,"wb+"); + if(fp==NULL)return; + for (size_t i = 0; i < filtration_data_count; i++) + { + fwrite(&filtration_data_T[i],sizeof(filtration_data),1,fp); + } + fclose(fp); +} + +void filtration_file_read(void) +{ + FILE *fp=fopen(ANCS_APP_FILTRATION_PATH,"rb+"); + if(fp==NULL)return; + for (size_t i = 0; i < filtration_data_count; i++) + { + int readsize= fread(&filtration_data_T[i],sizeof(filtration_data),1,fp); + if(readsize!=1) + break; + } + fclose(fp); +} + + +void filtration_file_updata(filtration_data *data) +{ + for (size_t i = 0; i < filtration_data_count; i++) + { + if(strlen( filtration_data_T[i].name)==0) + { + filtration_data_T[i].on=data->on; + filtration_data_T[i].len=data->len; + memset(filtration_data_T[i].name,0,filtration_data_max_len); + memcpy_s(filtration_data_T[i].name,filtration_data_max_len, data->name,strlen( data->name)); + break; + // printf("name:%s on:%d\r\n",data->name,data->on); + } + else if (strcmp(data->name,filtration_data_T[i].name)==0) + { + filtration_data_T[i].on=data->on; + break; + //printf("name:%s on:%d\r\n",data->name,data->on); + } + } +} + +static uint8_t get_other_filtration() +{ + for (size_t i = 0; i < filtration_data_count; i++) + { + if (strcmp("com.others",filtration_data_T[i].name)==0) + { + if(filtration_data_T[i].on) + { + return 1; + } + else + { + return 0; + } + } + } + return 1; + +} + +uint8_t is_filtration_data(char *data) +{ + for (size_t i = 0; i < filtration_data_count; i++) + { + if (strcmp(data,filtration_data_T[i].name)==0) + { + if(filtration_data_T[i].on) + { + return 1; + } + else + { + return 0; + } + } + } + if(get_other_filtration()) + return 1; + else + return 0; +} + + /* 获取通知属性 */ @@ -187,7 +315,7 @@ static void ble_ancs_client_notification_attr_rsp_cbk(uint8_t client_id, uint16_ uint16_t att_num = 1; char title_buf[256]={0}; char msg_buf[256]={0}; - char new_msg_buf[64]={0}; + char app_buf[32]={0}; while (node != NULL) { if (node != NULL) { printf("[ANCSClientNotifyATTRSPCBK]att id:%d length:%lu att_value:%s\r\n", @@ -200,9 +328,9 @@ static void ble_ancs_client_notification_attr_rsp_cbk(uint8_t client_id, uint16_ { sprintf_s(msg_buf,256,"%s",node->att); } - if(node->att_id==5) + if(node->att_id==0) { - sprintf_s(new_msg_buf,64,"%s",node->att); + sprintf_s(app_buf,64,"%s",node->att); } } node = lnext(node); @@ -220,6 +348,7 @@ static void ble_ancs_client_notification_attr_rsp_cbk(uint8_t client_id, uint16_ // 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"); + if(is_filtration_data(app_buf)) message_data(notify_attr_rsp->notification_uid,0,title_buf,msg_buf,0); diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.h b/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.h index b587f1d1c..0a2664a85 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.h @@ -17,13 +17,24 @@ #ifdef __cplusplus extern "C" { #endif - +#define filtration_data_max_len 32 //void ble_ancs_client_at_cmd(uint8_t cmd_id, char **params, uint8_t params_cnt); +typedef struct filtration_data_t +{ + uint32_t on; + uint32_t len; + char name[filtration_data_max_len]; +}filtration_data; + 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); +void filtration_file_updata(filtration_data *data); +void filtration_on_get(char *buf,uint8_t len); +void filtration_file_save(void); +void filtration_file_read(void); /** * @} */ 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 92af0fb98..0b220ff4f 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -42,6 +42,7 @@ extern "C" { #include "bletest.h" #include "custom_utils.h" #include "custom_runtime.h" +#include "bleANCS.h" #define DEBUG_TEST (0) #define CRC_CHECK_ERR 0 //crc校验失败 @@ -1874,6 +1875,50 @@ void SetsedentarinessSetParamCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t } } +void SetmsgfiltrationCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue)//设置久坐设置 +{ + uint32_t tmp = 1; + uint16_t tmp_data = 1; + uint8_t sendBuf[19]; + memset(sendBuf,0,19); + sendBuf[0] = 0x72; + sendBuf[1] = 0x02; + sendBuf[2] = 0x1E; + memcpy(sendBuf+3,&tmp,4); + memcpy(sendBuf+7,&tmp,4); + memcpy(sendBuf+11,&tmp,4); + memcpy(sendBuf+15,&tmp_data,2); + + if(Check_CRC(data,len,crcvalue)) + { + printf("总长%d\r\n",len); + uint32_t offset=0; + while (offsetaddr[0],addr->addr[1], addr->addr[2],addr->addr[3],addr->addr[4],addr->addr[5],status); - if(get_notify_switch()) + //if(get_notify_switch()) ble_ancs_client_cmd_setup_and_subscribe(g_ble_conn_id); } -- 2.17.1