From: hcj <1224667075@qq.com> Date: Fri, 19 Apr 2024 03:49:25 +0000 (+0800) Subject: 蓝牙设置用户数据设置获取步数目标及添加通讯录读取到开关机 X-Git-Tag: release_V1.2.70_20241020_135402~1170 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=refs%2Fchanges%2F51%2Fhead;p=mirrors%2FFD230.git 蓝牙设置用户数据设置获取步数目标及添加通讯录读取到开关机 --- 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 bd01055d2..abb090ed7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h @@ -64,6 +64,7 @@ namespace OHOS CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION, //运动目标时长 CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE, //运动目标距离 CONFIGMODEL_ITEM_DNOTDISTURB,//勿扰模式 + CONFIGMODEL_ITEM_TRANING_FREQ,//训练实时数据上传频率 CONFIGMODEL_ITEM_MAX, } ; @@ -176,6 +177,7 @@ namespace OHOS {ConfigDataType::DATATYPE_INT, "GoalDuration", "30" },// CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION, //运动目标时长 30(分钟) {ConfigDataType::DATATYPE_DOUBLE, "GoalDistance", "8.0" },// CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE, //运动目标距离 8.0(km) {ConfigDataType::DATATYPE_BOOL, "Dnotdisturb", "false" },// CONFIGMODEL_ITEM_DNOTDISTURB //勿扰模式默认关闭 + {ConfigDataType::DATATYPE_INT, "traningfreq", "10" },// CONFIGMODEL_ITEM_TRANING_FREQ //训练实时数据上传频率//单位秒 }; ConfigModel(); // 私有构造函数,确保无法在外部实例化 ConfigModel(const ConfigModel &) = delete; // 禁止拷贝构造 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 722bb88b5..3da92dc6a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/src/phoneaddressmodel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/src/phoneaddressmodel.cpp @@ -160,7 +160,7 @@ namespace OHOS FILE *fp= fopen(ADDRESS_BOOK_PATH,"wb+"); if(fp==NULL) return; - char buf[256*20]; + char buf[128*20]; // int ret=fread(buf,1,512,fp); // int offset_f=512; // while (ret==512) 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 586eb62b8..afc10ddcb 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt +++ b/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt @@ -17,6 +17,8 @@ ${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 +${ROOT_DIR}/application/wearable/fd230app/nativeui/traing/training_card/include +${ROOT_DIR}/application/wearable/fd230app/nativeui/config/include ) 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 7c6e4272f..484461bba 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -18,6 +18,9 @@ #include "health_service.h" #include "phoneaddressmodel.h" #include "LanguageInit.h" +#include "ConfigModel.h" +// #include "TraingCardPresenter.h" + #ifdef __cplusplus #if __cplusplus extern "C" { @@ -46,7 +49,7 @@ extern "C" { #include "custom_utils.h" #include "string.h" #include "bleService.h" - +#include "bletest.h" void add_addressbookToRead(char *data)//转化用于·c文件 { @@ -77,6 +80,13 @@ void addressbookToRead(void)//转化用于·c文件 OHOS::read_addressbook_bin_file(); return; } + +void addressbookTowrite(void)//转化用于·c文件 +{ + OHOS::write_addressbook_bin_flle(); + return; +} + // struct Weather_data // { // int humidity; @@ -88,6 +98,74 @@ void addressbookToRead(void)//转化用于·c文件 // }; uint8_t ble_falg=0; +void set_user_data(msg_user_info_t data) +{ + + OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); + printf("高:%d\r\n",data.height); + p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_CUSTOM_DATA_HEIGHT,data.height); + printf("重:%d\r\n",data.weight); + p_ConfigModel->set_condigData_Double(OHOS::ConfigModel::CONFIGMODEL_ITEM_CUSTOM_DATA_WEIGHT,(double)data.weight); + printf("性别:%d\r\n",data.gender); + p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_CUSTOM_DATA_SEX,data.gender); + printf("年纪:%d\r\n",data.age); + p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_CUSTOM_DATA_AGE,data.age); + printf("目标步数:%d\r\n",data.target_step); + p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEPCOUNT,data.target_step); + + /* + 目标站立 + p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_CUSTOM_DATA_AGE,data.target_stand); + 目标燃脂 + p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_CUSTOM_DATA_AGE,data.fat_time); + 时制 + p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_CUSTOM_DATA_AGE,data.timeformat); + */ + +} + +int get_goal_stepcount(void) +{ + OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); + return p_ConfigModel->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEPCOUNT); +} + +int get_vibrationremiander(void) +{ + OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); + return p_ConfigModel->GetVibrationReminder(); +} + +int get_SilentMode(void) +{ + OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); + return p_ConfigModel->GetSilentMode(); +} + +void set_goal_stepcount(uint32_t step) +{ + OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); + + p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEPCOUNT,step); + return ; +} + +void set_vibrationremiander(uint8_t falg) +{ + OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); + p_ConfigModel->SetVibrationReminder(falg); + return ; +} + +void set_SilentMode(uint8_t falg) +{ + OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); + p_ConfigModel->SetSilentMode(falg); + return; +} + + + uint8_t ble_is_ready(void) { return ble_falg; 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 27241aecf..715a99ac1 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -25,6 +25,8 @@ extern "C" #include "stdint.h" #include "errcode.h" +#include "bleEvent.h" + struct ancs_data_info_t { int uid;//uid 消息唯一编号 @@ -64,12 +66,24 @@ void set_weather_address_data(int lat, char* atm, char* city,char* subLocality,i void set_weather_one_data(int tempMin, int iconDay,int fxDate, int tempMax, char *textDay,int x); uint8_t ble_is_ready(void); -void set_ble_falg(uint8_t falg); +void set_ble_falg(bool falg); uint8_t ble_is_connect_ready(void); char *addressbook(void); void addressbookToRead(void); +void addressbookTowrite(void); const char *get_health_data_path(void); void add_addressbookToRead(char *data); + +void set_user_data(msg_user_info_t data); +int get_goal_stepcount(void); +int get_vibrationremiander(void); +int get_SilentMode(void); +void set_goal_stepcount(uint32_t step); + +void set_vibrationremiander(uint8_t falg); + +void set_SilentMode(uint8_t falg); + #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 d1bce8cc7..22eab0947 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -146,6 +146,13 @@ int ble_recv_msg_callback(uint8_t writ_read,uint16_t msg_typeID, uint8_t *msg_da drink_on_t.drink_on = 1; memcpy(msg_data,&drink_on_t,sizeof(msg_drink_param_info_t)); break; + + case USER_INFOR_CMD: + // memset(&user_info,0,sizeof(user_info)); + // memcpy(&user_info,msg_data,sizeof(user_info)); + set_user_data(user_info); + break; + default: break; @@ -265,6 +272,58 @@ void sendDataNow(uint8_t *buf,uint16_t len) svr_ble_bt_gatts_noyify(buf,len); } } + +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(data==NULL) + { + buf[17+datalen] = Calculate_CRC_Big((uint8_t *)data,datalen); + if(flag) + sendDataNow(buf,17+datalen+1); + else + sendBleData(buf,17+datalen+1); + + }else + { + memcpy(buf+17,data,datalen); + buf[17+datalen] = Calculate_CRC_Big((uint8_t *)data,datalen); + printf("xxxxxxxxxxxxx\r\n"); + if(flag) + sendDataNow(buf,17+datalen+1); + else + sendBleData(buf,17+datalen+1); + + } + + + // } + +} + +void sendtraningdata(msg_get_train_data_info_t *data) +{ + cJSON* dataJSON=cJSON_CreateObject(); + cJSON_AddNumberToObject(dataJSON,"st",data->st); + cJSON_AddNumberToObject(dataJSON,"hr",data->hr); + cJSON_AddNumberToObject(dataJSON,"ca",data->ca); + cJSON_AddNumberToObject(dataJSON,"di",data->di); + cJSON_AddNumberToObject(dataJSON,"stp",data->stp); + cJSON_AddNumberToObject(dataJSON,"ti",data->ti); + char *jsonString = cJSON_PrintUnformatted(dataJSON); + uint32_t data_len=strlen(jsonString); + printf("发送训练实时数据%d %s\r\n",data_len,jsonString); + send_big_data(0,jsonString,data_len,data_len,1,1,0x15); + + +} //发送ble数据 uint8_t phone_mac[6];//手机下发的mac地址 第一次连接为空 uint8_t parie_mac[6];//配对完成之后的的mac地址 @@ -1544,6 +1603,49 @@ void GetDrinkSetParamCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *tota func(WRITE_FLASH_DATA,SET_DRINK_PARAM_CMD,&drink_info,sizeof(msg_drink_set_param_info_t)); } + sendBuf[17] = 1; + sendBuf[18] = Calculate_CRC(sendBuf,18); + sendBleData(sendBuf,19); + } + else + { + sendBuf[17] = 0; + sendBuf[18] = Calculate_CRC(sendBuf,18); + sendBleData(sendBuf,19); + } + +} +//APP设置步数目标 +void SetsteptargetParamCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totalData,uint8_t crcvalue) +{ + uint32_t tmp = 1; + uint16_t tmp_data = 1; + uint8_t sendBuf[19]; + memset(sendBuf,0,19); + sendBuf[0] = 0x72; + sendBuf[1] = 0x02; + sendBuf[2] = 0x16; + memcpy(sendBuf+3,&tmp,4); + memcpy(sendBuf+7,&tmp,4); + memcpy(sendBuf+11,&tmp,4); + memcpy(sendBuf+15,&tmp_data,2); + + if(Check_CRC(crcnum,len,crcvalue)) + { + + uint32_t targetStep; + memcpy(&targetStep,crcnum,4); + uint8_t ringOn=crcnum[5]; + uint8_t vibration=crcnum[6]; + uint8_t notify=crcnum[7]; + printf("设置步数:%d\r\n",targetStep); + set_goal_stepcount(targetStep); + + set_vibrationremiander(vibration); + + set_SilentMode(ringOn); + + sendBuf[17] = 1; sendBuf[18] = Calculate_CRC(sendBuf,18); sendBleData(sendBuf,19); @@ -1655,7 +1757,7 @@ void GetWeatherCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totalData, } } -//获取用户数据 app下发的 +//APP下发设置用户数据 void getUserInfo(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totalData,uint8_t crcvalue)// { uint8_t value[19]; @@ -1681,9 +1783,11 @@ void getUserInfo(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totalData,ui user_info.age = crcnum[0]; user_info.gender = crcnum[1]; user_info.height = crcnum[2]; - memcpy(crcnum+3,&user_info.weight,2); - memcpy(crcnum+5,&user_info.target_step,4); - memcpy(crcnum+9,&user_info.fat_time,2); + memcpy(&user_info.weight,crcnum+3,2); + //memcpy(crcnum+3,&user_info.weight,2); + memcpy(&user_info.target_step,crcnum+5,4); + //memcpy(crcnum+5,&user_info.target_step,4); + memcpy(&user_info.fat_time,crcnum+9,2); user_info.target_stand = crcnum[11]; user_info.timeformat = crcnum[12]; if(func != NULL) @@ -1856,6 +1960,10 @@ void type2AE4Data(uint8_t *buf_cmd,uint8_t *data,uint16_t datalen,uint8_t *total case SET_DRINK_PARAM_CMD://app下发的喝水提醒设置 GetDrinkSetParamCmd(typeID,data,datalen,totalData,crcvalue); break; + case SET_STEP_TARGET_CMD://app下发的步数目标设置 + SetsteptargetParamCmd(typeID,data,datalen,totalData,crcvalue); + break; + case SET_WEATHER_DATA_CMD://app下发的天气数据 GetWeatherCmd(typeID,data,datalen,totalData,crcvalue); break; @@ -3105,10 +3213,11 @@ static void GetTargetStepCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t * memcpy(value+15,&tmp_data,2); if(1) { - uint32_t targetStep = 10000;//目标步数 4字节 - uint8_t ringOn = 0;//铃声提醒 - uint8_t vibration = 0;//振动提醒 - uint8_t notify = 0;//通知提醒 + uint32_t targetStep = get_goal_stepcount();//目标步数 4字节 + printf("目标步数:%d\r\n",targetStep); + uint8_t ringOn = get_SilentMode();//铃声提醒 + uint8_t vibration = get_vibrationremiander();//振动提醒 + uint8_t notify = 1;//通知提醒 memcpy(&value[17],&targetStep,4);//目标步数 value[21] = ringOn;//铃声提醒 value[22] = vibration;//振动提醒 @@ -3833,47 +3942,7 @@ uint8_t bleSendTypeID=0; //发送的数据类型 uint16_t max_mtu_szie_data_len = 200; uint32_t EACH_DATA_LEN=0;//每种数据类型的的长度 -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) - // { - // uint8_t crcvalue=Calculate_CRC_Big((uint8_t *)data,datalen); - // // uint16_t t= ble_nus_max_data_len -17 -crcvalue; - // // memcpy(buf+17,&t,2); - // memcpy(buf+17,data,datalen); - - // buf[17+datalen] = crcvalue; - // sendDataNow(buf,17+datalen+1); - - // } - // else - // { - if(data==NULL) - { - buf[17+datalen] = Calculate_CRC_Big((uint8_t *)data,datalen); - sendDataNow(buf,17+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 num) { @@ -3884,7 +3953,7 @@ void Read_spo2_file_buf_Data(uint8_t num) FILE *fp= fopen(path,"r+"); if(fp==NULL) { - send_big_data(0,NULL,0,0,1,1,0x40); + send_big_data(1,NULL,0,0,1,1,0x41); printf("打开文件失败%s\r\n",path); return; } @@ -3935,13 +4004,13 @@ void Read_spo2_file_buf_Data(uint8_t num) if(item_num-1==i) { 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); + send_big_data(1,send_buf,send_len,item_num*5,Packet_id,packet_total,0x41); free(send_buf); sendbigDataBufState=false; }else { - send_big_data(1,send_buf,send_len,item_num*5,Packet_id,packet_total,0x40); + send_big_data(1,send_buf,send_len,item_num*5,Packet_id,packet_total,0x41); free(send_buf); send_buf=(char *)malloc(sizeof(char)*HEART_DATA_LEN); send_len=0; @@ -3963,7 +4032,7 @@ void Read_heart_file_buf_Data(uint8_t num) FILE *fp= fopen(path,"r+"); if(fp==NULL) { - send_big_data(0,NULL,0,0,1,1,0x40); + send_big_data(1,NULL,0,0,1,1,0x40); return; } int ret=fread(buf,1,512,fp); @@ -4013,7 +4082,7 @@ void Read_heart_file_buf_Data(uint8_t num) if(item_num-1==i) { 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); + send_big_data(1,send_buf,send_len,item_num*5,Packet_id,packet_total,0x40); free(send_buf); sendbigDataBufState=false; @@ -4050,7 +4119,7 @@ void readDevDataBle(uint8_t *crcnum,uint16_t len,uint8_t crcvalue) case 0x41://同步血氧历史数据 printf("同步血氧数据\r\n"); EACH_DATA_LEN = SPO2_DATA_LEN; - Read_spo2_file_buf_Data(0x41); + Read_spo2_file_buf_Data(num); break; case 0x43: //同步步数历史数据 EACH_DATA_LEN = STEP_DATA_LEN; 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 e58123368..7bbb6270e 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h @@ -253,9 +253,24 @@ typedef struct #pragma pack() #pragma pack(1) -typedef struct -{ - +// 实时训练数据格式 +// { +// "st":1637825067, +// "hr":120, +// "ca":3657, //卡路里为该数值乘以0.1 +// "di":5273, //里程单位为米 +// "stp":1234, +// "ti:":3 +// } +typedef struct +{ + uint32_t st; + uint32_t hr; + uint32_t ca; + uint32_t di; + uint32_t stp; + uint32_t ti; + }msg_get_train_data_info_t;// SET_REAL_DATA_FREQ_CM获取实时训练数据 #pragma pack() @@ -490,6 +505,7 @@ TYPE:02 #define SET_WATCH_HR_SET_PARAM_CMD 0x0212 //app发送心率设置参数 #define SET_WATCH_SPO2_SET_PARAM_CMD 0x0213 //app发送血氧设置参数 #define SET_DRINK_PARAM_CMD 0x0214 //app发送喝水提醒设置 +#define SET_STEP_TARGET_CMD 0x0216 //app发送步数目标 #define SET_WEATHER_DATA_CMD 0x0220 //发送天气数据 #define SET_ALARM_DATA_CMD 0x0221 //发送闹钟数据 #define DELETE_FILE_CMD 0x0222 //删除指定文件 @@ -593,6 +609,8 @@ void cameraSend(void); void senfindphoneSend(uint8_t flag); void readDevDataBle(uint8_t *crcnum,uint16_t len,uint8_t crcvalue); void free_ble_data(void); + +void sendtraningdata(msg_get_train_data_info_t *data); #ifdef __cplusplus } #endif diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 73486935d..0e8d67873 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -126,6 +126,8 @@ void uapi_reboot_device(void) void shutdown_reboot_prejobs_task(void) { + addressbookTowrite(); + uapi_calendar_store_date(); sync_all_config_to_disk(); } @@ -137,7 +139,7 @@ void shutdown_reboot_prejobs(void) taskcfg.create_queue_handle = NULL; taskcfg.attr.name="shutdown_reboot_prejobs"; taskcfg.attr.priority = osPriorityNormal; - taskcfg.attr.stack_size = 0x1000; + taskcfg.attr.stack_size = 0x1000*2; taskcfg.func = shutdown_reboot_prejobs_task; taskcfg.use_mem = USE_EXTEND_MEM; @@ -221,6 +223,7 @@ void startup_post_init_task(void) initializeRaiseToWake(); LOS_Msleep(5000); + addressbookToRead(); if ( poweron_cat1_on_bootup_flag() ) { PRINT("PowerOn Cat1 !\r\n");