diff --git a/Src/AtGsmTelitLe910_Ecall.c b/Src/AtGsmTelitLe910_Ecall.c index bf5dc01..8575b58 100644 --- a/Src/AtGsmTelitLe910_Ecall.c +++ b/Src/AtGsmTelitLe910_Ecall.c @@ -42,18 +42,96 @@ AtCommandResult AtGsmTelitLe910_EcallSetModeBattle(tAtCmd *env) { AtCommandResult AtGsmTelitLe910_SIMCardDetect(tAtCmd *env) { AtCmdPrepare(env); - + AtCmdRxClear(env); AtCmdSendStatic(env, "AT#SIMDET=1\r\n"); + uint32_t timeout = SystemGetMs() + 4000; - return AtCmdOkErrAnswer(env, env->stdRxTimeout); + while ( (AtCmdReceiveNextLine(env, 500) == AT_OK) && (timeout > SystemGetMs()) ) { + if(AtCmdRxBeginWithStatic(env, "OK") == AT_OK){ + AtCmdPrepare(env); + AtCmdRxClear(env); + SystemDelayMs(500); + AtCmdSendStatic(env, "AT#CIMI\r\n"); + timeout = SystemGetMs() + 4000; + while ( (AtCmdReceiveNextLine(env, 500) == AT_OK) || (timeout > SystemGetMs()) ) { + if(AtCmdRxBeginWithStatic(env, "OK") == AT_OK){ + SystemDelayMs(1000); + return AT_OK; + } else if(AtCmdRxBeginWithStatic(env, "+CME ERROR: SIM not inserted") == AT_OK){ + AtCmdPrepare(env); + AtCmdRxClear(env); + SystemDelayMs(500); + AtCmdSendStatic(env, "AT#SIMDET=1\r\n"); + AtCmdPrepare(env); + AtCmdRxClear(env); + SystemDelayMs(500); + AtCmdSendStatic(env, "AT#CIMI\r\n"); + continue; + } + if(timeout < SystemGetMs()){ + return AT_TIMEOUT; + } + } + if(timeout < SystemGetMs()){ + return AT_TIMEOUT; + } else { + return AT_ERROR; + } + } else { + continue; + } + } + return AT_ERROR; + +///=================================================== +// +// AtCmdPrepare(env); +// AtCmdRxClear(env); +// AtCmdSendStatic(env, "AT#SIMDET=1\r\n"); +// +// uint32_t timeout = SystemGetMs() + 4000; +// +// while ( (AtCmdReceiveNextLine(env, 500) == AT_OK) && (timeout > SystemGetMs()) ) { +// if (AtCmdRxBeginWithStatic(env, "")) { +// if (AtCmdRxBeginWithStatic(env, "OK")) { +// AtCmdPrepare(env); +// AtCmdRxClear(env); +// SystemDelayMs(500); +// AtCmdSendStatic(env, "AT#CIMI\r\n"); +// timeout = SystemGetMs() + 4000; +// +// while ((AtCmdReceiveNextLine(env, 500) == AT_OK) && (timeout > SystemGetMs())) { +// if (AtCmdRxBeginWithStatic(env, "#CIMI: ")) { +// SystemDelayMs(1000); +// return AT_OK; +// } else if (AtCmdRxBeginWithStatic(env, "+CME ERROR: SIM not inserted")) { +// AtCmdPrepare(env); +// AtCmdRxClear(env); +// SystemDelayMs(500); +// AtCmdSendStatic(env, "AT#CIMI\r\n"); +// continue; +// } +// } +// } else { +// AtCmdPrepare(env); +// AtCmdRxClear(env); +// SystemDelayMs(500); +// AtCmdSendStatic(env, "AT#SIMDET=1\r\n"); +// continue; +// } +// } +// } +// +// return AT_ERROR; } AtCommandResult AtGsmTelitLe910_SIMCardNoDetect(tAtCmd *env) { AtCmdPrepare(env); - + AtCmdRxClear(env); AtCmdSendStatic(env, "AT#SIMDET=0\r\n"); - - return AtCmdOkErrAnswer(env, env->stdRxTimeout); + AtCommandResult res = AtCmdOkErrAnswer(env, env->stdRxTimeout); + SystemDelayMs(500); + return res; } AtCommandResult AtGsmTelitLe910_EcallWriteMsdToModem(tAtCmd *env, uint8_t *msd, size_t msdLength) {