~aleteoryx/muditaos

9cc5b47bdd32fd4f1d46ffb522131ab00bc2cbae — Maciej Gibowicz 5 years ago 5b0f2aa
[EGD-4863] Add harness test for cellular sleep mode

Adding test for outgoing call and text message
in cellular sleep mode
M module-bsp/board/rt1051/bsp/cellular/rt1051_cellular.hpp => module-bsp/board/rt1051/bsp/cellular/rt1051_cellular.hpp +0 -1
@@ 128,7 128,6 @@ namespace bsp
        static TaskHandle_t blockedTaskHandle;

      private:
        bool isInSleepMode{false};
        // Constants
        const static uint32_t baudrate                               = 115200;
        const static uint32_t rxStreamBufferLength                   = 1024;

M module-bsp/bsp/cellular/bsp_cellular.cpp => module-bsp/bsp/cellular/bsp_cellular.cpp +5 -0
@@ 41,4 41,9 @@ namespace bsp{
    	return lastCommunicationTimestamp;
    }

    [[nodiscard]] auto Cellular::IsCellularInSleepMode() const noexcept -> bool
    {
    	return isInSleepMode;
    }

}

M module-bsp/bsp/cellular/bsp_cellular.hpp => module-bsp/bsp/cellular/bsp_cellular.hpp +3 -0
@@ 57,10 57,13 @@ namespace cellular

        [[nodiscard]] auto GetCellularDevice() const noexcept -> std::shared_ptr<devices::Device>;
        [[nodiscard]] auto GetLastCommunicationTimestamp() const noexcept -> TickType_t;
        [[nodiscard]] auto IsCellularInSleepMode() const noexcept -> bool;

    protected:
        bool isInitialized = false;
        bool isInSleepMode{false};
        TickType_t lastCommunicationTimestamp;

        std::shared_ptr<drivers::DriverLPUART> driverLPUART;
    };
    namespace cellular

M module-cellular/Modem/TS0710/TS0710.cpp => module-cellular/Modem/TS0710/TS0710.cpp +5 -0
@@ 603,6 603,11 @@ void TS0710::RegisterCellularDevice(void)
    return pv_cellular->GetLastCommunicationTimestamp();
}

[[nodiscard]] auto TS0710::IsCellularInSleepMode() const noexcept -> bool
{
    return pv_cellular->IsCellularInSleepMode();
}

TS0710::ConfState TS0710::SetupEchoCanceller(EchoCancellerStrength strength)
{


M module-cellular/Modem/TS0710/TS0710.h => module-cellular/Modem/TS0710/TS0710.h +1 -0
@@ 442,6 442,7 @@ class TS0710
    void ExitSleepMode(void);
    void RegisterCellularDevice(void);
    [[nodiscard]] auto GetLastCommunicationTimestamp() const noexcept -> TickType_t;
    [[nodiscard]] auto IsCellularInSleepMode() const noexcept -> bool;
};

#endif //_TS0710_H

M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +6 -0
@@ 443,6 443,12 @@ void ServiceCellular::registerMessageHandlers()
            auto message = std::make_shared<sdesktop::developerMode::DeveloperModeRequest>(std::move(event));
            bus.sendUnicast(std::move(message), service::name::service_desktop);
        }
        if (typeid(*msg->event.get()) == typeid(sdesktop::developerMode::CellularSleepModeInfoRequestEvent)) {
            auto event = std::make_unique<sdesktop::developerMode::CellularSleepModeInfoRequestEvent>(
                cmux->IsCellularInSleepMode());
            auto message = std::make_shared<sdesktop::developerMode::DeveloperModeRequest>(std::move(event));
            bus.sendUnicast(std::move(message), service::name::service_desktop);
        }
        if (typeid(*msg->event.get()) == typeid(sdesktop::developerMode::ATResponseEvent)) {
            auto channel = cmux->get(TS0710::Channel::Commands);
            assert(channel);

M module-services/service-desktop/DesktopMessages.cpp => module-services/service-desktop/DesktopMessages.cpp +7 -0
@@ 31,6 31,13 @@ namespace sdesktop
            context.setEndpoint(EndpointType::developerMode);
            context.setResponseBody(json11::Json::object{{json::developerMode::cellularStateInfo, stateStr}});
        }

        CellularSleepModeInfoRequestEvent::CellularSleepModeInfoRequestEvent(bool isInSleepMode)
        {
            context.setResponseStatus(http::Code::OK);
            context.setEndpoint(EndpointType::developerMode);
            context.setResponseBody(json11::Json::object{{json::developerMode::cellularSleepModeInfo, isInSleepMode}});
        }
    } // namespace developerMode

} // namespace sdesktop

M module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp => module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp +18 -0
@@ 159,6 159,17 @@ auto DeveloperModeHelper::processGet(Context &context) -> ProcessResult
            if (requestServiceStateInfo(owner) == false) {
                return {sent::no, endpoint::ResponseContext{.status = http::Code::NotAcceptable}};
            }
            else {
                return {sent::delayed, std::nullopt};
            }
        }
        else if (keyValue == json::developerMode::cellularSleepModeInfo) {
            if (requestCellularSleepModeInfo(owner) == false) {
                return {sent::no, endpoint::ResponseContext{.status = http::Code::NotAcceptable}};
            }
            else {
                return {sent::delayed, std::nullopt};
            }
        }
        else {
            return {sent::no, endpoint::ResponseContext{.status = http::Code::BadRequest}};


@@ 312,3 323,10 @@ bool DeveloperModeHelper::requestServiceStateInfo(sys::Service *serv)
    auto msg   = std::make_shared<sdesktop::developerMode::DeveloperModeRequest>(std::move(event));
    return serv->bus.sendUnicast(std::move(msg), ServiceCellular::serviceName);
}

bool DeveloperModeHelper::requestCellularSleepModeInfo(sys::Service *serv)
{
    auto event = std::make_unique<sdesktop::developerMode::CellularSleepModeInfoRequestEvent>();
    auto msg   = std::make_shared<sdesktop::developerMode::DeveloperModeRequest>(std::move(event));
    return serv->bus.sendUnicast(std::move(msg), ServiceCellular::serviceName);
}

M module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.hpp => module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.hpp +2 -0
@@ 30,6 30,7 @@ namespace parserFSM
        auto smsRecordFromJson(json11::Json msgJson) -> SMSRecord;
        bool requestCellularPowerStateChange(const int simSelected);
        bool requestServiceStateInfo(sys::Service *serv);
        bool requestCellularSleepModeInfo(sys::Service *serv);
        auto prepareSMS(Context &context) -> ProcessResult;

      public:


@@ 68,6 69,7 @@ namespace parserFSM
        /// values for getInfo cmd
        inline constexpr auto simStateInfo      = "simState";
        inline constexpr auto cellularStateInfo = "cellularState";
        inline constexpr auto cellularSleepModeInfo = "cellularSleepMode";

        /// values for smsCommand
        inline constexpr auto smsAdd = "smsAdd";

M module-services/service-desktop/service-desktop/DesktopMessages.hpp => module-services/service-desktop/service-desktop/DesktopMessages.hpp +6 -0
@@ 189,6 189,12 @@ namespace sdesktop
            CellularStateInfoRequestEvent() = default;
            explicit CellularStateInfoRequestEvent(std::string stateStr);
        };
        class CellularSleepModeInfoRequestEvent : public Event
        {
          public:
            CellularSleepModeInfoRequestEvent() = default;
            explicit CellularSleepModeInfoRequestEvent(bool isInSleepMode);
        };
        class ScreenlockCheckEvent : public Event
        {
          public:

A test/pytest/test_cellular_sleep.py => test/pytest/test_cellular_sleep.py +58 -0
@@ 0,0 1,58 @@
# Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
import time
import pytest
from harness import log
from harness.interface.defs import status
from harness.interface.defs import key_codes
from test_call import  test_call as call
from test_send_message import test_send_prepared_message as send_prepared_message

def request_cellular_sleep_mode_info(harness):
    body = {"getInfo": "cellularSleepMode"}
    return harness.endpoint_request("developerMode", "get", body)
    

def wait_for_cellular_sleep(harness, max_attempts):
    for i in range(max_attempts):
        ret = request_cellular_sleep_mode_info(harness)
        assert ret["status"] == status["OK"]
        if  ret["body"]["cellularSleepMode"] == True:
            return True
        else:
            log.info("cellular is not in the sleep mode, waiting...")
            time.sleep(2)
    return False


@pytest.mark.rt1051
@pytest.mark.usefixtures("usb_unlocked")

def test_call_during_cellular_sleep_mode(harness, phone_number, call_duration, max_attempts = 10):
    cellular_sleep_mode = wait_for_cellular_sleep(harness, max_attempts)
    if (cellular_sleep_mode == False):
        log.warning("cellular is not in the sleep mode!")

    harness.unlock_phone()
    # try to make outgoing call
    call(harness, phone_number, call_duration)
    
    # cellular should be awake 
    ret = request_cellular_sleep_mode_info(harness)
    assert ret["status"] == status["OK"]
    assert ret["body"]["cellularSleepMode"] == False

@pytest.mark.rt1051
@pytest.mark.usefixtures("usb_unlocked")
def test_sms_during_cellular_sleep_mode(harness, phone_number, sms_text, max_attempts = 10):
    cellular_sleep_mode = wait_for_cellular_sleep(harness, max_attempts)
    if (cellular_sleep_mode == False):
        log.warning("cellular is not in the sleep mode!")
    
    # send text message
    send_prepared_message(harness, phone_number, sms_text)
    
    # cellular should be awake 
    ret = request_cellular_sleep_mode_info(harness)
    assert ret["status"] == status["OK"]
    assert ret["body"]["cellularSleepMode"] == False