bolar_1 date 2026-7-1 d:/proc

This commit is contained in:
2026-11-27 17:44:38 +08:00
commit 0dbdfa57bc
890 changed files with 325428 additions and 0 deletions

51
main/ota.h Normal file
View File

@@ -0,0 +1,51 @@
#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;
};