// // Created by xemon on 10.05.23. // #include "AtGsmTelitLe910_DefinePdpContext.h" #include "AtCmdCommonProtected.h" #include "SystemDelayInterface.h" AtCommandResult AtGsmTelitLe910_DefinePdpContext( tAtCmd *env, uint8_t cid, eAtGsmTelitLe910_PdpType pdpType, const char *apn, uint8_t apnLen ) { AtCmdPrepare(env); if (cid > 15) { return AT_ERROR; } AtCmdTxClear(env); AtCmdTxAddStatic(env, "AT+CGDCONT="); AtCmdTxAddDecimalIntWithLimit(env, cid, 2); AtCmdTxAddChar(env, ','); AtCmdTxAddChar(env, '"'); switch (pdpType) { case AtGsmTelitLe910_PdpType_IP: AtCmdTxAddStatic(env, "IP"); break; case AtGsmTelitLe910_PdpType_IPV6: AtCmdTxAddStatic(env, "IPV6"); break; case AtGsmTelitLe910_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, env->stdRxTimeout); } AtCommandResult AtGsmTelitLe910_PdpActivate(tAtCmd *env, uint8_t cid) { AtCmdPrepare(env); if (cid > 15) { return AT_ERROR; } AtCmdTxClear(env); AtCmdTxAddStatic(env, "AT#SGACT=1,"); AtCmdTxAddDecimalIntWithLimit(env, cid, 2); AtCmdTxSendLn(env); uint32_t leftMs; uint32_t endMs = SystemGetMs() + env->stdRxTimeout * 2; while (endMs > SystemGetMs()) { leftMs = endMs - SystemGetMs(); if ((AtCmdReceiveNextLine(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) { if (AtCmdRxBeginWithStatic(env, "OK"))return AT_OK; if (AtCmdRxBeginWithStatic(env, "ERROR"))return AT_ERROR; if (AtCmdRxBeginWithStatic(env, "+CME ERROR"))return AT_ERROR; AtCmdProcessUnresolvedLine(env); } } return AT_TIMEOUT; } AtCommandResult AtGsmTelitLe910_PdpDeactivate(tAtCmd *env, uint8_t cid) { AtCmdPrepare(env); if (cid > 15) { return AT_ERROR; } AtCmdTxClear(env); AtCmdTxAddStatic(env, "AT#SGACT=0,"); AtCmdTxAddDecimalIntWithLimit(env, cid, 2); AtCmdTxSendLn(env); return AtCmdOkErrAnswer(env, env->stdRxTimeout*10); } AtCommandResult AtGsmTelitLe910_SimProfileSelect(tAtCmd *env, tString32 *profileData) { AtCmdPrepare(env); AtCmdTxClear(env); AtCmdTxAddStatic(env, "AT+CSIM="); AtCmdTxAddDecimalIntWithLimit(env, profileData->length, 2); AtCmdTxAddStatic(env, ", "); AtCmdTxAddStatic(env, "\""); AtCmdTxAdd(env, profileData->data, profileData->length); AtCmdTxAddStatic(env, "\""); AtCmdTxAddStatic(env, "\r\n"); AtCmdTxSendLn(env); return AtCmdOkErrAnswer(env, 2000 * env->stdRxTimeout); } /* AtCommandResult AtGsmSimComA7600_DefinePdpContext( tAtCmd *env, uint8_t cid, eAtGsmSimComA7600_PdpType pdpType, const char *apn, uint8_t apnLen ) { AtCmdPrepare(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, env->stdRxTimeout); } AtCommandResult AtGsmSimComA7600_PdpActivate(tAtCmd *env, uint8_t cid) { AtCmdPrepare(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*10); } 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); } */