#include "gnss_http_server.h"
#endif
+//最长的有效期 目前为2天
+#define MAX_VALIDITY_PERIOD 2 * 24 * 60
+
namespace OHOS {
EphemerisDownloadModel::EphemerisDownloadModel() {}
EphemerisDownloadModel::~EphemerisDownloadModel() {}
+void EphemerisDownloadModel::DownloadEphemeris() {}
+//获取有效期接口
+bool EphemerisDownloadModel::GetValidityPeriod() {
+#if defined(SUPPORT_GNSS)
+ int validityPeriod = gnss_check_agnss_status();
+ if (validityPeriod > 0 && validityPeriod <= MAX_VALIDITY_PERIOD) {
+ return true;
+ }
+#endif
+ return false;
+}
+/*
+1、调用下载接口
+2、修改状态为下载中
+3、检测有效期,如果是有效的 则不能下载
+4、如果状态为下载中,则不能下载
+*/
void EphemerisDownloadModel::DownloadEphemeris() {
- //调用下载接口
- //修改状态为下载中
+ if (ephemerisDownloadStatus == EphemerisDownloadStatus::DOWNLOADING) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PGNSS正在下载");
+ return;
+ }
+#if defined(SUPPORT_GNSS)
+ if (GetValidityPeriod()) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PGNSS有效");
+ return;
+ }
+#endif
ephemerisDownloadStatus = EphemerisDownloadStatus::DOWNLOADING;
#if defined(SUPPORT_GNSS)
do_gnss_http_server_send_data(GNSS_HTTP_SERVICE_CMD_DOWNLOAD_AGNSS, NULL, 0);
}
/*
获取下载状态
-//返回值:过期返回8,有效返回剩余时间的分钟数,错误返回-1
+返回值:过期返回0,有效返回剩余时间的分钟数,错误返回-1
int gnss_check_agnss_status(void);
-//简化的下载进度状态位
-//0:正在建立HTTP连接
-//-1:下载失败
-//1-9:下载进度(10%,20%,...,90%)
-//10:下载完成
+简化的下载进度状态位
+0:正在建立HTTP连接
+-1:下载失败
+1-9:下载进度(10%,20%,...,90%)
+10:下载完成
int gnss_get_download_status(void);
*/
int EphemerisDownloadModel::GetEphemerisDownloadProgress() {
#if defined(SUPPORT_GNSS)
int download_status = gnss_get_download_status();
- if(download_status == -1)
- {
- ephemerisDownloadStatus = EphemerisDownloadStatus::FAILED;
- }
- else if(download_status == 0)
- {
- ephemerisDownloadStatus = EphemerisDownloadStatus::DOWNLOADING;
- }
- else if(download_status == 10)
- {
- ephemerisDownloadStatus = EphemerisDownloadStatus::DOWNLOADED;
+ if (download_status == -1) {
+ ephemerisDownloadStatus = EphemerisDownloadStatus::FAILED;
+ } else if (download_status == 0) {
+ ephemerisDownloadStatus = EphemerisDownloadStatus::DOWNLOADING;
+ } else if (download_status == 10) {
+ ephemerisDownloadStatus = EphemerisDownloadStatus::DOWNLOADED;
}
return download_status;
#endif
#if defined(SUPPORT_GNSS)
int validityPeriod = gnss_check_agnss_status();
if (validityPeriod > 0) {
- ephemerisValidityPeriod =
- "有效期: " + std::to_string(validityPeriod) + "分钟";
+
+ //需要显示 天 小时 分钟的格式
+ int days = validityPeriod / (24 * 60);
+ int hours = (validityPeriod % (24 * 60)) / 60;
+ int minutes = validityPeriod % 60;
+ ephemerisValidityPeriod = "有效期: " + std::to_string(days) + "天" +
+ std::to_string(hours) + "小时" +
+ std::to_string(minutes) + "分钟";
} else {
ephemerisValidityPeriod = "无星历数据";
}
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelTitle_ new failed");
return false;
}
- labelTitle_->SetPosition(83, 50, 300, 60);
+ labelTitle_->SetPosition(83, 50, 350, 60);
labelTitle_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
labelTitle_->SetText("下载星历");
labelTitle_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelStatus_ new failed");
return false;
}
- labelStatus_->SetPosition(90, 120, 200, 40);
+ labelStatus_->SetPosition(90, 120, 300, 40);
labelStatus_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24);
labelStatus_->SetText("未下载");
labelStatus_->SetTextColor(Color::Yellow());
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "labelValidity_ new failed");
return false;
}
- labelValidity_->SetPosition(90, 170, 300, 40);
+ labelValidity_->SetPosition(90, 170, 350, 40);
labelValidity_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20);
labelValidity_->SetText("有效期: 无");
labelValidity_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f));
btnDownload_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24);
btnDownload_->SetViewId(DOWNLOAD_ID);
btnDownload_->SetOnClickListener(presenter_);
+
+ //如果有效期大于0,则不能下载 下载按键显示灰色;否则显示绿色
+ if(EphemerisDownloadModel::GetInstance().GetValidityPeriod())
+ {
+ btnDownload_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x5f));
+ btnDownload_->SetBackgroundColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x5f));
+ }
+ else
+ {
+ btnDownload_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff));
+ btnDownload_->SetBackgroundColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff));
+ }
+
AddViewToRootContainer(btnDownload_);
// 初始化返回按钮