ota.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef _OTA_H
  2. #define _OTA_H
  3. #include <functional>
  4. #include <string>
  5. #include <map>
  6. class Ota {
  7. public:
  8. Ota();
  9. ~Ota();
  10. void SetCheckVersionUrl(std::string check_version_url);
  11. void SetHeader(const std::string& key, const std::string& value);
  12. void SetPostData(const std::string& post_data);
  13. bool CheckVersion();
  14. bool HasNewVersion() { return has_new_version_; }
  15. bool HasMqttConfig() { return has_mqtt_config_; }
  16. bool HasActivationCode() { return has_activation_code_; }
  17. bool HasServerTime() { return has_server_time_; }
  18. void StartUpgrade(std::function<void(int progress, size_t speed)> callback);
  19. void MarkCurrentVersionValid();
  20. const std::string& GetFirmwareVersion() const { return firmware_version_; }
  21. const std::string& GetCurrentVersion() const { return current_version_; }
  22. const std::string& GetActivationMessage() const { return activation_message_; }
  23. const std::string& GetActivationCode() const { return activation_code_; }
  24. private:
  25. std::string check_version_url_;
  26. std::string activation_message_;
  27. std::string activation_code_;
  28. bool has_new_version_ = false;
  29. bool has_mqtt_config_ = false;
  30. bool has_server_time_ = false;
  31. bool has_activation_code_ = false;
  32. std::string current_version_;
  33. std::string firmware_version_;
  34. std::string firmware_url_;
  35. std::string post_data_;
  36. std::map<std::string, std::string> headers_;
  37. void Upgrade(const std::string& firmware_url);
  38. std::function<void(int progress, size_t speed)> upgrade_callback_;
  39. std::vector<int> ParseVersion(const std::string& version);
  40. bool IsNewVersionAvailable(const std::string& currentVersion, const std::string& newVersion);
  41. };
  42. #endif // _OTA_H