Files
bolar_1/main/ota.h

52 lines
1.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include <string>
class Ota {
public:
// 检查版本(POST 到 OTA URL)
bool CheckVersion();
bool HasNewVersion() const { return has_new_version_; }
bool HasWebsocketConfig() const { return !websocket_url_.empty(); }
const std::string& GetCurrentVersion() const { return current_version_; }
const std::string& GetNewVersion() const { return new_version_; }
const std::string& GetDownloadUrl() const { return download_url_; }
const std::string& GetCheckVersionUrl() const { return check_url_; }
// 执行固件升级
bool StartUpgrade();
// A/B 分区回滚保护
void MarkCurrentVersionValid();
bool HasServerTime() const { return has_server_time_; }
// Auto-upgrade decision
bool IsAutoUpdate() const { return auto_update_; }
bool IsForceUpgrade() const { return force_upgrade_; }
bool ShouldUpgrade() const {
if (!has_new_version_) return false;
return auto_update_ || force_upgrade_;
}
bool CanDownload() const { return !download_url_.empty(); }
bool IsAutoUpgradeType() const { return auto_update_ && has_new_version_; }
bool IsForceUpgradeType() const { return !auto_update_ && force_upgrade_ && has_new_version_; }
bool IsOptionalUpgradeType() const { return !auto_update_ && !force_upgrade_ && has_new_version_; }
private:
bool ParseResponse(const char* json);
std::string check_url_;
std::string current_version_;
std::string new_version_;
std::string download_url_;
std::string websocket_url_;
std::string websocket_token_;
bool has_new_version_ = false;
bool has_server_time_ = false;
bool auto_update_ = false;
bool force_upgrade_ = false;
};