int32_t uapi_uart_write(uart_bus_t bus, const uint8_t *buffer, uint32_t length, uint32_t timeout)
{
#ifdef SUPPORT_GNSS
- if (getPGnssServerStat() == 1 && timeout != 0xFFFFFFF3)
+ if (getPGnssIsStart() == 1 && timeout != 0xFFFFFFF3)
return -1;
// if (getPGnssServerStat() == 1 && timeout == 0xFFFFFFF3 && !stat)
int32_t uapi_uart_read(uart_bus_t bus, const uint8_t *buffer, uint32_t length, uint32_t timeout)
{
#ifdef SUPPORT_GNSS
- if (getPGnssServerStat() == 1 && timeout != 0xFFFFFFF3)
+ if (getPGnssIsStart() == 1 && timeout != 0xFFFFFFF3)
return -1;
#else
/* timeout handled below */
#include "View.h"
+#include "components/ui_view.h"
+#include "components/ui_view_group.h"
#include "components/ui_scroll_view.h"
#include "components/ui_label.h"
#include "components/ui_label_ext.h"
//label
int label_x;
int label_y;
- uint8_t ALIGN;
+ UITextLanguageAlignment ALIGN;
int Fontsize;
};
virtual ~testGPSView();
static testGPSView *GetInstance(void);
- UIScrollView *testGPSInitIView(uint8_t);
+ UIViewGroup *testGPSInitIView(uint8_t);
void gpsdataTimerCallBack(void);
void ClearAll(void);
// 获取测试结果按钮的函数
UILabelButton* GetOKTestBtn() { return oktestBtn; }
UILabelButton* GetFailTestBtn() { return failtestBtn; }
+
+ // 按钮状态管理函数
+ void SetGPSButtonActive(bool isActive);
+ void ToggleGPSState(); // 切换GPS开关状态
private:
UILabelButtonExt *SetTheButton_ext(ButtonConfig_ext_t &buttonconfig);//, UIView::OnTouchListener *clickListener);
UILabel *InitLabel(LabelConfig &labelConfig);
bool testGPSScrollViewcrollViewinit(uint8_t);
- UIScrollView *testGPSScrollView{nullptr};
+
+ // 主容器和固定元素
+ UIViewGroup *mainContainer{nullptr}; // 主容器
+ UIScrollView *contentScrollView{nullptr}; // 可滚动内容区域
UILabel *label_1_GPS_MSG=NULL;
UILabel *label_1_GPS_on_or_off{nullptr};
UILabelButtonExt* GPSbutton[2]{nullptr};
+
+ // GPS状态变量
+ bool gpsIsOn{false}; // GPS开关状态
UILabelButtonExt* labelButton_next = nullptr;
bool initViewStatus{false};
#include "NMEA0183.h"
#include "pgnss_sample.h"
+#include "gnss_ctl.h"
// code/sdk/zhihui/services/gnss/inc/.h
#include "producttest/include/testView.h"
void testGPSView::ClearAll()
{
- if(testGPSScrollView)
+ if (GPS_TEST_timer != NULL) {
+ osTimerStop(GPS_TEST_timer);
+ osTimerDelete(GPS_TEST_timer);
+ GPS_TEST_timer = NULL;
+ }
+
+ // 清理固定元素
+ if(labelButton_next)
{
- testGPSScrollView->RemoveAll();
-
- if (GPS_TEST_timer != NULL) {
- osTimerStop(GPS_TEST_timer);
- osTimerDelete(GPS_TEST_timer);
- GPS_TEST_timer = NULL;
- }
- if(labelButton_next)
- {
- delete labelButton_next;
- labelButton_next=nullptr;
- }
- if(label_1_GPS_MSG)
- {
- delete label_1_GPS_MSG;
- label_1_GPS_MSG=nullptr;
- }
-
- if(label_1_GPS_on_or_off)
- {
- delete label_1_GPS_on_or_off;
- label_1_GPS_on_or_off=nullptr;
- }
-
- if(Title)
- {
- delete Title;
- Title=nullptr;
- }
-
- if(GPSbutton[0])
- {
- delete GPSbutton[0];
- GPSbutton[0]=nullptr;
- }
-
- if(GPSbutton[1])
- {
- delete GPSbutton[1];
- GPSbutton[1]=nullptr;
- }
-
- // 清理成功失败按钮
- if (oktestBtn)
- {
- delete oktestBtn;
- oktestBtn = nullptr;
- }
- if (failtestBtn)
- {
- delete failtestBtn;
- failtestBtn = nullptr;
- }
-
-
-
- delete testGPSScrollView;
- testGPSScrollView=nullptr;
- }
+ delete labelButton_next;
+ labelButton_next=nullptr;
+ }
+ if(label_1_GPS_MSG)
+ {
+ delete label_1_GPS_MSG;
+ label_1_GPS_MSG=nullptr;
+ }
+ if(label_1_GPS_on_or_off)
+ {
+ delete label_1_GPS_on_or_off;
+ label_1_GPS_on_or_off=nullptr;
+ }
+ if(Title)
+ {
+ delete Title;
+ Title=nullptr;
+ }
+ if(GPSbutton[0])
+ {
+ delete GPSbutton[0];
+ GPSbutton[0]=nullptr;
+ }
+ if(GPSbutton[1])
+ {
+ delete GPSbutton[1];
+ GPSbutton[1]=nullptr;
+ }
+
+ // 清理成功失败按钮
+ if (oktestBtn)
+ {
+ delete oktestBtn;
+ oktestBtn = nullptr;
+ }
+ if (failtestBtn)
+ {
+ delete failtestBtn;
+ failtestBtn = nullptr;
+ }
+
+ // 清理滚动内容区域
+ if(contentScrollView)
+ {
+ contentScrollView->RemoveAll();
+ delete contentScrollView;
+ contentScrollView=nullptr;
+ }
+
+ // 清理主容器
+ if(mainContainer)
+ {
+ mainContainer->RemoveAll();
+ delete mainContainer;
+ mainContainer=nullptr;
+ }
}
UILabelButtonExt *testGPSView::SetTheButton_ext(ButtonConfig_ext_t &buttonconfig)
}
button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h);
button->SetViewId(buttonconfig.ViewId);
+
+ // 默认状态:蓝色背景
button->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full);
- //button->SetStyle(STYLE_BORDER_RADIUS,0);
+ button->SetStyle(STYLE_BACKGROUND_OPA, 0x80);
+
+ // 按下状态:深灰色背景
button->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED);
- //button->SetStyleForState(STYLE_BORDER_RADIUS,0, UIButton::PRESSED);
+ button->SetStyleForState(STYLE_BACKGROUND_OPA, 0xff, UIButton::PRESSED);
+
button->SetTouchable(true);
- button->SetStyle(STYLE_BACKGROUND_OPA, 0x80);
button->SetText(buttonconfig.str);
- button->SetAlign(TEXT_ALIGNMENT_LEFT);
- button->SetLabelPosition(buttonconfig.label_x,buttonconfig.label_y );
+ button->SetAlign(buttonconfig.ALIGN); // 使用配置的对齐方式
+ button->SetLabelPosition(buttonconfig.label_x, buttonconfig.label_y);
button->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, buttonconfig.Fontsize);
- UIView:: OnClickListener *touchListener = static_cast<UIView::OnClickListener *>(testPresenter::GetInstance());
+
+ UIView::OnClickListener *touchListener = static_cast<UIView::OnClickListener *>(testPresenter::GetInstance());
button->SetOnClickListener(touchListener);
return button;
}
+
+ void testGPSView::SetGPSButtonActive(bool isActive)
+ {
+ if (GPSbutton[0] != nullptr)
+ {
+ if (isActive)
+ {
+ // 激活状态:绿色背景,文字显示"关"
+ GPSbutton[0]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Green().full);
+ GPSbutton[0]->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ GPSbutton[0]->SetText("关");
+ }
+ else
+ {
+ // 默认状态:蓝色背景,文字显示"开"
+ GPSbutton[0]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full);
+ GPSbutton[0]->SetStyle(STYLE_BACKGROUND_OPA, 0x80);
+ GPSbutton[0]->SetText("开");
+ }
+ }
+
+ // 强制刷新界面
+ RootView::GetInstance()->Invalidate();
+ }
+
+ void testGPSView::ToggleGPSState()
+ {
+ // 切换GPS状态
+ gpsIsOn = !gpsIsOn;
+
+ // 更新按钮颜色和文字
+ SetGPSButtonActive(gpsIsOn);
+
+ // 根据状态执行相应操作
+ if (gpsIsOn)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPS Toggle: Turning ON (Button: Green '关')");
+ gnss_start();
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPS Toggle: Turning OFF (Button: Blue '开')");
+ gnss_stop();
+ }
+ }
UILabel *testGPSView::InitLabel(LabelConfig &labelConfig)
{
void testGPSView:: gpsdataTimerCallBack(void)
{
if (label_1_GPS_MSG != nullptr) {
-
gps_data_t * gpsdata=getPGPSGlobaldata();
gps_data_t gpsd={0};
if (gpsdata->last_gps_time_ms>0)
bool testGPSView::testGPSScrollViewcrollViewinit(uint8_t id)
{
-
- testGPSScrollView = new UIScrollView();
- if (testGPSScrollView == nullptr)
+ // 创建主容器(固定布局)
+ mainContainer = new UIViewGroup();
+ if (mainContainer == nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemAboutTheWatchView::testGPSScrollView new fail!");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testGPSView::mainContainer new fail!");
return false;
}
- testGPSScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
- testGPSScrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
- testGPSScrollView->SetStyle(STYLE_BORDER_RADIUS, 0);
- testGPSScrollView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
- testGPSScrollView->SetStyle(STYLE_BORDER_COLOR, Color::Yellow().blue);
-
+ mainContainer->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+ mainContainer->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ mainContainer->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+
+ // 固定元素:标题(顶部固定)
+ Title = testAboutView::GetInstance()->init_title(165, 15, "GPS_TEST");
+ mainContainer->Add(Title);
+
+ // 固定元素:GPS状态显示(顶部固定,居中)
LabelConfig Config = {
- .left = 50,
- .top = 85,
- .width = Screen::GetInstance().GetWidth()-80,
+ .left = (Screen::GetInstance().GetWidth() - 200) / 2, // 居中显示
+ .top = 55,
+ .width = 200,
.height = 35,
- .fontSize = 20,
- .lineHeigh = 25,
+ .fontSize = 25, // 增大字体
+ .lineHeigh = 35,
.text = "",
.lineBreakMode = UILabel::LINE_BREAK_WRAP,
};
- label_1_GPS_MSG= InitLabel(Config);
- if (label_1_GPS_MSG == nullptr)
+ label_1_GPS_on_or_off = InitLabel(Config);
+ if (label_1_GPS_on_or_off == nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::SystemAboutTheWatchTitle new fail!");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testGPSView::label_1_GPS_on_or_off new fail!");
return false;
}
- testGPSScrollView->Add(label_1_GPS_MSG);
-
+ label_1_GPS_on_or_off->SetAlign(TEXT_ALIGNMENT_CENTER); // 设置文字居中对齐
+ mainContainer->Add(label_1_GPS_on_or_off);
+
+ // 固定元素:下一页按钮(右上角固定)
+ labelButton_next = testAboutView::GetInstance()->init_button_next(320, 55, Test_ViewMapper_t[id].viewid_str_next);
+ mainContainer->Add(labelButton_next);
+
+ // 固定元素:GPS开关按钮(中部固定,放大尺寸)
+ ButtonConfig_ext_t buttonconfig;
+ buttonconfig.x = (Screen::GetInstance().GetWidth() - 140) / 2; // 居中显示
+ buttonconfig.y = 100;
+ buttonconfig.w = 140; // 放大宽度
+ buttonconfig.h = 70; // 放大高度
+ buttonconfig.label_x = 0; // 文字居中,不需要偏移
+ buttonconfig.label_y = 0;
+ buttonconfig.Fontsize = 30; // 增大字体大小
+ buttonconfig.ViewId = GPS_OPEN_CONFIRM_BUTTON;
+ buttonconfig.str = "开"; // 改为"开"
+ buttonconfig.ALIGN = TEXT_ALIGNMENT_CENTER; // 居中对齐
+ GPSbutton[0] = SetTheButton_ext(buttonconfig);
+ mainContainer->Add(GPSbutton[0]);
+
+ // 将第二个按钮设为空,不再使用
+ GPSbutton[1] = nullptr;
+
+ // 确保按钮初始状态为蓝色(GPS关闭状态)
+ SetGPSButtonActive(false);
+
+ // 创建可滚动内容区域(下半部分)
+ contentScrollView = new UIScrollView();
+ if (contentScrollView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testGPSView::contentScrollView new fail!");
+ return false;
+ }
+ int scrollY = 190; // 固定元素下方开始滚动区域
+ int scrollHeight = Screen::GetInstance().GetHeight() - scrollY;
+ contentScrollView->SetPosition(0, scrollY, Screen::GetInstance().GetWidth(), scrollHeight);
+ contentScrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ contentScrollView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+
+ // 优化滚动体验参数 - 完全消除惯性
+ contentScrollView->SetScrollBlankSize(100); // 增大滚动空白区域,允许底部继续滑动
+ contentScrollView->SetReboundSize(0); // 设置为0,消除回弹惯性
+ contentScrollView->SetDirection(1); // 垂直滚动
+ contentScrollView->SetThrowDrag(false); // 关闭抛掷滚动惯性
+ contentScrollView->SetMaxScrollDistance(0); // 设置为0,消除最大滚动距离惯性
+ contentScrollView->SetSwipeACCLevel(0); // 关闭滑动加速度补偿
+ contentScrollView->SetYScrollBarVisible(true); // 显示滚动条
+
+ // 在可滚动区域添加GPS详细信息
Config = {
- .left = 50,
- .top = 50,
- .width = 350,
- .height = 30,
- .fontSize = 25,
- .lineHeigh = 35,
+ .left = 20,
+ .top = 20, // 相对于滚动视图的位置
+ .width = Screen::GetInstance().GetWidth()-40,
+ .height = 200, // 足够的高度容纳GPS信息
+ .fontSize = 20, // 增大GPS信息字体
+ .lineHeigh = 25,
.text = "",
.lineBreakMode = UILabel::LINE_BREAK_WRAP,
};
- label_1_GPS_on_or_off= InitLabel(Config);
- if (label_1_GPS_on_or_off == nullptr)
+ label_1_GPS_MSG = InitLabel(Config);
+ if (label_1_GPS_MSG == nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::SystemAboutTheWatchTitle new fail!");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testGPSView::label_1_GPS_MSG new fail!");
return false;
}
- testGPSScrollView->Add(label_1_GPS_on_or_off);
+ contentScrollView->Add(label_1_GPS_MSG);
- ButtonConfig_ext_t buttonconfig;
- buttonconfig.x = 20;
- buttonconfig.y = 400;
- buttonconfig.w = 180;
- buttonconfig.h = 96;
- buttonconfig.label_x=40;
- buttonconfig.label_y=0;
- buttonconfig.Fontsize=30;
- buttonconfig.ViewId=GPS_OPEN_CONFIRM_BUTTON;
- buttonconfig.str=GPS_OPEN_CONFIRM_BUTTON;
- buttonconfig.ALIGN=TEXT_ALIGNMENT_LEFT;
- GPSbutton[0]=SetTheButton_ext(buttonconfig);
- testGPSScrollView->Add( GPSbutton[0]);
- //testcat1ScrollView->Add(button);
-
- buttonconfig.x = 220;
- buttonconfig.y = 400;
- buttonconfig.w = 180;
- buttonconfig.h = 96;
- buttonconfig.label_x=40;
- buttonconfig.label_y=0;
- buttonconfig.Fontsize=30;
- buttonconfig.ViewId=GPS_CLOSE_CANCEL_BUTTON;
- buttonconfig.str=GPS_CLOSE_CANCEL_BUTTON;
- buttonconfig.ALIGN=TEXT_ALIGNMENT_LEFT;
- GPSbutton[1]=SetTheButton_ext(buttonconfig);
- testGPSScrollView->Add( GPSbutton[1]);
+ // 为可滚动区域设置拖拽属性和监听器
+ contentScrollView->SetTouchable(true);
+ contentScrollView->SetDraggable(true);
-
-
-
+ // 设置拖拽监听器以支持左滑退出功能
UIView::OnDragListener *draglistener = static_cast<UIView::OnDragListener *>(testPresenter::GetInstance());
- if (draglistener == nullptr)
+ if (draglistener != nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::draglistener can not be nullptr!");
- return false;
+ contentScrollView->SetOnDragListener(draglistener); // 恢复左滑退出功能
}
- testGPSScrollView->SetOnDragListener(draglistener);
-
-
- labelButton_next= testAboutView::GetInstance()->init_button_next(267,320,Test_ViewMapper_t[id].viewid_str_next);
- testGPSScrollView->Add(labelButton_next);
- Title= testAboutView::GetInstance()->init_title(165,45,"GPS_TEST");
- testGPSScrollView->Add(Title);
-
-
- testGPSScrollView->SetTouchable(true);
- testGPSScrollView->SetDraggable(true);
+ // 将滚动区域添加到主容器
+ mainContainer->Add(contentScrollView);
#if ENABLE_TEST_RESULT_BUTTONS
- // 使用通用的InitLabelButton函数初始化按钮,避免viewId地址过期问题
- // 获取GPS测试界面的按钮推荐位置
- int okX, okY, failX, failY;
- bool isScrollable;
- testView::GetInstance()->GetTestButtonPosition("GPS", okX, okY, failX, failY, isScrollable);
-
- if (!InitLabelButton(oktestBtn, okX, okY, 135, 88, "TestOKGPS", "成功", 30))
+ // 测试结果按钮(产测必需功能)
+ if (!InitLabelButton(oktestBtn, 50, 240, 135, 60, "TestOKGPS", "成功", 22))
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelButton for OK button failed");
return false;
}
- if (!InitLabelButton(failtestBtn, failX, failY, 135, 88, "TestNOGPS", "失败", 30))
+ if (!InitLabelButton(failtestBtn, 215, 240, 135, 60, "TestNOGPS", "失败", 22))
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitLabelButton for Fail button failed");
return false;
failtestBtn->SetOnClickListener(testPresenter::GetInstance());
// 添加到滚动视图
- testGPSScrollView->Add(oktestBtn);
- testGPSScrollView->Add(failtestBtn);
+ contentScrollView->Add(oktestBtn);
+ contentScrollView->Add(failtestBtn);
// 根据当前测试状态更新按钮颜色和状态
testView::GetInstance()->UpdateResultButtonStatus(GPS_TEST, oktestBtn, failtestBtn);
#endif
+ // 启动GPS数据更新定时器
uint32_t tick;
osStatus_t retTimer;
GPS_TEST_timer = osTimerNew((osTimerFunc_t)gpsdataTimerCallBackproc, osTimerPeriodic, NULL, NULL);
- tick =2000;// osMs2Tick(1000);
+ tick = 2000;
retTimer = osTimerStart(GPS_TEST_timer, tick);
if (retTimer != osOK && GPS_TEST_timer != NULL) {
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"StartCallTimer osTimerStart failed, ret = %lx!!", retTimer);
return true;
}
- UIScrollView *testGPSView::testGPSInitIView(uint8_t id)
+ UIViewGroup *testGPSView::testGPSInitIView(uint8_t id)
{
if (!testGPSScrollViewcrollViewinit(id))
{
return nullptr;
}
- return testGPSScrollView;
+ // 返回主容器(包含固定元素和可滚动区域)
+ return mainContainer;
}
}
{\r
return true;\r
}\r
+ \r
+ // 更严格的左滑退出限制条件\r
if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)\r
{\r
- for (int i = 1; i < MAX_TESTVIEWID; i++)\r
+ // 获取拖拽的起始点和结束点\r
+ Point startPoint = event.GetStartPoint();\r
+ Point endPoint = event.GetLastPoint();\r
+ \r
+ // 计算拖拽距离和速度\r
+ int dragDistance = endPoint.x - startPoint.x;\r
+ int dragHeight = abs(endPoint.y - startPoint.y);\r
+ \r
+ // 严格的退出条件:\r
+ // 1. 水平拖拽距离必须大于150像素\r
+ // 2. 垂直偏移不能超过50像素(保证是水平滑动)\r
+ // 3. 起始点必须在屏幕左侧30%区域内\r
+ // 4. 水平拖拽距离必须大于垂直偏移的3倍(确保是明确的水平滑动)\r
+ int screenWidth = Screen::GetInstance().GetWidth();\r
+ \r
+ if (dragDistance > 150 && // 最小拖拽距离150像素\r
+ dragHeight < 50 && // 垂直偏移不超过50像素\r
+ startPoint.x < screenWidth * 0.3 && // 起始点在左侧30%区域\r
+ dragDistance > dragHeight * 3) // 水平距离是垂直距离的3倍以上\r
{\r
- if (p_SystemView->GetSystemScrollView(i))\r
+ for (int i = 1; i < MAX_TESTVIEWID; i++)\r
{\r
- p_SystemView->ChangeView(i, TESTVIEW);\r
- break;\r
+ if (p_SystemView->GetSystemScrollView(i))\r
+ {\r
+ p_SystemView->ChangeView(i, TESTVIEW);\r
+ break;\r
+ }\r
}\r
+ return true;\r
}\r
- return true;\r
}\r
return false;\r
}\r
#if defined(SUPPORT_GNSS)\r
if (strcmp(view.GetViewId(), GPS_OPEN_CONFIRM_BUTTON) == 0)\r
{\r
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPS On OnClick");\r
- gnss_start();\r
- \r
- }\r
-\r
-\r
- if (strcmp(view.GetViewId(), GPS_CLOSE_CANCEL_BUTTON) == 0)\r
- {\r
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPS On OnClick");\r
- gnss_stop();\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPS Toggle Button OnClick");\r
+ \r
+ // 切换GPS开关状态\r
+ testGPSView* gpsView = testGPSView::GetInstance();\r
+ if (gpsView != nullptr)\r
+ {\r
+ gpsView->ToggleGPSState();\r
+ }\r
}\r
#endif\r
return false;\r
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView:: new scrollView[%d] fail", thisView);
return false;
}
- SystemScrollView[thisView] = test_GPS_view->testGPSInitIView((uint8_t)thisView);
+ SystemScrollView[thisView] = static_cast<UIScrollView*>(test_GPS_view->testGPSInitIView((uint8_t)thisView));
group->Add(SystemScrollView[thisView]);
}
/**GPS状态位*/
static int g_is_pgnss_poweron=0;
+static int g_is_pgnss_start=0;
static int g_is_pgnss_logon=0;
static int g_pgnss_stopflag=0;
static int g_cold_start_pgnss_stopflag = 0;
// {
// 设置停止标志
g_cold_start_pgnss_stopflag = 1;
- uapi_delete_files(PGNSS_DATA_PATH);
+
// }
return 0; // 返回0表示需要重新启动
cleanup_pgnss_encode_agnss_folder_path();
if (pgnss_log != NULL) {
+ printf("pgnss_log:%s\r\n",pgnss_log);
free(pgnss_log);
pgnss_log = NULL;
}
+
+ printf("PGnssServerStop: Force stop completed\r\n");
}
int getPGnssServerStat(void)
return g_is_pgnss_poweron;
}
+int getPGnssIsStart(void)
+{
+ return g_is_pgnss_start;
+}
+
int is_PGnssLogEnabled(void)
{
return g_is_pgnss_logon;
void PGnssServerStartColdStart(void)
{
printf("\nenter cold start mode\r\n");
-
- if (pgnss_log == NULL)
- {
- pgnss_log = (char *)malloc(2048);
- if (pgnss_log == NULL) {
- printf("error: malloc pgnss_log failed!\n");
- return;
- }
- memset(pgnss_log, 0, 2048);
- }
uapi_pm_add_sleep_veto(PM_ID_SYS);
#ifdef DOWNLOAD_GNSS_SWITCH
download_gnss_switch(SWITCH_TO_GNSS);
#endif
- g_is_pgnss_poweron = 1;
+
+ g_is_pgnss_start = 1;
g_pgnss_stopflag = 0;
g_cold_start_pgnss_stopflag = 0;
sw_debug_uart_deinit();
if (ret != 0) {
printf("tiot service init fail\r\n");
g_is_pgnss_poweron = 0;
+ g_is_pgnss_start = 0;
g_pgnss_stopflag = 1;
if (pgnss_log != NULL) {
free(pgnss_log);
if (handle == 0) {
printf("open tiot service fail\r\n");
g_is_pgnss_poweron = 0;
+ g_is_pgnss_start = 0;
g_pgnss_stopflag = 1;
if (pgnss_log != NULL) {
free(pgnss_log);
uapi_pm_remove_sleep_veto(PM_ID_SYS);
g_is_pgnss_poweron = 0;
+ g_is_pgnss_start = 0;
sw_debug_uart_deinit();
uart_config_init();
printf("finish cold start mode\r\n");
- printf("gnss_log: %s\r\n", pgnss_log);
+
// 释放pgnss_log内存
if (pgnss_log != NULL) {
+ printf("gnss_log: %s\r\n", pgnss_log);
free(pgnss_log);
pgnss_log = NULL;
}
}
+// 辅助函数:检查指定文件夹的文件数量
+static int count_files_in_folder(const char *folder_path)
+{
+ DIR *sub_dir = opendir(folder_path);
+ int file_count = 0;
+ if (sub_dir != NULL) {
+ struct dirent *sub_entry;
+ while ((sub_entry = readdir(sub_dir)) != NULL) {
+ // 跳过 . 和 .. 目录
+ if (strcmp(sub_entry->d_name, ".") == 0 || strcmp(sub_entry->d_name, "..") == 0) {
+ continue;
+ }
+ file_count++;
+ }
+ closedir(sub_dir);
+ }
+ return file_count;
+}
+
// 检查AGNSS文件夹是否过期的函数
static int check_agnss_folder_expired(void)
{
struct dirent *entry;
int found_valid_folder = 0;
uint32_t min_time_diff = 0xFFFFFFFF;
+ char *candidate_folder_path = malloc(512); // 存储候选文件夹路径
+ char *candidate_folder_name = malloc(256); // 存储候选文件夹名称
+ int has_candidate_folder = 0;
+ // 检查内存分配是否成功
+ if (candidate_folder_path == NULL || candidate_folder_name == NULL) {
+ printf("ERROR: Failed to allocate memory for candidate folder variables\n");
+ if (candidate_folder_path != NULL) free(candidate_folder_path);
+ if (candidate_folder_name != NULL) free(candidate_folder_name);
+ closedir(dir);
+ return 1;
+ }
+
+ // 初始化内存
+ memset(candidate_folder_path, 0, 512);
+ memset(candidate_folder_name, 0, 256);
+
+ // 第一遍扫描:查找时间有效的文件夹
while ((entry = readdir(dir)) != NULL) {
// 跳过 . 和 .. 目录
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
// 检查是否在24小时内
if (time_diff < 86400) { // 24小时 = 86400秒
- found_valid_folder = 1;
- if (time_diff < min_time_diff) {
- min_time_diff = time_diff;
- // 更新全局变量,存储最接近的时间戳文件夹路径
- if (g_current_agnss_folder != NULL) {
- free(g_current_agnss_folder);
- g_current_agnss_folder = NULL;
- }
- g_current_agnss_folder = malloc(256);
- if (g_current_agnss_folder != NULL) {
- int ret = snprintf(g_current_agnss_folder, 256, "%s/%s", PGNSS_DATA_PATH, entry->d_name);
- if (ret < 0 || ret >= 256) {
- printf("ERROR: snprintf failed or buffer overflow for g_current_agnss_folder\n");
+ // 构建完整路径以检查文件数量
+ char full_folder_path[512];
+ int path_ret = snprintf(full_folder_path, sizeof(full_folder_path), "%s/%s", PGNSS_DATA_PATH, entry->d_name);
+ if (path_ret < 0 || path_ret >= sizeof(full_folder_path)) {
+ printf("ERROR: snprintf failed for folder path\n");
+ continue;
+ }
+
+ // 检查文件夹内的文件数量
+ int file_count = count_files_in_folder(full_folder_path);
+ if (file_count < 0) {
+ printf("Cannot open AGNSS folder: %s\n", full_folder_path);
+ continue;
+ }
+
+ // 检查文件数量是否为26个
+ if (file_count >= 20) {
+ found_valid_folder = 1;
+ if (time_diff < min_time_diff) {
+ min_time_diff = time_diff;
+ // 更新全局变量,存储最接近的时间戳文件夹路径
+ if (g_current_agnss_folder != NULL) {
free(g_current_agnss_folder);
g_current_agnss_folder = NULL;
}
- } else {
- printf("ERROR: Failed to allocate memory for g_current_agnss_folder\n");
+ g_current_agnss_folder = malloc(256);
+ if (g_current_agnss_folder != NULL) {
+ int ret = snprintf(g_current_agnss_folder, 256, "%s/%s", PGNSS_DATA_PATH, entry->d_name);
+ if (ret < 0 || ret >= 256) {
+ printf("ERROR: snprintf failed or buffer overflow for g_current_agnss_folder\n");
+ free(g_current_agnss_folder);
+ g_current_agnss_folder = NULL;
+ }
+ } else {
+ printf("ERROR: Failed to allocate memory for g_current_agnss_folder\n");
+ }
+ }
+ printf("Found valid AGNSS folder: %s (time diff: %u seconds, file count: %d)\n",
+ entry->d_name, time_diff, file_count);
+ } else {
+ printf("Found AGNSS folder with invalid file count: %s (time diff: %u seconds, file count: %d/26)\n",
+ entry->d_name, time_diff, file_count);
+
+ // 如果时间有效但文件数量不足,记录为候选文件夹
+ if (time_diff < min_time_diff) {
+ min_time_diff = time_diff;
+ has_candidate_folder = 1;
+ strncpy(candidate_folder_path, full_folder_path, 512 - 1);
+ strncpy(candidate_folder_name, entry->d_name, 256 - 1);
+ candidate_folder_path[512 - 1] = '\0';
+ candidate_folder_name[256 - 1] = '\0';
}
}
- printf("Found valid AGNSS folder: %s (time diff: %u seconds)\n",
- entry->d_name, time_diff);
} else {
printf("Found expired AGNSS folder: %s (time diff: %u seconds, %.1f days)\n",
entry->d_name, time_diff, time_diff / 86400.0);
closedir(dir);
- if (!found_valid_folder) {
- printf("No valid AGNSS folder found within 24 hours\n");
- return 1; // 过期
+ // 如果找到了完整的有效文件夹,直接返回
+ if (found_valid_folder) {
+ free(candidate_folder_path);
+ free(candidate_folder_name);
+ return 0; // 未过期
}
-
- return 0; // 未过期
+
+ // 如果有候选文件夹(时间有效但文件不足),进入2秒循环检查
+ if (has_candidate_folder) {
+ printf("Found candidate AGNSS folder but file count insufficient. Starting 2-second interval monitoring...\n");
+ printf("Monitoring folder: %s\n", candidate_folder_name);
+
+ // 设置最大等待时间(只重试5次 = 10秒)
+ int max_wait_cycles = 5; // 10秒 / 2秒 = 5次
+ int current_cycle = 0;
+
+ while (current_cycle < max_wait_cycles) {
+ // 等待2秒
+ LOS_Msleep(2000);
+ current_cycle++;
+
+ // 检查文件数量
+ int file_count = count_files_in_folder(candidate_folder_path);
+ printf("Cycle %d: Checking %s - file count: %d/26\n",
+ current_cycle, candidate_folder_name, file_count);
+
+ if (file_count == 26) {
+ printf("SUCCESS: AGNSS folder now has 26 files! %s\n", candidate_folder_name);
+
+ // 更新全局变量,存储有效的文件夹路径
+ if (g_current_agnss_folder != NULL) {
+ free(g_current_agnss_folder);
+ g_current_agnss_folder = NULL;
+ }
+ g_current_agnss_folder = malloc(256);
+ if (g_current_agnss_folder != NULL) {
+ int ret = snprintf(g_current_agnss_folder, 256, "%s", candidate_folder_path);
+ if (ret < 0 || ret >= 256) {
+ printf("ERROR: snprintf failed or buffer overflow for g_current_agnss_folder\n");
+ free(g_current_agnss_folder);
+ g_current_agnss_folder = NULL;
+ free(candidate_folder_path);
+ free(candidate_folder_name);
+ return 1; // 失败
+ }
+ } else {
+ printf("ERROR: Failed to allocate memory for g_current_agnss_folder\n");
+ free(candidate_folder_path);
+ free(candidate_folder_name);
+ return 1; // 失败
+ }
+
+ free(candidate_folder_path);
+ free(candidate_folder_name);
+ return 0; // 未过期,文件已完整
+ }
+
+ // 每30次循环(60秒)打印一次状态
+ if (current_cycle % 30 == 0) {
+ printf("Still waiting for files... Elapsed: %d seconds, Files: %d/26\n",
+ current_cycle * 2, file_count);
+ }
+ }
+
+ printf("TIMEOUT: Waited %d seconds but AGNSS folder still incomplete (%s)\n",
+ max_wait_cycles * 2, candidate_folder_name);
+ }
+
+ printf("No valid AGNSS folder found within 24 hours with 26 files\n");
+ free(candidate_folder_path);
+ free(candidate_folder_name);
+ return 1; // 过期
}
// PGNSS启动前检查函数:检查AGNSS文件夹是否过期,过期则尝试下载
void PGnssServerStart(void)
{
+ if(g_is_pgnss_poweron == 1)
+ {
+ printf("gnss already on\r\n");
+ return ;
+ }
+
+ g_is_pgnss_poweron = 1;
//未绑定直接冷启动
if(cm_getisFirstTimeStart())
{
memset(pgnss_log, 0, 2048);
}
- if(g_is_pgnss_poweron == 1)
- {
- printf("gnss already on\r\n");
- if (pgnss_log != NULL) {
- free(pgnss_log);
- pgnss_log = NULL;
- }
- return ;
- }
+
uapi_pm_add_sleep_veto(PM_ID_SYS);
#ifdef DOWNLOAD_GNSS_SWITCH
download_gnss_switch(SWITCH_TO_GNSS);
#endif
- g_is_pgnss_poweron = 1;
+
+ g_is_pgnss_start = 1;
g_pgnss_stopflag = 0;
g_cold_start_pgnss_stopflag = 0;
sw_debug_uart_deinit();
if (ret != 0) {
printf("tiot service init fail\r\n");
g_is_pgnss_poweron = 0;
+ g_is_pgnss_start = 0;
g_pgnss_stopflag = 1;
if (pgnss_log != NULL) {
free(pgnss_log);
if (handle == 0) {
printf("open tiot service fail\r\n");
g_is_pgnss_poweron = 0;
+ g_is_pgnss_start = 0;
g_pgnss_stopflag = 1;
g_cold_start_pgnss_stopflag = 1;
if (pgnss_log != NULL) {
#endif
uapi_pm_remove_sleep_veto(PM_ID_SYS);
if(!g_cold_start_pgnss_stopflag)
+ {
+ g_is_pgnss_start = 0;
g_is_pgnss_poweron = 0;
+ }
+
sw_debug_uart_deinit();
uart_config_init();
printf("finish gnss samples\r\n");
- printf("pgnss_log: %s\r\n", pgnss_log);
+
// 释放pgnss_log内存
if (pgnss_log != NULL) {
+ printf("pgnss_log:%s\r\n",pgnss_log);
free(pgnss_log);
pgnss_log = NULL;
}
if(g_cold_start_pgnss_stopflag == 1)
{
- // GnssServerStart();
PGnssServerStartColdStart();
}
* @Author: penglei 1624952103@qq.com\r
* @Date: 2025-07-11 16:41:59\r
* @LastEditors: penglei 1624952103@qq.com\r
- * @LastEditTime: 2025-07-18 17:39:28\r
+ * @LastEditTime: 2025-09-12 11:37:49\r
* @FilePath: /FD230/code/sdk/drivers/peripheral/gnss/sample/pgnss_sample/pgnss_sample.h\r
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE\r
*/\r
void PGnssServerStart(void);\r
void PGnssServerStop(void);\r
int getPGnssServerStat(void);\r
+int getPGnssIsStart(void);\r
#ifdef __cplusplus\r
}\r
#endif /* __cplusplus */\r