From c2c84266587498ab361c3ae3233ff795303373c6 Mon Sep 17 00:00:00 2001 From: SnickerSun Date: Mon, 23 Dec 2024 09:23:31 +0800 Subject: [PATCH] =?utf8?q?U8=20GPS=20TestUI=20=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../wearable/nativeapp/CMakeLists.txt | 13 ++ .../nativelauncher/include/AppViewIDs.h | 1 + .../nativelauncher/include/NativeLauncher.h | 3 + .../nativelauncher/src/NativeLauncher.cpp | 21 ++- .../nativeui/TestGPS/include/GPSView.h | 36 ++++ .../TestGPS/include/TestGPSPresenter.h | 44 +++++ .../nativeui/TestGPS/include/TestGPSView.h | 65 +++++++ .../nativeui/TestGPS/src/GPSView.cpp | 147 +++++++++++++++ .../nativeui/TestGPS/src/TestGPSPresenter.cpp | 84 +++++++++ .../nativeui/TestGPS/src/TestGPSView.cpp | 177 ++++++++++++++++++ .../nativeui/settings/src/SettingModel.cpp | 4 + .../config/target_config/brandy/config.py | 1 + code/sdk/zhihui/services/gnss/inc/NMEA0183.h | 25 ++- code/sdk/zhihui/services/gnss/inc/gnss_ctl.h | 8 +- .../gnss/sample/gnss_sample/gnss_sample.c | 72 +++++-- .../gnss/sample/gnss_sample/gnss_sample.h | 12 +- code/sdk/zhihui/services/gnss/src/NMEA0183.c | 114 ++++++++--- .../sdk/zhihui/services/gnss/src/decodenmea.c | 4 +- code/sdk/zhihui/services/gnss/src/gnss_ctl.c | 9 +- .../sdk/zhihui/services/gnss/src/nmealist.txt | 56 ++++++ code/sdk/zhihui/services/gnss/src/uart_gnss.c | 2 +- 21 files changed, 838 insertions(+), 60 deletions(-) create mode 100644 code/sdk/application/wearable/nativeapp/nativeui/TestGPS/include/GPSView.h create mode 100644 code/sdk/application/wearable/nativeapp/nativeui/TestGPS/include/TestGPSPresenter.h create mode 100644 code/sdk/application/wearable/nativeapp/nativeui/TestGPS/include/TestGPSView.h create mode 100644 code/sdk/application/wearable/nativeapp/nativeui/TestGPS/src/GPSView.cpp create mode 100644 code/sdk/application/wearable/nativeapp/nativeui/TestGPS/src/TestGPSPresenter.cpp create mode 100644 code/sdk/application/wearable/nativeapp/nativeui/TestGPS/src/TestGPSView.cpp create mode 100644 code/sdk/zhihui/services/gnss/src/nmealist.txt diff --git a/code/sdk/application/wearable/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/nativeapp/CMakeLists.txt index 2bdf6263b..5d9ad9358 100644 --- a/code/sdk/application/wearable/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/nativeapp/CMakeLists.txt @@ -8,6 +8,7 @@ set(PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/nativelauncher/include/slices/main ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/screennotify/include ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bluetooth/include + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/TestGPS/include ) set(PRIVATE_HEADER @@ -289,7 +290,19 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialStaticImgView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/parser/DialBinParser.cpp ) +if("TEST_GPS_UI" IN_LIST DEFINES) +set(PRIVATE_HEADER + ${PRIVATE_HEADER} + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/TestGPS/include +) +set(SOURCES + ${SOURCES} + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/TestGPS/src/GPSView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/TestGPS/src/TestGPSView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/TestGPS/src/TestGPSPresenter.cpp +) +endif() if("SUPPORT_ALIPAY_SEC" IN_LIST DEFINES) set(SOURCES ${SOURCES} diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h index fa4182e25..43106102c 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h @@ -53,6 +53,7 @@ typedef enum : uint16_t { VIEW_ADD_CARD, VIEW_SET_DIAL, VIEW_SET_DIAL_STYLE, + VIEW_GPS_TESTUI, //GPS 测试页面 VIEW_MAX_INTER_APP, // 在此之前添加native应用ID. VIEW_EXTERN_APP = 0xFFFE, // 三方应用 VIEW_INVALIDE_APP = 0xFFFF, diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h index b05347ecd..5fc5bc04d 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h @@ -38,6 +38,9 @@ public: void InitCompassSlice(void); void InitOfflineVoice(void); void InitConnectPhoneSlice(void); + #ifdef TEST_GPS_UI + void InitGPSTestSlice(void); + #endif void InitMainTempSlice(void); void InitIndoorWalkSlice(void); void InitRebootSlice(void); diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp index 476286256..51b101da0 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp @@ -75,6 +75,10 @@ #include "SetDialPresenter.h" #include "SetDialStylePresenter.h" #include "SetDialStyleView.h" +#ifdef TEST_GPS_UI +#include "TestGPSView.h" +#include "TestGPSPresenter.h" +#endif #ifdef JS_ENABLE #include "product_adapter.h" #endif @@ -117,6 +121,9 @@ static const AppViewMapper SLICE_MAPPER[] = { {VIEW_ADD_CARD, &NativeLauncher::InitAddCardSlice}, {VIEW_SET_DIAL, &NativeLauncher::InitSetDialSlice}, {VIEW_SET_DIAL_STYLE, &NativeLauncher::InitSetDialStyleSlice}, + #ifdef TEST_GPS_UI + {VIEW_GPS_TESTUI, &NativeLauncher::InitGPSTestSlice}, + #endif }; static const ViewIdToString VIEW_MAPPER[] = { @@ -146,6 +153,7 @@ static const ViewIdToString VIEW_MAPPER[] = { {VIEW_ADD_CARD, "AddCard"}, {VIEW_SET_DIAL, "SetDial"}, {VIEW_SET_DIAL_STYLE, "SetDialStyle"}, + {VIEW_GPS_TESTUI, "GPSTest"}, }; NativeLauncher::NativeLauncher() {} @@ -279,7 +287,18 @@ void NativeLauncher::InitRebootSlice(void) } NativeAbility::GetInstance().AddSliceProxy(VIEW_REBOOT, rebootView); } - +#ifdef TEST_GPS_UI +void NativeLauncher::InitGPSTestSlice(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::TestGPSUI"); + SliceProxy *gpsView = new AbilitySliceProxy; + if (gpsView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gpsView is nullptr"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_GPS_TESTUI, gpsView); +} +#endif void NativeLauncher::InitConnectPhoneSlice(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::ConnectPhoneView"); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/include/GPSView.h b/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/include/GPSView.h new file mode 100644 index 000000000..526c6bfa0 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/include/GPSView.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: ConnectSelect View + * Create: 2022-03-22 + */ + +#ifndef GPS_VIEW_H +#define GPS_VIEW_H + +#include "View.h" +#include "TestGPSPresenter.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_view_group.h" +#include + +namespace OHOS { +class GPSView { +public: + GPSView(); + ~GPSView(); + static GPSView *GetInstance(); + UIViewGroup *InitShowUpView(void); + void updateGPSdata(std::string gpsdata); + void updateGPSstat(std::string gpsdata); +private: + void ShowUpTitleLabel(void); + void CreateUIButton(void); + UILabel *titleLabel{nullptr}; + UILabel *msgLabel{nullptr}; + UIButton *cancelButton{nullptr}; + UIButton *confirmButton{nullptr}; + UIViewGroup *group{nullptr}; +}; +} // namespace OHOS +#endif // GPS_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/include/TestGPSPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/include/TestGPSPresenter.h new file mode 100644 index 000000000..bad6b27fa --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/include/TestGPSPresenter.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: Connect Phone Presenter + * Create: 2022-01-19 + */ + +#ifndef TEST_GPS_PRESENTER_H +#define TEST_GPS_PRESENTER_H + +#include "Presenter.h" +#include "NativeLauncher.h" +#include "NativeAbility.h" +#include "BaseView.h" + +namespace OHOS { +enum TestGPSPresenterNum : uint8_t { + GPSVIEW = 0, + GPSVIEW_MAX, +}; + +#define GPS_CANCEL_BUTTON "close" +#define GPS_CONFIRM_BUTTON "open" +#define GPS_BACK_BUTTON "backButton" + +#define TEST_GPS_VIEW "testGPSView" + +class TestGPSView; +class TestGPSPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener { +public: + TestGPSPresenter(); + ~TestGPSPresenter(); + static TestGPSPresenter *GetInstance(); + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + bool OnClick(UIView& view, const ClickEvent& event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; +private: +}; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/include/TestGPSView.h b/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/include/TestGPSView.h new file mode 100644 index 000000000..ba7d2e93b --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/include/TestGPSView.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: Connect Phone View + * Create: 2022-01-19 + */ + +#ifndef TEST_GPS_VIEW_H +#define TEST_GPS_VIEW_H + +#include "View.h" +#include "TestGPSPresenter.h" +#include "GPSView.h" +#include "AppGroupView.h" +#include "animator/animator.h" +#include "sys/time.h" +namespace OHOS { +constexpr int16_t NUM_GPS_CONTAINER = 1; + +class TestGPSPresenter; +class GPSUpdateAnimatorCallback; +class TestGPSView : public View { +public: + TestGPSView(); + ~TestGPSView(); + static TestGPSView *GetInstance(); + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + void ChangeView(int16_t hideView, int16_t showView); + void updateGPS(); + +private: + bool ChangeGPSView(int16_t hideView, int16_t thisView); + bool CheckViewParam(int16_t hideView, int16_t showView); + GPSView *gpsUIView{nullptr}; + UIViewGroup *container[NUM_GPS_CONTAINER]{nullptr}; + typedef bool (TestGPSView::*PreprosssChangeView)(int16_t hideView, int16_t thisView); + Animator *gpsUpdateAnimator{nullptr}; + PreprosssChangeView preProcessView[NUM_GPS_CONTAINER]; + GPSUpdateAnimatorCallback *callBack; +}; + +class GPSUpdateAnimatorCallback : public AnimatorCallback { +public: + explicit GPSUpdateAnimatorCallback(TestGPSView *GPSView) : gpsview(GPSView) {} + ~GPSUpdateAnimatorCallback() override {} + + void Callback(UIView *view) override + { + + if (gpsview!=nullptr) + { + gpsview->updateGPS(); + + }else{ + printf("gps animator init fail"); + } + } +private: + TestGPSView *gpsview=nullptr; + +}; +} // namespace OHOS +#endif // DISTEST_GPS_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/src/GPSView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/src/GPSView.cpp new file mode 100644 index 000000000..8945fa46e --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/src/GPSView.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: ConnectSelect View + * Create: 2022-03-22 + */ +#include "GPSView.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "TestGPSPresenter.h" + +namespace OHOS { +static GPSView *g_pGPSView{nullptr}; + +GPSView::GPSView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GPSView::GPSView"); + g_pGPSView = this; +} + +GPSView::~GPSView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GPSView::~GPSView"); + group->RemoveAll(); + delete titleLabel; + titleLabel = nullptr; + delete msgLabel; + msgLabel = nullptr; + delete cancelButton; + cancelButton = nullptr; + delete confirmButton; + confirmButton = nullptr; + g_pGPSView = nullptr; +} + +GPSView *GPSView::GetInstance() +{ + return g_pGPSView; +} +void GPSView::updateGPSstat(std::string gpsdata) +{ + if (titleLabel != nullptr) { + titleLabel->SetText(gpsdata.c_str()); + } +} +void GPSView::updateGPSdata(std::string gpsdata) +{ + if (msgLabel != nullptr) { + msgLabel->SetText(gpsdata.c_str()); + } +} +void GPSView::ShowUpTitleLabel() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GPSView::ShowUpTitleLabel"); + if (titleLabel == nullptr) { + titleLabel = new UILabel(); + if (titleLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPSView titleLabel new fail"); + return; + } + titleLabel->SetPosition(65, 50, 324, 160); // 65:x, 100:y, 324:width, 160:height + titleLabel->SetText("GPS测试"); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 35); // 35:font data + titleLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + titleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + group->Add(titleLabel); + } + if (msgLabel == nullptr) { + msgLabel = new UILabel(); + if (msgLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPSView msgLabel new fail"); + return; + } + msgLabel->SetPosition(65, 100, 324, 160); // 65:x, 100:y, 324:width, 160:height + msgLabel->SetText(""); + msgLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); // 35:font data + msgLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + msgLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + msgLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + group->Add(msgLabel); + } + +} + +void GPSView::CreateUIButton() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GPSView::CreateUIButton"); + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::TestGPSPresenter::GetInstance(); + if (clickListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener nullptr"); + return; + } + if (cancelButton == nullptr) { + cancelButton = new UIButton(); + if (cancelButton == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPSView cancelButton new fail"); + return; + } + cancelButton->SetPosition(85, 400, 90, 90); // 85:x, 320:y, 90:width, 90:height + cancelButton->SetViewId(GPS_CANCEL_BUTTON); + cancelButton->SetImageSrc(ALARM_DELETE_ADD_PATH, ALARM_DELETE_ADD_PATH); + cancelButton->SetOnClickListener(clickListener); + group->Add(cancelButton); + } + if (confirmButton == nullptr) { + confirmButton = new UIButton(); + if (confirmButton == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPSView confirmButton new fail"); + return; + } + confirmButton->SetPosition(279, 400, 90, 90); // 279:x, 320:y, 90:width, 90:height + confirmButton->SetViewId(GPS_CONFIRM_BUTTON); + confirmButton->SetImageSrc(ALARM_TRUE_ADD_PATH, ALARM_TRUE_ADD_PATH); + confirmButton->SetOnClickListener(clickListener); + group->Add(confirmButton); + } +} + +UIViewGroup *GPSView::InitShowUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GPSView init"); + if (group == nullptr) { + group = new UIViewGroup(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return nullptr; + } + group->SetPosition(0, 0); + group->SetWidth(HORIZONTAL_RESOLUTION); + group->SetHeight(VERTICAL_RESOLUTION); + } + ShowUpTitleLabel(); + CreateUIButton(); + UIView::OnDragListener *connectDragListener = (UIView::OnDragListener *)OHOS::TestGPSPresenter::GetInstance(); + if (connectDragListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "connectDragListener GetInstance fail"); + return nullptr; + } + group->SetOnDragListener(connectDragListener); + group->SetViewId(TEST_GPS_VIEW); + group->SetDraggable(true); + group->SetTouchable(true); + return group; +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/src/TestGPSPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/src/TestGPSPresenter.cpp new file mode 100644 index 000000000..f17092b7d --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/src/TestGPSPresenter.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: Connect Phone Presenter + * Create: 2022-01-19 + */ + +#include "TestGPSPresenter.h" +#include "TestGPSView.h" +#include "BluetoothModel.h" +#include "bts_br_gap.h" +#include "bts_le_gap.h" +#include "drag_event.h" +#include "cmsis_os.h" +#include "UiConfig.h" +#include "wearable_log.h" +#include "custom_utils.h" +#include "gnss_ctl.h" +namespace OHOS { + +static TestGPSPresenter *g_pTestGPSPresenter = nullptr; + +TestGPSPresenter::TestGPSPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TestGPSPresenter::TestGPSPresenter"); + g_pTestGPSPresenter = this; +} + +TestGPSPresenter::~TestGPSPresenter() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TestGPSPresenter::~TestGPSPresenter"); + g_pTestGPSPresenter = nullptr; +} + +TestGPSPresenter *TestGPSPresenter::GetInstance() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TestGPSPresenter GetInstance"); + return g_pTestGPSPresenter; +} + +void TestGPSPresenter::OnStart() +{ + Presenter::OnStart(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TestGPSPresenter::On Start "); + ScreenAlwaysOnCtr(1); +} + +void TestGPSPresenter::OnPause(void) {} + +void TestGPSPresenter::OnResume(void) {} + +void TestGPSPresenter::OnStop(void) { + ScreenAlwaysOnCtr(0); +} + +bool TestGPSPresenter::OnClick(UIView& view, const ClickEvent& event) +{ + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClick OnClick"); + if (strcmp(view.GetViewId(), GPS_CANCEL_BUTTON) == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPS Off OnClick"); + gnss_stop(); + } else if (strcmp(view.GetViewId(), GPS_CONFIRM_BUTTON) == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPS On OnClick"); + gnss_start(); + } else if (strcmp(view.GetViewId(), GPS_BACK_BUTTON) == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Cancel OnClick"); + } + // NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); + return true; +} + +bool TestGPSPresenter::OnDrag(UIView& view, const DragEvent& event) +{ + std::string viewId = view.GetViewId(); + if ((viewId == TEST_GPS_VIEW) ) { + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TestGPSPresenter::OnDrag"); + NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); + } + } + return true; +} + +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/src/TestGPSView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/src/TestGPSView.cpp new file mode 100644 index 000000000..f3d089ac9 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/TestGPS/src/TestGPSView.cpp @@ -0,0 +1,177 @@ +/* + * Copyright (c) CompanyNameMagicTag 2022-2022. All rights reserved. + * Description: Connect Phone View + * Create: 2022-01-19 + */ + +#include "TestGPSView.h" +#include "components/ui_label.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include +#include "NMEA0183.h" +#include "gnss_sample.h" + +namespace OHOS { +static TestGPSView *g_pTestGPSView{nullptr}; + +TestGPSView::TestGPSView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TestGPSView::TestGPSView"); + preProcessView[GPSVIEW] = &TestGPSView::ChangeGPSView; + g_pTestGPSView = this; + callBack = new GPSUpdateAnimatorCallback(g_pTestGPSView); + if (callBack == nullptr) { + GRAPHIC_LOGE("callBack new fail\n"); + return ; + } + gpsUpdateAnimator = new Animator(callBack, (OHOS::UIView*)g_pTestGPSView, 1000, true); + if (gpsUpdateAnimator == nullptr) { + GRAPHIC_LOGE("gpsUpdateAnimator new fail\n"); + return ; + } + gpsUpdateAnimator->Start(); +} + +TestGPSView::~TestGPSView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TestGPSView::~TestGPSView"); + if (gpsUpdateAnimator != nullptr) { + gpsUpdateAnimator->Stop(); + delete gpsUpdateAnimator; + gpsUpdateAnimator = nullptr; + } + g_pTestGPSView = nullptr; +} + +TestGPSView *TestGPSView::GetInstance() +{ + return g_pTestGPSView; +} + +static char msgtmp[256]={0}; + +void TestGPSView::updateGPS() +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TestGPSView::updateGPS"); + if (gpsUIView != nullptr) { + + gps_data_t * gpsdata=getGPSGlobaldata(); + gps_data_t gpsd={0}; + if (gpsdata->last_gps_time_ms>0) + { + memcpy(&gpsd,gpsdata,sizeof(gps_data_t)); + } + memset_s(msgtmp,sizeof(msgtmp),0,sizeof(msgtmp)); + dump_location_data_to_buf(&gpsd,msgtmp,sizeof(msgtmp)); + PRINT("dump %s\n",msgtmp); + gpsUIView->updateGPSdata(msgtmp); + if (getGnssServerStat()==1) + { + gpsUIView->updateGPSstat("GPS已开启"); + }else{ + gpsUIView->updateGPSstat("GPS已关闭"); + } + } +} +void TestGPSView::OnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TestGPSView::~OnStart"); + View::OnStart(); + BaseView::RootView(Color::Black().full); + ChangeView(GPSVIEW_MAX, GPSVIEW); + RootView::GetInstance()->Invalidate(); + return; +} + +void TestGPSView::OnSetUpView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TestGPSView::~OnSetUpView"); + View::OnSetUpView(); + Draw(); +} + +void TestGPSView::OnTearDownView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TestGPSView::~OnTearDownView"); + View::OnTearDownView(); + return; +} + +void TestGPSView::OnStop() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TestGPSView::~OnStop"); + View::OnStop(); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + RootView::GetInstance()->ClearOnKeyActListener(); + RootView::GetInstance()->RemoveAll(); + return; +} + +bool TestGPSView::ChangeGPSView(int16_t hideView, int16_t thisView) +{ + UNUSED(hideView); + if (container[thisView] == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChangeGPSView"); + gpsUIView = new GPSView(); + if (gpsUIView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gpsUIView new fail"); + return false; + } + // init view + UIViewGroup *group = gpsUIView->InitShowUpView(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + RootView::GetInstance()->Add(container[thisView]); + } + return true; +} + +bool TestGPSView::CheckViewParam(int16_t hideView, int16_t showView) +{ + if (showView < 0 || showView >= GPSVIEW_MAX) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TestGPSView::CheckViewParam showView err."); + return false; + } + + if (hideView < 0 || hideView > GPSVIEW_MAX) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TestGPSView::CheckViewParam hideView err."); + return false; + } + + return true; +} + +void TestGPSView::ChangeView(int16_t hideView, int16_t showView) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TestGPSView::ChangeView %d, %d", hideView, showView); + + if (!CheckViewParam(hideView, showView)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TestGPSView::CheckViewParam failed."); + return; + } + + PreprosssChangeView tmpPreProcessView = preProcessView[showView]; + + if (!(this->*tmpPreProcessView)(hideView, showView)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TestGPSView::ChangeView %d %dfailed", showView, hideView); + return; + } + if (hideView != GPSVIEW_MAX) { + if (container[hideView] == nullptr) { + return; + } + container[hideView]->SetVisible(false); + } + container[showView]->SetVisible(true); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TestGPSView:: ChangeView end!!!%d", showView); + RootView::GetInstance()->Invalidate(); +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingModel.cpp index 8390cb1a8..acb8738c2 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingModel.cpp @@ -23,6 +23,10 @@ namespace OHOS { { int index = 0; settings[index++] = {VIEW_BLUETOOTH_EARPHONE, PNG_BLUETOOTH_STITLE, "蓝牙耳机", true}; + + #ifdef TEST_GPS_UI + settings[index++] = {VIEW_GPS_TESTUI, PNG_CONNECT_PHONE_IMAGE, "GPS", true}; + #endif #ifdef TEST_4G_UI settings[index++] = {VIEW_CONNECT_PHONE, PNG_CONNECT_PHONE_IMAGE, "4G开关", true}; #else diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index 219cbd072..df3a3bfaa 100644 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -460,6 +460,7 @@ target = { #"MEM_CHECK", #'ENABLE_WEBSOCKET', 'SINGLE_USER_PARTITION', + 'TEST_GPS_UI', 'BOARD_U8', 'GNSS_UART0', 'SUPPORT_AUTO_OTA_SERVER', diff --git a/code/sdk/zhihui/services/gnss/inc/NMEA0183.h b/code/sdk/zhihui/services/gnss/inc/NMEA0183.h index 17febca97..9f0adb611 100644 --- a/code/sdk/zhihui/services/gnss/inc/NMEA0183.h +++ b/code/sdk/zhihui/services/gnss/inc/NMEA0183.h @@ -33,8 +33,8 @@ $PNTH001,0.000000,0.00,0.00,300000.00,1,0,0*1D $PNTH002,,T,0.000000,0,200,0.000000,3,0.000000*4B - gps_nmea gps_nmea_temp; /// 定义解析时用到的暂存状态数据,只供解析时使用 - gps_data gps_data1; /// GPS解析得到的最终数据,用户可使用 + gps_nmea_t gps_nmea_temp; /// 定义解析时用到的暂存状态数据,只供解析时使用 + gps_data_t gps_data1; /// GPS解析得到的最终数据,用户可使用 unsigned int index = 0; for(index=0; index +#endif #include + static short int from_hex(char a); -static unsigned char nmea_term_complete(gps_nmea* pnmea, gps_data* pdata); +static unsigned char nmea_term_complete(gps_nmea_t* pnmea, gps_data_t* pdata); static int sring_to_int(const char* pstr, unsigned char* b); static int int_pow(int value, unsigned int count); static double double_pow(double value, unsigned int count); @@ -10,7 +15,7 @@ static unsigned char float_to_string(double value, char* pdest, unsigned int int static unsigned char int_to_string(int value, char* pdest, unsigned int intgr) ; static double string_to_float(const char* pstr, unsigned char* b); static int sring_to_int(const char* pstr, unsigned char* b); -static int make_date_time(gps_data* pdata, unsigned int date, unsigned int time); +static int make_date_time(gps_data_t* pdata, unsigned int date, unsigned int time); /* GPS数据解析 */ unsigned char nmea_decode(NMEA0183* nmea, char c) @@ -67,7 +72,7 @@ static short int from_hex(char a) } /* 处理单个字段域数据 */ -static unsigned char nmea_term_complete(gps_nmea* pnmea, gps_data* pdata) +static unsigned char nmea_term_complete(gps_nmea_t* pnmea, gps_data_t* pdata) { if((void*)0==pnmea || (void*)0==pdata) return 0; // handle the last term in a message @@ -80,8 +85,10 @@ static unsigned char nmea_term_complete(gps_nmea* pnmea, gps_data* pdata) { if (pnmea->gps_data_good) { - unsigned int now = current_time_ms(); - + unsigned int now = 1 ; +#ifndef NOUTILS + uapi_get_timestampe_ms(&now); +#endif switch (pnmea->sentence_type) { case GPS_SENTENCE_RMC: @@ -93,7 +100,6 @@ static unsigned char nmea_term_complete(gps_nmea* pnmea, gps_data* pdata) pdata->ground_speed = pnmea->new_speed; pdata->ground_course = pnmea->new_course; make_date_time(pdata, pnmea->new_date, pnmea->new_time); - pdata->last_gps_time_ms = now; break; case GPS_SENTENCE_GGA: @@ -170,6 +176,9 @@ static unsigned char nmea_term_complete(gps_nmea* pnmea, gps_data* pdata) case GPS_SENTENCE_ZDA: pnmea->last_ZDA_ms = now; break; + case GPS_SENTENCE_TH002: + pdata->last_gps_time_ms = now; + break; } } else { switch (pnmea->sentence_type) { @@ -218,7 +227,7 @@ static unsigned char nmea_term_complete(gps_nmea* pnmea, gps_data* pdata) pnmea->location_system = Galileo_E1C; break; case 'N': - pnmea->location_system = GNSS; + pnmea->location_system = GNSS_; break; default: pnmea->location_system = MAX_LOCATION_SYSTEM; @@ -245,7 +254,7 @@ static unsigned char nmea_term_complete(gps_nmea* pnmea, gps_data* pdata) pnmea->sentence_type = GPS_SENTENCE_TH001; } else if (strcmp(term_type, "TH002") == 0) {; pnmea->sentence_type = GPS_SENTENCE_TH002; - + pnmea->gps_data_good = 1; }else if (strcmp(term_type, "VTG") == 0) { pnmea->sentence_type = GPS_SENTENCE_VTG; // VTG may not contain a data qualifier, presume the solution is good @@ -612,7 +621,7 @@ static unsigned char int_to_string(int value, char* pdest, unsigned int intgr) } /* 时间处理 传入参数为日月年和毫秒*/ -static int make_date_time(gps_data* pdata, unsigned int date, unsigned int time) +static int make_date_time(gps_data_t* pdata, unsigned int date, unsigned int time) { unsigned char year, mon, day, hour, min, sec; @@ -726,7 +735,7 @@ char* get_gps_location_system_str(location_system_t lsystem) { switch(lsystem) { - case GNSS: + case GNSS_: return "全球导航卫星系统"; case GPS_L1C_A: return "全球定位系统"; @@ -743,25 +752,33 @@ switch(lsystem) } } -void dump_nmea_str(gps_nmea *nmeadata) +void dump_nmea_str(gps_nmea_t *nmeadata) { printf("\r\n"); printf("%s\r\n",get_gps_location_system_str(nmeadata->location_system)); printf("%s\r\n",get_gps_sentence_type_str(nmeadata->sentence_type)); + printf("gps_data_good %d\r\n",nmeadata->gps_data_good); + printf("\r\n"); } -void dump_location_data(gps_data*locationdata) +#define DUMP_BUF_SIZE 1024 +void dump_location_data_to_buf(gps_data_t *locationdata,char* buf,int max_buflen) { - - printf("\r\n"); - printf("20%02d-%02d-%02d,\r\n定位状态(%s)\r\n", + + char *tmpbuf=(char*)malloc(DUMP_BUF_SIZE); + if (tmpbuf == NULL) return; +#ifndef NOUTILS + memset_s(tmpbuf,DUMP_BUF_SIZE,0,DUMP_BUF_SIZE); + sprintf_s(tmpbuf,DUMP_BUF_SIZE,"20%02d-%02d-%02d,\n定位状态(%s)\n", locationdata->date_time.year, locationdata->date_time.month, locationdata->date_time.day, get_gps_status_str(locationdata->status) ); - printf("可见卫星颗数(%d),\r\n坐标(%f,%f,%d),\r\nhdop(%d),vdop(%d)\r\n", + strcat_s(buf,max_buflen,tmpbuf); + memset_s(tmpbuf,DUMP_BUF_SIZE,0,DUMP_BUF_SIZE); + sprintf_s(tmpbuf,DUMP_BUF_SIZE,"可见卫星颗数(%d),\n坐标(%f,%f,%d),\nhdop(%d),vdop(%d)\n", locationdata->num_sats, locationdata->location.lat, locationdata->location.lng, @@ -769,24 +786,79 @@ void dump_location_data(gps_data*locationdata) locationdata->hdop, locationdata->vdop ); + strcat_s(buf,max_buflen,tmpbuf); if (locationdata->startnum>0) { - printf("卫星数[%d]",locationdata->startnum); + memset_s(tmpbuf,DUMP_BUF_SIZE,0,DUMP_BUF_SIZE); + sprintf_s(tmpbuf,DUMP_BUF_SIZE,"卫星数[%d](strid,snr)",locationdata->startnum); + strcat_s(buf,max_buflen,tmpbuf); for(int i=0;i<20;i++) { if (i< locationdata->startnum) { - printf(",(%d,%d)", + memset_s(tmpbuf,DUMP_BUF_SIZE,0,DUMP_BUF_SIZE); + sprintf_s(tmpbuf,DUMP_BUF_SIZE,",(%d,%d)", locationdata->starts[i].starID, locationdata->starts[i].snr); + strcat_s(buf,max_buflen,tmpbuf); + } + } + strcat_s(buf,max_buflen,"\n"); + }else{ + strcat_s(buf,max_buflen,"无卫星数据\n"); + } +#else + strcat(buf,"\r\n"); + memset(tmpbuf,0,DUMP_BUF_SIZE); + sprintf(tmpbuf,"20%02d-%02d-%02d,\r\n定位状态(%s)\r\n", + locationdata->date_time.year, + locationdata->date_time.month, + locationdata->date_time.day, + get_gps_status_str(locationdata->status) + ); + strcat(buf,tmpbuf); + memset(tmpbuf,0,DUMP_BUF_SIZE); + sprintf(tmpbuf,"可见卫星颗数(%d),\r\n坐标(%f,%f,%d),\r\nhdop(%d),vdop(%d)\r\n", + locationdata->num_sats, + locationdata->location.lat, + locationdata->location.lng, + locationdata->location.alt, + locationdata->hdop, + locationdata->vdop + ); + strcat(buf,tmpbuf); + if (locationdata->startnum>0) + { + memset(tmpbuf,0,DUMP_BUF_SIZE); + sprintf(tmpbuf,"卫星数[%d](strid,snr)",locationdata->startnum); + strcat(buf,tmpbuf); + for(int i=0;i<20;i++) + { + if (i< locationdata->startnum) + { + memset(tmpbuf,0,DUMP_BUF_SIZE); + sprintf(tmpbuf,",(%d,%d)", + locationdata->starts[i].starID, + locationdata->starts[i].snr); + strcat(buf,tmpbuf); } } - printf("\r\n"); + strcat(buf,"\r\n"); }else{ - printf("无卫星数据\r\n"); + strcat(buf,"无卫星数据\r\n"); } - printf("\r\n"); + strcat(buf,"\r\n"); +#endif + free(tmpbuf); +} + +void dump_location_data(gps_data_t*locationdata) +{ + char* msgbuf=(char*)malloc(256); + dump_location_data_to_buf(locationdata,msgbuf,256); + printf("%s",msgbuf); + free(msgbuf); } diff --git a/code/sdk/zhihui/services/gnss/src/decodenmea.c b/code/sdk/zhihui/services/gnss/src/decodenmea.c index dbbaec492..d23c2aa69 100644 --- a/code/sdk/zhihui/services/gnss/src/decodenmea.c +++ b/code/sdk/zhihui/services/gnss/src/decodenmea.c @@ -71,7 +71,7 @@ int decode_nmea(char c) return 0; } -int main1(int argc, char** argv) +int main(int argc, char** argv) { char tmpc=0; @@ -83,7 +83,7 @@ int main1(int argc, char** argv) } -int main(int argc, char** argv) +int main1(int argc, char** argv) { for(int i=0; i