From 320174eafc1530c4ae4610499cc5466c9c7f347c Mon Sep 17 00:00:00 2001
From: kkleczkowski <49439739+kkleczkowski@users.noreply.github.com>
Date: Tue, 8 Dec 2020 12:01:58 +0100
Subject: [PATCH] [EGD-4522] USSD sesion handling (#1121)
Added USSD sesion handlig and small fixes on USSD.
Session handling was needed to show proper window on new incoming USSD code.
Co-authored-by: Kuba Kleczkowski
---
changelog.md | 1 +
.../ApplicationSettings.cpp | 21 ---
.../application-settings/CMakeLists.txt | 2 -
.../windows/SettingsMainWindow.cpp | 2 -
.../windows/USSDWindow.cpp | 120 ------------------
.../windows/USSDWindow.hpp | 49 -------
module-cellular/at/Urc.hpp | 5 +-
module-cellular/at/UrcCusd.hpp | 3 +-
module-cellular/at/src/Commands.cpp | 2 +-
module-cellular/at/src/Urc.cpp | 9 +-
module-cellular/at/src/UrcCusd.cpp | 29 +++++
module-cellular/at/src/UrcFactory.cpp | 1 -
.../service-cellular/CellularUrcHandler.cpp | 19 +--
.../service-cellular/ServiceCellular.cpp | 5 -
.../service-cellular/CellularMessage.hpp | 1 -
15 files changed, 51 insertions(+), 218 deletions(-)
delete mode 100644 module-apps/application-settings/windows/USSDWindow.cpp
delete mode 100644 module-apps/application-settings/windows/USSDWindow.hpp
diff --git a/changelog.md b/changelog.md
index 2cb0ed794620ea673e0b6e5325ba31983091bcf6..b9dc8ed030d3b460ff0260f2bc2dcb593210c2f7 100644
--- a/changelog.md
+++ b/changelog.md
@@ -19,6 +19,7 @@
* `[text]` Added cursor starting position handling.
* `[alarms]` Added main window
* `[PowerManagement]` PowerManagement: Enable FreeRTOS Run Time Statistics
+* `[cellular]` USSD session handling.
### Changed
diff --git a/module-apps/application-settings/ApplicationSettings.cpp b/module-apps/application-settings/ApplicationSettings.cpp
index 112dc170629476a57f466168e8f8ac0c14d81462..4535cdbbdca17dcead725433e67ab78d09e13d5d 100644
--- a/module-apps/application-settings/ApplicationSettings.cpp
+++ b/module-apps/application-settings/ApplicationSettings.cpp
@@ -12,7 +12,6 @@
#include "windows/Info.hpp"
#include "windows/LanguageWindow.hpp"
#include "windows/SettingsMainWindow.hpp"
-#include "windows/USSDWindow.hpp"
#include "windows/UITestWindow.hpp"
@@ -89,22 +88,6 @@ namespace app
// this variable defines whether message was processed.
bool handled = true;
- if (msgl->messageType == MessageType::CellularNotification) {
- auto msg = dynamic_cast(msgl);
- if (msg != nullptr) {
- if (msg->type == CellularNotificationMessage::Type::NewIncomingUSSD) {
-
- auto window = this->getCurrentWindow();
- if (window->getName() == gui::window::name::ussd_window) {
- auto ussdWindow = dynamic_cast(window);
- if (ussdWindow != nullptr) {
- ussdWindow->handleIncomingUSSD(msg->data);
- }
- }
- }
- }
- }
-
if (handled)
return std::make_shared();
else
@@ -177,10 +160,6 @@ namespace app
return std::make_unique(app);
});
}
-
- windowsFactory.attach(gui::window::name::ussd_window, [](Application *app, const std::string &name) {
- return std::make_unique(app);
- });
}
void ApplicationSettings::destroyUserInterface()
diff --git a/module-apps/application-settings/CMakeLists.txt b/module-apps/application-settings/CMakeLists.txt
index 1b93614b03c22cea261aa32f78028216d5138480..7cb646f14919145ea5613ed5005a55267675692f 100644
--- a/module-apps/application-settings/CMakeLists.txt
+++ b/module-apps/application-settings/CMakeLists.txt
@@ -28,7 +28,6 @@ target_sources( ${PROJECT_NAME}
windows/FotaWindow.cpp
windows/Fota.cpp
windows/SettingsChange.cpp
- windows/USSDWindow.cpp
windows/EinkModeWindow.cpp
PUBLIC
@@ -36,7 +35,6 @@ target_sources( ${PROJECT_NAME}
windows/SettingsMainWindow.hpp
windows/LanguageWindow.hpp
windows/DateTimeWindow.hpp
- windows/USSDWindow.hpp
)
add_dependencies(${PROJECT_NAME} version)
diff --git a/module-apps/application-settings/windows/SettingsMainWindow.cpp b/module-apps/application-settings/windows/SettingsMainWindow.cpp
index 5d109fd6d4ed0443864068f5154a979ffd5a04d4..13de55180d9522f5375570759e8a5a17dc74a977 100644
--- a/module-apps/application-settings/windows/SettingsMainWindow.cpp
+++ b/module-apps/application-settings/windows/SettingsMainWindow.cpp
@@ -8,7 +8,6 @@
#include "log/log.hpp"
#include "CellularPassthroughWindow.hpp"
#include "FotaWindow.hpp"
-#include "USSDWindow.hpp"
#include "EinkModeWindow.hpp"
std::list mainWindowOptions(app::Application *app)
@@ -40,7 +39,6 @@ std::list mainWindowOptions(app::Application *app)
addMenu(i18("app_settings_cellular_passthrough"), gui::window::cellular_passthrough::window_name);
}
addMenu(i18("Fota update"), gui::window::name::fota_window);
- addMenu(i18("USSD test"), gui::window::name::ussd_window);
addMenu("Eink Mode", gui::window::name::eink);
addMenu(i18("app_settings_display"));
addMenu(i18("app_settings_phone_modes"));
diff --git a/module-apps/application-settings/windows/USSDWindow.cpp b/module-apps/application-settings/windows/USSDWindow.cpp
deleted file mode 100644
index 93c89e952c10635a1f525f621189d34db5b439bb..0000000000000000000000000000000000000000
--- a/module-apps/application-settings/windows/USSDWindow.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
-// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-
-#include "USSDWindow.hpp"
-#include "../ApplicationSettings.hpp"
-#include "Label.hpp"
-#include "Margins.hpp"
-#include "module-utils/i18n/i18n.hpp"
-#include "messages/AppMessage.hpp"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-namespace gui
-{
-
- USSDWindow::USSDWindow(app::Application *app) : AppWindow(app, gui::window::name::ussd_window)
- {
- buildInterface();
- }
-
- void USSDWindow::rebuild()
- {}
-
- void USSDWindow::buildInterface()
- {
- AppWindow::buildInterface();
- bottomBar->setActive(BottomBar::Side::CENTER, true);
- bottomBar->setActive(BottomBar::Side::RIGHT, true);
- bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::select));
- bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));
-
- topBar->setActive(TopBar::Elements::SIGNAL, true);
- topBar->setActive(TopBar::Elements::BATTERY, true);
-
- setTitle("USSD test");
-
- uint32_t h = style::settings::ussd::commonYPos;
-
- incomingLabel = addTitle("Incoming code");
- incomingLabel->setPosition(style::settings::ussd::commonXPos, h);
- h += style::settings::ussd::commonLabelH;
-
- received = addText();
-
- received->setPosition(style::settings::ussd::commonXPos, h);
- h += style::settings::ussd::commonTextH;
-
- outgoingLabel = addTitle("Outgoing code");
- outgoingLabel->setPosition(style::settings::ussd::commonXPos, h);
- h += style::settings::ussd::commonLabelH;
-
- pullToSend = addText();
- pullToSend->setPosition(style::settings::ussd::commonXPos, h);
- pullToSend->activatedCallback = [=](gui::Item &) {
- std::string data = pullToSend->getText().c_str();
- CellularServiceAPI::USSDRequest(
- this->application, CellularUSSDMessage::RequestType::pullSesionRequest, data);
- return true;
- };
- pullToSend->setEditMode(EditMode::Edit);
- pullToSend->setInputMode(new InputMode(
- {InputMode::digit},
- [=](const UTF8 &text) { bottomBarTemporaryMode(text); },
- [=]() { bottomBarRestoreFromTemporaryMode(); },
- [=]() { selectSpecialCharacter(); }));
- setFocusItem(pullToSend);
- }
-
- void USSDWindow::destroyInterface()
- {
- erase();
- }
-
- void USSDWindow::onBeforeShow(ShowMode mode, SwitchData *data)
- {}
-
- gui::Label *USSDWindow::addTitle(const UTF8 &title)
- {
- gui::Label *label = new gui::Label(this,
- style::settings::ussd::commonXPos,
- style::settings::ussd::commonYPos,
- style::settings::ussd::commonW,
- style::settings::ussd::commonLabelH,
- title);
- label->setFilled(false);
- label->setPenFocusWidth(style::window::default_border_focus_w);
- label->setPenWidth(style::window::default_border_no_focus_w);
-
- label->setFont(style::window::font::verysmall);
- label->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
-
- return label;
- }
- gui::Text *USSDWindow::addText(void)
- {
- gui::Text *text = new gui::Text(this,
- style::settings::ussd::commonXPos,
- style::settings::ussd::commonYPos,
- style::settings::ussd::commonW,
- style::settings::ussd::commonTextH);
- text->setFilled(false);
- text->setPenFocusWidth(style::window::default_border_focus_w);
- text->setPenWidth(style::window::default_border_no_focus_w);
-
- text->setFont(style::window::font::verysmall);
- text->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
- text->setEdges(RectangleEdge::All);
- return text;
- }
-
- void USSDWindow::handleIncomingUSSD(const std::string &data)
- {
- received->setText(UTF8(data));
- }
-} // namespace gui
diff --git a/module-apps/application-settings/windows/USSDWindow.hpp b/module-apps/application-settings/windows/USSDWindow.hpp
deleted file mode 100644
index 93fb586dbc110335cbc53b5af8f12ca882a1789a..0000000000000000000000000000000000000000
--- a/module-apps/application-settings/windows/USSDWindow.hpp
+++ /dev/null
@@ -1,49 +0,0 @@
-// 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
-#include
-
-#include "AppWindow.hpp"
-#include "gui/widgets/Image.hpp"
-#include "gui/widgets/Label.hpp"
-#include "gui/widgets/Window.hpp"
-#include
-#include
-
-namespace gui
-{
- namespace window
- {
- namespace name
- {
- inline constexpr auto ussd_window = "ussd_window";
- } // namespace name
- } // namespace window
- class USSDWindow : public AppWindow
- {
- protected:
- gui::Label *incomingLabel = nullptr;
- gui::Label *outgoingLabel = nullptr;
-
- gui::Text *pullToSend = nullptr;
- gui::Text *received = nullptr;
-
- gui::VBox *box = nullptr;
-
- gui::Label *addTitle(const UTF8 &title);
- gui::Text *addText(void);
-
- public:
- USSDWindow(app::Application *app);
-
- void onBeforeShow(ShowMode mode, SwitchData *data) override;
- void rebuild() override;
- void buildInterface() override;
- void destroyInterface() override;
- void set_navigation();
- void handleIncomingUSSD(const std::string &data);
- };
-} // namespace gui
diff --git a/module-cellular/at/Urc.hpp b/module-cellular/at/Urc.hpp
index c03defd440b898bf359a34277b5d778e1dadb2af..bcedd1a73e0a8887f8cb00cf467309212a2c3037 100644
--- a/module-cellular/at/Urc.hpp
+++ b/module-cellular/at/Urc.hpp
@@ -18,7 +18,7 @@ namespace at::urc
* @param urcHead - Urc message head
* @param tokenDelimiter - sign that separates parameters in Urc message
*/
- Urc(const std::string &urcBody, const std::string &urcHead = std::string(), char tokenDelimiter = ',');
+ Urc(const std::string &urcBody, const std::string &urcHead = std::string());
virtual ~Urc() = default;
@@ -80,9 +80,8 @@ namespace at::urc
/**
* Splits Urc into head and tokenized data, cleans tokens from whitespaces and quotes
* @param str - string to be split
- * @param tokenDelimiter - sign that separates parameters in Urc message
*/
- void split(const std::string &str, char tokenDelimiter = ',');
+ virtual void split(const std::string &str);
};
} // namespace at::urc
diff --git a/module-cellular/at/UrcCusd.hpp b/module-cellular/at/UrcCusd.hpp
index ffb702d51f9dc248c75da00a88aa0ff0cd5b0fd6..cda524081db51ca865dd44f81d56331677b1b01e 100644
--- a/module-cellular/at/UrcCusd.hpp
+++ b/module-cellular/at/UrcCusd.hpp
@@ -30,7 +30,7 @@ namespace at::urc
OperationNotSupported,
NetworkTimeOut
};
-
+ Cusd(const std::string &urcBody, const std::string &urcHead = std::string());
static constexpr std::string_view head = "+CUSD";
static auto isURC(const std::string uHead) -> bool
{
@@ -45,6 +45,7 @@ namespace at::urc
[[nodiscard]] auto getMessage() const noexcept -> std::optional;
[[nodiscard]] auto getStatus() const noexcept -> std::optional;
[[nodiscard]] auto getDCS() const noexcept -> std::optional;
+ void split(const std::string &str) override;
void Handle(UrcHandler &h) final
{
diff --git a/module-cellular/at/src/Commands.cpp b/module-cellular/at/src/Commands.cpp
index 0c869ba27a8dada1475cd8c49fff49a075758b9d..cc79fba9d14ffb06727138356db16ce1c1682c36 100644
--- a/module-cellular/at/src/Commands.cpp
+++ b/module-cellular/at/src/Commands.cpp
@@ -30,7 +30,7 @@ namespace at
case commadsSet::smsInit:
ret.push_back(AT::SET_SMS_STORAGE);
ret.push_back(AT::SMS_TEXT_FORMAT);
- ret.push_back(AT::SMS_UCSC2);
+ ret.push_back(AT::SMS_GSM);
ret.push_back(AT::LIST_MESSAGES);
break;
}
diff --git a/module-cellular/at/src/Urc.cpp b/module-cellular/at/src/Urc.cpp
index f90f1a8a3ec79ddeb3a6e0831380f30d769ccc81..83250fb4831074c1a810127924a68fe09757251f 100644
--- a/module-cellular/at/src/Urc.cpp
+++ b/module-cellular/at/src/Urc.cpp
@@ -6,14 +6,15 @@
namespace at::urc
{
- Urc::Urc(const std::string &urcBody, const std::string &urcHead, char tokenDelimiter)
- : urcBody(urcBody), urcHead(urcHead)
+ Urc::Urc(const std::string &urcBody, const std::string &urcHead) : urcBody(urcBody), urcHead(urcHead)
{
- split(urcBody, tokenDelimiter);
+ split(urcBody);
}
- void Urc::split(const std::string &str, char tokenDelimiter)
+ void Urc::split(const std::string &str)
{
+ constexpr char tokenDelimiter = ',';
+
tokens = utils::split(str, tokenDelimiter);
constexpr auto urcStringDelimiter = "\"";
for (auto &t : tokens) {
diff --git a/module-cellular/at/src/UrcCusd.cpp b/module-cellular/at/src/UrcCusd.cpp
index 20b85e980ec27c23ba76066187dfa449aa5083a6..8c9b2d3dd250080b31909aa7a6f15f4c12a1fe81 100644
--- a/module-cellular/at/src/UrcCusd.cpp
+++ b/module-cellular/at/src/UrcCusd.cpp
@@ -7,6 +7,10 @@
using namespace at::urc;
+Cusd::Cusd(const std::string &urcBody, const std::string &urcHead) : Urc(urcBody, urcHead)
+{
+ split(urcBody);
+}
auto Cusd::isValid() const noexcept -> bool
{
return tokens.size() == magic_enum::enum_count();
@@ -70,3 +74,28 @@ auto Cusd::getDCS() const noexcept -> std::optional
return dcs;
}
+void Cusd::split(const std::string &str)
+{
+ constexpr auto commaString = ",";
+ constexpr char tokenDelimiter = '\"';
+
+ tokens = utils::split(str, tokenDelimiter);
+ for (auto &t : tokens) {
+ utils::findAndReplaceAll(t, "\"", "");
+ t = utils::trim(t);
+ }
+
+ auto dcs = tokens[Tokens::DCS];
+ auto dcsTokens = utils::split(dcs, commaString);
+
+ if (dcsTokens.size() > 1) {
+ tokens.pop_back();
+ for (auto el : dcsTokens) {
+ tokens.push_back(el);
+ }
+ }
+ for (auto &t : tokens) {
+ utils::findAndReplaceAll(t, commaString, "");
+ t = utils::trim(t);
+ }
+}
diff --git a/module-cellular/at/src/UrcFactory.cpp b/module-cellular/at/src/UrcFactory.cpp
index 231a70cb323b2e7962e260d23010c6816d9edf74..054477a77b70c7a7901542052dfd213decbc29cf 100644
--- a/module-cellular/at/src/UrcFactory.cpp
+++ b/module-cellular/at/src/UrcFactory.cpp
@@ -19,7 +19,6 @@ std::unique_ptr UrcFactory::Create(const std::string &urcMessage)
if (urcMessage.empty()) {
return std::make_unique(std::string());
}
-
const char headDelimiter = ':';
auto it = std::find(urcMessage.begin(), urcMessage.end(), headDelimiter);
std::string head = std::string(urcMessage.begin(), it);
diff --git a/module-services/service-cellular/CellularUrcHandler.cpp b/module-services/service-cellular/CellularUrcHandler.cpp
index c86d35e3d6b30a82643a791dc31540dc034e762a..0b4957dc7a0724e6d40395965637ac753175a7bd 100644
--- a/module-services/service-cellular/CellularUrcHandler.cpp
+++ b/module-services/service-cellular/CellularUrcHandler.cpp
@@ -9,6 +9,7 @@
#include
#include
#include
+#include
// this static function will be replaced by Settings API
static bool isSettingsAutomaticTimeSyncEnabled()
@@ -65,26 +66,28 @@ void CellularUrcHandler::Handle(Cmti &urc)
void CellularUrcHandler::Handle(Cusd &urc)
{
+ response = std::nullopt;
+ auto message = urc.getMessage();
+ if (!message) {
+ return;
+ }
+
if (urc.isActionNeeded()) {
if (cellularService.ussdState == ussd::State::pullRequestSent) {
cellularService.ussdState = ussd::State::pullResponseReceived;
cellularService.setUSSDTimer();
+ auto msg = std::make_shared(*message);
+ sys::Bus::SendUnicast(msg, app::manager::ApplicationManager::ServiceName, &cellularService);
}
}
else {
CellularServiceAPI::USSDRequest(&cellularService, CellularUSSDMessage::RequestType::abortSesion);
cellularService.ussdState = ussd::State::sesionAborted;
cellularService.setUSSDTimer();
+ auto msg = std::make_shared(*message);
+ sys::Bus::SendUnicast(msg, app::manager::ApplicationManager::ServiceName, &cellularService);
}
- auto message = urc.getMessage();
- if (!message) {
- response = std::nullopt;
- return;
- }
-
- response =
- std::make_unique(CellularNotificationMessage::Type::NewIncomingUSSD, *message);
urc.setHandled(true);
}
diff --git a/module-services/service-cellular/ServiceCellular.cpp b/module-services/service-cellular/ServiceCellular.cpp
index efa3231adf78e591703c387431c4865800fab2e2..aab13cdfb56b98e987c869ad71a32dfa4a69cda8 100644
--- a/module-services/service-cellular/ServiceCellular.cpp
+++ b/module-services/service-cellular/ServiceCellular.cpp
@@ -659,11 +659,6 @@ sys::MessagePointer ServiceCellular::DataReceivedHandler(sys::DataMessage *msgl,
auto resp = handleAllMessagesFromMessageStorage();
responseMsg = std::make_shared(resp);
} break;
- case CellularNotificationMessage::Type::NewIncomingUSSD: {
-
- auto message = std::make_shared(msg->data);
- sys::Bus::SendUnicast(message, app::manager::ApplicationManager::ServiceName, this);
- } break;
case CellularNotificationMessage::Type::SignalStrengthUpdate:
case CellularNotificationMessage::Type::NetworkStatusUpdate: {
// skipped
diff --git a/module-services/service-cellular/service-cellular/CellularMessage.hpp b/module-services/service-cellular/service-cellular/CellularMessage.hpp
index cc5dfcf1988329b03e9299bea52437bdaaf78ecd..57bf220b45cff08f5a165ec7196a86a2ddf915d3 100644
--- a/module-services/service-cellular/service-cellular/CellularMessage.hpp
+++ b/module-services/service-cellular/service-cellular/CellularMessage.hpp
@@ -69,7 +69,6 @@ class CellularNotificationMessage : public CellularMessage
RawCommand, // send raw command to modem -> returns raw, tokenised result
PowerDownDeregistering, // modem informed it has started to disconnect from network
PowerDownDeregistered, // modem informed it has disconnected from network
- NewIncomingUSSD, // modem received new ussd code from network
SMSDone, // SMS initialization finished
};