From 226f7804b00400513a6dcea59761d701a916e610 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Mon, 17 Jun 2024 10:45:58 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0ID=E6=96=87=E4=BB=B6=E4=BF=9D?= =?utf8?q?=E5=AD=98=EF=BC=8C=E4=BC=98=E5=8C=96=E8=A1=A8=E7=9B=98=E6=B3=A8?= =?utf8?q?=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/set_dial/include/SetDialModel.h | 2 + .../nativeui/set_dial/src/SetDialModel.cpp | 94 ++++++++++++++++++- .../service/ble_service/blemoder/bletest.cpp | 5 + .../service/ble_service/blemoder/bletest.h | 1 + .../drivers/peripheral/utils/custom_utils.c | 2 + 5 files changed, 101 insertions(+), 3 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h index 171f56f34..2838b0cca 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h @@ -36,6 +36,8 @@ namespace OHOS uint16_t GetDialIdFromName(const std::string &dialName); void PrintRegisteredDials(const std::unordered_map &dials); int GetAllDialIDs(char *allidStr); + bool readDialfile(); + bool saveDialfile(); private: void LoadAllDialFromRam(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp index 2e0bd59e5..2aba5345d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp @@ -22,7 +22,7 @@ #include #include #include - +#include namespace OHOS { // 定义特殊Id @@ -30,6 +30,10 @@ namespace OHOS constexpr uint16_t DEFAULT_DIAL_ID_1 = 1028; constexpr uint16_t DEFAULT_DIAL_ID_2 = 1052; + #define DIAL_ID_LENGTH 2 + #define DIAL_NAME_LENGTH 50 + #define DIAL_ID_PATH "user/userdata/dial_id.bin" + // 表盘map[Id--dialname] 前5个ID固定 std::unordered_map registeredDials{ {DEFAULT_DIAL_ID_1, "KUMI"}, @@ -38,9 +42,82 @@ namespace OHOS {102, "kaleidoscope"}, // 万花筒表盘102 {MAX_DEFAULT_DIAL_ID, "jellyfish"}, // 水母表盘 }; + // 表盘市场UID 对应表盘name + bool SetDialModel::saveDialfile() + { + FILE * fp= fopen(DIAL_ID_PATH,"wb+"); + + for (const auto &entry : registeredDials) + { + char buf[DIAL_ID_LENGTH+DIAL_NAME_LENGTH]={0}; + memcpy_s(buf,DIAL_ID_LENGTH+DIAL_NAME_LENGTH,&entry.first,2); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uid %d",entry.first); + memcpy_s(buf+DIAL_ID_LENGTH,DIAL_ID_LENGTH+DIAL_NAME_LENGTH,entry.second.c_str(),entry.second.length()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uid %s",entry.second.c_str()); + int size=fwrite(buf,1,DIAL_ID_LENGTH+DIAL_NAME_LENGTH,fp); + if(DIAL_ID_LENGTH+DIAL_NAME_LENGTH !=size ) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " fwrite is fail! %d",size); + return false; + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " fwrite is succ %d !",entry.first); + } + } + fclose(fp); + return true; + } + + bool SetDialModel::readDialfile() + { + FILE * fp= fopen(DIAL_ID_PATH,"rb+"); + if(fp==NULL) + return false; + fseek(fp, 0, SEEK_END); + int size = ftell(fp); + fseek(fp, 0, SEEK_SET); + //char * buf=(char *)malloc(size); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " readDialfile size is %d !",size); + + while (size) + { + uint16_t uid=0; + if(DIAL_ID_LENGTH !=fread( (void *)&uid,1,DIAL_ID_LENGTH,fp)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " fread is fail!"); + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uid %d",uid); + + char name_buf[DIAL_NAME_LENGTH]={0}; + if(DIAL_NAME_LENGTH !=fread((void *)name_buf,1,DIAL_NAME_LENGTH,fp)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " fread is fail!"); + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "name_buf %s",name_buf); + + if(uid!=0) + { + if( !IsDialInstalled(uid)) + { + RegisterDial(uid,name_buf); + } + + + } + size-=(DIAL_ID_LENGTH+DIAL_NAME_LENGTH); + } + + //free(buf); + fclose(fp); + return true; + } + SetDialModel::SetDialModel() { + readDialfile(); LoadAllDial(); } @@ -55,7 +132,14 @@ namespace OHOS /* 注册表盘map */ void SetDialModel::RegisterDial(uint16_t ID, const char *dialname) { - registeredDials[ID] = dialname; // 唯一性 + // char *dialname_=(char *)malloc(strlen(dialname)+1); + + // memcpy_s(dialname_,strlen(dialname)+1,dialname,strlen(dialname)+1); + + std::string * dialname_ = new std::string(dialname); + + registeredDials[ID] = *dialname_; // 唯一性 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RegisterDial %s is ok!", dialname); } /* 打印map */ @@ -100,7 +184,7 @@ namespace OHOS // allIDs += ss.str(); } - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "allidStr is %s", allIDs.c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "allidStr is %s %d", allIDs.c_str(),length); // // 将字符串拷贝到allidStr中 // int length = allIDs.size(); @@ -137,6 +221,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UninstallDial default dial %d fail", ID); return false; } + registeredDials.erase(ID); /*删除文件操作*/ std::string dialFullName = APP_DIAL_PATH; @@ -147,6 +232,7 @@ namespace OHOS if (uapi_delete_files(dialFullName.c_str())) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UninstallDial the dial %d is ok", ID); + return true; } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_delete_files the dial %d is false", ID); @@ -288,6 +374,8 @@ namespace OHOS dialInfo.dialName = preInfo.dialName; dialInfo.description = preInfo.description; dialInfo.preImageInfo = info; + + #if 0 // 需要判断表盘是否存在 不存在->新表盘注册 if (GetDialIdFromName(dialInfo.dialName) == 0) 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 3c6fd9ee8..0e31908bd 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -96,6 +96,11 @@ int get_all_dial_id( char * buf) return OHOS::SetDialModel::GetInstance().GetAllDialIDs(buf); } +bool dial_file_save(void ) +{ + return OHOS::SetDialModel::GetInstance().saveDialfile(); +} + void install_Register_dial( char * name,uint16_t id) { return OHOS::SetDialModel::GetInstance().RegisterDial(id,name); 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 af1fe85c3..5540c0cc8 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -221,6 +221,7 @@ int get_all_dial_id( char * buf); void install_Register_dial( char * name,uint16_t id); +bool dial_file_save(void); #ifdef __cplusplus #if __cplusplus diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 78b2cfac1..146fc17e8 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -148,6 +148,8 @@ void shutdown_reboot_prejobs_task(void) do_cywee_service_check_msg(CYWEE_SERVICE_CMD_SAVE_DATA,NULL); addressbookTowrite(); + + dial_file_save(); //同步所有需要保存实时数据到config文件 uapi_dev_runtime_sync_runtime_env_to_config(); //保存config文件到磁盘 -- 2.17.1