From 2e75434ea31189d24095866e715e4f0f4189b84b Mon Sep 17 00:00:00 2001 From: cfif Date: Wed, 18 Jun 2025 13:56:44 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BD=D0=B0=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inc/AtCmdBase.h | 4 +++- Src/AtCmdCommon.c | 2 ++ Src/AtCmdCommonRxUtils.c | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Inc/AtCmdBase.h b/Inc/AtCmdBase.h index 352fe5f..31957ad 100644 --- a/Inc/AtCmdBase.h +++ b/Inc/AtCmdBase.h @@ -8,6 +8,7 @@ #include #include "SerialPort.h" #include "stddef.h" +#include "cmsis_os2.h" typedef enum { AT_BUSY = -3, @@ -42,7 +43,8 @@ typedef struct { uint32_t stdRxTimeout; tAtCmdUrcProcessor urcProcessor; - tSystemMutexInterface *access; + osMutexId_t access; + uint8_t test; } tAtCmd; #endif //GSMAT_GSMATCOMMANDRESULT_H diff --git a/Src/AtCmdCommon.c b/Src/AtCmdCommon.c index dc44a73..0933c3d 100644 --- a/Src/AtCmdCommon.c +++ b/Src/AtCmdCommon.c @@ -29,6 +29,8 @@ void AtCmdInit( env->stdRxTimeout = stdRxTimeout; env->stdTxTimeout = stdTxTimeout; env->urcProcessor.process = NULL; + env->access= osMutexNew(NULL); + env->test = 0; } AtCommandResult AtCmd(tAtCmd *env) { diff --git a/Src/AtCmdCommonRxUtils.c b/Src/AtCmdCommonRxUtils.c index 0eba850..074f9eb 100644 --- a/Src/AtCmdCommonRxUtils.c +++ b/Src/AtCmdCommonRxUtils.c @@ -33,6 +33,7 @@ AtCommandResult AtCmdReceiveChar(tAtCmd *env, uint16_t timeout) { AtCommandResult AtCmdReceiveNextLine(tAtCmd *env, uint16_t timeout) { uint32_t endMs = SystemGetMs() + timeout; + uint8_t attemptsNotEndOfLine = 3; while (endMs > SystemGetMs()) { AtCmdRxClear(env); @@ -48,6 +49,30 @@ AtCommandResult AtCmdReceiveNextLine(tAtCmd *env, uint16_t timeout) { continue; } + if (env->rxBuffer.data[env->rxBuffer.len - 1] != '\n') { + + while (attemptsNotEndOfLine) { + + uint16_t limit = 0; + if (env->rxBuffer.limit >= env->rxBuffer.len) { + limit = env->rxBuffer.limit - env->rxBuffer.len; + } + + uint16_t len = SerialPortReceiveTo( + env->io, (uint8_t *) &env->rxBuffer.data[env->rxBuffer.len], limit, '\n', 5 + ); + + env->rxBuffer.len += len; + + if (env->rxBuffer.data[env->rxBuffer.len - 1] == '\n') { + break; + } + + --attemptsNotEndOfLine; + } + + } + if (env->rxBuffer.data[env->rxBuffer.len - 1] != '\n') { return AT_ERROR; }