From 064aeb7e9a0da997d9f993b0a8149808ce8354db Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Thu, 11 Jul 2024 16:45:37 +0800 Subject: [PATCH] =?utf8?q?=E6=B6=88=E6=81=AF=E5=8E=BB=E6=96=87=E4=BB=B6IO?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../service/ble_service/blemoder/bletest.h | 6 +- .../service/ble_service/bleservice/bleEvent.c | 82 ++++++++----------- .../service/ble_service/bleservice/bleEvent.h | 5 +- 3 files changed, 38 insertions(+), 55 deletions(-) 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 c9f65d3bf..7394c78f5 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -79,7 +79,7 @@ extern "C" #define MAX_MESSAGE_NUM 10 #define TITLE_BUF_LEN 256 #define MSG_BUF_LEN 300 -struct ancs_data_info_t +typedef struct ancs_data_info { uint32_t time;//时间戳 int uid;//uid 消息唯一编号 @@ -88,12 +88,12 @@ struct ancs_data_info_t char msg[MSG_BUF_LEN+1];//消息内容 int hasCode;//消息hash code int read;//是否已读 0 未读 1 已读 -}; +}ancs_data_info_t; struct message_infor_t { uint8_t num; - struct ancs_data_info_t message_t[MAX_MESSAGE_NUM]; + ancs_data_info_t message_t[MAX_MESSAGE_NUM]; }; typedef struct 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 35692e0f6..46472a8ce 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -5079,59 +5079,27 @@ char *get_message_dir_path(void)//获取信息的文件夹路径 return ANCS_DATA_CONFIG_DIR; } -uint32_t message_data(int uid,int appid,char *title,char *msg,int hasCode) +void* message_data(int uid,int appid,char *title,char *msg,int hasCode) { - if(!creatMessageDir())//创建文件夹失败 - { - return 0; - } - uint32_t index= ble_get_message_index(); - - 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; } + ancs_data_info_t *data= (ancs_data_info_t *)malloc(sizeof(ancs_data_info_t)); + if(data==NULL) + return NULL; - sprintf_s(message_data_path,128,ANCS_DATA_MSG_CJSON_PATH,index); - - FILE *jsfile = fopen(message_data_path, "w+"); - if(jsfile==NULL) - { - printf("message_data open %s fail\r\n",message_data_path); - } - - - 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); + data->appid=appid; + memcpy_s(data->title,TITLE_BUF_LEN+1,title,strlen(title)); + memcpy_s(data->msg,TITLE_BUF_LEN+1,title,strlen(msg)); + data->uid=uid; + data->time=timeBuf; + data->read=0; + data->hasCode=hasCode; - 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("message_data fwrite fail\r\n"); - } - - fclose(jsfile); - cJSON_free(json_format); - ble_add_message_index(index); - return index; + return data; //read_message_data(); } int uft8_check(char *chinese_string,int length) @@ -5164,7 +5132,9 @@ int uft8_check(char *chinese_string,int length) } return i; } -static uint32_t ancs_msg_index =0; +static void* ancs_msg_data =NULL; + + //安卓消息接收解析数据 //ANCS 2AE1 uint8_t jscheck_ancs(uint8_t *data) { @@ -5236,7 +5206,13 @@ uint8_t jscheck_ancs(uint8_t *data) hasCode_t = hasCode->valueint; } cJSON_Delete(root); - ancs_msg_index= message_data(uid_t,appid_t,titleBuf,msgBuf,hasCode_t); + if(ancs_msg_data!=NULL) + { + free(ancs_msg_data); + ancs_msg_data=NULL; + } + ancs_msg_data= message_data(uid_t,appid_t,titleBuf,msgBuf,hasCode_t); + if(titleBuf != NULL){ ym_free(titleBuf); titleBuf = NULL; @@ -5269,8 +5245,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,&ancs_msg_index,4); + if(ancs_msg_data) + CustomEventPublish_TOPIC_EVENT_MESSAGENOTE(ancs_msg_data); }else{ value[17] = 0; value[18] = Calculate_CRC(value,18); @@ -5278,9 +5254,15 @@ void ancsDataShowCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData, } } -void CustomEventPublish_TOPIC_EVENT_MESSAGENOTE(uint32_t index) +void CustomEventPublish_TOPIC_EVENT_MESSAGENOTE(void *data) { - CustomEventPublish(TOPIC_EVENT_MESSAGENOTE,&index,4); + CustomEventPublish(TOPIC_EVENT_MESSAGENOTE,(uint8_t*)data,sizeof(ancs_data_info_t)); + if(data) + { + free(data); + data=NULL; + } + } 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 1395f98a0..9dfeba67f 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h @@ -9,6 +9,7 @@ extern "C" { #include "stdbool.h" #include "errcode.h" #include "bts_def.h" +//#include "bletest.h" #define PHONE_WATCH_CONFIG_PATH "/user/userdata/phone_watch.json" #define ALARM_DATA_CONFIG_PATH "/user/userdata/alarm_test.json" #define ANCS_DATA_CONFIG_DIR "/user/userdata/message" @@ -771,9 +772,9 @@ uint8_t get_crc_from_lrc(uint8_t lrcValue); uint8_t calculate_lrc_file(char *file_path); -uint32_t message_data(int uid,int appid,char *title,char *msg,int hasCode); +void* message_data(int uid,int appid,char *title,char *msg,int hasCode); -void CustomEventPublish_TOPIC_EVENT_MESSAGENOTE(uint32_t index); +void CustomEventPublish_TOPIC_EVENT_MESSAGENOTE(void*); void send_AI_is_ready(uint8_t type); -- 2.17.1