From 882d7da2f230d1e6a17cd2d035fd0a615558b384 Mon Sep 17 00:00:00 2001 From: Mateusz Date: Fri, 5 Jul 2019 07:43:25 +0200 Subject: [PATCH] WiP: Looks like communication with GSM modem was fixed --- CMakeLists.txt | 2 +- .../board/rt1051/cellular/rt1051_cellular.cpp | 7 ++-- module-cellular/Modem/InputSerialWorker.cpp | 3 +- module-cellular/Modem/MuxDaemon.cpp | 37 ++++++++----------- module-cellular/Modem/MuxDaemon.hpp | 2 +- .../service-cellular/ServiceCellular.cpp | 2 +- 6 files changed, 23 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a5c874132..7ce556010 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,8 +150,8 @@ target_link_libraries(${PROJECT_NAME} module-cellular module-db module-gui - module-os module-bsp + module-os module-vfs module-services module-apps diff --git a/module-bsp/board/rt1051/cellular/rt1051_cellular.cpp b/module-bsp/board/rt1051/cellular/rt1051_cellular.cpp index e2a18c5e5..80a5690ad 100644 --- a/module-bsp/board/rt1051/cellular/rt1051_cellular.cpp +++ b/module-bsp/board/rt1051/cellular/rt1051_cellular.cpp @@ -13,6 +13,7 @@ #include "FreeRTOS.h" #include "task.h" +#include "stream_buffer.h" #include "dma_config.h" #include "fsl_cache.h" @@ -200,7 +201,7 @@ namespace bsp { if (LPUART_SendEDMA(CELLULAR_UART_BASE, &uartDmaHandle, &sendXfer) != kStatus_Success) { LOG_ERROR("Cellular: TX Failed!"); DisableTx(); - return 0; + return -1; } auto ulNotificationValue = ulTaskNotifyTake(pdFALSE, 100); @@ -208,11 +209,11 @@ namespace bsp { if (ulNotificationValue == 0) { LOG_ERROR("Cellular Uart error: TX Transmission timeout"); DisableTx(); - return 0; + return -1; } DisableTx(); - return 1; + return nbytes; } ssize_t RT1051Cellular::Read(void *buf, size_t nbytes) { diff --git a/module-cellular/Modem/InputSerialWorker.cpp b/module-cellular/Modem/InputSerialWorker.cpp index f26163782..ce8195712 100644 --- a/module-cellular/Modem/InputSerialWorker.cpp +++ b/module-cellular/Modem/InputSerialWorker.cpp @@ -31,7 +31,6 @@ void workerTaskFunction(void *ptr) { //TODO:M.P implement error handling ? } -/* //TODO:M.P sth broken here if (worker->muxDaemon->inputBuffer->readp != worker->muxDaemon->inputBuffer->data) { //relayout data in cache_buf if (worker->muxDaemon->inputBuffer->GetDataLength()) { @@ -42,7 +41,7 @@ void workerTaskFunction(void *ptr) { worker->muxDaemon->inputBuffer->readp = worker->muxDaemon->inputBuffer->data; worker->muxDaemon->inputBuffer->writep = worker->muxDaemon->inputBuffer->data + worker->muxDaemon->inputBuffer->GetDataLength(); - }*/ + } } } } diff --git a/module-cellular/Modem/MuxDaemon.cpp b/module-cellular/Modem/MuxDaemon.cpp index efa2e74c2..aeaf2b22f 100644 --- a/module-cellular/Modem/MuxDaemon.cpp +++ b/module-cellular/Modem/MuxDaemon.cpp @@ -101,14 +101,14 @@ int MuxDaemon::Start() { static_cast(MuxDefines::GSM0710_TYPE_UIH)); vTaskDelay(500); // give modem some time to establish mux // Try sending AT command once again - if (SendAT("AT\r\n", 500) == -1) { + if (SendAT("AT\r", 500) == -1) { LOG_INFO("Starting power up procedure..."); // If no response, power up modem and try again cellular->PowerUp(); uint32_t retries = 10; while (--retries) { - if (SendAT("AT\r\n", 500) == 0) { + if (SendAT("AT\r", 500) == 0) { break; } } @@ -126,7 +126,7 @@ int MuxDaemon::Start() { if (hardwareControlFlowEnable) { SendAT("AT+IFC=2,2\r\n", 500); // enable flow control function for module } else { - SendAT("AT+IFC=0,0\r\n", 500); // disable flow control function for module + SendAT("AT+IFC=0,0\r", 500); // disable flow control function for module } // Set fixed baudrate @@ -134,30 +134,29 @@ int MuxDaemon::Start() { // Turn off local echo SendAT("ATE0\r", 500); // Route URCs to first MUX channel - SendAT("AT+QCFG=\"cmux/urcport\",1\r\n", 500); + SendAT("AT+QCFG=\"cmux/urcport\",1\r", 500); // Turn off RI pin for incoming calls - SendAT("AT+QCFG=\"urc/ri/ring\",\"off\"\r\n", 500); + SendAT("AT+QCFG=\"urc/ri/ring\",\"off\"\r", 500); // Turn off RI pin for incoming sms - SendAT("AT+QCFG=\"urc/ri/smsincoming\",\"off\"\r\n", 500); + SendAT("AT+QCFG=\"urc/ri/smsincoming\",\"off\"\r", 500); // Route URCs to UART1 - SendAT("AT+QURCCFG=\"urcport\",\"uart1\"\r\n", 500); + SendAT("AT+QURCCFG=\"urcport\",\"uart1\"\r", 500); // Turn on signal strength change URC - // SendAT("AT+QINDCFG=\"csq\",1\r\n", 500); - // Set Message format to Text + SendAT("AT+QINDCFG=\"csq\",1\r", 500); +/* // Set Message format to Text SendAT("AT+CMGF=1\r", 500); - - + // Set SMS received report format + SendAT("AT+CNMI=1,2,0,1,0\r", 500);*/ char gsm_command[128] = {}; - snprintf(gsm_command, sizeof(gsm_command), "AT+CMUX=0\r\n"); -/* if (cmuxMode) { + if (cmuxMode) { snprintf(gsm_command, sizeof(gsm_command), "AT+CMUX=1\r\n"); } else { snprintf(gsm_command, sizeof(gsm_command), "AT+CMUX=%d,%d,%d,%d\r\n", cmuxMode, cmuxSubset, QuectelBaudrates::Baudrates::Value, frameSize ); - }*/ + } // Start CMUX multiplexer SendAT(gsm_command, 500); @@ -233,14 +232,8 @@ ssize_t MuxDaemon::WriteMuxFrame(int channel, const unsigned char *input, int le LOG_DEBUG("Sending frame to channel %d", channel); - if(type & static_cast(MuxDefines::GSM0710_TYPE_UIH)){ - prefix[1] &= ~static_cast(MuxDefines::GSM0710_CR); - prefix[1] = prefix[1] | ((63 & (unsigned char) channel) << 2); - } - else{ - /* GSM0710_EA=1, Command, let's add address */ - prefix[1] = prefix[1] | ((63 & (unsigned char) channel) << 2); - } + /* GSM0710_EA=1, Command, let's add address */ + prefix[1] = prefix[1] | ((63 & (unsigned char) channel) << 2); /* let's set control field */ prefix[2] = type; diff --git a/module-cellular/Modem/MuxDaemon.hpp b/module-cellular/Modem/MuxDaemon.hpp index a2d29c3b5..36a98c6d7 100644 --- a/module-cellular/Modem/MuxDaemon.hpp +++ b/module-cellular/Modem/MuxDaemon.hpp @@ -102,7 +102,7 @@ private: const static uint32_t baudRate = 115200; const static uint32_t virtualPortsCount = 4; // max number of virtual channels supported by EG25 - const static uint32_t frameSize = 127; // default basic frame size, can be extended to max 32kBytes if needed + const static uint32_t frameSize = 127; // default basic frame size const static bool hardwareControlFlowEnable = false; const static bool cmuxMode = false; const static uint32_t cmuxSubset = 0; diff --git a/module-services/service-cellular/ServiceCellular.cpp b/module-services/service-cellular/ServiceCellular.cpp index fca68a0ac..0d6836fb7 100644 --- a/module-services/service-cellular/ServiceCellular.cpp +++ b/module-services/service-cellular/ServiceCellular.cpp @@ -40,7 +40,7 @@ ServiceCellular::~ServiceCellular() { // Invoked when timer ticked void ServiceCellular::TickHandler(uint32_t id) { - char* resp = "ATI\r"; + char* resp = "AT\r"; muxdaemon->WriteMuxFrame(1, reinterpret_cast(resp),strlen(resp), static_cast(MuxDefines::GSM0710_TYPE_UIH)); }