ota.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef _OTA_H
  2. #define _OTA_H
  3. #include <functional>
  4. #include <string>
  5. #include <esp_err.h>
  6. #include "board.h"
  7. class Ota {
  8. public:
  9. Ota();
  10. ~Ota();
  11. bool CheckVersion();
  12. esp_err_t Activate();
  13. bool HasActivationChallenge() { return has_activation_challenge_; }
  14. bool HasNewVersion() { return has_new_version_; }
  15. bool HasMqttConfig() { return has_mqtt_config_; }
  16. bool HasWebsocketConfig() { return has_websocket_config_; }
  17. bool HasActivationCode() { return has_activation_code_; }
  18. bool HasServerTime() { return has_server_time_; }
  19. bool StartUpgrade(std::function<void(int progress, size_t speed)> callback);
  20. void MarkCurrentVersionValid();
  21. const std::string& GetFirmwareVersion() const { return firmware_version_; }
  22. const std::string& GetCurrentVersion() const { return current_version_; }
  23. const std::string& GetActivationMessage() const { return activation_message_; }
  24. const std::string& GetActivationCode() const { return activation_code_; }
  25. std::string GetCheckVersionUrl();
  26. private:
  27. std::string activation_message_;
  28. std::string activation_code_;
  29. bool has_new_version_ = false;
  30. bool has_mqtt_config_ = false;
  31. bool has_websocket_config_ = false;
  32. bool has_server_time_ = false;
  33. bool has_activation_code_ = false;
  34. bool has_serial_number_ = false;
  35. bool has_activation_challenge_ = false;
  36. std::string current_version_;
  37. std::string firmware_version_;
  38. std::string firmware_url_;
  39. std::string activation_challenge_;
  40. std::string serial_number_;
  41. int activation_timeout_ms_ = 30000;
  42. bool Upgrade(const std::string& firmware_url);
  43. std::function<void(int progress, size_t speed)> upgrade_callback_;
  44. std::vector<int> ParseVersion(const std::string& version);
  45. bool IsNewVersionAvailable(const std::string& currentVersion, const std::string& newVersion);
  46. std::string GetActivationPayload();
  47. std::unique_ptr<Http> SetupHttp();
  48. };
  49. #endif // _OTA_H