From 015f4c67cb915d5076381abe1c2c3478360e9a54 Mon Sep 17 00:00:00 2001 From: zhangyuhang Date: Fri, 8 Jul 2022 19:18:29 +0800 Subject: [PATCH] ci_test Signed-off-by: zhangyuhang --- ci_test_zyh/BUILD.gn | 65 +++++ ci_test_zyh/src/common.c | 245 +++++++++++++++++ .../src/electr_board_ability_slice.cpp | 247 ++++++++++++++++++ 3 files changed, 557 insertions(+) create mode 100644 ci_test_zyh/BUILD.gn create mode 100644 ci_test_zyh/src/common.c create mode 100644 ci_test_zyh/src/electr_board_ability_slice.cpp diff --git a/ci_test_zyh/BUILD.gn b/ci_test_zyh/BUILD.gn new file mode 100644 index 00000000..fe2b09d9 --- /dev/null +++ b/ci_test_zyh/BUILD.gn @@ -0,0 +1,65 @@ +# Copyright (c) 2020 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/lite/config/hap_pack.gni") + +shared_library("electrBoard") { + sources = [ + "src/electronic_board_ability.cpp", + "src/electr_board_ability_slice.cpp", + "src/weather_time_view.cpp", + "src/schedule_list_view.cpp", + "src/sntp.c", + "src/LinkList.c", + "src/schedule_server.c", + "src/common.c" + ] + + deps = [ + "${aafwk_lite_path}/frameworks/ability_lite:aafwk_abilitykit_lite", + "${appexecfwk_lite_path}/frameworks/bundle_lite:bundle", + "//foundation/communication/ipc_lite:liteipc_adapter", + "//foundation/distributedschedule/samgr_lite/samgr:samgr", + "//foundation/graphic/surface", + "//foundation/graphic/ui:lite_ui", + "//foundation/graphic/utils:lite_graphic_utils", + "//foundation/multimedia/camera_lite/frameworks:camera_lite", + "//foundation/multimedia/media_lite/frameworks/recorder_lite:recorder_lite", + "//utils/native/lite/kv_store:kv_store", + ] + + include_dirs = [ + "include", + "${aafwk_lite_path}/interfaces/kits/ability_lite", + "${appexecfwk_lite_path}/interfaces/kits/bundle_lite", + "${aafwk_lite_path}/interfaces/kits/want_lite", + "//base/startup/syspara_lite/interfaces/kits", + "//foundation/multimedia/camera_lite/interfaces/kits", + "//foundation/graphic/utils/interfaces/kits/gfx_utils", + "//third_party/cJSON", + ] + + ldflags = [ + "-L$ohos_root_path/sysroot/usr/lib", + "-Wl,-rpath-link=$ohos_root_path/sysroot/usr/lib", + "-lstdc++", + "-lcamera_lite", + "-lsurface", + "-lrecorder_lite", + ] + defines = [ + "ENABLE_WINDOW=1", + "ABILITY_WINDOW_SUPPORT", + ] + +} diff --git a/ci_test_zyh/src/common.c b/ci_test_zyh/src/common.c new file mode 100644 index 00000000..b1fde822 --- /dev/null +++ b/ci_test_zyh/src/common.c @@ -0,0 +1,245 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cJSON.h" +#include "sntp.h" +#include "common.h" + +#define LOG_DEBUG(fmt, args...) printf("[DEBUG][%s|%d]" fmt, __func__, __LINE__, ##args) +#define LOG_INFO(fmt, args...) printf("[INFO ][%s|%d]" fmt, __func__, __LINE__, ##args) +#define LOG_ERROR(fmt, args...) printf("[ERROR][%s|%d]" fmt, __func__, __LINE__, ##args) + +static int g_connectStatus = 1; + +//test +// +// +// +// + + + +#define abc 1; +g_abc =1; + + + +typedef struct { + unsigned short protocol; + unsigned char cmd; + char msg[1024]; +}WifiResponseInfo; + +typedef struct { + unsigned char status; + char ssid[32]; +} WifiStatus; + +static int GetNetStatus(void) +{ + return 1; +} + +static int GetLocalTime(struct tm *tm) +{ + time_t t = time(NULL); + struct tm *mt = localtime(&t); + if (mt) { + (void)memcpy_s(tm, sizeof(struct tm), mt, sizeof(struct tm)); + } else { + LOG_ERROR("get localtime failed! \n"); + return -1; + } + + return 0; +} + +int SystemGetTime(struct tm *rtcTime) +{ + int ret = 0; + if (rtcTime == NULL) { + return -1; + } + g_connectStatus = GetNetStatus(); + if (g_connectStatus == 1) { + ret = SntpGetRtcTime(LOCAL_TIME_ZONE, rtcTime); + } else { + ret = GetLocalTime(rtcTime); + } + + return ret; +} + +// ***************** weather ************************************************ // +#define USE_WEATHER_API_FREE 0 + +#if USE_WEATHER_API_FREE +// 没有空气湿度以及PM2.5 无限制次数 +#define GET_REQUEST_PACKAGE "GET https://www.tianqiapi.com/free/day?appid=%s&appsecret=%s&unescape=1\r\n\r\n" +#else +// 每天限制访问次数 300 +#define GET_REQUEST_PACKAGE "GET http://www.tianqiapi.com/api/?version=v6&appid=%s&appsecret=%s\r\n\r\n" +#endif + +#define WEATHER_PORT 80 +#define WEATHER_IP_ADDR "120.27.2.251" + +#define APPID "54612715" +#define APPSECRET "4dlrQLn8 " + +static int GetWeatherMsgFromNet(char *weatherRecvBuf, int size) +{ + int sockfd = -1; + char getRequestBuf[256] = {0}; + struct sockaddr_in ServerSockAddr; + + if (weatherRecvBuf == NULL || size <= 0) { + return -1; + } + + (void)memset_s(weatherRecvBuf, size, 0x00, size); + + (void)memset_s(&ServerSockAddr, sizeof(ServerSockAddr), 0, sizeof(ServerSockAddr)); + ServerSockAddr.sin_family = AF_INET; // IPv4 + ServerSockAddr.sin_addr.s_addr = inet_addr(WEATHER_IP_ADDR); // 天气服务器IP + ServerSockAddr.sin_port = htons(WEATHER_PORT); // 端口 + + sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + if (sockfd < 0) { + LOG_ERROR("socket failed!\n"); + return -1; + } + + if (connect(sockfd, (struct sockaddr*)&ServerSockAddr, sizeof(struct sockaddr)) < 0) { + close(sockfd); + LOG_ERROR("connect failed!\n"); + return -1; + } + + (void)sprintf_s(getRequestBuf, sizeof(getRequestBuf), GET_REQUEST_PACKAGE, APPID, APPSECRET); + if (send(sockfd, getRequestBuf, strlen(getRequestBuf), 0) <= 0) { + close(sockfd); + LOG_ERROR("send failed! \n"); + return -1; + } + + if (recv(sockfd, weatherRecvBuf, size, 0) <= 0) { + close(sockfd); + LOG_ERROR("recv failed! \n"); + return -1; + } + + LOG_DEBUG("recv msg -- %s \n", weatherRecvBuf); + close(sockfd); + + return 0; +} + +static int GetJsonItemValue(const cJSON *const json, const char *const item, char *buff, int size) +{ + cJSON *obj; + obj = cJSON_GetObjectItem(json, item); + if (obj == NULL) { + LOG_ERROR("get json %s failed! \n", item); + return -1; + } + (void)strcpy_s(buff, size, cJSON_GetStringValue(obj)); + + return 0; +} + +static int ParseWeatherInfo(const char *pMsg, WeatherInfo *wInfo) +{ +#define WEATHER_NBR 10 + cJSON *root = NULL; + const char *keyWord[WEATHER_NBR] = { + "city", "date", "week", "update_time", + "wea", "tem", "humidity", "win_meter", + "air", "air_pm25" + }; + char *msgBuff[WEATHER_NBR]; + int retval = 0; + + if (wInfo == NULL) { + LOG_ERROR("NULL POINT! \n"); + return -1; + } + (void)memset_s(wInfo, sizeof(WeatherInfo), 0x00, sizeof(WeatherInfo)); + msgBuff[0] = wInfo->city; // idx 0 + msgBuff[1] = wInfo->date; // idx 1 + msgBuff[2] = wInfo->week; // idx 2 + msgBuff[3] = wInfo->time; // idx 3 + msgBuff[4] = wInfo->weather; // idx 4 + msgBuff[5] = wInfo->temperature; // idx 5 + msgBuff[6] = wInfo->humidity; // idx 6 + msgBuff[7] = wInfo->airSpeed; // idx 7 + msgBuff[8] = wInfo->airQuality; // idx 8 + msgBuff[9] = wInfo->airPM25; // idx 9 + + root = cJSON_Parse(pMsg); + if (root == NULL) { + LOG_ERROR("cJSON_Parse failed! \n"); + return -1; + } + + for (int i = 0; i < WEATHER_NBR; i++) { + if (GetJsonItemValue(root, keyWord[i], msgBuff[i], WEATHER_BUF_SIZE) < 0) { + LOG_ERROR("GetJsonItemValue %s failed! \n", keyWord[i]); + retval = -1; + break; + } + } + + cJSON_Delete(root); + + return retval; +} + +int SystemGetWeather(WeatherInfo *wInfo) +{ + char weatherRecvBuf[1024 * 4]; + g_connectStatus = GetNetStatus(); + if (g_connectStatus <= 0) { + LOG_ERROR("network have not been connectted! \n"); + return -1; + } + + if (wInfo == NULL) { + return -1; + } + + if (GetWeatherMsgFromNet(weatherRecvBuf, sizeof(weatherRecvBuf)) < 0) { + LOG_ERROR("GetWeatherMsgFromNet failed! \n"); + return -1; + } + + if (ParseWeatherInfo((const char *)weatherRecvBuf, wInfo) < 0) { + LOG_ERROR("ParseWeatherInfo failed! \n"); + return -1; + } + + return 0; +} diff --git a/ci_test_zyh/src/electr_board_ability_slice.cpp b/ci_test_zyh/src/electr_board_ability_slice.cpp new file mode 100644 index 00000000..11454a9d --- /dev/null +++ b/ci_test_zyh/src/electr_board_ability_slice.cpp @@ -0,0 +1,247 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "ability_manager.h" +#include "gfx_utils/color.h" + +#include "electr_board_ability_slice.h" +#include "sntp.h" + +//test +// +// +// +// + + + +#define abc 1; +g_abc =1; + + +namespace OHOS { +REGISTER_AS(ElectrBoardAbilitySlice) +ElectrBoardAbilitySlice::~ElectrBoardAbilitySlice() +{ + if (labelTitle_ != nullptr) { + delete labelTitle_; + labelTitle_ = nullptr; + } + if (buttonListener_ != nullptr) { + delete buttonListener_; + buttonListener_ = nullptr; + } + if (backButton_ != nullptr) { + delete backButton_; + backButton_ = nullptr; + } + if (backButtonB_ != nullptr) { + delete backButtonB_; + backButtonB_ = nullptr; + } + if (weatherTimeView_ != nullptr) { + delete weatherTimeView_; + weatherTimeView_ = nullptr; + } + if (dateInfo_ != nullptr) { + DeleteChildren(dateInfo_); + dateInfo_ = nullptr; + } + + if (scheduleInfo_ != nullptr) { + DeleteChildren(scheduleInfo_); + scheduleInfo_ = nullptr; + } + + if (scheduleTask_ != nullptr) { + delete scheduleTask_; + scheduleTask_ = nullptr; + } + + if (scheduleList_.Size() > 0) { + scheduleList_.Clear(); + } +} + +UILabel *GetLabel(const char *text, BoardRect r, int font) +{ + UILabel *label = new UILabel(); + label->SetPosition(r.x, r.y, r.w, r.h); + label->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + label->SetFont((const char *)FONT_PATH, font); + label->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); + label->SetStyle(STYLE_BACKGROUND_OPA, OPATICY_ALL); + label->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + label->SetText(text); + return label; +} + +void ElectrBoardAbilitySlice::SetScrollView(void) +{ + scheduleView_->ScheduleListViewNotify(); +} + +void ElectrBoardAbilitySlice::SetScheduleView(void) +{ + scheduleInfo_ = new UIViewGroup(); + scheduleInfo_->SetPosition(SCHEDULE_START_X, SCHEDULE_START_Y, SCHEDULE_START_W, SCHEDULE_START_H); + scheduleInfo_->SetStyle(STYLE_BACKGROUND_OPA, OPATICY_ALL); + + UIImageView *bk = new UIImageView(); + bk->SetPosition(START_X_POS, START_Y_POS, SCHEDULE_START_W, SCHEDULE_START_H); + bk->SetStyle(STYLE_BACKGROUND_OPA, OPATICY_ALL); + bk->SetSrc(SCH_LIST_BACKGROUND); + scheduleInfo_->Add(bk); + + scheduleView_ = new ScheduleListView(scheduleInfo_, weatherTimeView_); + scheduleView_->ScheduleListViewSetup(); + scheduleView_->ScheduleListViewSetList(&scheduleList_); + + rootview_->Add(scheduleInfo_); + + scheduleTask_ = new ScheduleListTask(weatherTimeView_, scheduleView_, &scheduleList_); + scheduleTask_->TaskStart(); +} + +void ElectrBoardAbilitySlice::SetDateItemView(void) +{ + dateInfo_ = new UIViewGroup(); + dateInfo_->SetPosition(WeatherTimeView::WEATHER_TIME_VIEW_XPOS, WeatherTimeView::WEATHER_TIME_VIEW_YPOS,\ + WeatherTimeView::WEATHER_TIME_VIEW_WIDTH, WeatherTimeView::WEATHER_TIME_VIEW_HEIGHT); + dateInfo_->SetStyle(STYLE_BACKGROUND_OPA, OPATICY_ALL); + UIImageView *imageV = new UIImageView(); + imageV->SetPosition(0, 0, WeatherTimeView::WEATHER_TIME_VIEW_WIDTH, WeatherTimeView::WEATHER_TIME_VIEW_HEIGHT); + imageV->SetStyle(STYLE_BACKGROUND_OPA, OPATICY_ALL); + imageV->SetSrc(WEATHER_TIME_VIEW_BKGND); + dateInfo_->Add(imageV); + + weatherTimeView_ = new WeatherTimeView(dateInfo_); + weatherTimeView_->SetUpView(); + + rootview_->Add(dateInfo_); +} + +void ElectrBoardAbilitySlice::SetBackButton() +{ + backButtonB_ = new UIImageView(); + backButtonB_->SetPosition(BACK_BUTTON_B_X, BACK_BUTTON_B_Y, BACK_BUTTON_B_W, BACK_BUTTON_B_H); + backButtonB_->SetStyle(STYLE_BACKGROUND_OPA, OPATICY_ALL); + backButtonB_->SetTouchable(true); + + backButton_ = new UIImageView(); + backButton_->SetPosition(BACK_BUTTON_X, BACK_BUTTON_Y, BACK_BUTTON_W, BACK_BUTTON_H); + backButton_->SetStyle(STYLE_BACKGROUND_OPA, OPATICY_ALL); + backButton_->SetSrc(BACK_BUTTON_ICON); + backButton_->SetTouchable(true); + auto backBttnonClick = [this](UIView &view, const Event &event) -> bool { + TerminateAbility(); + return true; + }; + + buttonListener_ = new EventListener(backBttnonClick, nullptr); + backButton_->SetOnClickListener(buttonListener_); + backButtonB_->SetOnClickListener(buttonListener_); + + rootview_->Add(backButtonB_); + rootview_->Add(backButton_); +} + +void ElectrBoardAbilitySlice::SetTitle() +{ + labelTitle_ = new UILabel(); + labelTitle_->SetPosition(TITLE_XPOS, TITLE_YPOS, TITLE_WIDTH, TITLE_HEIGHT); + labelTitle_->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + labelTitle_->SetFont((const char *)FONT_PATH, TITLE_FONT); + labelTitle_->SetStyle(STYLE_TEXT_COLOR, Color::ColorTo32(Color::White())); + labelTitle_->SetStyle(STYLE_BACKGROUND_OPA, OPATICY_ALL); + labelTitle_->SetText("130XXXX4309的家"); + + rootview_->Add(labelTitle_); +} + +void ElectrBoardAbilitySlice::ScheduleUpdateList(ListHandle list) +{ + int total = LinkListGetSize(list); + + if (scheduleList_.Size() > 0) { + scheduleList_.Clear(); + } + + for (int i = 0; i < total; i++) { + ScheduleInfo info_d; + ScheduleInfoT *info_s = (ScheduleInfoT *)LinkListGetWithIndex(list, i); + info_d.setId(info_s->id); + info_d.setName(info_s->name); + info_d.setTime(info_s->startTime, info_s->endTime); + info_d.setDetails(info_s->details); + + scheduleList_.PushBack(info_d); + } + scheduleView_->ScheduleListViewNotify(); +} + +static int ScheduleUpdateProcess(void *data, ListHandle list) +{ + ElectrBoardAbilitySlice *s = (ElectrBoardAbilitySlice *)data; + s->ScheduleUpdateList(list); + return 0; +} + +void ElectrBoardAbilitySlice::OnStart(const Want &want) +{ + AbilitySlice::OnStart(want); + + rootview_ = RootView::GetWindowRootView(); + rootview_->SetPosition(START_X_POS, START_Y_POS); + rootview_->Resize(SCREEN_WIDTH, SCREEN_HEIGHT); + rootview_->SetStyle(STYLE_BACKGROUND_OPA, OPATICY_NONE); + rootview_->SetStyle(STYLE_BACKGROUND_COLOR, Color::ColorTo32(Color::GetColorFromRGB(0x30, 0x30, 0x30))); + + SetTitle(); + SetBackButton(); + SetDateItemView(); + SetScheduleView(); + SetScrollView(); + SetUIContent(rootview_); + rootview_->Invalidate(); + + ScheduleServerStart(ScheduleUpdateProcess, (void *)this); +} + +void ElectrBoardAbilitySlice::OnInactive() +{ + AbilitySlice::OnInactive(); +} + +void ElectrBoardAbilitySlice::OnActive(const Want &want) +{ + AbilitySlice::OnActive(want); +} + +void ElectrBoardAbilitySlice::OnBackground() +{ + AbilitySlice::OnBackground(); +} + +void ElectrBoardAbilitySlice::OnStop() +{ + AbilitySlice::OnStop(); +} +} + -- Gitee