98 lines
2.4 KiB
C
98 lines
2.4 KiB
C
//
|
|
// Created by cfif on 10.05.23.
|
|
//
|
|
#include "AtGsmSimComA7600_SocketSendData.h"
|
|
#include "AtCmdCommonProtected.h"
|
|
#include "SystemDelayInterface.h"
|
|
|
|
|
|
AtCommandResult AtGsmSimComA7600_SocketSendData(
|
|
tAtCmd *env, uint8_t linkNum, uint8_t *data, uint16_t dataLen, uint32_t timeout
|
|
) {
|
|
return AtGsmSimComA7600_SocketSendDataUdp(env, linkNum, data, dataLen, 0, 0, 0, timeout);
|
|
}
|
|
|
|
AtCommandResult AtGsmSimComA7600_SocketSendDataUdp(
|
|
tAtCmd *env,
|
|
uint8_t linkNum,
|
|
uint8_t *data,
|
|
uint16_t dataLen,
|
|
char *srvIp,
|
|
uint8_t srvIpLen,
|
|
uint16_t srvPort,
|
|
uint32_t timeout
|
|
) {
|
|
AtCmdPrepare(env);
|
|
AtCmdRxClear(env);
|
|
|
|
if (linkNum > 9) {
|
|
return AT_ERROR;
|
|
}
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdTxAddStatic(env, "AT+CIPSEND=");
|
|
AtCmdTxAddDecimalIntWithLimit(env, linkNum, 1);
|
|
AtCmdTxAddChar(env, ',');
|
|
AtCmdTxAddDecimalIntWithLimit(env, dataLen, 5);
|
|
|
|
|
|
if (srvPort || srvIpLen) {
|
|
AtCmdTxAddChar(env, ',');
|
|
|
|
if (srvIpLen) {
|
|
AtCmdTxAddChar(env, '"');
|
|
AtCmdTxAdd(env, srvIp, srvIpLen);
|
|
AtCmdTxAddChar(env, '"');
|
|
}
|
|
|
|
if (srvPort) {
|
|
AtCmdTxAddChar(env, ',');
|
|
AtCmdTxAddDecimalIntWithLimit(env, srvPort, 5);
|
|
}
|
|
}
|
|
|
|
|
|
AtCmdTxSendLn(env);
|
|
|
|
|
|
uint32_t endMs = SystemGetMs() + timeout;
|
|
uint32_t leftMs = timeout;
|
|
|
|
while ((AtCmdReceiveNextChar(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) {
|
|
leftMs = endMs - SystemGetMs();
|
|
if (AtCmdRxIsCompleteLine(env)) {
|
|
if (AtCmdRxBeginWithStatic(env, ">")) {
|
|
AtCmdRxClear(env);
|
|
AtCmdSend(env, data, dataLen);
|
|
} else if (AtCmdRxBeginWithStatic(env, "ERROR")) {
|
|
AtCmdRxClear(env);
|
|
return AT_ERROR;
|
|
} else if (AtCmdRxBeginWithStatic(env, "+CIPERROR:")) {
|
|
AtCmdRxClear(env);
|
|
return AT_ERROR;
|
|
} else if (AtCmdRxBeginWithStatic(env, "+CIPSEND: ")) {
|
|
AtCmdRxClear(env);
|
|
return AT_OK;
|
|
} else {
|
|
AtCmdProcessUnresolvedLine(env);
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
}
|
|
} else {
|
|
if (AtCmdRxBeginWithStatic(env, ">")) {
|
|
AtCmdRxClear(env);
|
|
AtCmdSend(env, data, dataLen);
|
|
|
|
// return AT_OK;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return AT_TIMEOUT;
|
|
|
|
}
|