~aleteoryx/muditaos

56449096fd1a0a3a8e9ce70e713864cbde4b142d — Pawel Olejniczak 4 years ago 73bb668
[CP-267] Ensure cellular logging

Log information such as: selected SIM slot,
received signal parameters (QNWINFO, CSQ),
selected antenna, AT commands exchanged
with the modem, slider position.
Also fixed logging level for rt1051.
M module-bsp/board/rt1051/bsp/cellular/rt1051_cellular.cpp => module-bsp/board/rt1051/bsp/cellular/rt1051_cellular.cpp +4 -6
@@ 737,12 737,10 @@ namespace bsp

            void simSelect()
            {
                if (Store::GSM::get()->selected == Store::GSM::SIM::SIM2) {
                    GPIO_PinWrite(BSP_CELLULAR_SIM_CARD_PRESENCE_PORT, BSP_CELLULAR_SIMSEL_PIN, 1);
                }
                else {
                    GPIO_PinWrite(BSP_CELLULAR_SIM_CARD_PRESENCE_PORT, BSP_CELLULAR_SIMSEL_PIN, 0);
                }
                GPIO_PinWrite(BSP_CELLULAR_SIM_CARD_PRESENCE_PORT,
                              BSP_CELLULAR_SIMSEL_PIN,
                              static_cast<uint8_t>(Store::GSM::get()->selected));
                LOG_INFO("%s slot selected", magic_enum::enum_name(Store::GSM::get()->selected).data());
            }
        } // namespace sim


M module-cellular/modem/ATCommon.cpp => module-cellular/modem/ATCommon.cpp +4 -6
@@ 36,17 36,15 @@ void Channel::cmdLog(std::string cmd, const Result &result, std::chrono::millise
                  utils::to_string(timeout.count()).c_str());
    } break;
    case Result::Code::ERROR: {
        LOG_ERROR("[AT]: >%s<, >%s<", cmd.c_str(), result.response.size() ? result.response.back().c_str() : "");
        LOG_ERROR("[AT]: >%s<, >%s<", cmd.c_str(), !result.response.empty() ? result.response.back().c_str() : "");
    } break;
    default:
        LOG_DEBUG("[AT]: >%s<, >%s<", cmd.c_str(), result.response.size() ? result.response.back().c_str() : "");
        LOG_INFO("[AT]: >%s<, >%s<", cmd.c_str(), !result.response.empty() ? result.response.back().c_str() : "");
        break;
    }
#if DEBUG_MODEM_OUTPUT_RESPONSE
    for (auto s : result.response) {
        LOG_DEBUG("[AT] > %s", s.c_str());
    for (const auto &s : result.response) {
        LOG_INFO("[AT] > %s", s.c_str());
    }
#endif
}

std::string Channel::formatCommand(const std::string &cmd) const

M module-services/service-antenna/ServiceAntenna.cpp => module-services/service-antenna/ServiceAntenna.cpp +12 -8
@@ 68,7 68,7 @@ ServiceAntenna::ServiceAntenna()
            timer.stop();
            auto stateToSet = state->get();
            if (state->timeoutOccured(cpp_freertos::Ticks::GetTicks())) {
                LOG_WARN("State [ %s ] timeout occured, setting [ %s ] state",
                LOG_WARN("State [ %s ] timeout occurred, setting [ %s ] state",
                         c_str(state->get()),
                         c_str(state->getTimeoutState()));
                stateToSet = state->getTimeoutState();


@@ 335,7 335,9 @@ bool ServiceAntenna::signalCheckStateHandler(void)
    if (CellularServiceAPI::GetCSQ(this, csq)) {
        at::response::parseCSQ(csq, csqValue);
        if (csqValue <= antenna::signalTreshold) {
            LOG_INFO("Signal strength below treshold. Switch antenna");
            LOG_INFO("Signal strength below the threshold (CSQ = %" PRIu32 ", Threshold = %" PRIu32 "). Switch antenna",
                     csqValue,
                     antenna::signalTreshold);
            state->set(antenna::State::switchAntenna);
            return true;
        }


@@ 350,12 352,13 @@ bool ServiceAntenna::bandCheckStateHandler(void)
{
    std::string cellularResponse;
    if (CellularServiceAPI::GetQNWINFO(this, cellularResponse)) {
        std::string band;
        at::response::parseQNWINFO(cellularResponse, band);

        auto bandFrequency     = at::response::qnwinfo::parseNetworkFrequency(band);
        std::string qnwinfo;
        at::response::parseQNWINFO(cellularResponse, qnwinfo);
        LOG_INFO("QNWINFO: %s", qnwinfo.c_str());
        const auto bandFrequency = at::response::qnwinfo::parseNetworkFrequency(qnwinfo);
        LOG_INFO("Band frequency: %" PRIu32, bandFrequency);
        constexpr uint32_t GHz = 1000;
        bool isBandSubGHz      = bandFrequency < GHz ? true : false;
        const bool isBandSubGHz = bandFrequency < GHz;
        if (currentAntenna == bsp::cellular::antenna::highBand) {
            LOG_INFO("High band antenna.");
            if (isBandSubGHz) {


@@ 405,12 408,13 @@ bool ServiceAntenna::csqChangeStateHandler(void)

    auto nextState = antenna::State::idle;
    if (lastCsq != currentCsq || currentCsq == notValidCsq) {
        LOG_INFO("CSQ change occurent, check connection.");
        LOG_INFO("CSQ change occurrence, check connection.");
        nextState = antenna::State::connectionStatus;
    }
    if (currentCsq != notValidCsq) {
        lastCsq = currentCsq;
    }
    LOG_INFO("CSQ value:  %" PRIu32, currentCsq);

    state->set(nextState);
    return true;

M module-services/service-cellular/CellularUrcHandler.cpp => module-services/service-cellular/CellularUrcHandler.cpp +4 -0
@@ 129,6 129,10 @@ void CellularUrcHandler::Handle(Qind &urc)
            Store::GSM::get()->setSignalStrength(signalStrength.data);
            response = std::make_unique<CellularSignalStrengthUpdateNotification>(urc.getUrcBody());
        }
        auto ber = urc.getBER();
        if (ber.has_value()) {
            LOG_INFO("BER value: %d", ber.value());
        }
        urc.setHandled(true);
    }
    else if (urc.isFota()) {

M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +6 -0
@@ 2053,6 2053,12 @@ auto ServiceCellular::handleCellularSelectAntennaMessage(sys::Message *msg) -> s
    cmux->selectAntenna(message->antenna);
    vTaskDelay(50); // sleep for 50 ms...
    auto actualAntenna  = cmux->getAntenna();
    if (actualAntenna == bsp::cellular::antenna::lowBand) {
        LOG_INFO("Low band antenna set");
    }
    else {
        LOG_INFO("High band antenna set");
    }
    bool changedAntenna = (actualAntenna == message->antenna);

    auto notification = std::make_shared<AntennaChangedMessage>();

M module-services/service-evtmgr/EventManager.cpp => module-services/service-evtmgr/EventManager.cpp +1 -1
@@ 83,7 83,6 @@ EventManager::~EventManager()
    }
}


// Invoked upon receiving data message
sys::MessagePointer EventManager::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp)
{


@@ 371,6 370,7 @@ void EventManager::handleKeyEvent(sys::Message *msg)
void EventManager::handleKeyMoveEvent(RawKey key)
{
    if (isSliderKeyCode(key.key_code)) {
        LOG_INFO("Slider position: %s", magic_enum::enum_name(key.key_code).data());
        const auto mode = sys::SystemManager::translateSliderState(key);
        bus.sendUnicast(std::make_shared<sys::PhoneModeRequest>(mode), service::name::system_manager);
    }

M module-utils/board/cross/log_rt1051.cpp => module-utils/board/cross/log_rt1051.cpp +1 -1
@@ 45,7 45,7 @@ namespace Log

    bool Logger::filterLogs(logger_level level)
    {
        return getLogLevel(getTaskDesc()) < level;
        return getLogLevel(getTaskDesc()) <= level;
    }

    void Logger::logToDevice(const char *fmt, va_list args)

M module-utils/log/debug.hpp => module-utils/log/debug.hpp +0 -1
@@ 8,7 8,6 @@
#define DEBUG_CELLULAR_UART          0 /// show full modem uart communication
#define DEBUG_BLUETOOTH_HCI_COMS     0 /// show communication with BT module - transactions
#define DEBUG_BLUETOOTH_HCI_BYTES    0 /// show communication with BT module - all the HCI bytes
#define DEBUG_MODEM_OUTPUT_RESPONSE  0 /// show full modem output
#define DEBUG_SERVICE_MESSAGES       0 /// show messages prior to handling in service
#define DEBUG_DB_MODEL_DATA          0 /// show messages prior to handling in service
#define DEBUG_FONT                   0 /// show Font debug messages