~aleteoryx/muditaos

ref: 8fd488b08459d68f6101aeb681104cc172ada768 muditaos/module-apps/application-antenna/ApplicationAntenna.cpp -rw-r--r-- 5.3 KiB
8fd488b0 — Piotr Tanski [EGD-3720] Database service API cleanup for messages application. (#720) 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * ApplicationAntenna.cpp
 *
 *  Created on: 18 lut 2020
 *      Author: kuba
 */

#include "ApplicationAntenna.hpp"
#include "service-cellular/api/CellularServiceAPI.hpp"
#include "module-cellular/at/response.hpp"

#include "windows/AntennaMainWindow.hpp"
#include "windows/ScanModesWindow.hpp"

#include <ticks.hpp>
namespace app
{

    void ApplicationAntenna::timerHandler(void)
    {
        auto win = getCurrentWindow();

        if (win->getName() == gui::name::window::main_window) {
            auto window = dynamic_cast<gui::AntennaMainWindow *>(win);
            if (window != nullptr) {
                if (!cellularRequestInProgress) {
                    LOG_INFO("Get Network info");
                    cellularRequestInProgress = true;
                    CellularServiceAPI::GetNetworkInfo(this);
                }
            }
        }
    }

    ApplicationAntenna::ApplicationAntenna(std::string name, std::string parent, bool startBackgound)
        : Application(name, parent, startBackgound, 4096 * 2),
          appTimer(CreateAppTimer(2000, true, [=]() { timerHandler(); }))

    {
        busChannels.push_back(sys::BusChannels::AntennaNotifications);

        appTimer.restart();
    }

    ApplicationAntenna::~ApplicationAntenna()
    {}

    // Invoked upon receiving data message
    sys::Message_t ApplicationAntenna::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp)
    {
        auto retMsg = Application::DataReceivedHandler(msgl);
        // if message was handled by application's template there is no need to process further.
        if ((reinterpret_cast<sys::ResponseMessage *>(retMsg.get())->retCode == sys::ReturnCodes::Success)) {
            return retMsg;
        }

        // this variable defines whether message was processed.
        bool handled = false;
        if (msgl->messageType == MessageType::CellularOperatorsScanResult) {
            auto msg = dynamic_cast<cellular::RawCommandRespAsync *>(msgl);
            if (msg != nullptr) {
                auto win = getCurrentWindow();

                if (win->getName() == gui::name::window::main_window) {
                    auto window = dynamic_cast<gui::AntennaMainWindow *>(win);
                    if (window != nullptr) {

                        window->updateOperatorsScan(msg->data);
                    }
                }
                cellularRequestInProgress = false;
            }
            handled = true;
        }
        if (msgl->messageType == MessageType::CellularNetworkInfoResult) {
            auto msg = dynamic_cast<cellular::RawCommandRespAsync *>(msgl);
            if (msg != nullptr) {
                auto win = getCurrentWindow();

                if (win->getName() == gui::name::window::main_window) {
                    auto window = dynamic_cast<gui::AntennaMainWindow *>(win);
                    if (window != nullptr) {

                        window->updateDebugInfo(msg->data);
                    }
                }
                cellularRequestInProgress = false;
            }
            handled = true;
        }
        if (msgl->messageType == MessageType::CellularGetScanModeResult) {
            auto msg = dynamic_cast<cellular::RawCommandRespAsync *>(msgl);
            if (msg != nullptr) {
                auto win = getWindow(gui::name::window::scan_window);

                if (win->getName() == gui::name::window::scan_window) {
                    auto window = dynamic_cast<gui::ScanModesWindow *>(win);
                    if (window != nullptr) {

                        window->updateCurrentMode(msg->data[0]);
                    }
                }
                cellularRequestInProgress = false;
            }
            handled = true;
        }
        if (msgl->messageType == MessageType::AntennaChanged) {
            bsp::cellular::antenna antenna;
            CellularServiceAPI::GetAntenna(this, antenna);
            auto win = getCurrentWindow();

            if (win->getName() == gui::name::window::main_window) {
                auto window = dynamic_cast<gui::AntennaMainWindow *>(win);
                if (window != nullptr) {

                    window->updateAntennaButtons(antenna);
                }
            }
            handled = true;
        }
        if (handled)
            return std::make_shared<sys::ResponseMessage>();
        else
            return std::make_shared<sys::ResponseMessage>(sys::ReturnCodes::Unresolved);
    }

    // Invoked during initialization
    sys::ReturnCodes ApplicationAntenna::InitHandler()
    {

        auto ret = Application::InitHandler();
        if (ret != sys::ReturnCodes::Success)
            return ret;

        createUserInterface();

        setActiveWindow(gui::name::window::main_window);

        return ret;
    }

    sys::ReturnCodes ApplicationAntenna::DeinitHandler()
    {
        return sys::ReturnCodes::Success;
    }

    void ApplicationAntenna::createUserInterface()
    {

        gui::AppWindow *win = new gui::AntennaMainWindow(this);
        windows.insert(std::pair<std::string, gui::AppWindow *>(gui::name::window::main_window, win));

        win = new gui::ScanModesWindow(this);
        windows.insert(std::pair<std::string, gui::AppWindow *>(gui::name::window::scan_window, win));
    }

    void ApplicationAntenna::destroyUserInterface()
    {}

} /* namespace app */