From e797f1d56a57a947c5b405ca733f6019ea9df868 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Wed, 28 Aug 2024 15:53:32 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96ble=E5=8F=91=E9=80=81=E6=95=B0?= =?utf8?q?=E6=8D=AE=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84=E8=A7=A3=E5=86=B3?= =?utf8?q?=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E5=88=9A=E5=A5=BD=E6=BB=A1m?= =?utf8?q?tu=E5=AF=BC=E8=87=B4=E5=8F=91=E9=80=81=E7=A9=BA=E5=8C=85?= =?utf8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=B7=B2=E7=BB=8F=E5=8F=AF=E8=83=BD?= =?utf8?q?=E5=AD=98=E5=9C=A8=E5=8F=82=E6=95=B0=E8=BF=87=E5=A4=9A=E5=AF=BC?= =?utf8?q?=E8=87=B4=E7=9A=84=E5=AE=89=E5=85=A8=E9=9A=90=E6=82=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../service/ble_service/bleservice/bleEvent.c | 190 ++++++++++++++---- .../service/ble_service/bleservice/bleEvent.h | 14 ++ 2 files changed, 166 insertions(+), 38 deletions(-) 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 56678a547..43d0de0e0 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -360,25 +360,27 @@ void sendDataNow(uint8_t *buf,uint16_t len) } } -void send_big_data(uint8_t flag, char *data, uint16_t datalen, uint32_t total, uint32_t Packet_id, uint32_t packet_total, uint8_t type_id, uint8_t type) +void send_big_data(ble_data_type type,char *data, uint16 datalen) { // 动态分配内存空间,防止堆栈溢出 - uint8_t *buf = ym_malloc(17 + datalen + 1); - if (buf == NULL) { + uint8_t *buf =NULL; + buf = ym_malloc(17 + datalen + 1); + memset_s(buf,500,0,17 + datalen + 1); + if (buf == NULL && datalen!=0) { printf("内存分配失败\n"); return; } - if(Packet_id>=2) + if(type.Packet_id>=2) { msleep(10);//多包数据发送增加延迟 } // 设置消息头部信息 buf[0] = 0x72; // 消息头 - buf[1] = type; // 类型 - buf[2] = type_id; // 类型ID - memcpy(buf + 3, &packet_total, 4); // 总包数 - memcpy(buf + 7, &total, 4); // 总数据长度 - memcpy(buf + 11, &Packet_id, 4); // 数据包ID + buf[1] = type.type; // 类型 + buf[2] = type.type_id; // 类型ID + memcpy(buf + 3, &type.packet_total, 4); // 总包数 + memcpy(buf + 7, &type.total, 4); // 总数据长度 + memcpy(buf + 11, &type.Packet_id, 4); // 数据包ID memcpy(buf + 15, &datalen, 2); // 包数据长度 // 处理数据和计算CRC @@ -391,7 +393,7 @@ void send_big_data(uint8_t flag, char *data, uint16_t datalen, uint32_t total, u } // 根据标志位选择发送数据的方式 - if (flag) { + if (1) { sendDataNow(buf, 17 + datalen + 1); // 直接发送数据 } else { sendBleData(buf, 17 + datalen + 1); // 判断是否在传输或接收多包数据 @@ -409,7 +411,8 @@ void sendtraningstatedata(uint8_t state ,uint16_t time) data[0]=state; memcpy(&data[1],&time,2); printf("发送训练状态数据%d %d\r\n",data[0],time); - send_big_data(0,data,data_len,data_len,1,1,0x50,5); + ble_data_type type={0x05,0x50,data_len,1,1}; + send_big_data(type,data,data_len); } @@ -420,7 +423,10 @@ void sendtraningstateend(void) uint32_t data_len=1; data[0]=0; //[0 结束] printf("发送训练状态结束%d\r\n",data[0]); - send_big_data(0,data,data_len,data_len,1,1,0x51,5); + + ble_data_type type={0x05,0x51,data_len,1,1}; + send_big_data(type,data,data_len); + //end_big_data(0,data,data_len,data_len,1,1,0x51,5); } void sendtraningdata(msg_get_train_data_info_t *data) @@ -457,7 +463,9 @@ void sendtraningdata(msg_get_train_data_info_t *data) } printf("发送训练实时数据 %d %s\n", data_len, jsonString); - send_big_data(0, jsonString, data_len, data_len, 1, 1, 0x0f, 1); + ble_data_type type={0x01,0x0f,data_len,1,1}; + send_big_data(type,data,data_len); + //send_big_data(0, jsonString, data_len, data_len, 1, 1, 0x0f, 1); cJSON_free(jsonString); } @@ -471,7 +479,10 @@ void send_AI_is_ready(uint8_t type) { printf("发送AI准备就绪\r\n"); - send_big_data(0, (char *)&type, 1, 1, 1, 1, 0x05, 5); + ble_data_type type_={0x05,0x05,1,1,1}; + send_big_data(type_,(char *)&type,1); + + //send_big_data(0, (char *)&type, 1, 1, 1, 1, 0x05, 5); } //查询AI 模型是否可用,结果通过2AE4返回 /*使用模型: @@ -483,7 +494,9 @@ void inquire_AI_is_ready(uint8_t type) { printf("查询AI模型,是否准备就绪\r\n"); - send_big_data(0, (char *)&type, 1, 1, 1, 1, 0x06, 5); + ble_data_type type_={0x05,0x06,1,1,1}; + send_big_data(type_,(char *)&type,1); + //send_big_data(0, (char *)&type, 1, 1, 1, 1, 0x06, 5); } void cancel_AI_cur_chat(void) @@ -491,7 +504,10 @@ void cancel_AI_cur_chat(void) printf("取消当前AI对话\r\n"); uint8_t data=1; - send_big_data(0, (char *)&data, 1, 1, 1, 1, 0x07, 5); + ble_data_type type_={0x05,0x07,data_len,1,1}; + send_big_data(type_,(char *)&data,data_len); + + //send_big_data(0, (char *)&data, 1, 1, 1, 1, 0x07, 5); } @@ -894,6 +910,7 @@ static uint8_t *GetwatchSaveName(void)//获取手表本地保存的手机设备 } } + void cleanUnbindInfor(uint8_t flag)//和旧手机解绑清除配对信息 { uint8_t value[19]; @@ -2630,7 +2647,10 @@ void APP_send_schedule_Cmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *tota void GetGPSCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue) { - send_big_data(1,NULL,0,0,1,1,0x4f,2); + ble_data_type type_={0x02,0x4f,0,1,1}; + send_big_data(type_,NULL,0); + + //send_big_data(1,NULL,0,0,1,1,0x4f,2); } void query_dial_installed(ble_read_data *buffer_handle,uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue)// @@ -3218,7 +3238,9 @@ void GetCurDataCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totaldata,ui { if(!Check_CRC(data,len,crcvalue)) { - send_big_data(1,NULL,0,0,1,1,0x06,1); + int data_len=0; + ble_data_type type_={0x01,0x06,data_len,1,1}; + send_big_data(type_,NULL,0); return; } cJSON *dataJSON = cJSON_CreateObject(); @@ -3291,14 +3313,21 @@ void GetCurDataCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totaldata,ui if(surplus_len>=pack_size) { surplus_len=surplus_len-pack_size; - send_big_data(1,json_format+offset,pack_size,data_len,pack_id,pack,0x06,1); + + + ble_data_type type_={0x01,0x06,data_len,pack,pack_id}; + send_big_data(type_,json_format+offset,pack_size); + + //send_big_data(1,json_format+offset,pack_size,data_len,pack_id,pack,0x06,1); offset+=pack_size; } else { printf("%d %d %d %d\r\n",data_len,surplus_len,pack_id,pack); - send_big_data(1,json_format+offset,surplus_len,data_len,pack_id,pack,0x06,1); + ble_data_type type_={0x01,0x06,data_len,pack,pack_id}; + send_big_data(type_,json_format+offset,surplus_len); + //send_big_data(1,json_format+offset,surplus_len,data_len,pack_id,pack,0x06,1); break; } pack_id++; @@ -3635,7 +3664,10 @@ void sendRealTimeDataToAPP(uint8_t flag) { if(flag == 0)//校验失败 { - send_big_data(0,NULL,0,0,1,1,0x0f,1); + ble_data_type type_={0x01,0x0f,0,1,1}; + send_big_data(type_,NULL,0); + + //send_big_data(0,NULL,0,0,1,1,0x0f,1); }else { @@ -4336,7 +4368,9 @@ static void GetAllDialUidCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *to printf( "GetAllDialUidCmd yes\r\n"); } - send_big_data(0,dail_uid_buf,data_size,temp_data_size,1,1,0x2a,1); + ble_data_type type_={0x01,0x2a,temp_data_size,1,1}; + send_big_data(type_,dail_uid_buf,data_size); + //send_big_data(0,dail_uid_buf,data_size,temp_data_size,1,1,0x2a,1); free(dail_uid_buf); @@ -4554,8 +4588,14 @@ static void GetAiRecordCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *tota { memset_s(data,num+1,0,num+1); read_size=fread(data,1,num,fp); - - send_big_data(1,data,read_size,file_size,pack_id,pack,0x34,1); + + if(read_size!=0) + { + ble_data_type type_={0x01,0x34,file_size,pack,pack_id}; + send_big_data(type_,data,read_size); + } + + //send_big_data(1,data,read_size,file_size,pack_id,pack,0x34,1); pack_id++; msleep(SEND_AIVOICE_PACKAGE_DELAY); @@ -4807,14 +4847,20 @@ static void Send_json_Data_Cmd(uint8_t day,uint16_t pack_size,uint8_t id) if(surplus_len>=pack_size) { surplus_len=surplus_len-pack_size; - send_big_data(1,json_format+offset,pack_size,data_len,pack_id,pack,id,1); + + ble_data_type type_={0x01,id,data_len,pack,pack_id}; + send_big_data(type_,json_format+offset,pack_size); + + //send_big_data(1,json_format+offset,pack_size,data_len,pack_id,pack,id,1); offset+=pack_size; } else { printf("%d %d %d %d\r\n",data_len,surplus_len,pack_id,pack); - send_big_data(1,json_format+offset,surplus_len,data_len,pack_id,pack,id,1); + ble_data_type type_={0x01,id,data_len,pack,pack_id}; + send_big_data(type_,json_format+offset,surplus_len); + //send_big_data(1,json_format+offset,surplus_len,data_len,pack_id,pack,id,1); break; } pack_id++; @@ -5305,7 +5351,11 @@ void Send_Sleep_Bin_Data(uint8_t day, uint16_t num) if(data==NULL || file_size==1) { - send_big_data(1,NULL,0,0,1,1,0x4b,1); + ble_data_type type_={0x01,0x4b,0,1,1}; + send_big_data(type_,NULL,0); + + //send_big_data(1,NULL,0,0,1,1,0x4b,1); + sendbigDataBufState = false;//分包同步数据不允许打断 return; } @@ -5329,7 +5379,10 @@ void Send_Sleep_Bin_Data(uint8_t day, uint16_t num) { surplus_len=surplus_len-num; printf("%d %d %d %d\r\n",num,file_size,pack_id,pack); - send_big_data(1,data+offset,num,file_size,pack_id,pack,0x4b,1); + + ble_data_type type_={0x01,0x4b,file_size,pack,pack_id}; + send_big_data(type_,data+offset,num); + //send_big_data(1,data+offset,num,file_size,pack_id,pack,0x4b,1); offset+=num; } else @@ -5337,7 +5390,10 @@ void Send_Sleep_Bin_Data(uint8_t day, uint16_t num) //#ifdef BLE_LOG printf("%d %d %d %d\r\n",surplus_len,file_size,pack_id,pack); //#endif - send_big_data(1,data+offset,surplus_len,file_size,pack_id,pack,0x4b,1); + ble_data_type type_={0x01,0x4b,file_size,pack,pack_id}; + send_big_data(type_,data+offset,surplus_len); + + //send_big_data(1,data+offset,surplus_len,file_size,pack_id,pack,0x4b,1); break; } pack_id++; @@ -5373,6 +5429,13 @@ bool Read_Health_BIN_file_buf_send_bin_Data(uint8_t day, uint16_t num,uint16_t i fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 file_size = ftell(fp); // 获取当前文件指针位置,即文件大小 fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 + + int num=file_size%5; + if(num!=0) + { + printf("数据有误 %d \r\n",id); + return false; + } buf = (char *)ym_malloc(sizeof(char)*num+1); if(buf==NULL){fclose(fp); return false;} @@ -5388,7 +5451,14 @@ bool Read_Health_BIN_file_buf_send_bin_Data(uint8_t day, uint16_t num,uint16_t i { memset_s(buf,num+1,0,num+1); read_size=fread(buf,1,num,fp); - send_big_data(1,buf,read_size,file_size,pack_id,pack,id,1); + if(read_size!=0) + { + ble_data_type type_={0x01,id,file_size,pack,pack_id}; + send_big_data(type_,buf,read_size); + } + + + //send_big_data(1,buf,read_size,file_size,pack_id,pack,id,1); pack_id++; } while (read_size==num); @@ -5407,10 +5477,32 @@ void Read_BIN_file_buf_send_bin_Data(uint8_t day,uint32_t pack_size,uint16_t id) if(data==NULL) { - send_big_data(1,NULL,0,0,1,1,id,1); - printf("Read_BIN_file_buf_send_bin_Data is NULL"); + ble_data_type type_={0x01,id,0,1,1}; + send_big_data(type_,NULL,0); + + //send_big_data(1,NULL,0,0,1,1,id,1); + sendbigDataBufState = false;//分包同步数据不允许打断 return; } + uint8_t single_data=8; + if(id==0x44) + { + single_data=6; + } + else if (id==0x45) + { + single_data=4; + } + int check_num=data_len%single_data; + if(check_num!=0) + { + printf("数据有误 %d \r\n",id); + + ble_data_type type_={0x01,id,0,1,1}; + send_big_data(type_,NULL,0); + + return ; + } uint32_t surplus_len=data_len; uint32_t pack; @@ -5430,7 +5522,9 @@ void Read_BIN_file_buf_send_bin_Data(uint8_t day,uint32_t pack_size,uint16_t id) if(surplus_len>=pack_size) { surplus_len=surplus_len-pack_size; - send_big_data(1,data+offset,pack_size,data_len,pack_id,pack,id,1); + ble_data_type type_={0x01,id,data_len,pack,pack_id}; + send_big_data(type_,data+offset,pack_size); + //send_big_data(1,data+offset,pack_size,data_len,pack_id,pack,id,1); offset+=pack_size; } else @@ -5438,7 +5532,11 @@ void Read_BIN_file_buf_send_bin_Data(uint8_t day,uint32_t pack_size,uint16_t id) #ifdef BLE_LOG printf("%d %d %d %d\r\n",data_len,surplus_len,pack_id,pack); #endif - send_big_data(1,data+offset,surplus_len,data_len,pack_id,pack,id,1); + + ble_data_type type_={0x01,id,data_len,pack,pack_id}; + send_big_data(type_,data+offset,surplus_len); + + //send_big_data(1,data+offset,surplus_len,data_len,pack_id,pack,id,1); break; } pack_id++; @@ -5485,14 +5583,21 @@ void readDevDataBle(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,u printf("同步心率数据,每包最多:%d 数据 data:%d %d\r\n",num,data[0],len); #endif if(!Read_Health_BIN_file_buf_send_bin_Data(data[0],num,0x40)) - send_big_data(1,NULL,0,0,1,1,0x40,1); + { + ble_data_type type_={0x01,0x40,0,1,1}; + send_big_data(type_,NULL,0); + } + //send_big_data(1,NULL,0,0,1,1,0x40,1); break; case 0x41://同步血氧历史数据 num=(ble_nus_max_data_len-18); if(num>482)num=482; if(!Read_Health_BIN_file_buf_send_bin_Data(data[0],num,0x41)) - send_big_data(1,NULL,0,0,1,1,0x41,1); + { + ble_data_type type_={0x01,0x41,0,1,1}; + send_big_data(type_,NULL,0); + } break; case 0x43: //同步步数历史数据 @@ -6602,8 +6707,14 @@ bool Read_tar_file_buf_send_Data(uint16_t pack_size,uint8_t id) { memset_s(data,pack_size+1,0,pack_size+1); read_size=fread(data,1,pack_size,fp); + if(read_size!=0) + { + ble_data_type type_={0x05,id,read_size,pack,pack_id}; + send_big_data(type_,(char *)&data,read_size); + } - send_big_data(1,data,read_size,file_size,pack_id,pack,id,5); + + //send_big_data(1,data,read_size,file_size,pack_id,pack,id,5); pack_id++; msleep(50); } while (read_size==pack_size); @@ -6622,7 +6733,10 @@ bool read_dir_send_json() send_buf=tar_dir_to_json_buf_malloc_(file_name,&file_size); if( send_buf!=NULL) { - send_big_data(1,send_buf,strlen(send_buf),strlen(send_buf),1,1,0x26,0x04); + //send_big_data(1,send_buf,strlen(send_buf),strlen(send_buf),1,1,0x26,0x04); + ble_data_type type_={0x04,0x26,strlen(send_buf),1,1}; + send_big_data(type_,(char *)&send_buf,strlen(send_buf)); + free(send_buf); return true; } 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 3f8f1f33c..16a251459 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h @@ -575,6 +575,20 @@ typedef struct }msg_get_other_target_info_t;//获取其他目标设置 #pragma pack() + +typedef struct +{ + uint8_t type; + uint8_t type_id; + uint32_t total; + uint32_t packet_total; + uint32_t Packet_id; + + +}ble_data_type;//获取其他目标设置 + + + /*********************ANCS********安卓指令********************/ #define ANDROID_ANCS_CMD 0x0301 -- 2.17.1