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; }