68 lines
2.1 KiB
C
68 lines
2.1 KiB
C
//
|
|
// Created by cfif on 16.10.2023.
|
|
//
|
|
|
|
#include "AtGsmTelitLe910_SocketReadData.h"
|
|
#include "AtCmdCommonProtected.h"
|
|
#include "SystemDelayInterface.h"
|
|
#include "string.h"
|
|
#include "stdlib.h"
|
|
#include "AsciiStringParsingUtils.h"
|
|
|
|
AtCommandResult xAtGsmTelit_ReadSocket(tAtCmd *env, int idSocket, uint8_t *dataSocketRead, uint32_t dataSocketReadMaxLen, uint32_t *dataSocketReadLen) {
|
|
// AtCmdPrepare(env);
|
|
AtCmdTxClear(env);
|
|
AtCmdTxAddStatic(env, "AT#SRECV=");
|
|
AtCmdTxAddDecimalIntWithLimit(env, idSocket, 1);
|
|
AtCmdTxAddStatic(env, ",");
|
|
AtCmdTxAddDecimalIntWithLimit(env, dataSocketReadMaxLen, 4);
|
|
AtCmdTxSendLn(env);
|
|
|
|
//debug_printf(env->io, "AT#SRECV=%u,%u\r\n", idSocket, dataSocketReadMaxLen);
|
|
|
|
*dataSocketReadLen = 0;
|
|
|
|
uint32_t timeout = env->stdRxTimeout;
|
|
uint32_t endMs = SystemGetMs() + timeout;
|
|
uint32_t leftMs = timeout;
|
|
|
|
while ((AtCmdReceiveNextLine(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) {
|
|
leftMs = endMs - SystemGetMs();
|
|
|
|
if (AtCmdRxBeginWithStatic(env, "#SRECV: ")) {
|
|
|
|
char *front;
|
|
char *div = env->rxBuffer.data + sizeof("#SRECV:") - 1;
|
|
char *end = div + env->rxBuffer.len;
|
|
|
|
if (iAsciiStringMoveToNextParsingBlock(&front, &div, end, ',')) {
|
|
uint32_t id = atoi(front);
|
|
}
|
|
|
|
if (iAsciiStringMoveToNextParsingBlock(&front, &div, end, ',')) {
|
|
*dataSocketReadLen = atoi(front);
|
|
}
|
|
|
|
|
|
// *dataSocketReadLen = atoi(&env->rxBuffer.data[strlen("#SRECV: ")]);
|
|
AtCmdRxClear(env);
|
|
break;
|
|
} else if (AtCmdRxBeginWithStatic(env, "ERROR")) {
|
|
AtCmdRxClear(env);
|
|
return AT_ERROR;
|
|
} else if (AtCmdRxBeginWithStatic(env, "Operation")) {
|
|
AtCmdRxClear(env);
|
|
return AT_ERROR;
|
|
} else {
|
|
// AtCmdProcessUnresolvedLine(env);
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
}
|
|
}
|
|
|
|
AtCmdRxReadRAW(env, dataSocketRead, *dataSocketReadLen, env->stdRxTimeout);
|
|
|
|
return AT_OK;
|
|
// return AtCmdOkErrAnswer(env, env->stdRxTimeout);
|
|
}
|