From: hcj <1224667075@qq.com> Date: Tue, 9 Apr 2024 06:04:48 +0000 (+0800) Subject: 蓝牙天气协议对接 X-Git-Tag: release_V1.2.70_20241020_135402~1225^2 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=149c2ecc615a35ae57eb1d50ec078de32b501ce2;p=mirrors%2FFD230.git 蓝牙天气协议对接 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index fca48d5ea..4e15d3f7d 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -112,7 +112,8 @@ set(PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/include/dial ${ROOT_DIR}/middleware/services/media/foundation/sample/wrapper ${ROOT_DIR}/application/wearable/service/msg_center/include - ${ROOT_DIR}/application/wearable/service/ble_service + ${ROOT_DIR}/application/wearable/service/ble_service/bleservice + ${ROOT_DIR}/application/wearable/service/ble_service/blemoder ${ROOT_DIR}/application/wearable/nativeabilityfwk/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/parser ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/audio_player/interfaces/kits diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h index eb86b43d6..e8abffec2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h @@ -55,6 +55,71 @@ struct QuickTraining training2_Image(OHOS::RIDING_60_IMAGE), training3_Image(OHOS::RUNNING_60_IMAGE) {} }; +/* +"src":0, +"ty":0, +"st":1657865201, +"sp":1657867001, +"tgt":0, +"tg":5000, +"pg":60, +"du":1800, +"ca":2355,//卡路里为该数值乘以0.1 +"di":3000, +"hr":127, +"stp":10000 +*/ +#ifdef __cplusplus +extern "C" { +#endif +struct Trainingdata_hard +{ + uint32_t num; +}; + +struct Trainingdata +{ + //0:手表开启的训练1:APP开启的训练 + uint32_t src; + //0:健身类1:舞蹈类2:休闲运动3:球类4:水上项目5:冰上项目6:极限运动 7:其他 + uint32_t bt; + //训练类型0:健走1:跑步2:骑行 + uint32_t ty; + //开始时间戳 + uint32_t st; + //结束时间戳 + uint32_t sp; + //训练目标类型 + uint32_t tgt; + //训练目标 + uint32_t tg; + //目标完成度 + uint32_t pg; + //训练时长 + uint32_t du; + //卡路里 + uint32_t ca; + //距离 + uint32_t di; + //平均心率 + uint32_t hr; + //步数 + uint32_t stp; + //训练强度 + uint32_t ti; + //圈数 + uint32_t cir; + //最高海拔高度 + uint32_t alt; +}; +Trainingdata *read_Trainingdata_data(uint32_t timedata,uint16_t offset); + +int write_Trainingdata_data(Trainingdata data); + + +#ifdef __cplusplus +} +#endif namespace OHOS { diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp index 584fde2a6..94eda9839 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp @@ -14,9 +14,234 @@ #define TIMER 0 #define CHECK 0 +#define HARD_OFF 1 +#define TRAINING_PATH "user/userdata/" namespace OHOS { +// struct Trainingdata_hard +// { +// uint32_t st; +// uint32_t num; +// }; + +// struct Trainingdata +// { +// //0:手表开启的训练1:APP开启的训练 +// uint32_t src; +// //0:健身类1:舞蹈类2:休闲运动3:球类4:水上项目5:冰上项目6:极限运动 7:其他 +// uint32_t bt; +// //训练类型0:健走1:跑步2:骑行 +// uint32_t ty; +// //开始时间戳 +// uint32_t st; +// //结束时间戳 +// uint32_t sp; +// //训练目标类型 +// uint32_t tgt; +// //训练目标 +// uint32_t tg; +// //目标完成度 +// uint32_t pg; +// //训练时长 +// uint32_t du; +// //卡路里 +// uint32_t ca; +// //距离 +// uint32_t di; +// //平均心率 +// uint32_t hr; +// //步数 +// uint32_t stp; +// //训练强度 +// uint32_t ti; +// //圈数 +// uint32_t cir; +// //最高海拔高度 +// uint32_t alt; +// }; +#ifdef __cplusplus +extern "C" { +#endif + //处理数据头 + static void write_Trainingdata_hard_data(uint32_t data) + { + char file_path[128]={0}; + sprintf(file_path,"%shard_%d.bin",TRAINING_PATH,data); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s",file_path); + FILE *fp= fopen(file_path,"rb+"); + Trainingdata_hard hard; + int ret=0; + if(fp==NULL) + { + hard.num=0; + fp= fopen(file_path,"wb+"); + } + else + { + ret=fread((void *)&hard,sizeof(Trainingdata_hard),1,fp); + } + + fseek(fp, 0, SEEK_SET); + fclose(fp); + + fp= fopen(file_path,"wb+"); + hard.num++; + ret=fwrite((void *)&hard,sizeof(Trainingdata_hard),1,fp); + fseek(fp, 0, SEEK_SET); + fclose(fp); + } + //获得数据个数 + static int get_Trainingdata_data_num(uint32_t data) + { + + char file_path[128]={0}; + sprintf(file_path,"%shard_%d.bin",TRAINING_PATH,data); + + FILE *fp= fopen(file_path,"ab"); + if(fp==NULL) + { + return 0xffffff; + } + fseek(fp,0,SEEK_SET); + Trainingdata_hard hard; + int ret=fread((void *)&hard,sizeof(Trainingdata_hard),1,fp); + fseek(fp, 0, SEEK_SET); + fclose(fp); + return hard.num; + + } + + //写数据 + int write_Trainingdata_data(Trainingdata data) + { + uint64_t time; + uapi_get_timestampe_ms(&time); + uint32_t timeday = time/1000/60/60/12; + char file_path[128]={0}; + sprintf(file_path,"%s%d.bin",TRAINING_PATH,timeday); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s",file_path); + write_Trainingdata_hard_data(timeday); + FILE *fp= fopen(file_path,"ab"); + if(fp==NULL) + { + fopen(file_path,"wb+"); + } + #if HARD_OFF + int ret=0; + + ret=fwrite((void *)&data,sizeof(Trainingdata),1,fp); + if(ret!=1) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "2 fwrite_data %d",ret); + } + + + #else + if(fp==NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "file is NULL"); + } + Trainingdata_hard hard={0}; + fseek(fp,0,SEEK_SET); + int ret=fread((void *)&hard,sizeof(Trainingdata_hard),1,fp); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hard num %d",hard.num); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "fread %d",ret); + if(ret==0) + { + hard.num=1; + hard.st=timeday; + fseek(fp,0,SEEK_SET); + ret=fwrite((void *)&hard,sizeof(Trainingdata_hard),1,fp); + + if(ret!=1) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "fwrite_hard %d",ret); + } + + ret=fwrite((void *)&data,sizeof(Trainingdata),1,fp); + if(ret!=1) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "1 fwrite_data %d",ret); + } + } + else + { + ret=fseek(fp,8,SEEK_END); + if(ret!=0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "fseek %d",ret); + } + hard.num++; + ret=fwrite((void *)&(hard),sizeof(Trainingdata_hard),1,fp); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hard num %d",hard.num); + if(ret) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "fwrite_hard %d",ret); + } + + fseek(fp,0,SEEK_END); + // fclose(fp); + + // fp= fopen(file_path,"ab+"); + ret=fwrite((void *)&data,sizeof(Trainingdata),1,fp); + if(ret!=1) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "2 fwrite_data %d",ret); + } + } + #endif + + fseek(fp, 0, SEEK_SET); + fclose(fp); + return 1; + } +//读数据 +Trainingdata *read_Trainingdata_data(uint32_t timedata,uint16_t offset) +{ + char file_path[128]={0}; + sprintf(file_path,"%s%d.bin",TRAINING_PATH,timedata); + + FILE *fp= fopen(file_path,"rb+"); + Trainingdata* data=(Trainingdata*)malloc(sizeof(Trainingdata)); + if(fp==NULL || get_Trainingdata_data_num(timedata)src); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d %d ",offset,sizeof(Trainingdata)); + #else + fseek(fp,0,SEEK_SET); + Trainingdata_hard hard; + int ret=fread((void *)&hard,sizeof(Trainingdata_hard),1,fp); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hard num %d",hard.num); + if(ret==0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "file is NULL"); + return NULL; + + } + else + { + fread((void *)data,sizeof(Trainingdata),1,fp); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d",data->src); + } + #endif + fseek(fp, 0, SEEK_SET); + fclose(fp); + return data; +} +#ifdef __cplusplus +} +#endif + + #if TIMER // 声明定时器变量 static osTimerId_t g_timer = NULL; diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h index c0cdf226a..90e56719f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h @@ -9,8 +9,57 @@ #define WEATHER_MODEL_H #include "wearable_log.h" +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#include "string.h" +struct Weather_data +{ + int humidity; + char windScale[16]; + char textNight[16]; + int uvIndex; + int temp; + int iconNight; +}; + +// "address": +// {"lat":225737664, +// "atm":"1010", +// "city":"深圳", +// "subLocality":"宝安", +// "lon":1138535138}, +struct Weather_data_address +{ + int lat; + char atm[16]; + char city[32]; + char subLocality[32]; + int lon; +}; + +//{"tempMin":22,"iconDay":6,"fxDate":1712505600,"textDay":"阵雨","tempMax":29}, +struct ONE_DAY_DATA +{ + int tempMin; + int iconDay; + int fxDate; + char textDay[16]; + int tempMax; +}; + +void UI_set_weather_now_data(int humidity, char* windScale, char* textNight,int uvIndex,int temp,int iconNight); + +void UI_set_weather_address_data(int lat, char* atm, char* city,char* subLocality,int lon); + +void UI_set_weather_seven_day_data(struct ONE_DAY_DATA *t); +#if __cplusplus +} +#endif /* __cplusplus */ namespace OHOS { + + class WeatherModel { public: diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp index f09e621a5..94b9e33c9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp @@ -7,6 +7,54 @@ */ #include "weather/include/WeatherModel.h" +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +Weather_data Weather_data_t_now; +Weather_data_address Weather_data_t_address; +ONE_DAY_DATA Weather_data_seven_data[7]; +void UI_set_weather_now_data(int humidity, char* windScale, char* textNight,int uvIndex,int temp,int iconNight) +{ + Weather_data_t_now.humidity=humidity; + memset((void*)Weather_data_t_now.windScale,0,16); + strcpy(Weather_data_t_now.windScale,windScale); + memset((void*)Weather_data_t_now.textNight,0,16); + strcpy(Weather_data_t_now.textNight,textNight); + Weather_data_t_now.uvIndex=uvIndex; + Weather_data_t_now.temp=temp; + Weather_data_t_now.iconNight=iconNight; +} + +void UI_set_weather_address_data(int lat, char* atm, char* city,char* subLocality,int lon) +{ + Weather_data_t_address.lat=lat; + Weather_data_t_address.lon=lon; + memset((void*)Weather_data_t_address.atm,0,16); + strcpy(Weather_data_t_address.atm,atm); + memset((void*)Weather_data_t_address.city,0,32); + strcpy(Weather_data_t_address.city,city); + memset((void*)Weather_data_t_address.subLocality,0,32); + strcpy(Weather_data_t_address.subLocality,subLocality); +} + +void UI_set_weather_seven_day_data(struct ONE_DAY_DATA *t) +{ + for(int i=0;i<7;i++) + { + Weather_data_seven_data[i].fxDate=t[i].fxDate; + Weather_data_seven_data[i].iconDay=t[i].iconDay; + Weather_data_seven_data[i].tempMax=t[i].tempMax; + Weather_data_seven_data[i].tempMin=t[i].tempMin; + Weather_data_seven_data[i].fxDate=t[i].fxDate; + memset((void*)Weather_data_seven_data[i].textDay,0,16); + strcpy(Weather_data_seven_data[i].textDay,t[i].textDay); + } +} + + +#if __cplusplus +} +#endif /* __cplusplus */ namespace OHOS { WeatherModel::WeatherModel() diff --git a/code/sdk/application/wearable/service/ble_service/CMakeLists.txt b/code/sdk/application/wearable/service/ble_service/CMakeLists.txt index c578369d0..d2c28bbd7 100644 --- a/code/sdk/application/wearable/service/ble_service/CMakeLists.txt +++ b/code/sdk/application/wearable/service/ble_service/CMakeLists.txt @@ -1,35 +1,2 @@ -set(COMPONENT_NAME "ble_service") -set(PUBLIC_HEADER - ${CMAKE_CURRENT_SOURCE_DIR} -) - - -set(PRIVATE_HEADER - -) -set(SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/bleService.c - ${CMAKE_CURRENT_SOURCE_DIR}/bleEvent.c -) - -set(COMPONENT_PUBLIC_CCFLAGS -) - -set(COMPONENT_CCFLAGS -) - -set(WHOLE_LINK - true -) - -set(MAIN_COMPONENT - false -) - -set(PUBLIC_DEFINES -) - -set(PRIVATE_DEFINES -) - -build_component() +add_subdirectory_if_exist(bleservice) +add_subdirectory_if_exist(blemoder) diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt b/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt new file mode 100644 index 000000000..56aa04d34 --- /dev/null +++ b/code/sdk/application/wearable/service/ble_service/blemoder/CMakeLists.txt @@ -0,0 +1,59 @@ +#=============================================================================== +# @brief cmake file +# Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. +#=============================================================================== + +set(COMPONENT_NAME "blemoder") + +set(PUBLIC_HEADER +${CMAKE_CURRENT_SOURCE_DIR} +) +set(PRIVATE_HEADER +${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits +${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits +${ROOT_DIR}/application/wearable/nativeapp/nativeui/heartrate/include +${ROOT_DIR}/application/wearable/fd230app/nativeui/weather/include + +) + +set(SOURCES +${CMAKE_CURRENT_SOURCE_DIR}/bletest.cpp +) + +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + -std=c++11 + -Wno-error + -Wno-unused-parameter + -fno-exceptions + -fno-unwind-tables + -fno-asynchronous-unwind-tables + -Wno-undef + -Wno-bitwise-op-parentheses + -Wno-shift-op-parentheses + -nostdlibinc + -nostdinc + -nostdlib + -Wno-c++11-narrowing + -Wno-error=unused-function +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +set(PUBLIC_DEFINES +SUPPORT_PPG_SERVICE +SUPPORT_AT_PPG +) + +set(PRIVATE_DEFINES +) + +build_component() diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp new file mode 100644 index 000000000..45acec4cc --- /dev/null +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -0,0 +1,92 @@ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Test source \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-08-16, Create file. \n + */ +#include "wearable_log.h" +#include "securec.h" +#include "broadcast_service.h" +#include "broadcast_feature.h" +#include "service_id_define.h" +#include "samgr_lite.h" +#include "thread_adapter.h" +#include "graphic_service.h" +#include "WeatherModel.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#include "pinctrl.h" +#include "debug_print.h" +#include "soc_osal.h" +#include "tcxo.h" +#include "irmalloc.h" +#include "errcode.h" +#include "common_def.h" + +#include "chip_core_irq.h" +#include "chip_io.h" +#include "gpio.h" +#include "pm_veto.h" + +#include "rtc.h" +#include "timer.h" +#include "systick.h" +#include "cmsis_os2.h" +#include "los_printf.h" + +#include "custom_utils.h" +#include "string.h" +// struct Weather_data +// { +// int humidity; +// char* windScale; +// char* textNight; +// int uvIndex; +// int temp; +// int iconNight; +// }; + + +void set_weather_now_data(int humidity, char* windScale, char* textNight,int uvIndex,int temp,int iconNight) +{ + return UI_set_weather_now_data(humidity, windScale, textNight,uvIndex,temp,iconNight); +} + +void set_weather_address_data(int lat, char* atm, char* city,char* subLocality,int lon) +{ + return UI_set_weather_address_data(lat, atm, city,subLocality,lon); +} +// struct ONE_DAY_DATA +// { +// int tempMin; +// int iconDay; +// int fxDate; +// char textDay[16]; +// int tempMax; +// }; + +static struct ONE_DAY_DATA data_t[7]; +void set_weather_one_data(int tempMin, int iconDay,int fxDate, int tempMax, char *textDay,int x) +{ + data_t[x].tempMin=tempMin; + data_t[x].iconDay=iconDay; + data_t[x].fxDate=fxDate; + data_t[x].tempMax=tempMax; + memset((void*)data_t[x].textDay,0,16); + strcpy(data_t[x].textDay,textDay); + + if(x==6) + return UI_set_weather_seven_day_data(data_t); +} +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h new file mode 100644 index 000000000..6335a4a14 --- /dev/null +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -0,0 +1,32 @@ +/** + * Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. \n + * + * Description: Test adc header \n + * Author: @CompanyNameTag \n + * History: \n + * 2022-08-16, Create file. \n + */ + +#ifndef BLE_MODER_H__ +#define BLE_MODER_H__ + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#include "stdint.h" +#include "errcode.h" + +void set_weather_now_data(int humidity, char* windScale, char* textNight,int uvIndex,int temp,int iconNight); + +void set_weather_address_data(int lat, char* atm, char* city,char* subLocality,int lon); +void set_weather_one_data(int tempMin, int iconDay,int fxDate, int tempMax, char *textDay,int x) ; +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/CMakeLists.txt b/code/sdk/application/wearable/service/ble_service/bleservice/CMakeLists.txt new file mode 100644 index 000000000..53daf6184 --- /dev/null +++ b/code/sdk/application/wearable/service/ble_service/bleservice/CMakeLists.txt @@ -0,0 +1,39 @@ + +set(COMPONENT_NAME "bleservice") +set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR} + +) + + +set(PRIVATE_HEADER + #${CMAKE_CURRENT_SOURCE_DIR}/../../fd230app/nativeui/weather/include +) +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/bleService.c + ${CMAKE_CURRENT_SOURCE_DIR}/bleEvent.c +) + +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +set(PUBLIC_DEFINES +) + +set(PRIVATE_DEFINES + +) + +build_component() + diff --git a/code/sdk/application/wearable/service/ble_service/bleEvent.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c similarity index 94% rename from code/sdk/application/wearable/service/ble_service/bleEvent.c rename to code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c index 3b3d97a6e..9b76a232d 100644 --- a/code/sdk/application/wearable/service/ble_service/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -5,6 +5,10 @@ * Create: */ + +#ifdef __cplusplus +extern "C" { +#endif #include "common_def.h" #include "bts_def.h" #include "bts_gatt_stru.h" @@ -27,13 +31,16 @@ #include "bleEvent.h" #include "ppg_service.h" #include "broadcast_feature.h" -#ifdef SUPPORT_BLE_SERVICE +#if 1//#ifdef //SUPPORT_BLE_SERVICE #include "app_common_api.h" #include "hidService.h" #include "../../../../../open_source/openharmony/third_party/cJSON/cJSON.h" #include "errcode.h" #define PHONE_WATCH_CONFIG_PATH "/user/userdata/phone_watch.json" #define ALARM_DATA_CONFIG_PATH "/user/userdata/alarm_test.json" +#include "bletest.h" + + uint8_t *bigDataBuf = NULL;//大数据buf uint8_t bigDataBufLen=0; bool sendbigDataBufState = false;//发送大数据表示不要被其他指令打断 @@ -167,19 +174,23 @@ static bool Check_CRC(uint8_t *crcnum,uint16_t len,uint8_t crcvalue)//计算20by lrcValue =lrcValue+ crcnum[i]; // printf("%02x ",crcnum[i]); } + //"{\"pn\":\"iPhone\",\"tp\":1}"; + crcbuf = lrcValue%256; crcbuf = 256-crcbuf; crcbuf = crcbuf%256; WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Check_CRC ret:0x%x len:%d\r\n",crcbuf,len); - if(crcbuf == crcvalue) - { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Check_CRC true:\r\n"); - return true; - } - else{ - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Check_CRC false:\r\n"); - return false; - } + + return true; + // if(crcbuf == crcvalue) + // { + // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Check_CRC true:\r\n"); + // return true; + // } + // else{ + // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Check_CRC false:\r\n"); + // return false; + // } } static uint8_t Calculate_CRC(uint8_t *crcnum,uint16_t len)//计算20byte @@ -407,7 +418,12 @@ void comfirmPaire(uint8_t flag) first_bond = 1; printf("gap_ble_pair_remote_device 333333333 %x-%x-%x-%x-%x-%x\r\n",phone_addr.addr[0],phone_addr.addr[1],phone_addr.addr[2],phone_addr.addr[3],phone_addr.addr[4],phone_addr.addr[5]); - gap_ble_pair_remote_device(&phone_addr); + errcode_t code = gap_ble_pair_remote_device(&phone_addr); + if(code!=ERRCODE_SUCC) + { + printf("gap_ble_pair_remote_device fail %X\r\n",code); + } + }else{ first_bond = 0; printf("gap_ble_pair_remote_device 444444444\r\n"); @@ -715,8 +731,17 @@ void cleanUnbindInfor(void)//和旧手机解绑清除配对信息 inforaddr.addr[5] = mac_data[5]; inforaddr.type = MacType; // printf("inforaddr:%x-%x-%x-%x-%x-%x",inforaddr.addr[0],inforaddr.addr[1],inforaddr.addr[2],inforaddr.addr[3],inforaddr.addr[4],inforaddr.addr[5]); - gap_ble_remove_pair(&inforaddr);//清除配对信息 + errcode_t ret= gap_ble_remove_pair(&inforaddr);//清除配对信息 + if(ret!=ERRCODE_SUCC) + { + printf("gap_ble_remove_pair : %X\r\n",ret); + } //清除保存的文件信息 + if(0!=remove(PHONE_WATCH_CONFIG_PATH)) + { + printf("json remove fail\r\n"); + } + } void sendBindInfor(uint8_t *crcnum) { @@ -753,7 +778,7 @@ void sendBindInfor(uint8_t *crcnum) GetwatchSaveMac(&save_mac,&MacType);//获取手表设备本地保存的mac地址和mac地址类型 getPhoneMac(crcnum,&copare_mac); - memset(copare_mac,0,6); + if(save_mac[0] == 0 && save_mac[1] == 0 && save_mac[2] == 0 && save_mac[3] == 0 && save_mac[4] == 0 && save_mac[5] == 0)//只要手表本地存储没有mac地址就走连接流程重新绑定 { #ifdef SUPPORT_DEVICE_PAIRING_NOTIFICATION @@ -843,7 +868,6 @@ void sendParieSuccess(uint8_t flag,bd_addr_t *addr)//发送配对成功指令to { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sendParieSuccess:0x%x-0x%x-0x%x-0x%x-0x%x-0x%x\r\n",addr->addr[0],addr->addr[1],addr->addr[2],addr->addr[3],addr->addr[4],addr->addr[5]); if(first_bond == 1 && phoneDataFlag == 1)//第一次连接绑定 - // if(1) { uint8_t value[25]; uint8_t length = 0; @@ -910,6 +934,7 @@ void sendParieSuccess(uint8_t flag,bd_addr_t *addr)//发送配对成功指令to } phoneDataFlag = 0; } + } @@ -1051,6 +1076,7 @@ static void jsonCheck_alarm(uint8_t *buf)//json 解析闹钟数据 int alarmCount = cJSON_GetArraySize(alarms); printf("alarmCount %d\n",alarmCount); } + void GetAlarmDataCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totalData,uint8_t crcvalue)//获取app下发的屏幕参数 { uint32_t tmp = 1; @@ -1078,12 +1104,12 @@ void GetAlarmDataCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totalDat sendBuf[17] = 0; sendBuf[18] = Calculate_CRC(sendBuf,18); sendBleData(sendBuf,19); - } - + } } + void GetWatchLcdParamCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totalData,uint8_t crcvalue)//获取app下发的屏幕参数 { uint32_t tmp = 1; @@ -1332,17 +1358,64 @@ static void jsonCheck_weather(uint8_t *buf)//json 格式解析 天气数据 { uint8_t *json; json = buf; + #if 0 + FILE *fp=fopen("user/weather.json","wb+"); + printf("jsonCheck_weather len %d",strlen((char *)buf)+1); + //fwrite((void*)buf,1,strlen((char *)buf)+1,fp); + fputs((char *)buf,fp); + fclose(fp); + #endif cJSON* root = cJSON_Parse((const char *)json); if (root == NULL) { printf("天气 JSON解析错误\n"); return; } - cJSON *address_cjson = cJSON_GetObjectItem(root, "address"); - cJSON *city_cjson = cJSON_GetObjectItem(address_cjson, "city"); + cJSON *now_cjson = cJSON_GetObjectItem(root, "now"); - if (cJSON_IsString(city_cjson)) { - printf("city: %s\n", city_cjson->valuestring); + int humidity = cJSON_GetObjectItem(now_cjson, "humidity")->valueint; + char * windScale = cJSON_GetObjectItem(now_cjson, "windScale")->valuestring; + char *textNight = cJSON_GetObjectItem(now_cjson, "textNight")->valuestring; + int uvIndex = cJSON_GetObjectItem(now_cjson, "uvIndex")->valueint; + int temp = cJSON_GetObjectItem(now_cjson, "temp")->valueint; + int iconNight = cJSON_GetObjectItem(now_cjson, "iconNight")->valueint; + + set_weather_now_data(humidity,windScale,textNight,uvIndex,temp,iconNight); + +// "address": +// {"lat":225737664, +// "atm":"1010", +// "city":"深圳", +// "subLocality":"宝安", +// "lon":1138535138}, + + cJSON *address_cjson = cJSON_GetObjectItem(root, "address"); + char*city = cJSON_GetObjectItem(address_cjson, "city")->valuestring; + char*subLocality = cJSON_GetObjectItem(address_cjson, "subLocality")->valuestring; + char*atm = cJSON_GetObjectItem(address_cjson, "atm")->valuestring; + int lat = cJSON_GetObjectItem(address_cjson, "lat")->valueint; + int lon = cJSON_GetObjectItem(address_cjson, "lon")->valueint; + set_weather_address_data(lat,atm,city,subLocality,lon); + + cJSON *daily = cJSON_GetObjectItem(root, "daily"); + for(int i=0;i<7;i++) + { + //{"tempMin":22,"iconDay":6,"fxDate":1712505600,"textDay":"阵雨","tempMax":29}, + cJSON *data=cJSON_GetArrayItem(daily,i); + int tempMin=cJSON_GetObjectItem(data,"tempMin")->valueint; + int iconDay=cJSON_GetObjectItem(data,"iconDay")->valueint; + int fxDate=cJSON_GetObjectItem(data,"fxDate")->valueint; + char * textDay=cJSON_GetObjectItem(data,"textDay")->valueint; + int tempMax=cJSON_GetObjectItem(data,"tempMax")->valueint; + set_weather_one_data(tempMin,iconDay,fxDate,textDay,tempMax,i); } + + //cJSON_GetObjectItem(daily, "daily"); + + + + // if (cJSON_IsString(city_cjson)) { + // printf("city: %s\n", city_cjson->valuestring); + // } cJSON_Delete(root); printf("weather data!!!!!!!!!!end\r\n"); } @@ -1424,6 +1497,10 @@ void getUserInfo(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totalData,ui } } +void getTRAIN_TARGETInfo(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totalData,uint8_t crcvalue)// +{ + +} //02 类型 void type2AE4Data(uint8_t *buf_cmd,uint8_t *data,uint16_t datalen,uint8_t *totalData,uint8_t crcvalue) { @@ -1444,6 +1521,7 @@ void type2AE4Data(uint8_t *buf_cmd,uint8_t *data,uint16_t datalen,uint8_t *total getPhoneInfo_test(); break; case SET_TRAIN_TARGET_CMD: + break; case SET_ALARM_DATA_CMD: GetAlarmDataCmd(typeID,data,datalen,totalData,crcvalue); @@ -3667,11 +3745,17 @@ void bleLongRecvData(uint8_t *data, uint16_t data_size,uint8_t *buf_cmd,uint8_t { uint8_t type=buf_cmd[1]; printf("type:%d %d data_size:%d data:%d crcvalue:%x",buf_cmd[0],type,data_size,data[0],crcvalue); + FILE *fp= fopen("user/ble_test.json","w+"); + fwrite((void *)data,1,data_size,fp); + fclose(fp); switch (type) { case 0x02://获取手机信息 type2AE4Data(buf_cmd,data,data_size,totalData,crcvalue); break; + // case 0x02://获取手机信息 + // type2AE4Data(buf_cmd,data,data_size,totalData,crcvalue); + // break; default: break; } @@ -3684,6 +3768,7 @@ uint8_t totalpack = 0; uint8_t cmd_data[17]; 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); if(sendbigDataBufState == true)//正在发送大数据不接收任何app指令下发的数据 { return; @@ -3712,7 +3797,7 @@ void bleDataRecv(uint8_t *totalData, uint16_t event_size,uint16_t handle) free(recvData); } } - }else if(data2ae4Cmd == handle) + }else if(handle) { while (1) { @@ -3807,12 +3892,20 @@ void bleDataRecv(uint8_t *totalData, uint16_t event_size,uint16_t handle) } } } + // else if(data2ae5Cmd == handle) + // { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "xhandle %d,%d %d",data2ae3Cmd,data2ae4Cmd,handle); + // } } //接收app下发的原始数据 void revBleOldData(uint8_t *buf, uint16_t event_size,uint16_t handle)//每包的数据大小 { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "xxxxxxxxxxxxxxxx"); printf("handle :%d data2ae3Cmd:%d data2ae4Cmd:%d buf:%d event_size %d\r\n",handle,data2ae3Cmd,data2ae4Cmd,buf,event_size); bleDataRecv(buf,event_size,handle); } #endif +#endif +#ifdef __cplusplus +} #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/service/ble_service/bleEvent.h b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h similarity index 99% rename from code/sdk/application/wearable/service/ble_service/bleEvent.h rename to code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h index 2516b0bb8..06b33918d 100644 --- a/code/sdk/application/wearable/service/ble_service/bleEvent.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h @@ -1,13 +1,15 @@ #ifndef _BLE_EVENT_H #define _BLE_EVENT_H + +#ifdef __cplusplus +extern "C" { +#endif #include #include #include "stdbool.h" #include "errcode.h" #include "bts_def.h" -#ifdef __cplusplus -extern "C" { -#endif + #define READ_FLASH_DATA 0x01 //读flash数据 #define WRITE_FLASH_DATA 0x02 //写flash数据 typedef struct { @@ -82,6 +84,8 @@ void cameram_send_data(void); #define SYN_BASIC_TRANIN_HISTORY_DATA_CMD 0x0149 //同步基础训练历史数据basic training #define SYN_SLEEP_HISTORY_DATA_CMD 0x014B //同步睡眠历史数据 +#define FIND_PHONE_CMD 0x0501 //同步睡眠历史数据 + /*******************data structure*************************/ #pragma pack(1) diff --git a/code/sdk/application/wearable/service/ble_service/bleService.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c similarity index 96% rename from code/sdk/application/wearable/service/ble_service/bleService.c rename to code/sdk/application/wearable/service/ble_service/bleservice/bleService.c index 8b1d1ff9c..2fde4750f 100644 --- a/code/sdk/application/wearable/service/ble_service/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -5,6 +5,11 @@ * Create: */ + +#ifdef __cplusplus +extern "C" { +#endif + #include "common_def.h" #include "bts_def.h" #include "bts_gatt_stru.h" @@ -28,6 +33,9 @@ #include "bleEvent.h" #include "hidService.h" #include "factorytestService.h" + +// extern void bts_data_to_uuid_len2(uint16_t uuid_data, bt_uuid_t *out_uuid); +// extern void bts_init_128bit_uuid(const bt_uuid_t *uuid); // #include "ble_hid_take_photo_server.h" /* Gatt service UUID */ #define BLE_SERVICE_UUID 0x18e0 @@ -57,6 +65,8 @@ #define BLE_DEFAULT_NAME "KUMI U6" #define BLE_DEFAULT_NAME_LEN 32 #define BLE_MAC_MAX_LEN 6 //蓝牙mac地址最大个数6个 + + // 蓝牙模块全局变量 static gap_ble_callbacks_t g_ble_gapble_cbs; static gatts_callbacks_t g_ble_gatts_cbs; @@ -90,7 +100,8 @@ static osal_timer g_a2dp_stream_accept_timer = {NULL, NULL, 0, 0}; uint8_t data2ae3Cmd = 0;//2ae3短指令特征值 uint8_t data2ae4Cmd = 0; -#ifdef SUPPORT_BLE_SERVICE +uint8_t data2ae5Cmd = 0; +#if 1//def SUPPORT_BLE_SERVICE static void set_phone_info(bd_addr_t *addr)//保存手机信息 包含手机mac地址 { bd_addr_t new_addr; @@ -143,8 +154,8 @@ static void svr_ble_adv_data_set(int adv_id) gap_ble_config_adv_data_t adv_data_info; memset_s(&adv_data_info, sizeof(gap_ble_config_adv_data_t), 0, sizeof(gap_ble_config_adv_data_t)); -#if U6_DEBUG - unsigned char set_mac[6] = {0x61,0x22,0x33,0x44,0x09,0x17}; +#if 1 + unsigned char set_mac[6] = {0x61,0x22,0x33,0x44,0x09,0x20}; bluetooth_set_local_addr(set_mac,6); bd_addr_t addr_info; int32_t ret= 0; @@ -286,7 +297,6 @@ static void svr_ble_connstate_change_cb(unsigned short conn_id, bd_addr_t *addr, set_phone_info(addr); Bleconnect = GAP_BLE_STATE_CONNECTED;//蓝牙已连接 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GAP_BLE_STATE_CONNECTED!!! 0x%x\r\n",pair_state); - svr_ble_adv_stop(); } } @@ -661,6 +671,7 @@ static void svr_ble_bt_gatts_characteristic_add_cb(uint8_t server_id, bt_uuid_t if(ble_gatts_cmp_uuid(uuid, &chara_uuid_data1)) { g_ble_server_handle = result->value_handle; + data2ae5Cmd = result->value_handle; WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "result->value_handle1 %d\r\n",result->value_handle); } @@ -805,6 +816,7 @@ static void svr_ble_bt_gatts_req_write_cb(uint8_t server_id, uint16_t conn_id, g 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()) { factory_recv_cmd_data(write_cb_para->value,write_cb_para->length,write_cb_para->handle); @@ -1281,4 +1293,7 @@ void openBle(void) svr_bluetooth_init(); } } +#endif +#ifdef __cplusplus +} #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/service/ble_service/bleService.h b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h similarity index 94% rename from code/sdk/application/wearable/service/ble_service/bleService.h rename to code/sdk/application/wearable/service/ble_service/bleservice/bleService.h index 8c53e028b..4bbc7d0c4 100644 --- a/code/sdk/application/wearable/service/ble_service/bleService.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h @@ -1,5 +1,9 @@ #ifndef __BLESERVICE_H #define __BLESERVICE_H + +#ifdef __cplusplus +extern "C" { +#endif #include #include #include "stdbool.h" @@ -26,5 +30,8 @@ void srv_ble_server_register_gatt_callbacks(void); errcode_t svr_ble_bt_gatts_noyify(uint8_t *data, uint16_t data_len); void svr_ble_adv_start(void); void svr_ble_adv_stop(void); +#ifdef __cplusplus +} +#endif #endif diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index cbfc288f6..d46509234 100755 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -169,7 +169,8 @@ target = { # "acc_sensor", "cywee", "batterry_service", - "ble_service", + "bleservice", + "blemoder", "factorytest_service", "hid_service" ],