процедуры получения индификатора модеме и индификатора симЧипа переписаны на блокировку по мьютэксам, причина - добавление потоков одновременно обращяющихся к АТ интерфейсу модема

This commit is contained in:
parent aef4a5ad65
commit b1ef6e7e77
1 changed files with 35 additions and 65 deletions

View File

@ -278,81 +278,51 @@ AtCommandResult GsmWithGnss_StopRMCThread(tAtCmd *env) {
} }
AtCommandResult GsmWithGnss_GetCGSN(tAtCmd *env, char *acpString, size_t *acpStringLen) { AtCommandResult GsmWithGnss_GetCGSN(tAtCmd *env, char *acpString, size_t *acpStringLen) {
AtCmdPrepare(env); if (osMutexAcquire(env->access, 5000) == osOK) {
AtCmdPrepare(env);
AtCmdTxClear(env);
AtCmdSendStatic(env, "AT#CGSN\r\n");
AtCmdTxClear(env); SystemDelayMs(2000);
AtCmdSendStatic(env, "AT#CGSN\r\n"); while (AtCmdReceiveNextLine(env, 15000) == AT_OK) {
if (AtCmdRxBeginWithStatic(env, "#CGSN: ")) {
SystemDelayMs(2000); static const uint16_t prefixSize = sizeof("#CGSN: ") - 1;
while (AtCmdReceiveNextLine(env, 15000) == AT_OK) { *acpStringLen = env->rxBuffer.len - (prefixSize + 2);
if (AtCmdRxBeginWithStatic(env, "#CGSN: ")) { memcpy(acpString, env->rxBuffer.data + prefixSize, *acpStringLen);
static const uint16_t prefixSize = sizeof("#CGSN: ") - 1; osMutexRelease(env->access);
*acpStringLen = env->rxBuffer.len - (prefixSize + 2); return AT_OK;
memcpy(acpString, env->rxBuffer.data + prefixSize, *acpStringLen); }
if (AtCmdRxBeginWithStatic(env, "ERROR")) {
return AT_OK; osMutexRelease(env->access);
} return AT_ERROR;
if (AtCmdRxBeginWithStatic(env, "ERROR")) { }
return AT_ERROR;
} }
osMutexRelease(env->access);
} }
return AT_TIMEOUT; return AT_TIMEOUT;
} }
AtCommandResult GsmWithGnss_GetCCID(tAtCmd *env, char *acpStr, size_t *acpStrLen) { AtCommandResult GsmWithGnss_GetCCID(tAtCmd *env, char *acpStr, size_t *acpStrLen) {
// AtCmdPrepare(env); if (osMutexAcquire(env->access, 5000) == osOK) {
// AtCmdRxClear(env); AtCmdPrepare(env);
// AtCmdSendStatic(env, "AT#CCID\r\n"); AtCmdTxClear(env);
// AtCmdSendStatic(env, "AT#CCID\r\n");
// uint32_t timeout = 4000;
// 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);
// continue;
//
// } else if (AtCmdRxBeginWithStatic(env, "ERROR")) {
// AtCmdRxClear(env);
// return AT_ERROR;
//
// } else if (AtCmdRxBeginWithStatic(env, "#CCID: ")) {
//
// static const uint16_t prefixSize = sizeof("#CCID: ") - 1;
// *acpStrLen = env->rxBuffer.len - (prefixSize + 2);
// memcpy(acpStr, env->rxBuffer.data+ prefixSize,*acpStrLen);
// AtCmdRxClear(env);
// return AT_OK;
//
// } else {
// AtCmdProcessUnresolvedLine(env);
// AtCmdRxClear(env);
// continue;
// }
// }
// return AT_TIMEOUT;
//
AtCmdPrepare(env); while (AtCmdReceiveNextLine(env, 1500) == AT_OK) {
if (AtCmdRxBeginWithStatic(env, "#CCID: ")) {
static const uint16_t prefixSize = sizeof("#CCID: ") - 1;
*acpStrLen = env->rxBuffer.len - (prefixSize + 2);
memcpy(acpStr, env->rxBuffer.data+ prefixSize,*acpStrLen);
osMutexRelease(env->access);
return AT_OK;
}
AtCmdTxClear(env); if (AtCmdRxBeginWithStatic(env, "ERROR")) {
AtCmdSendStatic(env, "AT#CCID\r\n"); osMutexRelease(env->access);
return AT_ERROR;
while (AtCmdReceiveNextLine(env, 1500) == AT_OK) { }
if (AtCmdRxBeginWithStatic(env, "#CCID: ")) {
static const uint16_t prefixSize = sizeof("#CCID: ") - 1;
*acpStrLen = env->rxBuffer.len - (prefixSize + 2);
memcpy(acpStr, env->rxBuffer.data+ prefixSize,*acpStrLen);
return AT_OK;
}
if (AtCmdRxBeginWithStatic(env, "ERROR")) {
return AT_ERROR;
} }
osMutexRelease(env->access);
} }
return AT_TIMEOUT; return AT_TIMEOUT;
} }