191 lines
4.6 KiB
C
191 lines
4.6 KiB
C
//
|
|
// Created by cfif on 24.05.2024.
|
|
//
|
|
#include "AtGsmSimComA7600_SSL_SocketSendData.h"
|
|
#include "AtCmdCommonProtected.h"
|
|
#include "SystemDelayInterface.h"
|
|
|
|
AtCommandResult AtGsmSimComA7600_SSL_SocketSendData(
|
|
tAtCmd *env, uint8_t linkNum, uint8_t *data, uint16_t dataLen, uint32_t timeout
|
|
) {
|
|
return AtGsmSimComA7600_SSL_SocketSendDataEx(env, linkNum, data, dataLen, 0, 0, 0, timeout);
|
|
}
|
|
|
|
|
|
AtCommandResult AtGsmSimComA7600_SSL_SocketSendDataEx(
|
|
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 > 1) {
|
|
return AT_ERROR;
|
|
}
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdTxAddStatic(env, "AT+CCHSEND=");
|
|
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, "OK")) {
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
AtCommandResult AtGsmSimComA7600_SSL_SocketSendDataEx(
|
|
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 > 1) {
|
|
return AT_ERROR;
|
|
}
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdTxAddStatic(env, "AT+CCHSEND=");
|
|
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, "ERROR")) {
|
|
AtCmdRxClear(env);
|
|
return AT_ERROR;
|
|
|
|
} else if (AtCmdRxBeginWithStatic(env, "OK")) {
|
|
AtCmdRxClear(env);
|
|
return AT_OK;
|
|
} else {
|
|
AtCmdProcessUnresolvedLine(env);
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
}
|
|
|
|
} else {
|
|
if (AtCmdRxBeginWithStatic(env, ">")) {
|
|
AtCmdRxClear(env);
|
|
AtCmdSend(env, data, dataLen);
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
while ((AtCmdReceiveNextLine(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) {
|
|
leftMs = endMs - SystemGetMs();
|
|
|
|
if (AtCmdRxBeginWithStatic(env, "ERROR")) {
|
|
AtCmdRxClear(env);
|
|
return AT_ERROR;
|
|
|
|
} else if (AtCmdRxBeginWithStatic(env, "OK")) {
|
|
AtCmdRxClear(env);
|
|
return AT_OK;
|
|
} else {
|
|
AtCmdProcessUnresolvedLine(env);
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
}
|
|
}
|
|
return AT_TIMEOUT;
|
|
|
|
}
|
|
*/ |