diff --git a/Inc/AtGsmA76xx.h b/Inc/AtGsmA76xx.h index c117d79..6c245bb 100644 --- a/Inc/AtGsmA76xx.h +++ b/Inc/AtGsmA76xx.h @@ -22,7 +22,7 @@ // IMEI AtCommandResult AtGsm_Simcom_A76xx_GET_CGSN(tAtCmd *env, char *acpString, size_t *acpStringLen); -AtCommandResult AtGsm_Simcom_A76xx_CCID(tAtCmd *env, char *acpString, size_t *acpStringLen); +AtCommandResult AtGsm_Simcom_A76xx_CCID(tAtCmd *env, char *ssidStr, size_t *ssidStrLen); // конец-------------------------- Служебные ---------------------------------------------------------------------- diff --git a/Src/AtGsmA76xx.c b/Src/AtGsmA76xx.c index aa92ae7..b00984a 100644 --- a/Src/AtGsmA76xx.c +++ b/Src/AtGsmA76xx.c @@ -46,38 +46,31 @@ AtCommandResult AtGsm_Simcom_A76xx_GET_CGSN(tAtCmd *env, char *acpString, size_t return AT_TIMEOUT; } -AtCommandResult AtGsm_Simcom_A76xx_CCID(tAtCmd *env, char *acpString, size_t *acpStringLen) { +AtCommandResult AtGsm_Simcom_A76xx_CCID(tAtCmd *env, char *ssidStr, size_t *ssidStrLen) { AtCmdPrepare(env); - AtCmdTxClear(env); - AtCmdTxAddStatic(env, "AT+CICCID"); - AtCmdTxSendLn(env); + AtCmdSendStatic(env, "AT+CICCID\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, "ERROR")) { - AtCmdRxClear(env); - return AT_ERROR; - - } else if (AtCmdRxBeginWithStatic(env, "+CCID: ")) { - while (AtCmdReceiveNextLine(env, 1000) == AT_OK) { - char *start = env->rxBuffer.data + sizeof("+CCID:"); - *acpStringLen = env->rxBuffer.len - sizeof("+CCID:") - 2; - memcpy(acpString, start, *acpStringLen); - AtCmdRxClear(env); - return AtCmdOkErrAnswer(env, env->stdRxTimeout); + uint32_t endMs = SystemGetMs() + 5000; + while (endMs > SystemGetMs()) { + if (AtCmdReceiveNextLine(env, 1000) == AT_OK) { + if (AtCmdRxBeginWithStatic(env, "+ICCID: ")) { + static const uint16_t prefixSize = sizeof("+ICCID: ") - 1; + *ssidStrLen = env->rxBuffer.len - (prefixSize + 2); + memcpy(ssidStr, env->rxBuffer.data + prefixSize, *ssidStrLen); + return AT_OK; + } + + if (AtCmdRxBeginWithStatic(env, "ERROR")) { + return AT_ERROR; + } + if (AtCmdRxBeginWithStatic(env, "+CME ERROR: SIM busy")) { + AtCmdPrepare(env); + AtCmdRxClear(env); + continue; } - } else { AtCmdProcessUnresolvedLine(env); - AtCmdRxClear(env); - continue; } }