From d7f606830dfa4b3c6239ad09b6821535b9e64492 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Wed, 10 Jul 2024 14:11:16 +0800 Subject: [PATCH] =?utf8?q?=E6=B6=88=E6=81=AF=E6=9C=BA=E5=88=B6=E9=87=8D?= =?utf8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../service/ble_service/blemoder/bletest.cpp | 26 ++++ .../service/ble_service/blemoder/bletest.h | 5 + .../service/ble_service/bleservice/bleANCS.c | 22 +-- .../service/ble_service/bleservice/bleEvent.c | 142 ++++++------------ .../service/ble_service/bleservice/bleEvent.h | 6 +- 5 files changed, 89 insertions(+), 112 deletions(-) diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index 386f03112..876e958f6 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -74,6 +74,9 @@ extern "C" { #include #include + + + void ble_set_ai_Question_str(char *buf) { OHOS::AiVoiceModel::GetInstance().SetUserQuestionStr(std::string(buf)); @@ -687,9 +690,18 @@ char * ble_sywee_history(uint8_t day,uint16_t *len ,uint8_t type) if(day==0) { + time_t currtime; uint32_t creationTime=0; int ret = uapi_get_timestampe_ss(&creationTime); + uint32_t value=0; + + struct tm *timeinfo; + time(&currtime); + timeinfo = localtime(&currtime); + //printf("localtime %d",timeinfo->tm_min); + creationTime-=(timeinfo->tm_min*60); + switch (type) { case 0x43: //同步步数历史数据 @@ -1777,6 +1789,20 @@ message_infor_t *get_message_info(void) { return &message_infor_s; } + +void ble_add_message_index(uint32_t old_index) +{ + OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); + old_index++; + p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_MESSAGE_INDEX,old_index); +} + +uint32_t ble_get_message_index() +{ + OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); + return p_ConfigModel->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_MESSAGE_INDEX); +} + #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h index 21cc0ef33..8d7f2098f 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -315,6 +315,11 @@ uint8_t ble_get_oxygen_data(void); cJSON* ble_get_recs_data(void); +////////////////////消息//////////////////////////// +void ble_add_message_index(uint32_t old_index); + +uint32_t ble_get_message_index(void); + #ifdef __cplusplus #if __cplusplus } 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 bc1dbcd59..d6f946845 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c @@ -162,7 +162,7 @@ static void ble_ancs_client_notify_source_cbk(uint8_t client_id, uint16_t conn_i uint32_t creationTime=0; int ret = uapi_get_timestampe_ss(&creationTime); //当前时间戳减去订阅通知时间戳3s以上的通知,才要求数据(过滤ios将所有未查看消息发过来) - if(creationTime-subscribe_notify_creationTime>=3) + if(creationTime!=subscribe_notify_creationTime) ble_ancs_client_at_cmd_get_notify_att(conn_id, notify_src->notification_uid); // @@ -171,7 +171,8 @@ static void ble_ancs_client_notify_source_cbk(uint8_t client_id, uint16_t conn_i conn_id, status); } } -static char old_time_buf[64]={0}; +//static char old_time_buf[64]={0}; +static uint32_t ancs_msg_index =0; //"20240709T093253" /* ANCS服务通知属性响应结果回调 */ @@ -214,17 +215,16 @@ static void ble_ancs_client_notification_attr_rsp_cbk(uint8_t client_id, uint16_ 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(); + // 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"); + ancs_msg_index = message_data(notify_attr_rsp->notification_uid,0,title_buf,msg_buf,0); + CustomEventPublish_TOPIC_EVENT_MESSAGENOTE(ancs_msg_index); - } + //} } else { printf("[ANCSClientNotifyATTRSPCBK]conn_id:%d status:0x%x.\r\n", 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 12477ec21..ddf095f38 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -5079,120 +5079,61 @@ char *get_message_dir_path(void)//获取信息的文件夹路径 { return ANCS_DATA_CONFIG_DIR; } -void message_data(int uid,int appid,char *title,char *msg,int hasCode) + +uint32_t message_data(int uid,int appid,char *title,char *msg,int hasCode) { if(!creatMessageDir())//创建文件夹失败 { - return; - } - 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); - long fileSize = ftell(jsfile); - fseek(jsfile, 0, SEEK_SET); - char *jsonData = (char *)ym_malloc(fileSize + 1); - fread(jsonData, 1, fileSize, jsfile); - jsonData[fileSize] = '\0'; - fclose(jsfile); - // 解析JSON数据 - // printf("jsonData %s",jsonData); - data_root= cJSON_Parse(jsonData); - // data_root = cJSON_GetObjectItem(modifiedJson,"infor"); - ym_free(jsonData); - - }else{ - data_root = cJSON_Parse("{\ - \"infor\": [\ - ]}"); + return 0; } + uint32_t index= ble_get_message_index(); - cJSON *dataJSON = cJSON_CreateObject(); - - cJSON *detialJSON = cJSON_CreateObject(); - - cJSON* itemJSON = cJSON_CreateObject(); + uint8_t buf_size = 0; + char message_data_path[128]={0}; uint32_t timeBuf = 0; if (uapi_get_timestampe_ss(&timeBuf) != ERRCODE_SUCC) { timeBuf = 0; } + + sprintf_s(message_data_path,128,ANCS_DATA_MSG_CJSON_PATH,index); - cJSON_AddNumberToObject(itemJSON,"uid",uid); - cJSON_AddNumberToObject(itemJSON,"appid_t",appid);//消息类型 微信 qq 等看结构体或者协议定义 - cJSON_AddStringToObject(itemJSON,"title",title);//消息发送者 - cJSON_AddStringToObject(itemJSON,"msg",msg);//消息内容 - cJSON_AddNumberToObject(itemJSON,"time",timeBuf);//时间戳 - cJSON_AddNumberToObject(itemJSON,"hasCode",hasCode);//暂时不需要预留接口 - cJSON_AddBoolToObject(itemJSON,"read",false);//是否已读 false未读 1 已读默认存的时候已经未读 - - cJSON *dataList = cJSON_GetObjectItem(data_root, "infor"); - if (dataList != NULL && cJSON_IsArray(dataList)) + FILE *jsfile = fopen(message_data_path, "w+"); + if(jsfile==NULL) { - int numData = cJSON_GetArraySize(dataList); - if(numData >= MAX_MESSAGE_NUM)//大于20条就循环迭代显示并保存数据 - { - for (uint8_t i = 0; i < MAX_MESSAGE_NUM-1; i++)//2-1 1 0 - { - // printf("ancs !!!!!!!!!!!! i:%d\r\n",i); - cJSON *object = NULL; - cJSON *uid = NULL; - cJSON *appid_t = NULL; - cJSON *title = NULL; - cJSON *msg = NULL; - cJSON *time = NULL; - cJSON *hasCode = NULL; - cJSON *read = NULL; - cJSON* deitemJSON = cJSON_CreateObject(); - cJSON *detialJSON = cJSON_CreateObject(); - object = cJSON_GetArrayItem(dataList,i+1);//9 9-18 0+1 9+1 - uid = cJSON_GetObjectItem(object, "uid"); - appid_t = cJSON_GetObjectItem(object, "appid_t"); - title = cJSON_GetObjectItem(object, "title"); - msg = cJSON_GetObjectItem(object, "msg"); - time = cJSON_GetObjectItem(object, "time"); - hasCode = cJSON_GetObjectItem(object, "hasCode"); - read = cJSON_GetObjectItem(object, "read"); - // printf("ancs title->valuestring:%s msg->valuestring:%s\r\n",title->valuestring,msg->valuestring); - cJSON_AddNumberToObject(deitemJSON,"uid",uid->valueint); - cJSON_AddNumberToObject(deitemJSON,"appid_t",appid_t->valueint);//消息类型 微信 qq 等看结构体或者协议定义 - cJSON_AddStringToObject(deitemJSON,"title",title->valuestring);//消息发送者 - cJSON_AddStringToObject(deitemJSON,"msg",msg->valuestring);//消息内容 - cJSON_AddNumberToObject(deitemJSON,"time",time->valueint);//时间戳 - cJSON_AddNumberToObject(deitemJSON,"hasCode",hasCode->valueint);//暂时不需要预留接口 - cJSON_AddBoolToObject(deitemJSON,"read",read->valueint);//是否已读 false未读 1 已读默认存的时候已经未读 - cJSON_ReplaceItemInArray(dataList, i, deitemJSON);// - } - cJSON_ReplaceItemInArray(dataList,MAX_MESSAGE_NUM-1, itemJSON); - }else{ - cJSON_AddItemToArray(dataList, itemJSON); - } + printf("message_data open %s fail\r\n",message_data_path); } - char *jsonString = cJSON_Print(data_root); - // printf("ancs %s",jsonString); - FILE *fp = fopen(ANCS_DATA_CJSON_PATH, "wb"); - if (fp) - { - int ret=fwrite(jsonString, 1, strlen(jsonString), fp); - if(ret!=strlen(jsonString)) - printf("message_data write fail\r\n"); - fclose(fp); - } + cJSON* dataJSON = cJSON_CreateObject(); + + cJSON_AddNumberToObject(dataJSON,"uid",uid); + cJSON_AddNumberToObject(dataJSON,"appid_t",appid);//消息类型 微信 qq 等看结构体或者协议定义 + cJSON_AddStringToObject(dataJSON,"title",title);//消息发送者 + cJSON_AddStringToObject(dataJSON,"msg",msg);//消息内容 + cJSON_AddNumberToObject(dataJSON,"time",timeBuf);//时间戳 + cJSON_AddNumberToObject(dataJSON,"hasCode",hasCode);//暂时不需要预留接口 + cJSON_AddBoolToObject(dataJSON,"read",false);//是否已读 false未读 1 已读默认存的时候已经未读 + + char *json_format = cJSON_PrintUnformatted(dataJSON); + cJSON_Delete(dataJSON); + + if(json_format==NULL) + return 0; else + printf("message_data json:%s\r\n",json_format); + + if( strlen(json_format)!=fwrite(json_format,1,strlen(json_format),jsfile)) { - printf("fopen fail\r\n"); + printf("message_data fwrite fail\r\n"); } - cJSON_free(jsonString); - cJSON_Delete(data_root); - read_message_data(); - - + + fclose(jsfile); + cJSON_free(json_format); + ble_add_message_index(index); + return index; + //read_message_data(); } int uft8_check(char *chinese_string,int length) { @@ -5224,6 +5165,7 @@ int uft8_check(char *chinese_string,int length) } return i; } +static uint32_t ancs_msg_index =0; //安卓消息接收解析数据 //ANCS 2AE1 uint8_t jscheck_ancs(uint8_t *data) { @@ -5295,7 +5237,7 @@ uint8_t jscheck_ancs(uint8_t *data) hasCode_t = hasCode->valueint; } cJSON_Delete(root); - message_data(uid_t,appid_t,titleBuf,msgBuf,hasCode_t); + ancs_msg_index= message_data(uid_t,appid_t,titleBuf,msgBuf,hasCode_t); if(titleBuf != NULL){ ym_free(titleBuf); titleBuf = NULL; @@ -5306,6 +5248,7 @@ uint8_t jscheck_ancs(uint8_t *data) } return 1; } + void ancsDataShowCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue)// { uint8_t value[19]; @@ -5327,7 +5270,8 @@ void ancsDataShowCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData, value[17] = 1; value[18] = Calculate_CRC(value,18); sendBleData(value,19); - CustomEventPublish(TOPIC_EVENT_MESSAGENOTE,&data,1); + + CustomEventPublish(TOPIC_EVENT_MESSAGENOTE,&ancs_msg_index,4); }else{ value[17] = 0; value[18] = Calculate_CRC(value,18); @@ -5335,9 +5279,9 @@ void ancsDataShowCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData, } } -void CustomEventPublish_TOPIC_EVENT_MESSAGENOTE(void) +void CustomEventPublish_TOPIC_EVENT_MESSAGENOTE(uint32_t index) { - CustomEventPublish(TOPIC_EVENT_MESSAGENOTE,NULL,0); + CustomEventPublish(TOPIC_EVENT_MESSAGENOTE,&index,4); } void type2AE1Data(uint8_t *buf_cmd,uint8_t *data,uint16_t datalen,uint8_t *totalData,uint8_t crcvalue) diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h index 60977436c..1395f98a0 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h @@ -17,6 +17,8 @@ extern "C" { #define ANCS_DATA_CJSON_PATH "/user/userdata/message/ancs.json" //消息文件可以任意更改 +#define ANCS_DATA_MSG_CJSON_PATH "/user/userdata/message/%d.json" //消息文件可以任意更改 + #define READ_FLASH_DATA 0x01 //读flash数据 #define WRITE_FLASH_DATA 0x02 //写flash数据 bool creatMessageDir(void);//创建消息文件夹 @@ -769,9 +771,9 @@ uint8_t get_crc_from_lrc(uint8_t lrcValue); uint8_t calculate_lrc_file(char *file_path); -void message_data(int uid,int appid,char *title,char *msg,int hasCode); +uint32_t message_data(int uid,int appid,char *title,char *msg,int hasCode); -void CustomEventPublish_TOPIC_EVENT_MESSAGENOTE(void); +void CustomEventPublish_TOPIC_EVENT_MESSAGENOTE(uint32_t index); void send_AI_is_ready(uint8_t type); -- 2.17.1