~aleteoryx/muditaos

ref: 9a7982f8efa4974f7f1396232fa2c09db0f6908e muditaos/module-apps/application-settings/windows/Fota.hpp -rw-r--r-- 1.7 KiB
9a7982f8 — Marcin Smoczyński changelog: update changelog for v0.48.1 (#1104) (#1106) 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <Service/Service.hpp>
#include <Application.hpp>

#include <string>

namespace gui
{
    class Label;
    class FotaWindow;
} // namespace gui

class Fota
{
    enum class State
    {
        Disconnected,
        Configuring,
        Configured,
        Connecting,
        Connected,
        DownloadingInfo,
        DownloadedInfo,
        ParsingInfo,
        NeedUpdate,
        Updating,
        Finished,
        Reboot,
    };

  public:
    struct VersionInfo
    {
        std::string newVersion;
        std::string file;
    };
    using VersionMap = std::unordered_map<std::string, VersionInfo>;
    Fota(gui::FotaWindow *parent);
    virtual ~Fota();
    void next();
    std::string getCurrentFirmwareVersion()
    {
        return currentFirmwareVersion;
    }
    std::string getStateString();
    State getState()
    {
        return currentState;
    };

  private:
    void configureAPN();
    void connect();
    void downloadInfo();
    void parseInfo(std::string data);
    void checkIfUpdateRequired();
    void update();
    void reboot();

    void registerHandlers();
    void handleInternetNotification();
    void handleHTTPResponse();
    void handleFotaProgres();
    void handleFotaFinished();

    void getCurrentVersion();
    void updateStatus();
    State currentState;

    gui::FotaWindow *parent = nullptr;
    std::shared_ptr<app::Application> app;
    std::string currentFirmwareVersion;
    std::string newFirmwareVersion;
    VersionMap versionMap;
    static std::string urlPrefix;
    static std::string versionFile;
};