From: Caisking <3449750381@qq.com> Date: Thu, 10 Oct 2024 03:17:04 +0000 (+0800) Subject: 消息:增加信息时间戳过滤 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=88461fe739247280e97d99e83ad538d5bf6bd749;p=mirrors%2FFD230.git 消息:增加信息时间戳过滤 --- 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 deabc5e5c..ddef52575 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleANCS.c @@ -17,6 +17,9 @@ #include #include #include "stdbool.h" +#include +#include +#include #include "bts_le_gap.h" #include "bts_br_gap.h" @@ -289,10 +292,10 @@ 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); //当前时间戳减去订阅通知时间戳10s以上的通知,才要求数据(过滤ios将所有未查看消息发过来) - if(creationTime-subscribe_notify_creationTime>10) - { + // 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", @@ -302,65 +305,62 @@ static void ble_ancs_client_notify_source_cbk(uint8_t client_id, uint16_t conn_i //static char old_time_buf[64]={0}; static uint32_t ancs_msg_index =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[300]={0}; - char msg_buf[300]={0}; - char app_buf[70]={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,300,"%s",node->att); - } - if(node->att_id==3) - { - sprintf_s(msg_buf,300,"%s",node->att); - } - if(node->att_id==0) - { - sprintf_s(app_buf,70,"%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"); - if(is_filtration_data(app_buf)) - message_data(notify_attr_rsp->notification_uid,0,title_buf,msg_buf,0); - - - - //} - - } else { - printf("[ANCSClientNotifyATTRSPCBK]conn_id:%d status:0x%x.\r\n", - conn_id, status); - } +/* 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[300] = {0}; + char msg_buf[300] = {0}; + char app_buf[70] = {0}; + time_t timestamp = 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, 300, "%s", node->att); + } else if (node->att_id == 3) { + sprintf_s(msg_buf, 300, "%s", node->att); + } else if (node->att_id == 0) { + sprintf_s(app_buf, 70, "%s", node->att); + } else if (node->att_id == 5) { + struct tm tm = {0}; + // 将 node->att 强制转换为 const char * + if (strptime((const char *)node->att, "%Y%m%dT%H%M%S", &tm) != NULL) { + timestamp = mktime(&tm); // 获取时间戳 + } else { + printf("时间字符串解析失败: %s\r\n", node->att); + } + } + } + node = lnext(node); + if (att_num == notify_attr_rsp->att_num) { + break; + } + att_num++; + } + + printf("ble_ancs_client_notification_attr_rsp_cbk test\r\n"); + + // 只有在成功解析时间戳后才进行后续操作 + if (is_filtration_data(app_buf) && (timestamp >= subscribe_notify_creationTime)) { + message_data(notify_attr_rsp->notification_uid, 0, title_buf, msg_buf, 0); + } + + } 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)