From 278f97eb4dfc38e28f97002eff933f7cf03842ad Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E9=82=93=E9=9B=AA=E8=8B=B1?= <1731678236@qq.com> Date: Tue, 16 Apr 2024 13:13:05 +0000 Subject: [PATCH] Merge #15 into xts_origin from refs/changes/15/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 通讯录协议对接完成 * refs/changes/15/head: (3 commits squashed) - test - 1.通许录协议对接已完成 2.更改时间 天气 训练目标解析返回值传参出错的问题 - Merge branch 'xts_origin' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into xts_origin Signed-off-by: d15521469561 <1731678236@qq.com> Commented-by: d15521469561 <1731678236@qq.com> Commented-by: Caisking <3449750381@qq.com> Commented-by: snickersun@163.com Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/15 --- .../nativeui/alipay/src/AlipayHelp.cpp | 2 +- .../phone/include/phoneaddressmodel.h | 13 +- .../nativeui/phone/src/phoneaddressmodel.cpp | 249 ++++++++++-------- .../service/ble_service/blemoder/bletest.cpp | 11 +- .../service/ble_service/blemoder/bletest.h | 2 + .../service/ble_service/bleservice/bleEvent.c | 70 +++-- .../service/ble_service/bleservice/bleEvent.h | 3 +- .../ble_service/bleservice/bleService.c | 12 +- 8 files changed, 220 insertions(+), 142 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/alipay/src/AlipayHelp.cpp b/code/sdk/application/wearable/fd230app/nativeui/alipay/src/AlipayHelp.cpp index 9f29dedf8..aec899fcf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alipay/src/AlipayHelp.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alipay/src/AlipayHelp.cpp @@ -10,7 +10,7 @@ #include "cmsis_os.h" #include "AlipayHelp.h" #include "AlipayModel.h" - + namespace OHOS { static const char *HELP_TITLE = (char*)"使用支付宝扫码求助"; static const int16 HELP_TITLE_FONT = 30; diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/include/phoneaddressmodel.h b/code/sdk/application/wearable/fd230app/nativeui/phone/include/phoneaddressmodel.h index 3e872892f..cc2b5eb86 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/include/phoneaddressmodel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/include/phoneaddressmodel.h @@ -4,22 +4,25 @@ #define ADDRESS_BOOK_PATH "/user/userdata/addressbook.bin" - +#define NAME_LEN (10*3) +#define NUMBER_LEN 20 +#define AREA_LEN (20*3) +#define OPERATOR_LEN (4*3) namespace OHOS { struct phone_number { - char *number={NULL}; - char *affiliating_area={NULL}; - char *operator_t={NULL}; + char number[NUMBER_LEN]; + char affiliating_area[AREA_LEN];//归属地 + char operator_t[OPERATOR_LEN];//运营商 //struct phone_number *next; }; struct Contact { - char *name={NULL}; + char name[NAME_LEN]; int phone_num=0; uint8_t sex; struct phone_number phone_number_t[2]; diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/src/phoneaddressmodel.cpp b/code/sdk/application/wearable/fd230app/nativeui/phone/src/phoneaddressmodel.cpp index 5fbe59a16..cf41b1c76 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/src/phoneaddressmodel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/src/phoneaddressmodel.cpp @@ -20,89 +20,117 @@ namespace OHOS { struct addressbook addressbook_t; - + static char *buf = NULL; void read_addressbook_bin_file() { - FILE *fp= fopen(ADDRESS_BOOK_PATH,"rb+"); - if(fp==NULL) - { - fp= fopen(ADDRESS_BOOK_PATH,"wb+"); - fclose(fp); - return; - } - char buf[124*20]; - int ret=fread(buf,1,512,fp); - int offset_f=512; - while (ret==512) - { - ret=fread(&buf[offset_f],1,512,fp); - offset_f+=512; - } - - int num=buf[0];//人数 - printf("人数: %d\r\n",num); - addressbook_t.num=num; - int offset=1; - for (int j=0;j NAME_LEN) + { + addressbook_t.Contact_t[j].name[NAME_LEN] = '\0'; + memcpy(addressbook_t.Contact_t[j].name,&buf[offset+1],NAME_LEN); + }else{ + memcpy(addressbook_t.Contact_t[j].name,&buf[offset+1],name_len); + } + + printf("姓名: %s\r\n",addressbook_t.Contact_t[j].name); + // addressbook_t.Contact_t[j].name=name; + } + offset=offset+name_len+1; + uint8_t phone_num=buf[offset]; + offset=offset+1; + addressbook_t.Contact_t[j].phone_num=phone_num; + for(int i=0;i NUMBER_LEN) + { + addressbook_t.Contact_t[j].phone_number_t[i].number[NUMBER_LEN] = '\0'; + memcpy(addressbook_t.Contact_t[j].phone_number_t[i].number,&buf[offset+1],NUMBER_LEN); + }else{ + memcpy(addressbook_t.Contact_t[j].phone_number_t[i].number,&buf[offset+1],phonen_len); + } + + printf("号码: %s\r\n",addressbook_t.Contact_t[j].phone_number_t[i].number); + // addressbook_t.Contact_t[j].phone_number_t[i].number=phonen_name; + offset=offset+phonen_len+1; + } + for(int i=0;i OPERATOR_LEN) + { + addressbook_t.Contact_t[j].phone_number_t[i].operator_t[OPERATOR_LEN]='\0'; + memcpy(addressbook_t.Contact_t[j].phone_number_t[i].operator_t,&buf[offset+1],OPERATOR_LEN); + }else{ + memcpy(addressbook_t.Contact_t[j].phone_number_t[i].operator_t,&buf[offset+1],yun); + } + printf("运营商: %s\r\n",addressbook_t.Contact_t[j].phone_number_t[i].operator_t); + // addressbook_t.Contact_t[j].phone_number_t[i].operator_t=yun_buf; - offset=offset+yun+1; + offset=offset+yun+1; + } + } + fclose(fp); + if(buf) + { + free(buf); } - } - fclose(fp); } void get_phone_addrss_name(char *name,const char *phone) @@ -129,6 +157,7 @@ namespace OHOS void write_addressbook_bin_flle() { + #if 0 FILE *fp= fopen(ADDRESS_BOOK_PATH,"wb+"); if(fp==NULL) return; @@ -180,12 +209,13 @@ namespace OHOS } fwrite((void *)buf,1,offset,fp); fclose(fp); + #endif } void add_addressbook(struct Contact *data) { - + #if 0 if(data->name!=NULL) { @@ -253,54 +283,57 @@ namespace OHOS } } addressbook_t.num+=1; - + #endif } void add_addressbook_by_AT(char *name,char *phone) { - Contact data; - data.sex=0; - data.name=name; - data.phone_num=1; - data.phone_number_t[0].number=phone; - data.phone_number_t[0].affiliating_area=NULL; - data.phone_number_t[0].operator_t=NULL; + // Contact data; + // data.sex=0; + // data.name=name; + // data.phone_num=1; - data.phone_number_t[1].number=NULL; - data.phone_number_t[1].affiliating_area=NULL; - data.phone_number_t[1].operator_t=NULL; + // data.phone_number_t[0].number=phone; + // memset(data.phone_number_t[0].affiliating_area,0,AREA_LEN); + // // data.phone_number_t[0].affiliating_area=NULL; + // // data.phone_number_t[0].operator_t=NULL; + // memset(data.phone_number_t[0].affiliating_area,0,OPERATOR_LEN); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneaddressbook::phoneaddressbook"); - add_addressbook(&data); + // data.phone_number_t[1].number=NULL; + // data.phone_number_t[1].affiliating_area=NULL; + // data.phone_number_t[1].operator_t=NULL; + + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneaddressbook::phoneaddressbook"); + // add_addressbook(&data); } void free_address() { - for(int i=0;ivalueint); } cJSON_Delete(root); - return 2; + return 1; } @@ -1555,7 +1559,7 @@ uint8_t jsonCheck_weather(uint8_t *buf)//json 格式解析 天气数据 cJSON* root = cJSON_Parse((const char *)json); if (root == NULL) { printf("天气 JSON解析错误\n"); - return 1; + return 2; } cJSON *now_cjson = cJSON_GetObjectItem(root, "now"); @@ -1605,7 +1609,7 @@ uint8_t jsonCheck_weather(uint8_t *buf)//json 格式解析 天气数据 // } cJSON_Delete(root); printf("weather data!!!!!!!!!!end\r\n"); - return 2; + return 1; } @@ -1689,7 +1693,7 @@ void getTRAIN_TARGETInfo(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *tota { } - +// #include "phoneaddressmodel.h" //电话薄解析函数 void Parse_addressbook_bin(uint8_t *crcnum,uint16_t len) { @@ -1769,9 +1773,17 @@ void getAPPaddressbook(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totalD if(Check_CRC(crcnum,len,crcvalue)) { //解析,传来的二进制数据 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, ""); - Parse_addressbook_bin(crcnum,len); - + char *address_path = addressbook(); + FILE *file = fopen(address_path, "wb+"); + if (file) + { + size_t len_t = fwrite((void *)crcnum,1,len,file); + fclose(file); + if(len_t == len){ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "fwrite:%d",len_t); + addressbookToRead(); + } + } value[17] = 0x01; value[18] = Calculate_CRC(value,18); sendBleData(value,19); @@ -3836,6 +3848,9 @@ void sendReadData(void) } while (1) { + + + //json id=0 time = 1711348052+3600*packCount; memcpy(buf+startDataLen,&time,4);//21 startDataLen=startDataLen+4; @@ -4102,7 +4117,7 @@ void bleDataRecv(uint8_t *totalData, uint16_t event_size,uint16_t handle) free(recvData); } } - }else if(data2ae4Cmd == handle) + }else if(data2ae4Cmd == handle)//长数据接收 { while (1) { @@ -4192,9 +4207,9 @@ void bleDataRecv(uint8_t *totalData, uint16_t event_size,uint16_t handle) if(bigDataBuf != NULL){ free(bigDataBuf); } - // if(recvData != NULL){ - // // free(recvData); - // } + if(recvData != NULL){ + free(recvData); + } break; } } @@ -4204,6 +4219,19 @@ void bleDataRecv(uint8_t *totalData, uint16_t event_size,uint16_t handle) // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "xhandle %d,%d %d",data2ae3Cmd,data2ae4Cmd,handle); // } } +void free_ble_data(void)//以防断开蓝牙没有释放数据类型 +{ + totalpack = 0; + muiltFlag = 0; + packdataLen = 0; + totalDataLen = 0; + if(bigDataBuf != NULL){ + free(bigDataBuf); + } + if(recvData != NULL){ + free(recvData); + } +} //接收app下发的原始数据 void revBleOldData(uint8_t *buf, uint16_t event_size,uint16_t handle)//每包的数据大小 { 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 1e4f6b02e..ed6d2147a 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h @@ -581,13 +581,14 @@ errcode_t sendBleData(uint8_t *buf,uint16_t len); void sendParieSuccess(uint8_t flag,bd_addr_t *addr);//发送配对成功指令to app mac手机端的地址 void getPhoneInfo_test(void); void setFindWatchFlag(uint8_t flag);//查找手表标识 -errcode_t UnbindSucessCmd(void);//发送解绑指令,解绑界面调用这个函数 如果点了✓调用这个函数 返回成功后延迟10s再重启设备 +errcode_t UnbindSucessCmd(uint8_t flag);// 1确认解绑 0取消解绑 发送解绑指令,解绑界面调用这个函数 如果点了✓调用这个函数 返回成功后延迟10s再重启设备 void getDeviceState(void); void cleanUnbindInfor(uint8_t flag);//和旧手机解绑清除配对信息 0不清除配对信息 1清除配对信息重启 void comfirmPaire(uint8_t flag);//发送确认配对指令 1确认配对 0取消配对 void cameraSend(void); void senfindphoneSend(uint8_t flag); void readDevDataBle(uint8_t *crcnum,uint16_t len,uint8_t crcvalue); +void free_ble_data(void); #ifdef __cplusplus } #endif diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c index 7923ce581..af60f704f 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -283,6 +283,7 @@ static void svr_ble_connstate_change_cb(unsigned short conn_id, bd_addr_t *addr, WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GAP_BLE_STATE_DISCONNECTED!!! 0x%x ret:%d\r\n",pair_state,AdverFlag); // if(AdverFlag == true){ svr_ble_adv_start(); + free_ble_data(); // } } else { devpair_state = 0;// @@ -805,11 +806,7 @@ static void svr_ble_bt_gatts_req_write_cb(uint8_t server_id, uint16_t conn_id, g { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "g_ble_server_handle %d conn_id :%d write_cb_para->length:%d write_cb_para->handle %d write_cb_para->request_id:%d",g_ble_server_handle,conn_id,write_cb_para->length, write_cb_para->handle,write_cb_para->request_id); - for(uint16_t i = 0;ilength;i++) - { - printf("%x ",write_cb_para->value[i]); - - } + //WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"handle :%d %d %d".write_cb_para->handle,get_factory_ate_write_handl(),get_factory_ota_write_handl()); if (write_cb_para->handle == get_factory_ate_write_handl()) { @@ -819,6 +816,11 @@ static void svr_ble_bt_gatts_req_write_cb(uint8_t server_id, uint16_t conn_id, g { factory_recv_ota_data(write_cb_para->value,write_cb_para->length,write_cb_para->handle); }else{ + for(uint16_t i = 0;ilength;i++) + { + printf("%02x ",write_cb_para->value[i]); + + } revBleOldData(write_cb_para->value,write_cb_para->length,write_cb_para->handle); } } -- 2.17.1