~aleteoryx/muditaos

53a51e866d908877d06fb87fdba84e744b7b0ce5 — Marek Niepieklo 4 years ago bf30504
[EGD-6991] Message from the operator is not fully shown

Added handling of errors in retrieving a message from the modem
2 files changed, 25 insertions(+), 6 deletions(-)

M module-cellular/at/Commands.hpp
M module-services/service-cellular/ServiceCellular.cpp
M module-cellular/at/Commands.hpp => module-cellular/at/Commands.hpp +4 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 145,4 145,7 @@ namespace at
    };

    std::vector<AT> getCommadsSet(commadsSet set);

    constexpr auto AtCmdMaxRetries   = 3;
    constexpr auto AtCmdRetryDelayMS = 50;
}; // namespace at

M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +21 -5
@@ 912,8 912,6 @@ std::optional<std::shared_ptr<sys::Message>> ServiceCellular::identifyNotificati

auto ServiceCellular::receiveSMS(std::string messageNumber) -> bool
{
    constexpr auto ucscSetMaxRetries = 3;

    auto retVal = true;

    auto channel = cmux->get(CellularMux::Channel::Commands);


@@ 923,7 921,7 @@ auto ServiceCellular::receiveSMS(std::string messageNumber) -> bool
    }

    auto ucscSetRetries = 0;
    while (ucscSetRetries < ucscSetMaxRetries) {
    while (ucscSetRetries < at::AtCmdMaxRetries) {
        if (!channel->cmd(at::AT::SMS_UCSC2)) {
            ++ucscSetRetries;
            LOG_ERROR("Could not set UCS2 charset mode for TE. Retry %d", ucscSetRetries);


@@ 948,8 946,26 @@ auto ServiceCellular::receiveSMS(std::string messageNumber) -> bool
    std::string messageRawBody;
    UTF8 receivedNumber;
    const auto &cmd = at::factory(at::AT::QCMGR);
    auto ret        = channel->cmd(cmd + messageNumber, cmd.getTimeout());
    if (!ret) {
    at::Result ret;
    auto qcmgrRetries = 0;

    while (qcmgrRetries < at::AtCmdMaxRetries) {
        ret = channel->cmd(cmd + messageNumber, cmd.getTimeout());
        if (!ret) {
            ++qcmgrRetries;
            LOG_ERROR("Could not read text message. Retry %d", qcmgrRetries);
            // There are cases where +QCMGR command is issued to soon after +CMTI URC,
            // and modem is still busy processing messages. This results with an error
            // and some garbage frame. To work around this, we delay a bit and retry +QCMGR
            // to get the message.
            vTaskDelay(at::AtCmdRetryDelayMS);
        }
        else {
            break;
        }
    }

    if (!ret || qcmgrRetries == at::AtCmdMaxRetries) {
        LOG_ERROR("!!!! Could not read text message !!!!");
        retVal = false;
    }