~aleteoryx/muditaos

ref: 9eeeb6ae929009c475b2748dc79e3407002876d6 muditaos/source/main.cpp -rw-r--r-- 8.5 KiB
9eeeb6ae — Bartek Cichocki [EGD-3502] reworked endpoints and handlers 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include <memory>
#include <list>

#include "../module-gui/gui/core/ImageManager.hpp"
#include "log/log.hpp"
#include "memory/usermem.h"
#include "ticks.hpp"
#include <source/version.hpp>

// module-applications
#include "application-antenna/ApplicationAntenna.hpp"
#include "application-call/ApplicationCall.hpp"
#include "application-calllog/ApplicationCallLog.hpp"
#include "application-clock/ApplicationClock.hpp"
#include "application-desktop/ApplicationDesktop.hpp"
#include "application-messages/ApplicationMessages.hpp"
#include "application-notes/ApplicationNotes.hpp"
#include "application-phonebook/ApplicationPhonebook.hpp"
#include "application-settings/ApplicationSettings.hpp"
#include "application-special-input/AppSpecialInput.hpp"
#include "application-viewer/ApplicationViewer.hpp"
#include "application-calendar/ApplicationCalendar.hpp"
#include "application-music-player/ApplicationMusicPlayer.hpp"

// module-services
#include "service-appmgr/ApplicationManager.hpp"
#include "service-audio/ServiceAudio.hpp"
#include "service-audio/api/AudioServiceAPI.hpp"
#include "service-cellular/ServiceCellular.hpp"
#include "service-cellular/api/CellularServiceAPI.hpp"
#include "service-db/ServiceDB.hpp"
#include "service-db/api/DBServiceAPI.hpp"
#include "service-desktop/ServiceDesktop.hpp"
#include "service-evtmgr/Constants.hpp"
#include "service-evtmgr/EventManager.hpp"
#include "service-fota/ServiceFota.hpp"
#include "service-antenna/ServiceAntenna.hpp"

// module-bsp
#include "bsp/bsp.hpp"
#include "bsp/rtc/rtc.hpp"
#include "bsp/keyboard/keyboard.hpp"

// module-vfs
#include "vfs.hpp"

// module-sys
#include "SystemManager/SystemManager.hpp"

// libphonenumber
#include <phonenumbers/phonenumberutil.h>

class vfs vfs;

class BlinkyService : public sys::Service
{

  public:
    BlinkyService(const std::string &name) : sys::Service(name)
    {
        timerBlinkyID = CreateTimer(5000, true);
        // ReloadTimer(timer_id);
    }

    ~BlinkyService()
    {}
    //    DBThreadResponseMessage* threadResponse = reinterpret_cast<DBThreadResponseMessage*>(ret.second.get());
    //    if((ret.first == sys::ReturnCodes::Success) && (threadResponse->retCode == true)){
    //        return std::move(threadResponse->records);
    //    }
    //    else{
    //        return std::make_unique<std::vector<ThreadRecord>>();
    //    }
    // Invoked upon receiving data message
    sys::Message_t DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp = nullptr) override
    {

#if 0 // M.P: left here on purpose
      // auto ret = AudioServiceAPI::PlaybackStart(this,"/home/mateusz/Music/limowreck.mp3");
/*        auto ret = AudioServiceAPI::PlaybackStart(this,"sys/audio/limowreck.flac");
        AudioServiceAPI::Stop(this);
        AudioServiceAPI::PlaybackStart(this,"sys/audio/limowreck.flac");*/
        //vTaskDelay(3000);
        //AudioServiceAPI::SetOutputVolume(this,0.6);
        //auto ret = AudioServiceAPI::RecordingStart(this,"sys/audio/rec1mono.wav");
        //vTaskDelay(3000);
        //ret = AudioServiceAPI::Stop(this);
        //vTaskDelay(500);
        //ret = AudioServiceAPI::PlaybackStart(this,"sys/audio/limowreck.flac");


       //auto ret = AudioServiceAPI::RoutingStart(this);
        /*
         //AudioServiceAPI::RoutingRecordCtrl(this,true);
         vTaskDelay(1000);
         //AudioServiceAPI::RoutingSpeakerPhone(this,true);
         vTaskDelay(2000);
         AudioServiceAPI::Stop(this);*/

        //auto ret = AudioServiceAPI::PlaybackStart(this,"sys/audio/limowreck.flac");

#endif

        return std::make_shared<sys::ResponseMessage>();
    }

    // Invoked when timer ticked
    void TickHandler(uint32_t id) override
    {

#if 0 // M.P: left here on purpose
        LOG_DEBUG("Blinky service tick!");

        stopTimer(timerClockID);
        std::shared_ptr<sys::DataMessage> msg = std::make_shared<sys::DataMessage>(static_cast<uint32_t >(MessageType::AudioSetInputGain));

        sys::Bus::SendUnicast(msg,GetName(),this);
#endif
    }

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

        return sys::ReturnCodes::Success;
    }

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

    sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode /*mode*/) override final
    {
        return sys::ReturnCodes::Success;
    }

    uint32_t timerBlinkyID = 0;
};

int main()
{

#if SYSTEM_VIEW_ENABLED
    SEGGER_SYSVIEW_Conf();
    SEGGER_SYSVIEW_DisableEvents(SYSVIEW_EVTMASK_ISR_ENTER);
    SEGGER_SYSVIEW_DisableEvents(SYSVIEW_EVTMASK_ISR_EXIT);
    SEGGER_SYSVIEW_DisableEvents(SYSVIEW_EVTMASK_ISR_TO_SCHEDULER);
    SEGGER_SYSVIEW_WaitForConnection();
    SEGGER_SYSVIEW_Start();
#endif

    bsp::BoardInit();

    LOG_PRINTF("Launching PurePhone \n");
    LOG_PRINTF("commit: %s tag: %s branch: %s\n", GIT_REV, GIT_TAG, GIT_BRANCH);

#if 1
    auto sysmgr = std::make_shared<sys::SystemManager>(5000);

    sysmgr->StartSystem([sysmgr]() -> int {
        /// force initialization of PhonenumberUtil because of its stack usage
        /// otherwise we would end up with an init race and PhonenumberUtil could
        /// be initiated in a task with stack not big enough to handle it
        i18n::phonenumbers::PhoneNumberUtil::GetInstance();

        vfs.Init();

        bool ret = false;

        ret |=
            sys::SystemManager::CreateService(std::make_shared<EventManager>(service::name::evt_manager), sysmgr.get());
        ret |= sys::SystemManager::CreateService(std::make_shared<ServiceDB>(), sysmgr.get());
        ret |= sys::SystemManager::CreateService(std::make_shared<BlinkyService>("Blinky"), sysmgr.get());
//        ret |= sys::SystemManager::CreateService(std::make_shared<ServiceAntenna>(), sysmgr.get());
#if defined(TARGET_Linux) && not defined(SERIAL_PORT)
        // For now disable pernamenlty Service cellular when there is no GSM configured
        LOG_INFO("ServiceCellular (GSM) - Disabled");
#else
        LOG_INFO("ServiceCellular (GSM) - Enabling");
        ret |= sys::SystemManager::CreateService(std::make_shared<ServiceCellular>(), sysmgr.get());
        ret |= sys::SystemManager::CreateService(std::make_shared<FotaService::Service>(), sysmgr.get());
#endif
        ret |= sys::SystemManager::CreateService(std::make_shared<ServiceAudio>(), sysmgr.get());

        // Service Desktop disabled on master - pulling read on usb driver
        ret |= sys::SystemManager::CreateService(std::make_shared<ServiceDesktop>(), sysmgr.get());

        // vector with launchers to applications
        std::vector<std::unique_ptr<app::ApplicationLauncher>> applications;
#ifdef ENABLE_APP_VIEWER
        applications.push_back(app::CreateLauncher<app::ApplicationViewer>(app::name_viewer));
#endif
#ifdef ENABLE_APP_DESKTOP
        applications.push_back(app::CreateLauncher<app::ApplicationDesktop>(app::name_desktop, false));
#endif
#ifdef ENABLE_APP_CALL
        applications.push_back(app::CreateLauncher<app::ApplicationCall>(app::name_call, false));
#endif
#ifdef ENABLE_APP_SETTINGS
        applications.push_back(app::CreateLauncher<app::ApplicationSettings>(app::name_settings));
#endif
#ifdef ENABLE_APP_NOTES
        applications.push_back(app::CreateLauncher<app::ApplicationNotes>(app::name_notes));
#endif
#ifdef ENABLE_APP_CALLLOG
        applications.push_back(app::CreateLauncher<app::ApplicationCallLog>(app::CallLogAppStr));
#endif
#ifdef ENABLE_APP_PHONEBOOK
        applications.push_back(app::CreateLauncher<app::ApplicationPhonebook>(app::name_phonebook));
#endif
#ifdef ENABLE_APP_MESSAGES
        applications.push_back(app::CreateLauncher<app::ApplicationMessages>(app::name_messages));
#endif
#ifdef ENABLE_APP_SPECIAL_INPUT
        applications.push_back(app::CreateLauncher<app::AppSpecialInput>(app::special_input, false));
#endif
#ifdef ENABLE_APP_ANTENNA
        applications.push_back(app::CreateLauncher<app::ApplicationAntenna>(app::name_antenna));
#endif
#ifdef ENABLE_APP_CALENDAR
        applications.push_back(app::CreateLauncher<app::ApplicationCalendar>(app::name_calendar));
#endif
#ifdef ENABLE_APP_MUSIC_PLAYER
        applications.push_back(app::CreateLauncher<app::ApplicationMusicPlayer>(app::name_music_player));
#endif

        // start application manager
        ret |= sysmgr->CreateService(
            std::make_shared<sapm::ApplicationManager>("ApplicationManager", sysmgr.get(), applications), sysmgr.get());

        if (ret) {
            return 0;
        }

        return 0;
    });

    cpp_freertos::Thread::StartScheduler();
#endif
    return 1;
}