From: 胡传军 <1224667075@qq.com> Date: Wed, 17 Apr 2024 03:09:24 +0000 (+0000) Subject: Merge #25 into xts_origin from refs/changes/25/head X-Git-Tag: release_V1.2.70_20241020_135402~1176^2 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=3242ff38217f7067fbbfc23a5cfb2eba58e19787;p=mirrors%2FFD230.git Merge #25 into xts_origin from refs/changes/25/head 多包数据发送修改及通讯录AT指令添加修改 * refs/changes/25/head: (2 commits squashed) - 多包数据发送修改及通讯录AT指令添加修改 - 修改编译错误 Signed-off-by: aliyun8003852482 <1224667075@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/25 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h index 79e625221..f687ee063 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h @@ -116,7 +116,7 @@ namespace OHOS void SetLanguage(int languageid); int GetLanguage(); - void SetLanguageCode(char *languagecode); + void SetLanguageCode(const char *languagecode); std::string GetLanguageCode(void); std::string Getimei(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp index cf522e3ea..4cc722289 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp @@ -521,7 +521,7 @@ namespace OHOS return get_configData_int(CONFIGMODEL_ITEM_LANGUAGE_ID); } - void ConfigModel::SetLanguageCode(char *languagecode) + void ConfigModel::SetLanguageCode(const char *languagecode) { set_condigData_String(CONFIGMODEL_ITEM_LANGUAGE_CODE,languagecode); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp index 25aa4002d..6ec0faa2a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp @@ -9,6 +9,21 @@ namespace OHOS { static HealthService *g_pHealthService = nullptr; static constexpr const char *HEALTH_JSON_PATH = "/user/userdata/health/"; + std::string GetCurrentDate() + { + time_t now = time(0); + tm *ltm = localtime(&now); + char date[20]; + strftime(date, sizeof(date), "%Y%m%d", ltm); + return std::string(date); + } + //static char *JSON_F_buf=NULL; + const char *GET_HEALTH_JSON_PATH_C_STR() + { + + + return HEALTH_JSON_PATH; + } cJSON *root = NULL; HealthService::HealthService() @@ -42,14 +57,7 @@ namespace OHOS return true; } /*获取日期*/ - std::string GetCurrentDate() - { - time_t now = time(0); - tm *ltm = localtime(&now); - char date[20]; - strftime(date, sizeof(date), "%Y%m%d", ltm); - return std::string(date); - } + /*生成文件*/ std::string GetJsonFilePath() { diff --git a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h index d6175d759..3b8b54fa6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h +++ b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h @@ -7,6 +7,7 @@ #define HEART_MAX_POINTS 360 namespace OHOS { + const char * GET_HEALTH_JSON_PATH_C_STR(); typedef struct { uint16_t SPO2; // 血氧值 diff --git a/code/sdk/application/wearable/fd230app/nativeui/language/LanguageInit.cpp b/code/sdk/application/wearable/fd230app/nativeui/language/LanguageInit.cpp index 8840ec1d8..c9dcb392c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/language/LanguageInit.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/language/LanguageInit.cpp @@ -134,7 +134,7 @@ namespace OHOS } // 切换语言功能 - bool language::ChangeLanguage(int language_status) + bool language::ChangeLanguage(uint32_t currentLanguageId) { if (!FontGlobalManager::GetInstance() || !UIFont::GetInstance()) @@ -143,15 +143,16 @@ namespace OHOS return false; } - FontGlobalManager::GetInstance()->RegisterLanguageInfo(resFiles, MAX_LANGUAGE, language_status); - UIFont::GetInstance()->SetCurrentLangId(language_status); + FontGlobalManager::GetInstance()->RegisterLanguageInfo(resFiles, MAX_LANGUAGE, currentLanguageId); + UIFont::GetInstance()->SetCurrentLangId(currentLanguageId); - ConfigModel::GetInstance()->SetLanguage(language_status); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "resFiles[language_status]:%s", resFiles[language_status]); + ConfigModel::GetInstance()->SetLanguageCode(languages[currentLanguageId].code); + ConfigModel::GetInstance()->SetLanguage(currentLanguageId); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "resFiles[language_status]:%s", resFiles[language_status]); return true; } - bool language::ChangeLanguage(char *language_code) + bool language::ChangeLanguage( char *language_code) { if (!FontGlobalManager::GetInstance() || !UIFont::GetInstance()) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/language/LanguageInit.h b/code/sdk/application/wearable/fd230app/nativeui/language/LanguageInit.h index 4f71525ad..1e6a343eb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/language/LanguageInit.h +++ b/code/sdk/application/wearable/fd230app/nativeui/language/LanguageInit.h @@ -65,7 +65,7 @@ namespace OHOS ~language(); static language *GetInstance(); bool InitLangues(); - bool ChangeLanguage(int language_status); + bool ChangeLanguage(uint32_t); bool ChangeLanguage(char *language_code); bool fileExists(const char *fileName); }; 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 cf41b1c76..420a57ae8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/src/phoneaddressmodel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/src/phoneaddressmodel.cpp @@ -157,7 +157,6 @@ namespace OHOS void write_addressbook_bin_flle() { - #if 0 FILE *fp= fopen(ADDRESS_BOOK_PATH,"wb+"); if(fp==NULL) return; @@ -209,26 +208,26 @@ namespace OHOS } fwrite((void *)buf,1,offset,fp); fclose(fp); - #endif + } void add_addressbook(struct Contact *data) { - #if 0 - if(data->name!=NULL) + if(strlen(data->name)>0) { - addressbook_t.Contact_t[addressbook_t.num].name=(char *)malloc(strlen(data->name)); + // addressbook_t.Contact_t[addressbook_t.num].name=(char *)malloc(strlen(data->name)); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s %d",data->name,addressbook_t.num); + memset(addressbook_t.Contact_t[addressbook_t.num].name,0,NAME_LEN); strcpy(addressbook_t.Contact_t[addressbook_t.num].name,data->name); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s",addressbook_t.Contact_t[addressbook_t.num].name); } else { - addressbook_t.num-=1; - return; - addressbook_t.Contact_t[addressbook_t.num].name=(char *)malloc(strlen("未知")); + + //addressbook_t.Contact_t[addressbook_t.num].name=(char *)malloc(strlen("未知")); + memset(addressbook_t.Contact_t[addressbook_t.num].name,0,NAME_LEN); strcpy(addressbook_t.Contact_t[addressbook_t.num+1].name,"未知"); } @@ -240,72 +239,79 @@ namespace OHOS data->phone_num=2; for(int i=0;iphone_num;i++) { - if(data->phone_number_t[i].number) + if(strlen( data->phone_number_t[i].number)>0) { - addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].number - =(char *)malloc(strlen(data->phone_number_t[i].number)); + // addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].number + // =(char *)malloc(strlen(data->phone_number_t[i].number)); + memset(addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].number,0,NUMBER_LEN); strcpy(addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].number,data->phone_number_t[i].number); } else { - addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].number - =(char *)malloc(strlen("未知")); + // addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].number + // =(char *)malloc(strlen("未知")); + memset(addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].number,0,NUMBER_LEN); strcpy(addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].number,"未知"); } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneaddressbook::phoneaddressbook1111111111"); - if(data->phone_number_t[i].affiliating_area) + if(strlen(data->phone_number_t[i].affiliating_area)>0) { - addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].affiliating_area - =(char *)malloc(strlen(data->phone_number_t[i].affiliating_area)); + // addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].affiliating_area + // =(char *)malloc(strlen(data->phone_number_t[i].affiliating_area)); + memset(addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].affiliating_area,0,AREA_LEN); strcpy(addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].affiliating_area,data->phone_number_t[i].affiliating_area); } else { - addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].affiliating_area - =(char *)malloc(strlen("未知")); + // addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].affiliating_area + memset(addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].affiliating_area,0,AREA_LEN); strcpy(addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].affiliating_area,"未知"); } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneaddressbook::phoneaddressbook2222222222"); - if(data->phone_number_t[i].operator_t) + if(strlen(data->phone_number_t[i].operator_t)>0) { - addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].operator_t - =(char *)malloc(strlen(data->phone_number_t[i].operator_t)); + // addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].operator_t + // =(char *)malloc(strlen(data->phone_number_t[i].operator_t)); + memset(addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].affiliating_area,0,OPERATOR_LEN); strcpy(addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].operator_t,data->phone_number_t[i].operator_t); } else { - addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].operator_t - =(char *)malloc(strlen("未知")); + // addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].operator_t + // =(char *)malloc(strlen("未知")); + memset(addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].affiliating_area,0,OPERATOR_LEN); strcpy(addressbook_t.Contact_t[addressbook_t.num].phone_number_t[i].operator_t,"未知"); } } 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; + Contact data; + data.sex=0; + + strcpy(data.name,name); + data.phone_num=2; - // 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); + // =phone; + strcpy(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); // 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); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneaddressbook::phoneaddressbook"); + add_addressbook(&data); } void free_address() diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt b/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt index 95375d0a5..586eb62b8 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt +++ b/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt @@ -15,6 +15,9 @@ ${ROOT_DIR}/application/wearable/nativeapp/nativeui/heartrate/include ${ROOT_DIR}/application/wearable/fd230app/nativeui/weather/include ${ROOT_DIR}/application/wearable/fd230app/nativeui/heart_blood/health_service ${ROOT_DIR}/application/wearable/fd230app/nativeui/phone/include +${ROOT_DIR}/application/wearable/fd230app/nativeui/language/include +${ROOT_DIR}/application/wearable/fd230app/nativeui/language + ) set(SOURCES 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 32e99fe23..713397a29 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -17,6 +17,7 @@ #include "WeatherModel.h" #include "health_service.h" #include "phoneaddressmodel.h" +#include "LanguageInit.h" #ifdef __cplusplus #if __cplusplus extern "C" { @@ -47,6 +48,14 @@ extern "C" { #include "bleService.h" + + +void set_languaage(uint32_t id) +{ + OHOS:: language language; + language.ChangeLanguage(id); +} + char *addressbook(void)//获取通讯录保存文件地址路径 { return ADDRESS_BOOK_PATH; @@ -81,6 +90,27 @@ void set_ble_falg(bool falg) { ble_falg=falg; } +static char* JSON_F_buf=NULL; +const char *get_health_data_path(void) +{ + time_t now = time(0); + tm *ltm = localtime(&now); + char day[20]; + strftime(day, sizeof(day), "%Y%m%d", ltm); + char buf[124]={0}; + sprintf(buf,"%s%s.json",OHOS::GET_HEALTH_JSON_PATH_C_STR(),day); + if(JSON_F_buf!=NULL) + { + free(JSON_F_buf); + JSON_F_buf=NULL; + + } + JSON_F_buf=(char *)malloc(strlen(buf)+1); + strcpy(JSON_F_buf,buf); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s",JSON_F_buf); + return JSON_F_buf; +} void set_weather_now_data(int humidity, char* windScale, char* textNight,int uvIndex,int temp,int iconNight) { 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 4199b7fb9..e5f438867 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -22,7 +22,9 @@ enum PAIRING { DEVICEBIND = 0,// DEVICEUNBIND,//设备解绑通知 - DeviceUnBindingRequest//设备解绑请求(与新设备连接)通知 + DeviceUnBindingRequest,//设备解绑请求(与新设备连接)通知 + REBOOT, + SHUTDOWN }; void set_weather_now_data(int humidity, char* windScale, char* textNight,int uvIndex,int temp,int iconNight); @@ -34,6 +36,7 @@ void set_ble_falg(uint8_t falg); uint8_t ble_is_connect_ready(void); char *addressbook(void); void addressbookToRead(void); +const char *get_health_data_path(void); #ifdef __cplusplus #if __cplusplus 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 af4bba70b..b3fb0d9c6 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -2340,7 +2340,7 @@ static void SetLanguageCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *to if(Check_CRC(crcnum,len,crcvalue)) { uint8_t language = crcnum[0]; - + set_languaage(language); value[17] = 1; //1 操作成功 2 操作失败 value[18] = Calculate_CRC(value,18); sendBleData(value,19); @@ -2908,6 +2908,7 @@ static void GetFactoryCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *tot } } //APP发送重新启动 +static uint8_t power_buf[2]={0}; static void GetResetCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totaldata,uint8_t crcvalue) { uint8_t value[19]; @@ -2926,7 +2927,10 @@ static void GetResetCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *total value[17] = 1;// value[18] = Calculate_CRC(value,18); + power_buf[0]=REBOOT; + CustomEventPublish(TOPIC_EVENT_DEVICE_BIND,power_buf,2); sendBleData(value,19); + }else { value[17] = 0; @@ -2953,6 +2957,8 @@ static void GetPowerOffCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *to value[17] = 1;// value[18] = Calculate_CRC(value,18); + power_buf[0]=SHUTDOWN; + CustomEventPublish(TOPIC_EVENT_DEVICE_BIND,power_buf,2); sendBleData(value,19); }else { @@ -3753,8 +3759,7 @@ void type2AE3Data(uint16_t cmd ,uint8_t *data,uint16_t datalen,uint8_t *totaldat GetSynDataEndCmd(cmd,data,datalen,totaldata,crcvalue); break; case SYN_HEART_HISTORY_DATA_CMD://同步心率历史数据 - heartDataCmd(cmd,data,datalen,totaldata,crcvalue); - break; + //heartDataCmd(cmd,data,datalen,totaldata,crcvalue); case SYN_SPO2_HISTORY_DATA_CMD://同步血氧历史数据 case SYN_STEP_HISTORY_DATA_CMD: //同步步数历史数据 case SYN_FAT_BURN_HISTORY_DATA_CMD://同步燃脂时间数据 @@ -3763,7 +3768,7 @@ void type2AE3Data(uint16_t cmd ,uint8_t *data,uint16_t datalen,uint8_t *totaldat case SYN_DIS_HISTORY_DATA_CMD://同步距离历史数据 case SYN_BASIC_TRANIN_HISTORY_DATA_CMD://同步基础训练历史数据 case SYN_SLEEP_HISTORY_DATA_CMD://睡眠历史数据 - // readDevDataBle(totaldata,datalen+18,crcvalue); + readDevDataBle(totaldata,datalen+18,crcvalue); break; default: @@ -3815,129 +3820,189 @@ uint8_t bleSendTypeID=0; //发送的数据类型 //发送读出来的设备数据to APP uint16_t max_mtu_szie_data_len = 200; uint32_t EACH_DATA_LEN=0;//每种数据类型的的长度 -void sendReadData(void) + +void send_big_data(uint8_t flag,char *data,int datalen,int total,uint32_t Packet_id,uint32_t packet_total,uint8_t type_id) +{ + uint8_t buf[512]={0}; + buf[0]=0x72; + buf[1]=0x01; + buf[2]=type_id; + memcpy(buf+3,&packet_total,4); + memcpy(buf+7,&total,4); + memcpy(buf+11,&Packet_id,4); + memcpy(buf+15,&datalen,2); + if(flag) + { + uint16_t t=0x00; + memcpy(buf+17,&t,2); + memcpy(buf+19,data,datalen); + buf[19+datalen] = Calculate_CRC_Big((uint8_t *)data,datalen); + sendDataNow(buf,19+datalen+1); + + } + else + { + + memcpy(buf+17,data,datalen); + buf[17+datalen] = Calculate_CRC_Big((uint8_t *)data,datalen); + printf("xxxxxxxxxxxxx\r\n"); + sendDataNow(buf,17+datalen+1); + + } + +} + +void Read_spo2_file_buf_Data(uint8_t id) { sendbigDataBufState = true;//分包同步数据不允许打断 - static uint32_t packCount = 0; - uint8_t buf[517]; - memset(buf,0,517); - uint32_t dataLen = 0; - uint32_t sendDataLen = 0; - uint32_t totalLen = 0; - dataLen = 640; - uint32_t dataPack = 1; - uint16_t dataPackLen = 640;//减掉前面17+2个字节的包头总共就是19个数据(多包) 一包就减去17个字节 - uint32_t time = 0; - uint32_t step = 0; - packCount = 1; - - uint16_t startDataLen = 17; - uint8_t crc = 0x00; - uint8_t crcvalue = 0x00; - uint16_t totalEnd = 0; - buf[0] = 0x72; - buf[1] = 0x01; - buf[2] = bleSendTypeID; - memcpy(buf+3,&dataPack,4); - memcpy(buf+7,&dataLen,4); - memcpy(buf+11,&dataPack,4); - memcpy(buf+15,&dataPackLen,2); - if(dataLen > ble_nus_max_data_len)//300-192=108 - { - startDataLen = 19; - } - while (1) - { - - - //json id=0 - time = 1711348052+3600*packCount; - memcpy(buf+startDataLen,&time,4);//21 - startDataLen=startDataLen+4; - step = 1000+packCount*1000; - memcpy(buf+startDataLen,&step,4);//25 - startDataLen=startDataLen+4;//时间 步数 时间 步数 时间 步数 每八个字节一个数据 + char *buf=(char *)malloc(sizeof(char)*512); + + const char *path=get_health_data_path(); + FILE *fp= fopen(path,"r+"); + if(fp==NULL) + { + printf("打开文件失败%s\r\n",path); + return; + } + int ret=fread(buf,1,512,fp); + uint8_t count=1; + while (ret==512) + { + buf=realloc(buf,512*count+512); + ret=fread(buf+512*count,1,512,fp); + count++; + } + cJSON *heart_data=cJSON_Parse(buf); + free(buf); + printf("读文件\r\n"); + if(heart_data==NULL) + { + printf("解析失败\r\n"); + } + cJSON * heart_data_list=cJSON_GetObjectItem(heart_data,"spo2_data_list"); + int item_num=cJSON_GetArraySize(heart_data_list); + char *send_buf=(char *)malloc(sizeof(char)*HEART_DATA_LEN); + int send_len=0; + uint32_t Packet_id=1; + uint16_t packet_total; + if(item_num%96==0) + { + packet_total=item_num/96; + } + else + { + packet_total=item_num/96+1; + } + for(int i=0;ivalueint; + uint8_t vale=cJSON_GetObjectItem(heart_data_item,"oxygen_value")->valueint; + memcpy(send_buf+send_len,×tamp,4); + send_len+=4; + memcpy(send_buf+send_len,&vale,1); + send_len+=1; - //498 - // printf("startDataLen:%d totalEnd:%d ble_nus_max_data_len %d\r\n",startDataLen,totalEnd,ble_nus_max_data_len); - if( startDataLen+EACH_DATA_LEN > ble_nus_max_data_len-3){ - // printf("startDataLen111111111111:%d totalEnd:%d crcvalue:%d\r\n",startDataLen,totalEnd,crcvalue); - totalEnd = totalEnd+startDataLen;//240 300-240 + if((i%96==0 && i!=0) || (item_num-1==i)) + { + //发送数据 + if(item_num-1==i) + { + send_big_data(0,send_buf,send_len,item_num*5,Packet_id,packet_total,0x40); + free(send_buf); + sendbigDataBufState=false; - - // printf("startDataLen22222222222:%d totalEnd:%d crcvalue:%x\r\n",startDataLen,totalEnd,crcvalue); - if((totalEnd-17) >= dataLen && totalEnd > 17) + }else { - memcpy(buf+11,&packCount,4); - dataPackLen = startDataLen-17; - memcpy(buf+15,&dataPackLen,2); - crcvalue = Calculate_CRC_Big(buf+17,dataPackLen); - printf("end crcvalue1:%x\r\n",crcvalue); - buf[startDataLen] = crcvalue; - sendDataNow(buf,startDataLen+1); - - packCount = 1; - sendbigDataBufState = false; - break; - }else{ - memcpy(buf+11,&packCount,4); - dataPackLen = startDataLen-19;//减掉前面17+2个字节的包头总共就是19个数据 - memcpy(buf+15,&dataPackLen,2); - crcvalue = Calculate_CRC_Big(buf+19,dataPackLen); - uint16_t pack_size = ble_nus_max_data_len-17-crcvalue; - memcpy(buf+17,&pack_size,2); - printf("end crcvalue3:%x %d %d %d\r\n",crcvalue,ble_nus_max_data_len,pack_size,crcvalue); - buf[startDataLen] = crcvalue;// - sendDataNow(buf,startDataLen+1); - packCount+=1; - if(dataLen - totalEnd > ble_nus_max_data_len)//总的减去已发送的数据,如果还是大于最大mtu的大小还是还是按照分包来计算 - { - startDataLen = 19; - } - else{ - startDataLen = 17; - } + send_big_data(1,send_buf,send_len,item_num*5,Packet_id,packet_total,0x40); + free(send_buf); + send_buf=(char *)malloc(sizeof(char)*HEART_DATA_LEN); + send_len=0; } - // printf("startDataLen2222222222:%d totalEnd:%d\r\n",startDataLen,totalEnd); } - else{ - if(packCount > 0) + send_buf=realloc(send_buf,i*5+5); + } + cJSON_free(heart_data); + +} + +void Read_heart_file_buf_Data(uint8_t num) +{ + sendbigDataBufState = true;//分包同步数据不允许打断 + char *buf=(char *)malloc(sizeof(char)*512); + + const char *path=get_health_data_path(); + FILE *fp= fopen(path,"r+"); + if(fp==NULL) + { + return; + } + int ret=fread(buf,1,512,fp); + uint8_t count=1; + while (ret==512) + { + buf=realloc(buf,512*count+512); + ret=fread(buf+512*count,1,512,fp); + count++; + } + printf("读文件\r\n"); + cJSON *heart_data=cJSON_Parse(buf); + free(buf); + if(heart_data==NULL) + { + printf("解析失败\r\n"); + } + cJSON * heart_data_list=cJSON_GetObjectItem(heart_data,"heart_data_list"); + int item_num=cJSON_GetArraySize(heart_data_list); + char *send_buf=(char *)malloc(sizeof(char)*HEART_DATA_LEN); + int send_len=0; + uint32_t Packet_id=1; + uint16_t packet_total; + if(item_num%num==0) + { + packet_total=item_num/num; + } + else + { + packet_total=item_num/num+1; + } + for(int i=0;ivalueint; + uint8_t vale=cJSON_GetObjectItem(heart_data_item,"heart_value")->valueint; + printf("heart_value :%d\r\n",vale); + printf("timestamp :%d\r\n",timestamp); + memcpy(send_buf+send_len,×tamp,4); + send_len+=4; + memcpy(send_buf+send_len,&vale,1); + send_len+=1; + + if(((i+1)%num==0 && i!=0) || (item_num-1==i)) + { + //发送数据 + if(item_num-1==i) { - totalEnd = totalEnd+EACH_DATA_LEN;//第二包开始只加每个数据类型的总的字节数据大小 比如步数 数据类型 时间 步数 总共是8个就加8 - // printf("pack1 startDataLen22222222222:%d totalEnd:%d crcvalue:%x\r\n",startDataLen,totalEnd,crcvalue); - if((totalEnd-17) >= dataLen && totalEnd > 17) - { - memcpy(buf+11,&packCount,4); - dataPackLen = startDataLen-17; - memcpy(buf+15,&dataPackLen,2); - crcvalue = Calculate_CRC_Big(buf+17,dataPackLen); - buf[startDataLen] = crcvalue; - sendDataNow(buf,startDataLen+1); - sendbigDataBufState = false; - break; - } - }else{ - if(dataPackLen < ble_nus_max_data_len) //只有总的包数小于最大的mtu的大小 - { - totalEnd = startDataLen-17;//不包含前17个字节的数据,前17个不是数据类型 - // printf("pack0 startDataLen22222222222:%d totalEnd:%d crcvalue:%x\r\n",startDataLen,totalEnd,crcvalue); - if(totalEnd >= dataLen && totalEnd > 0) - { - memcpy(buf+11,&packCount,4); - dataPackLen = startDataLen-17; - memcpy(buf+15,&dataPackLen,2); - crcvalue = Calculate_CRC_Big(buf+17,dataPackLen); - printf("total end crcvalue2:%x\r\n",crcvalue); - buf[startDataLen] = crcvalue;//校验和的值 最后一个校验和也要发给app - sendDataNow(buf,startDataLen+1); - sendbigDataBufState = false; - break; - } - } + printf("sendbuf :%s sendbuf_len%d\r\n",send_buf,send_len); + send_big_data(0,send_buf,send_len,item_num*5,Packet_id,packet_total,0x40); + free(send_buf); + sendbigDataBufState=false; + + }else + { + send_big_data(1,send_buf,send_len,item_num*5,Packet_id,packet_total,0x40); + free(send_buf); + send_buf=(char *)malloc(sizeof(char)*HEART_DATA_LEN); + send_len=0; } } + send_buf=realloc(send_buf,i*5+10); } + cJSON_free(heart_data); + } + + //手机app下发读设备数据指令 void readDevDataBle(uint8_t *crcnum,uint16_t len,uint8_t crcvalue) { @@ -3948,9 +4013,12 @@ void readDevDataBle(uint8_t *crcnum,uint16_t len,uint8_t crcvalue) { case 0x40://同步心率历史数据 EACH_DATA_LEN = HEART_DATA_LEN; + Read_heart_file_buf_Data(3); break; case 0x41://同步血氧历史数据 + printf("同步血氧数据\r\n"); EACH_DATA_LEN = SPO2_DATA_LEN; + Read_spo2_file_buf_Data(0x41); break; case 0x43: //同步步数历史数据 EACH_DATA_LEN = STEP_DATA_LEN; @@ -3975,7 +4043,7 @@ void readDevDataBle(uint8_t *crcnum,uint16_t len,uint8_t crcvalue) default: break; } - sendReadData(); + //sendReadData(); }else{ crcnum[0] = 0x72; crcnum[len-1] = 0; diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/charge_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/charge_notification.h index 809a6f84e..357ed567f 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/charge_notification.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/charge_notification.h @@ -10,7 +10,7 @@ namespace OHOS UIViewGroup* lowPowerShow(void); void set_lowpower_falg(bool falg); void FreelowPower(void); - void low_power_paly(void); + void low_power_paly(bool); class lowppowrAnimatorStopListener :public OHOS::UIImageAnimatorView::AnimatorStopListener { diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index bfe9013eb..feeab27aa 100755 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -40,6 +40,7 @@ #include "testhrsenson.h" #include "ConfigModel.h" #include "power_display_service.h" +#include "bletest.h" //#include "Systemupgrade.h" namespace OHOS { @@ -278,7 +279,7 @@ void MsgCenterNotifyLowPowerAlarmProc(const Topic topic, Request* req) if(*x==3) { //倒计时结束后,直接执行关机动画 - low_power_paly(); + low_power_paly(true); } else if(*x==0) { @@ -742,19 +743,53 @@ void MsgCenterNotifyCat1PowerOnProc(const Topic topic, Request* req) #endif -#ifdef SUPPORT_DEVICE_PAIRING_NOTIFICATION //如果支持设备配对通知 +//#ifdef SUPPORT_DEVICE_PAIRING_NOTIFICATION //如果支持设备配对通知 //设备绑定通知 void MsgCenterNotifyDeviceBindProc(const Topic topic, Request* req) { - unused(req); + //unused(req); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyBindProc Bind!"); const power_display_svr_api_t *display_api = power_display_svr_get_api(); if (display_api->get_screen_state() != SCREEN_ON) { display_api->turn_on_screen(); } - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); - NotificationManager::GetInstance()->ShowNotify(showDeviceBindingNotify, (uint16_t)topic, true); + uint8_t* data=(uint8_t*)req->data; + if(data!=NULL && req->len>=2) + { + switch (data[0]) + { + case DEVICEBIND: + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); + NotificationManager::GetInstance()->ShowNotify(showDeviceBindingNotify, (uint16_t)topic, true); + break; + case DEVICEUNBIND: + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); + NotificationManager::GetInstance()->ShowNotify(showDeviceUnBindingNotify, (uint16_t)topic, true); + break; + case DeviceUnBindingRequest: + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); + NotificationManager::GetInstance()->ShowNotify(showDeviceUnbindingRequestNotify, (uint16_t)topic, true); + break; + case SHUTDOWN: + set_lowpower_falg(true); + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); + NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true); + low_power_paly(true); + break; + case REBOOT: + set_lowpower_falg(true); + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); + NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true); + low_power_paly(false); + break; + + default: + break; + } + + } + } //设备解绑通知 @@ -785,7 +820,7 @@ void MsgCenterNotifyDeviceUnBindingRequestProc(const Topic topic, Request* req) NotificationManager::GetInstance()->ShowNotify(showDeviceUnbindingRequestNotify, (uint16_t)topic, true); } -#endif +//#endif //查找手表通知 void MsgCenterNotifyFindWatchProc(const Topic topic, Request* req) diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp index a1c358d66..f2c2a9b1d 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp @@ -175,9 +175,11 @@ namespace OHOS } } - void low_power_paly(void) + bool poweroff_flag=true; + void low_power_paly(bool falg) { //uapi_poweroff_device(); // 关机 + poweroff_flag=falg; group->SetVisible(true); UIImageAnimatorView::AnimatorStopListener *stoplistener = static_cast(lowppowrAnimatorStopListener::GetInstance()); ShutDownImageAnimatorView->SetAnimatorStopListener(stoplistener); @@ -313,7 +315,7 @@ namespace OHOS if(battery_falg) { osTimerStop(low_power_timer); - low_power_paly(); + low_power_paly(true); } else @@ -330,9 +332,10 @@ namespace OHOS { //UNUSED(view); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "xxxxxxxxxxxxxxxxxxxxOnAnimatorStop"); - - uapi_poweroff_device(); // 关机 - + if(poweroff_flag) + uapi_poweroff_device(); // 关机 + else + uapi_reboot_device(); //NotificationManager::GetInstance()->StopNotify(); // // if(strcmp(view.GetViewId(),LOW_POWER_BUTTON)!=0)