177 lines
4.6 KiB
C
Executable File
177 lines
4.6 KiB
C
Executable File
//
|
|
// Created by xemon on 10.05.23.
|
|
//
|
|
#include "AtGsmTelitLe910_SocketSendData.h"
|
|
#include "AtCmdCommonProtected.h"
|
|
#include "SystemDelayInterface.h"
|
|
|
|
|
|
AtCommandResult AtGsmTelitLe910_SocketSendData(
|
|
tAtCmd *env, uint8_t linkNum, uint8_t *data, uint16_t dataLen, uint32_t timeout
|
|
) {
|
|
return AtGsmTelitLe910_SocketSendDataUdp(env, linkNum, data, dataLen, 0, 0, 0, timeout);
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_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;
|
|
}
|
|
|
|
AtCmdPrepare(env);
|
|
AtCmdTxClear(env);
|
|
AtCmdTxAddStatic(env, "AT#SSENDEXT=");
|
|
AtCmdTxAddDecimalIntWithLimit(env, linkNum, 1);
|
|
AtCmdTxAddStatic(env, ",");
|
|
AtCmdTxAddDecimalIntWithLimit(env, dataLen, 4);
|
|
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;
|
|
/*
|
|
//debug_printf(env->io, "AT#SSENDEXT=%u,%u\r\n", idSocket, dataSocketWriteLen);
|
|
|
|
AtCommandResult ready = AtCmdWaitChar(env, env->stdRxTimeout, '>');
|
|
|
|
if (ready != AT_OK) {
|
|
AtCmdSendStatic(env, AT_ESC_STR);
|
|
return ready;
|
|
}
|
|
|
|
AtCmdSend(env, data, dataLen);
|
|
|
|
AtCmdSendStatic(env, AT_ESC_STR);
|
|
|
|
return AtCmdOkErrAnswer(env, env->stdRxTimeout);
|
|
*/
|
|
}
|
|
|
|
/*
|
|
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);
|
|
|
|
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: ")) {
|
|
//todo check
|
|
AtCmdRxClear(env);
|
|
return AT_OK;
|
|
} else {
|
|
AtCmdProcessUnresolvedLine(env);
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
}
|
|
} else {
|
|
if (AtCmdRxBeginWithStatic(env, ">")) {
|
|
AtCmdRxClear(env);
|
|
AtCmdSend(env, data, dataLen);
|
|
}
|
|
}
|
|
}
|
|
|
|
return AT_TIMEOUT;
|
|
}
|
|
*/ |