2024-11-05 20:15:00 +08:00
|
|
|
#ifndef _OTA_H
|
|
|
|
|
#define _OTA_H
|
2024-10-01 14:16:12 +08:00
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <map>
|
2024-10-03 06:39:22 +08:00
|
|
|
|
2024-11-05 20:15:00 +08:00
|
|
|
class Ota {
|
2024-10-01 14:16:12 +08:00
|
|
|
public:
|
2024-11-05 20:15:00 +08:00
|
|
|
Ota();
|
|
|
|
|
~Ota();
|
2024-10-01 14:16:12 +08:00
|
|
|
|
|
|
|
|
void SetCheckVersionUrl(std::string check_version_url);
|
|
|
|
|
void SetHeader(const std::string& key, const std::string& value);
|
2024-11-03 05:54:15 +08:00
|
|
|
void SetPostData(const std::string& post_data);
|
2024-11-15 04:44:53 +08:00
|
|
|
bool CheckVersion();
|
2024-10-01 14:16:12 +08:00
|
|
|
bool HasNewVersion() { return has_new_version_; }
|
2024-11-14 23:15:43 +08:00
|
|
|
bool HasMqttConfig() { return has_mqtt_config_; }
|
2025-02-11 16:56:23 +08:00
|
|
|
bool HasActivationCode() { return has_activation_code_; }
|
2024-10-01 14:16:12 +08:00
|
|
|
void StartUpgrade(std::function<void(int progress, size_t speed)> callback);
|
|
|
|
|
void MarkCurrentVersionValid();
|
|
|
|
|
|
2024-11-18 06:17:39 +08:00
|
|
|
const std::string& GetFirmwareVersion() const { return firmware_version_; }
|
|
|
|
|
const std::string& GetCurrentVersion() const { return current_version_; }
|
2025-02-11 16:56:23 +08:00
|
|
|
const std::string& GetActivationMessage() const { return activation_message_; }
|
|
|
|
|
const std::string& GetActivationCode() const { return activation_code_; }
|
2024-11-18 06:17:39 +08:00
|
|
|
|
2024-10-01 14:16:12 +08:00
|
|
|
private:
|
|
|
|
|
std::string check_version_url_;
|
2025-02-11 16:56:23 +08:00
|
|
|
std::string activation_message_;
|
|
|
|
|
std::string activation_code_;
|
2024-10-01 14:16:12 +08:00
|
|
|
bool has_new_version_ = false;
|
2024-11-14 23:15:43 +08:00
|
|
|
bool has_mqtt_config_ = false;
|
2025-02-11 16:56:23 +08:00
|
|
|
bool has_activation_code_ = false;
|
2024-11-18 06:17:39 +08:00
|
|
|
std::string current_version_;
|
2024-10-01 14:16:12 +08:00
|
|
|
std::string firmware_version_;
|
|
|
|
|
std::string firmware_url_;
|
2024-11-03 05:54:15 +08:00
|
|
|
std::string post_data_;
|
2024-10-01 14:16:12 +08:00
|
|
|
std::map<std::string, std::string> headers_;
|
|
|
|
|
|
|
|
|
|
void Upgrade(const std::string& firmware_url);
|
|
|
|
|
std::function<void(int progress, size_t speed)> upgrade_callback_;
|
|
|
|
|
std::vector<int> ParseVersion(const std::string& version);
|
|
|
|
|
bool IsNewVersionAvailable(const std::string& currentVersion, const std::string& newVersion);
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-05 20:15:00 +08:00
|
|
|
#endif // _OTA_H
|