commit 81f8941556cf49c9dba913c702ede7b76e72c610 Author: cfif Date: Mon Jun 2 14:32:56 2025 +0300 Init diff --git a/Inc/AtGsmSimComA7600.h b/Inc/AtGsmSimComA7600.h new file mode 100644 index 0000000..b632138 --- /dev/null +++ b/Inc/AtGsmSimComA7600.h @@ -0,0 +1,21 @@ +// +// Created by xemon on 10.05.23. +// + +#ifndef ATGSMSIMCOMA7600_H +#define ATGSMSIMCOMA7600_H + +#include "AtGsmSimComA7600_DefinePdpContext.h" +#include "AtGsmSimComA7600_StartSocketService.h" +#include "AtGsmSimComA7600_StopSocketService.h" +#include "AtGsmSimComA7600_EstablishConnection.h" +#include "AtGsmSimComA7600_SocketSendData.h" + +#include "AtGsmSimComA7600_SSL_DefinePdpContext.h" +#include "AtGsmSimComA7600_SSL_StartSocketService.h" +#include "AtGsmSimComA7600_SSL_StopSocketService.h" +#include "AtGsmSimComA7600_SSL_EstablishConnection.h" +#include "AtGsmSimComA7600_SSL_SocketSendData.h" + + +#endif //ATGSMSIMCOMA7600_H diff --git a/Inc/AtGsmSimComA7600_DefinePdpContext.h b/Inc/AtGsmSimComA7600_DefinePdpContext.h new file mode 100644 index 0000000..cc9795a --- /dev/null +++ b/Inc/AtGsmSimComA7600_DefinePdpContext.h @@ -0,0 +1,30 @@ +// +// Created by xemon on 10.05.23. +// + +#ifndef ATGSMSIMCOMA7600_DEFINEPDPCONTEXT_H +#define ATGSMSIMCOMA7600_DEFINEPDPCONTEXT_H + +#include "AtCmdCommon.h" + +typedef enum { + AtGsmSimComA7600_PdpType_IP, + AtGsmSimComA7600_PdpType_IPV6, + AtGsmSimComA7600_PdpType_IPV4V6 +} eAtGsmSimComA7600_PdpType; + + +AtCommandResult AtGsmSimComA7600_DefinePdpContext( + tAtCmd *env, uint8_t cid, eAtGsmSimComA7600_PdpType pdpType, const char *apn, uint8_t apnLen +); + +AtCommandResult AtGsmSimComA7600_PdpActivate(tAtCmd *env, uint8_t cid); + +AtCommandResult AtGsmSimComA7600_PdpDeactivate(tAtCmd *env, uint8_t cid); + +AtCommandResult AtGsmSimComA7600_DefinePdpAuthContext( + tAtCmd *env, uint8_t cid, uint8_t auth_type, const char *user, uint8_t userLen, const char *pass, uint8_t passLen +); + +#define AtGsmSimComA7600_DefinePdpIpContextStaticApn(ENV, CID, APN) AtGsmSimComA7600_DefinePdpContext(ENV,CID,AtGsmSimComA7600_PdpType_IP,APN,sizeof(APN)-1) +#endif //ATGSMSIMCOMA7600_DEFINEPDPCONTEXT_H diff --git a/Inc/AtGsmSimComA7600_EstablishConnection.h b/Inc/AtGsmSimComA7600_EstablishConnection.h new file mode 100644 index 0000000..47772e2 --- /dev/null +++ b/Inc/AtGsmSimComA7600_EstablishConnection.h @@ -0,0 +1,32 @@ +// +// Created by xemon on 10.05.23. +// + +#ifndef ATGSMSIMCOMA7600_ESTEBLISHCONNECTION_H +#define ATGSMSIMCOMA7600_ESTEBLISHCONNECTION_H + +#include "AtCmdCommon.h" + +typedef enum { + eAtGsmSimComA7600_IpType_TCP, + eAtGsmSimComA7600_IpType_UDP, +} eAtGsmSimComA7600_IpType; + + +AtCommandResult AtGsmSimComA7600_EstablishConnection( + tAtCmd *env, + uint8_t linkNum, + eAtGsmSimComA7600_IpType type, + char *srvIp, + uint8_t srvIpLen, + uint16_t srvPort, + uint16_t localPort +); + +#define AtGsmSimComA7600_EstablishTcpConnStatic(ENV, LNK, SRV, PORT) AtGsmSimComA7600_EstablishConnection(ENV,LNK,eAtGsmSimComA7600_IpType_TCP,SRV,sizeof(SRV)-1,PORT,0) + +AtCommandResult AtGsmSimComA7600_HasConnection(tAtCmd *env, uint8_t linkNum, bool *status); + +AtCommandResult AtGsmSimComA7600_CloseConnection(tAtCmd *env, uint8_t linkNum); + +#endif //ATGSMSIMCOMA7600_ESTEBLISHCONNECTION_H diff --git a/Inc/AtGsmSimComA7600_Http.h b/Inc/AtGsmSimComA7600_Http.h new file mode 100644 index 0000000..f5cecca --- /dev/null +++ b/Inc/AtGsmSimComA7600_Http.h @@ -0,0 +1,44 @@ +// +// Created by xemon on 10.07.23. +// + +#ifndef ATGSMSIMCOMA7600_ATGSMSIMCOMA7600_HTTP_H +#define ATGSMSIMCOMA7600_ATGSMSIMCOMA7600_HTTP_H + +#include "AtCmdCommon.h" + +typedef enum { + eAtGsmSimComA7600_HttpMethod_GET = '0', + eAtGsmSimComA7600_HttpMethod_POST = '1', + eAtGsmSimComA7600_HttpMethod_HEAD = '2', + eAtGsmSimComA7600_HttpMethod_DELETE = '3', +} eAtGsmSimComA7600_HttpMethod; + + +AtCommandResult AtGsmSimComA7600_HttpInit(tAtCmd *env); + +AtCommandResult AtGsmSimComA7600_HttpHead(tAtCmd *env); + +AtCommandResult AtGsmSimComA7600_HttpTerminate(tAtCmd *env); + +AtCommandResult AtGsmSimComA7600_HttpSetUrl(tAtCmd *env, char *url, size_t urlSize); + +AtCommandResult AtGsmSimComA7600_HttpSetCid(tAtCmd *env, uint8_t cid); + +AtCommandResult AtGsmSimComA7600_HttpMethodAction( + tAtCmd *env, + eAtGsmSimComA7600_HttpMethod method, + uint16_t *resultCode, + size_t *responseLen, + uint32_t timeout +); + +AtCommandResult AtGsmSimComA7600_HttpRead( + tAtCmd *env, + uint8_t *data, + size_t dataOffset, + size_t dataLimit, + size_t *readLen +); + +#endif //ATGSMSIMCOMA7600_ATGSMSIMCOMA7600_HTTP_H diff --git a/Inc/AtGsmSimComA7600_SSL_DefinePdpContext.h b/Inc/AtGsmSimComA7600_SSL_DefinePdpContext.h new file mode 100644 index 0000000..af7f70a --- /dev/null +++ b/Inc/AtGsmSimComA7600_SSL_DefinePdpContext.h @@ -0,0 +1,16 @@ +// +// Created by cfif on 24.05.2024. +// + +#ifndef SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_DEFINEPDPCONTEXT_H +#define SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_DEFINEPDPCONTEXT_H + +typedef enum { + eAtGsmSimComA7600_SslCfgType_INT, + eAtGsmSimComA7600_SslCfgType_STR, +} eAtGsmSimComA7600_SSL_Cfg_Type; + +AtCommandResult AtGsmSimComA7600_SSL_SetContext(tAtCmd *env, uint8_t linkNum, uint8_t ctx); +AtCommandResult AtGsmSimComA7600_SSL_CfgContext(tAtCmd *env, eAtGsmSimComA7600_SSL_Cfg_Type type, char *param, uint8_t paramLen, uint8_t ctx, char *value, uint8_t valueLen); + +#endif //SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_DEFINEPDPCONTEXT_H diff --git a/Inc/AtGsmSimComA7600_SSL_EstablishConnection.h b/Inc/AtGsmSimComA7600_SSL_EstablishConnection.h new file mode 100644 index 0000000..7156792 --- /dev/null +++ b/Inc/AtGsmSimComA7600_SSL_EstablishConnection.h @@ -0,0 +1,28 @@ +// +// Created by cfif on 24.05.2024. +// + +#ifndef SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_ESTABLISHCONNECTION_H +#define SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_ESTABLISHCONNECTION_H + +#include "AtCmdCommon.h" +#include "AtGsmSimComSSLType.h" + +AtCommandResult AtGsmSimComA7600_SSL_EstablishConnection( + tAtCmd *env, + uint8_t linkNum, + char *srvIp, + uint8_t srvIpLen, + uint16_t srvPort, + eAtGsmSimComA7600_SSL_Type clientType, + uint8_t *codeResultOpen +); + +AtCommandResult AtGsmSimComA7600_SSL_HasConnection(tAtCmd *env, uint8_t linkNum, bool *status); + +AtCommandResult AtGsmSimComA7600_SSL_CloseConnection( + tAtCmd *env, + uint8_t linkNum +); + +#endif //SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_ESTABLISHCONNECTION_H diff --git a/Inc/AtGsmSimComA7600_SSL_SocketSendData.h b/Inc/AtGsmSimComA7600_SSL_SocketSendData.h new file mode 100644 index 0000000..0b60a54 --- /dev/null +++ b/Inc/AtGsmSimComA7600_SSL_SocketSendData.h @@ -0,0 +1,25 @@ +// +// Created by cfif on 24.05.2024. +// + +#ifndef SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_SOCKETSENDDATA_H +#define SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_SOCKETSENDDATA_H + +#include "AtCmdCommon.h" + +AtCommandResult AtGsmSimComA7600_SSL_SocketSendData( + tAtCmd *env, uint8_t linkNum, uint8_t *data, uint16_t dataLen, uint32_t 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 +); + +#endif //SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_SOCKETSENDDATA_H diff --git a/Inc/AtGsmSimComA7600_SSL_StartSocketService.h b/Inc/AtGsmSimComA7600_SSL_StartSocketService.h new file mode 100644 index 0000000..651fab4 --- /dev/null +++ b/Inc/AtGsmSimComA7600_SSL_StartSocketService.h @@ -0,0 +1,11 @@ +// +// Created by cfif on 24.05.2024. +// + +#ifndef SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_STARTSOCKETSERVICE_H +#define SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_STARTSOCKETSERVICE_H + +AtCommandResult AtGsmSimComA7600_SSL_StartSocketService(tAtCmd *env); +AtCommandResult AtGsmSimComA7600_SSL_HasIp(tAtCmd *env); + +#endif //SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_STARTSOCKETSERVICE_H diff --git a/Inc/AtGsmSimComA7600_SSL_StopSocketService.h b/Inc/AtGsmSimComA7600_SSL_StopSocketService.h new file mode 100644 index 0000000..f37eca5 --- /dev/null +++ b/Inc/AtGsmSimComA7600_SSL_StopSocketService.h @@ -0,0 +1,12 @@ +// +// Created by cfif on 24.05.2024. +// + +#ifndef SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_STOPSOCKETSERVICE_H +#define SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_STOPSOCKETSERVICE_H + +#include "AtCmdCommon.h" + +AtCommandResult AtGsmSimComA7600_SSL_StopSocketService(tAtCmd *env); + +#endif //SMART_COMPONENTS_ATGSMSIMCOMA7600_SSL_STOPSOCKETSERVICE_H diff --git a/Inc/AtGsmSimComA7600_SocketSendData.h b/Inc/AtGsmSimComA7600_SocketSendData.h new file mode 100644 index 0000000..4aa1849 --- /dev/null +++ b/Inc/AtGsmSimComA7600_SocketSendData.h @@ -0,0 +1,28 @@ +// +// Created by xemon on 10.05.23. +// + +#ifndef ATGSMSIMCOMA7600_SOCKETSENDDATA_H +#define ATGSMSIMCOMA7600_SOCKETSENDDATA_H + +#include "AtCmdCommon.h" + + +AtCommandResult AtGsmSimComA7600_SocketSendData( + tAtCmd *env, uint8_t linkNum, uint8_t *data, uint16_t dataLen, uint32_t 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 +); + +#define AtGsmSimComA7600_SocketSendDataStatic(ENV, LNK, STR, TOUT) AtGsmSimComA7600_SocketSendData(ENV,LNK,(uint8_t*)STR,sizeof(STR)-1,TOUT) +#endif //ATGSMSIMCOMA7600_SOCKETSENDDATA_H diff --git a/Inc/AtGsmSimComA7600_StartSocketService.h b/Inc/AtGsmSimComA7600_StartSocketService.h new file mode 100644 index 0000000..28a9aa8 --- /dev/null +++ b/Inc/AtGsmSimComA7600_StartSocketService.h @@ -0,0 +1,12 @@ +// +// Created by xemon on 10.05.23. +// + +#ifndef ATGSMSIMCOMA7600_STARTSOCKETSERVICE_H +#define ATGSMSIMCOMA7600_STARTSOCKETSERVICE_H + +#include "AtCmdCommon.h" + +AtCommandResult AtGsmSimComA7600_StartSocketService(tAtCmd *env); +AtCommandResult AtGsmSimComA7600_HasIp(tAtCmd *env); +#endif //ATGSMSIMCOMA7600_STARTSOCKETSERVICE_H diff --git a/Inc/AtGsmSimComA7600_StopSocketService.h b/Inc/AtGsmSimComA7600_StopSocketService.h new file mode 100644 index 0000000..dc10fb7 --- /dev/null +++ b/Inc/AtGsmSimComA7600_StopSocketService.h @@ -0,0 +1,12 @@ +// +// Created by xemon on 10.05.23. +// + +#ifndef ATGSMSIMCOMA7600_STOPSOCKETSERVICE_H +#define ATGSMSIMCOMA7600_STOPSOCKETSERVICE_H + +#include "AtCmdCommon.h" + +AtCommandResult AtGsmSimComA7600_StopSocketService(tAtCmd *env); + +#endif //ATGSMSIMCOMA7600_STOPSOCKETSERVICE_H diff --git a/Inc/AtGsmSimComSSLType.h b/Inc/AtGsmSimComSSLType.h new file mode 100644 index 0000000..4030b12 --- /dev/null +++ b/Inc/AtGsmSimComSSLType.h @@ -0,0 +1,13 @@ +// +// Created by cfif on 05.07.2024. +// + +#ifndef SMART_COMPONENTS_BOOT_ATGSMSIMCOMSSLTYPE_H +#define SMART_COMPONENTS_BOOT_ATGSMSIMCOMSSLTYPE_H + +typedef enum { + eAtGsmSimComA7600_SslType_TCP = 1, + eAtGsmSimComA7600_SslType_TLS = 2, +} eAtGsmSimComA7600_SSL_Type; + +#endif //SMART_COMPONENTS_BOOT_ATGSMSIMCOMSSLTYPE_H diff --git a/Src/AtGsmSimComA7600_DefinePdpContext.c b/Src/AtGsmSimComA7600_DefinePdpContext.c new file mode 100644 index 0000000..2279232 --- /dev/null +++ b/Src/AtGsmSimComA7600_DefinePdpContext.c @@ -0,0 +1,118 @@ +// +// Created by cfif on 10.05.23. +// +#include "AtGsmSimComA7600_DefinePdpContext.h" +#include "AtCmdCommonProtected.h" +#include "SystemDelayInterface.h" + + +AtCommandResult AtGsmSimComA7600_DefinePdpAuthContext( + tAtCmd *env, uint8_t cid, uint8_t auth_type, const char *user, uint8_t userLen, const char *pass, uint8_t passLen +) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + if (cid > 15) { + return AT_ERROR; + } + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+CGAUTH="); + AtCmdTxAddDecimalIntWithLimit(env, cid, 2); + AtCmdTxAddChar(env, ','); + AtCmdTxAddDecimalIntWithLimit(env, auth_type, 2); + AtCmdTxAddChar(env, ','); + + AtCmdTxAddChar(env, '"'); + AtCmdTxAdd(env, pass, passLen); + AtCmdTxAddChar(env, '"'); + + AtCmdTxAddChar(env, ','); + + AtCmdTxAddChar(env, '"'); + AtCmdTxAdd(env, user, userLen); + AtCmdTxAddChar(env, '"'); + + AtCmdTxSendLn(env); + + return AtCmdOkErrAnswer(env, 10000); +} + + +AtCommandResult AtGsmSimComA7600_DefinePdpContext( + tAtCmd *env, uint8_t cid, eAtGsmSimComA7600_PdpType pdpType, const char *apn, uint8_t apnLen +) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + if (cid > 15) { + return AT_ERROR; + } + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+CGDCONT="); + AtCmdTxAddDecimalIntWithLimit(env, cid, 2); + AtCmdTxAddChar(env, ','); + + AtCmdTxAddChar(env, '"'); + switch (pdpType) { + + case AtGsmSimComA7600_PdpType_IP: + AtCmdTxAddStatic(env, "IP"); + break; + + case AtGsmSimComA7600_PdpType_IPV6: + AtCmdTxAddStatic(env, "IPV6"); + break; + case AtGsmSimComA7600_PdpType_IPV4V6: + AtCmdTxAddStatic(env, "IPV4V6"); + break; + default: + return AT_ERROR; + + } + AtCmdTxAddChar(env, '"'); + AtCmdTxAddChar(env, ','); + + + AtCmdTxAddChar(env, '"'); + AtCmdTxAdd(env, apn, apnLen); + AtCmdTxAddChar(env, '"'); + + AtCmdTxSendLn(env); + + return AtCmdOkErrAnswer(env, 10000); +} + +AtCommandResult AtGsmSimComA7600_PdpActivate(tAtCmd *env, uint8_t cid) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + if (cid > 15) { + return AT_ERROR; + } + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+CGACT=1,"); + AtCmdTxAddDecimalIntWithLimit(env, cid, 2); + + AtCmdTxSendLn(env); + + return AtCmdOkErrAnswer(env, env->stdRxTimeout); +} + +AtCommandResult AtGsmSimComA7600_PdpDeactivate(tAtCmd *env, uint8_t cid) { + AtCmdPrepare(env); + + if (cid > 15) { + return AT_ERROR; + } + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+CGACT=0,"); + AtCmdTxAddDecimalIntWithLimit(env, cid, 2); + + AtCmdTxSendLn(env); + + return AtCmdOkErrAnswer(env, env->stdRxTimeout*10); +} diff --git a/Src/AtGsmSimComA7600_EstablishConnection.c b/Src/AtGsmSimComA7600_EstablishConnection.c new file mode 100644 index 0000000..e6533e0 --- /dev/null +++ b/Src/AtGsmSimComA7600_EstablishConnection.c @@ -0,0 +1,178 @@ +// +// Created by cfif on 10.05.23. +// +#include +#include "AtGsmSimComA7600_EstablishConnection.h" +#include "AtCmdCommonProtected.h" +#include "SystemDelayInterface.h" + + +AtCommandResult AtGsmSimComA7600_EstablishConnection( + tAtCmd *env, + uint8_t linkNum, + eAtGsmSimComA7600_IpType type, + char *srvIp, + uint8_t srvIpLen, + uint16_t srvPort, + uint16_t localPort +) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + if (linkNum > 9) { + return AT_ERROR; + } + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+CIPOPEN="); + AtCmdTxAddDecimalIntWithLimit(env, linkNum, 1); + AtCmdTxAddChar(env, ','); + + AtCmdTxAddChar(env, '"'); + switch (type) { + + case eAtGsmSimComA7600_IpType_TCP: + AtCmdTxAddStatic(env, "TCP"); + break; + + case eAtGsmSimComA7600_IpType_UDP: + AtCmdTxAddStatic(env, "UDP"); + break; + default: + return AT_ERROR; + + } + AtCmdTxAddChar(env, '"'); + AtCmdTxAddChar(env, ','); + + + if (srvIpLen) { + AtCmdTxAddChar(env, '"'); + AtCmdTxAdd(env, srvIp, srvIpLen); + AtCmdTxAddChar(env, '"'); + } + AtCmdTxAddChar(env, ','); + + if (srvPort) { + AtCmdTxAddDecimalIntWithLimit(env, srvPort, 5); + } + if (localPort) { + AtCmdTxAddChar(env, ','); + AtCmdTxAddDecimalIntWithLimit(env, localPort, 5); + } + + AtCmdTxSendLn(env); + + uint32_t timeout = 20000; + uint32_t endMs = SystemGetMs() + timeout; + uint32_t leftMs = timeout; + + while ((AtCmdReceiveNextLine(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) { + leftMs = endMs - SystemGetMs(); + + if (AtCmdRxBeginWithStatic(env, "OK")) { + AtCmdRxClear(env); + } else if (AtCmdRxBeginWithStatic(env, "+CIPOPEN: ")) { + AtCommandResult res = (env->rxBuffer.data[sizeof("+CIPOPEN: X,") - 1] == '0') ? AT_OK : AT_ERROR; + AtCmdRxClear(env); + return res; + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} + + +AtCommandResult AtGsmSimComA7600_HasConnection(tAtCmd *env, uint8_t linkNum, bool *status) { + + char pattern[11]; + + memcpy(pattern, "+CIPOPEN: X", 11); + + pattern[sizeof(pattern) - 1] = vAsciiStringDecimalIntToChar(linkNum); + uint8_t pattern_len = sizeof(pattern); + *status = false; + + AtCmdPrepare(env); + AtCmdSendStatic(env, "AT+CIPOPEN?\r\n"); + + 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, "OK")) { + AtCmdRxClear(env); + return AT_OK; + } else if (AtCmdRxBeginWithStatic(env, "+CIPOPEN")) { + if (AtCmdRxBeginWith(env, pattern, pattern_len)) { + if (env->rxBuffer.data[pattern_len] == '\r') + *status = false; + else if (env->rxBuffer.data[pattern_len] == ',') { + *status = true; + } + } + AtCmdRxClear(env); + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} + + +AtCommandResult AtGsmSimComA7600_CloseConnection( + tAtCmd *env, + uint8_t linkNum +) { + AtCmdPrepare(env); + + if (linkNum > 9) { + return AT_ERROR; + } + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+CIPClOSE="); + AtCmdTxAddDecimalIntWithLimit(env, linkNum, 1); + + AtCmdTxSendLn(env); + + uint32_t timeout = 1000;//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, "OK")) { + AtCmdRxClear(env); + } else if (AtCmdRxBeginWithStatic(env, "CLOSED")) { + AtCmdRxClear(env); + return AT_OK; + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} diff --git a/Src/AtGsmSimComA7600_Http.c b/Src/AtGsmSimComA7600_Http.c new file mode 100644 index 0000000..2d0e383 --- /dev/null +++ b/Src/AtGsmSimComA7600_Http.c @@ -0,0 +1,195 @@ +// +// Created by cfif on 10.07.23. +// + +#include +#include "AtGsmSimComA7600_Http.h" +#include "AtCmdCommonProtected.h" +#include "AsciiStringParsingUtils.h" +#include "stdlib.h" + +AtCommandResult AtGsmSimComA7600_HttpInit(tAtCmd *env) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + AtCmdSendStatic(env, "AT+HTTPINIT\r\n"); + + return AtCmdOkErrAnswer(env, 10000); +} + +AtCommandResult AtGsmSimComA7600_HttpHead(tAtCmd *env) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + AtCmdSendStatic(env, "AT+HTTPHEAD\r\n"); + + return AtCmdOkErrAnswer(env, env->stdRxTimeout); +} + + +AtCommandResult AtGsmSimComA7600_HttpTerminate(tAtCmd *env) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + AtCmdSendStatic(env, "AT+HTTPTERM\r\n"); + + return AtCmdOkErrAnswer(env, env->stdRxTimeout); +} + + +AtCommandResult AtGsmSimComA7600_HttpSetUrl(tAtCmd *env, char *url, size_t urlSize) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+HTTPPARA=\"URL\","); + + + AtCmdTxAddChar(env, '"'); + AtCmdTxAdd(env, url, urlSize); + AtCmdTxAddChar(env, '"'); + + AtCmdTxSendLn(env); + + return AtCmdOkErrAnswer(env, env->stdRxTimeout); +} + +AtCommandResult AtGsmSimComA7600_HttpSetCid(tAtCmd *env, uint8_t cid) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+HTTPPARA=\"CID\","); + AtCmdTxAddDecimalIntWithLimit(env, cid, 2); + + AtCmdTxSendLn(env); + + return AtCmdOkErrAnswer(env, env->stdRxTimeout); +} + + +AtCommandResult AtGsmSimComA7600_HttpMethodAction( + tAtCmd *env, + eAtGsmSimComA7600_HttpMethod method, + uint16_t *resultCode, + size_t *responseLen, + uint32_t timeout +) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+HTTPACTION="); + AtCmdTxAddChar(env, method); + + + AtCmdTxSendLn(env); + +// uint32_t timeout = env->stdRxTimeout * 5; + uint32_t endMs = SystemGetMs() + timeout; + uint32_t leftMs = timeout; + + while ((AtCmdReceiveNextLine(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) { + leftMs = endMs - SystemGetMs(); + + if (AtCmdRxBeginWithStatic(env, "OK")) { + AtCmdRxClear(env); + } else if (AtCmdRxBeginWithStatic(env, "+HTTPACTION: ")) { + + char *blockBeginPos = env->rxBuffer.data + (sizeof("+HTTPACTION: ") - 1) - 1; + char *blockDividerPos = blockBeginPos; + char *strEnd = env->rxBuffer.data + env->rxBuffer.len; + + iAsciiStringMoveToNextParsingBlock(&blockBeginPos, &blockDividerPos, strEnd, ','); + eAtGsmSimComA7600_HttpMethod methodRes = (eAtGsmSimComA7600_HttpMethod) *((char *) blockBeginPos); + + iAsciiStringMoveToNextParsingBlock(&blockBeginPos, &blockDividerPos, strEnd, ','); + *resultCode = iAsciiStringParseUnsignedLongDecimalNumber(blockBeginPos, blockDividerPos); + + iAsciiStringMoveToNextParsingBlock(&blockBeginPos, &blockDividerPos, strEnd, ','); + *responseLen = iAsciiStringParseUnsignedLongDecimalNumber(blockBeginPos, blockDividerPos); + + AtCmdRxClear(env); + return methodRes == method ? AT_OK : AT_ERROR; + + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} + + +AtCommandResult AtGsmSimComA7600_HttpRead( + tAtCmd *env, + uint8_t *data, + size_t dataOffset,// непонятный параметр, + size_t dataLimit, + size_t *readLen +) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+HTTPREAD="); + AtCmdTxAddDecimalIntWithLimit(env, dataOffset, 16); + AtCmdTxAddChar(env, ','); + AtCmdTxAddDecimalIntWithLimit(env, dataLimit, 16); + + AtCmdTxSendLn(env); + + uint32_t timeout = 20000; + uint32_t endMs = SystemGetMs() + timeout; + uint32_t leftMs = timeout; + + bool dataOk = false; + + while ((AtCmdReceiveNextLine(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) { + leftMs = endMs - SystemGetMs(); + + if (AtCmdRxBeginWithStatic(env, "OK")) { + AtCmdRxClear(env); +// return dataOk ? AT_OK : AT_ERROR; + } else if (AtCmdRxBeginWithStatic(env, "+HTTPREAD: ")) { + + *readLen = iAsciiStringParseUnsignedLongDecimalNumber( + env->rxBuffer.data + sizeof("+HTTPREAD: DATA,") - 1, env->rxBuffer.data + env->rxBuffer.len - 1 + ); + + uint16_t bufferLen = SerialPortReceive(env->io, data, *readLen, timeout); + + /* + char *blockBeginPos = env->rxBuffer.data + (sizeof("+HTTPREAD: ") - 1) - 1; + char *blockDividerPos = blockBeginPos; + char *strEnd = env->rxBuffer.data + env->rxBuffer.len; + +// DATA word +// iAsciiStringMoveToNextParsingBlock(&blockBeginPos, &blockDividerPos, strEnd, ','); + + iAsciiStringMoveToNextParsingBlock(&blockBeginPos, &blockDividerPos, strEnd, ','); + *readLen = iAsciiStringParseUnsignedLongDecimalNumber(blockBeginPos, blockDividerPos); + + AtCmdRxReadRAW(env, data, *readLen, timeout); +*/ + + dataOk = true; + AtCmdRxClear(env); + return AT_OK; + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} \ No newline at end of file diff --git a/Src/AtGsmSimComA7600_SSL_DefinePdpContext.c b/Src/AtGsmSimComA7600_SSL_DefinePdpContext.c new file mode 100644 index 0000000..4c7fc95 --- /dev/null +++ b/Src/AtGsmSimComA7600_SSL_DefinePdpContext.c @@ -0,0 +1,89 @@ +// +// Created by cfif on 24.05.2024. +// +#include "AtCmdCommonProtected.h" +#include "SystemDelayInterface.h" +#include "AtGsmSimComA7600_SSL_DefinePdpContext.h" + +AtCommandResult AtGsmSimComA7600_SSL_SetContext(tAtCmd *env, uint8_t linkNum, uint8_t ctx) { + AtCmdPrepare(env); + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+CCHSSLCFG="); + AtCmdTxAddDecimalIntWithLimit(env, linkNum, 1); + AtCmdTxAddChar(env, ','); + AtCmdTxAddDecimalIntWithLimit(env, ctx, 1); + AtCmdTxSendLn(env); + + 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, "OK")) { + AtCmdRxClear(env); + return AT_OK; + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} + +AtCommandResult +AtGsmSimComA7600_SSL_CfgContext(tAtCmd *env, eAtGsmSimComA7600_SSL_Cfg_Type type, char *param, uint8_t paramLen, + uint8_t ctx, char *value, uint8_t valueLen) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+CSSLCFG="); + + AtCmdTxAddChar(env, '"'); + AtCmdTxAdd(env, param, paramLen); + AtCmdTxAddChar(env, '"'); + + AtCmdTxAddChar(env, ','); + AtCmdTxAddDecimalIntWithLimit(env, ctx, 1); + AtCmdTxAddChar(env, ','); + + if (type == eAtGsmSimComA7600_SslCfgType_STR) + AtCmdTxAddChar(env, '"'); + + AtCmdTxAdd(env, value, valueLen); + + if (type == eAtGsmSimComA7600_SslCfgType_STR) + AtCmdTxAddChar(env, '"'); + + AtCmdTxSendLn(env); + + 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, "OK")) { + AtCmdRxClear(env); + return AT_OK; + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} \ No newline at end of file diff --git a/Src/AtGsmSimComA7600_SSL_EstablishConnection.c b/Src/AtGsmSimComA7600_SSL_EstablishConnection.c new file mode 100644 index 0000000..99eac9a --- /dev/null +++ b/Src/AtGsmSimComA7600_SSL_EstablishConnection.c @@ -0,0 +1,167 @@ +// +// Created by cfif on 24.05.2024. +// +#include "AtGsmSimComA7600_SSL_EstablishConnection.h" +#include "AtCmdCommonProtected.h" +#include "SystemDelayInterface.h" +#include +#include "stdlib.h" + +AtCommandResult AtGsmSimComA7600_SSL_EstablishConnection( + tAtCmd *env, + uint8_t linkNum, + char *srvIp, + uint8_t srvIpLen, + uint16_t srvPort, + eAtGsmSimComA7600_SSL_Type sslType, + uint8_t *codeResultOpen +) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + if (linkNum > 1) { + return AT_ERROR; + } + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+CCHOPEN="); + AtCmdTxAddDecimalIntWithLimit(env, linkNum, 1); + AtCmdTxAddChar(env, ','); + + if (srvIpLen) { + AtCmdTxAddChar(env, '"'); + AtCmdTxAdd(env, srvIp, srvIpLen); + AtCmdTxAddChar(env, '"'); + } + AtCmdTxAddChar(env, ','); + + if (srvPort) { + AtCmdTxAddDecimalIntWithLimit(env, srvPort, 5); + } + if (sslType) { + AtCmdTxAddChar(env, ','); + AtCmdTxAddDecimalIntWithLimit(env, sslType, 1); + } + + AtCmdTxSendLn(env); + + uint32_t timeout = 20000; + uint32_t endMs = SystemGetMs() + timeout; + uint32_t leftMs = timeout; + + while ((AtCmdReceiveNextLine(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) { + leftMs = endMs - SystemGetMs(); + + if (AtCmdRxBeginWithStatic(env, "OK")) { + AtCmdRxClear(env); + } else if (AtCmdRxBeginWithStatic(env, "+CCHOPEN: ")) { + + *codeResultOpen = atoi(&env->rxBuffer.data[sizeof("+CIPOPEN: X,") - 1]); + + AtCommandResult res = (env->rxBuffer.data[sizeof("+CIPOPEN: X,") - 1] == '0') ? AT_OK : AT_ERROR; + AtCmdRxClear(env); + return res; + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + *codeResultOpen = 20; + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} + + +AtCommandResult AtGsmSimComA7600_SSL_HasConnection(tAtCmd *env, uint8_t linkNum, bool *status) { + + char pattern[13]; + + memcpy(pattern, "+CCHOPEN: X", 11); + + pattern[10] = vAsciiStringDecimalIntToChar(linkNum); + pattern[11] = ','; + pattern[12] = '"'; + + uint8_t pattern_len = sizeof(pattern); + *status = false; + + AtCmdPrepare(env); + AtCmdSendStatic(env, "AT+CCHOPEN?\r\n"); + + 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, "OK")) { + AtCmdRxClear(env); + return AT_OK; + } else if (AtCmdRxBeginWithStatic(env, "+CCHOPEN")) { + if (AtCmdRxBeginWith(env, pattern, pattern_len)) { + if (env->rxBuffer.data[pattern_len] == '"') + *status = false; + else if (env->rxBuffer.data[pattern_len] != '"') { + *status = true; + } + } + AtCmdRxClear(env); + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} + + +AtCommandResult AtGsmSimComA7600_SSL_CloseConnection( + tAtCmd *env, + uint8_t linkNum +) { + AtCmdPrepare(env); + + if (linkNum > 9) { + return AT_ERROR; + } + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+CCHCLOSE="); + AtCmdTxAddDecimalIntWithLimit(env, linkNum, 1); + + AtCmdTxSendLn(env); + + uint32_t timeout = 1000;//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, "OK")) { + AtCmdRxClear(env); + } else if (AtCmdRxBeginWithStatic(env, "CLOSED")) { + AtCmdRxClear(env); + return AT_OK; + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} \ No newline at end of file diff --git a/Src/AtGsmSimComA7600_SSL_SocketSendData.c b/Src/AtGsmSimComA7600_SSL_SocketSendData.c new file mode 100644 index 0000000..618c16e --- /dev/null +++ b/Src/AtGsmSimComA7600_SSL_SocketSendData.c @@ -0,0 +1,191 @@ +// +// 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; + +} +*/ \ No newline at end of file diff --git a/Src/AtGsmSimComA7600_SSL_StartSocketService.c b/Src/AtGsmSimComA7600_SSL_StartSocketService.c new file mode 100644 index 0000000..d97a101 --- /dev/null +++ b/Src/AtGsmSimComA7600_SSL_StartSocketService.c @@ -0,0 +1,71 @@ +// +// Created by cfif on 24.05.2024. +// + +#include "AtCmdCommonProtected.h" +#include "SystemDelayInterface.h" + + +AtCommandResult AtGsmSimComA7600_SSL_StartSocketService(tAtCmd *env) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + AtCmdSendStatic(env, "AT+CCHSTART\r\n"); + + 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, "OK")) { + AtCmdRxClear(env); + } else if (AtCmdRxBeginWithStatic(env, "+CCHSTART: 0")) { + AtCmdRxClear(env); + return AT_OK; + } else if (AtCmdRxBeginWithStatic(env, "+CCHSTART: 1")) { + AtCmdRxClear(env); + return AT_ERROR; + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} + +AtCommandResult AtGsmSimComA7600_SSL_HasIp(tAtCmd *env) { + AtCmdPrepare(env); + + AtCmdSendStatic(env, "AT+CCHADDR\r\n"); + + 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, "OK")) { + AtCmdRxClear(env); + return AT_OK; + } else if (AtCmdRxBeginWithStatic(env, "+IP ERROR:")) { + AtCmdRxClear(env); + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} \ No newline at end of file diff --git a/Src/AtGsmSimComA7600_SSL_StopSocketService.c b/Src/AtGsmSimComA7600_SSL_StopSocketService.c new file mode 100644 index 0000000..e11da76 --- /dev/null +++ b/Src/AtGsmSimComA7600_SSL_StopSocketService.c @@ -0,0 +1,13 @@ +// +// Created by cfif on 24.05.2024. +// +#include "AtCmdCommonProtected.h" + +AtCommandResult AtGsmSimComA7600_SSL_StopSocketService(tAtCmd *env) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + AtCmdSendStatic(env, "AT+CCHSTOP\r\n"); + + return AtCmdOkErrAnswer(env, env->stdRxTimeout); +} \ No newline at end of file diff --git a/Src/AtGsmSimComA7600_SocketSendData.c b/Src/AtGsmSimComA7600_SocketSendData.c new file mode 100644 index 0000000..b096d2e --- /dev/null +++ b/Src/AtGsmSimComA7600_SocketSendData.c @@ -0,0 +1,97 @@ +// +// 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; + +} diff --git a/Src/AtGsmSimComA7600_StartSocketService.c b/Src/AtGsmSimComA7600_StartSocketService.c new file mode 100644 index 0000000..d08c43a --- /dev/null +++ b/Src/AtGsmSimComA7600_StartSocketService.c @@ -0,0 +1,71 @@ +// +// Created by cfif on 10.05.23. +// +#include "AtGsmSimComA7600_StartSocketService.h" +#include "AtCmdCommonProtected.h" +#include "SystemDelayInterface.h" + + +AtCommandResult AtGsmSimComA7600_StartSocketService(tAtCmd *env) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + AtCmdSendStatic(env, "AT+NETOPEN\r\n"); + + 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, "OK")) { + AtCmdRxClear(env); + } else if (AtCmdRxBeginWithStatic(env, "+NETOPEN: 0")) { + AtCmdRxClear(env); + return AT_OK; + } else if (AtCmdRxBeginWithStatic(env, "+NETOPEN: 1")) { + AtCmdRxClear(env); + return AT_ERROR; + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} + +AtCommandResult AtGsmSimComA7600_HasIp(tAtCmd *env) { + AtCmdPrepare(env); + + AtCmdSendStatic(env, "AT+IPADDR\r\n"); + + 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, "OK")) { + AtCmdRxClear(env); + return AT_OK; + } else if (AtCmdRxBeginWithStatic(env, "+IP ERROR:")) { + AtCmdRxClear(env); + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} diff --git a/Src/AtGsmSimComA7600_StopSocketService.c b/Src/AtGsmSimComA7600_StopSocketService.c new file mode 100644 index 0000000..627cfba --- /dev/null +++ b/Src/AtGsmSimComA7600_StopSocketService.c @@ -0,0 +1,16 @@ +// +// Created by cfif on 10.05.23. +// +#include "AtGsmSimComA7600_StopSocketService.h" +#include "AtCmdCommonProtected.h" +#include "SystemDelayInterface.h" + + +AtCommandResult AtGsmSimComA7600_StopSocketService(tAtCmd *env) { + AtCmdPrepare(env); + AtCmdRxClear(env); + + AtCmdSendStatic(env, "AT+NETCLOSE\r\n"); + + return AtCmdOkErrAnswer(env, env->stdRxTimeout); +} diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..fc7e35d --- /dev/null +++ b/modular.json @@ -0,0 +1,17 @@ +{ + "dep": [ + { + "type": "git", + "provider": "Smart_Components_Aurus", + "repo": "AtGsmCommon" + } + ], + "cmake": { + "inc_dirs": [ + "./Inc" + ], + "srcs": [ + "./Src/**.c" + ] + } +} \ No newline at end of file