// // Created by xemon on 28.11.22. // #include "GsmWithGnss_Private.h" #include #define LOG_SIGN "Главн. Вкл" #define LOGGER env->logger bool GsmWithGnss_GetCurrentCallGranted(tGsmWithGnss *env, tGsmCurrentCallsTable *callsTable) { if (osMutexAcquire(env->gsmAt.access, 1000) == osOK) { static const uint8_t tries_limit = 10; uint8_t tries = tries_limit; do { bool gotGable = (AtGsmListOfCurrentCalls(&env->gsmAt, callsTable) == AT_OK); if (gotGable) { osMutexRelease(env->gsmAt.access); return true; } else { SystemDelayMs(200); --tries; } } while (tries); osMutexRelease(env->gsmAt.access); return false; } else { LoggerInfoStatic(LOGGER, LOG_SIGN, "Ошибка захвата управления GsmWithGnss_GetCurrentCallGranted") return false; } } bool GsmWithGnss_SetNewMSD(tGsmWithGnss *env, uint8_t *msd, size_t msdLength, eEcallActivationType activationType, eEcallTestMode testMode ) { // AtGsmSimComSim7600_EcallSetUrc(&env->gsmAt, GSM_SIMCOM_ECALL_URC_MODE_2); return AtGsmSimComSim7600_ResetiingMsd(&env->gsmAt, msd, msdLength, activationType, testMode) == AT_OK; } bool GsmWithGnss_Ecall(tGsmWithGnss *env, uint8_t *msd, size_t msdLength, char *phoneNumber, size_t phoneNumberLength, eEcallActivationType activationType, eEcallTestMode testMode ) { LoggerTraceStatic(LOGGER, LOG_SIGN, "Проверка наличия сети") // if(env->flBlockReg == false) { // if( ! GsmWithGnss_WaitNetworkRegistration(env, 4000) ) { // LoggerInfoStatic(LOGGER, LOG_SIGN, "Сеть или сим-чип отсутствует, попытка регистрации_4..."); // if (GsmWithGnss_NetworkSetStateInnaterups(env, 4,6000) == AT_OK) { // LoggerTraceStatic(LOGGER, LOG_SIGN, "Сеть присутствует") // } else { // LoggerTraceStatic(LOGGER, LOG_SIGN, "Сеть или сим-чип отсутствует") // } // } else { // LoggerErrorStatic(LOGGER, LOG_SIGN, "Регистрация в сети присутствует"); // } // } else { // LoggerErrorStatic(LOGGER, LOG_SIGN, "Регистрация сети запрещена настройками"); // } env->urc.msdSendResult = false; return AtGsmSimComSim7600_SendEcall( &env->gsmAt, activationType, testMode, msd, msdLength, phoneNumber, phoneNumberLength ) == AT_OK; } bool GsmWithGnss_isCallDialing(tGsmWithGnss *env) { tGsmCurrentCallsTable callsTable; GsmWithGnss_GetCurrentCallGranted(env, &callsTable); if (callsTable.count) { for (uint8_t call = 0; call < callsTable.count; ++call) { if (callsTable.calls[call].direction == GSM_CURRENT_CALL_DIRECTION_MOBILE_ORIGINATED) { if (callsTable.calls->state != GSM_CURRENT_CALL_STATE_ACTIVE) { return true; } } } } return false; } bool GsmWithGnss_isOutCallActive(tGsmWithGnss *env) { tGsmCurrentCallsTable callsTable; GsmWithGnss_GetCurrentCallGranted(env, &callsTable); if (callsTable.count) { for (uint8_t call = 0; call < callsTable.count; ++call) { if (callsTable.calls[call].direction == GSM_CURRENT_CALL_DIRECTION_MOBILE_ORIGINATED) { if (callsTable.calls->state == GSM_CURRENT_CALL_STATE_ACTIVE) { return true; } } } } return false; } bool GsmWithGnss_isInpCallActive(tGsmWithGnss *env) { tGsmCurrentCallsTable callsTable; GsmWithGnss_GetCurrentCallGranted(env, &callsTable); if (callsTable.count) { for (uint8_t call = 0; call < callsTable.count; ++call) { if (callsTable.calls[call].direction == GSM_CURRENT_CALL_DIRECTION_MOBILE_TERMINATED) { if (callsTable.calls->state == GSM_CURRENT_CALL_STATE_ACTIVE) { return true; } } } } return false; } bool GsmWithGnss_isMsdReSent(tGsmWithGnss *env) { if (osMutexAcquire(env->gsmAt.access, 1000) == osOK) { AtCmdProcessUnresolvedLines(&env->gsmAt); if(env->urc.msdPull){ env->urc.msdPull = false; osMutexRelease(env->gsmAt.access); return true; } else { osMutexRelease(env->gsmAt.access); return false; } } else { LoggerInfoStatic(LOGGER, LOG_SIGN, "Ошибка захвата управления GsmWithGnss_isMsdReSent") return false; } } bool GsmWithGnss_isMsdSent(tGsmWithGnss *env) { if (osMutexAcquire(env->gsmAt.access, 1000) == osOK) { AtCmdProcessUnresolvedLines(&env->gsmAt); osMutexRelease(env->gsmAt.access); return env->urc.msdSendResult; } else { LoggerInfoStatic(LOGGER, LOG_SIGN, "Ошибка захвата управления GsmWithGnss_isMsdSent") return false; } } bool GsmWithGnss_GetUrcIsNetReg(tGsmWithGnss *env) { if (osMutexAcquire(env->gsmAt.access, 1000) == osOK) { AtCmdProcessUnresolvedLines(&env->gsmAt); osMutexRelease(env->gsmAt.access); return env->urc.netReg; } else { LoggerInfoStatic(LOGGER, LOG_SIGN, "Ошибка захвата управления GsmWithGnss_GetUrcIsNetReg") return false; } } void GsmWithGnss_ResetUrcIsNetReg(tGsmWithGnss *env) { if (osMutexAcquire(env->gsmAt.access, 1000) == osOK) { AtCmdProcessUnresolvedLines(&env->gsmAt); env->urc.netReg = false; osMutexRelease(env->gsmAt.access); } else { LoggerInfoStatic(LOGGER, LOG_SIGN, "Ошибка захвата управления GsmWithGnss_GetUrcIsNetReg") } } bool AtGsmPrepHangCall(tGsmWithGnss *env) { AtCommandResult res; if (osMutexAcquire(env->gsmAt.access, 1000) == osOK) { res = AtGsmPrepareHangCall(&env->gsmAt); osMutexRelease(env->gsmAt.access); return res; } else { LoggerInfoStatic(LOGGER, LOG_SIGN, "Ошибка захвата управления AtGsmPrepHangCall") } return AT_ERROR; } bool GsmWithGnss_HangUp(tGsmWithGnss *env) { AtCommandResult res; if (osMutexAcquire(env->gsmAt.access, 1000) == osOK) { env->urc.msdSendResult = false; env->urc.msdPull = false; res = AtGsmHangUpCall(&env->gsmAt); osMutexRelease(env->gsmAt.access); return res; } else { LoggerInfoStatic(LOGGER, LOG_SIGN, "Ошибка захвата управления GsmWithGnss_HangUp") } return AT_ERROR; } bool GsmWithGnss_HangUpEcoll(tGsmWithGnss *env) { AtCommandResult res; if (osMutexAcquire(env->gsmAt.access, 1000) == osOK) { env->urc.msdSendResult = false; env->urc.msdPull = false; res = AtGsmHangUpEcoll(&env->gsmAt); GsmWithGnss_resetInputCall(env); osMutexRelease(env->gsmAt.access); return res; } else { LoggerInfoStatic(LOGGER, LOG_SIGN, "Ошибка захвата управления GsmWithGnss_HangUpEcoll") } return AT_ERROR; }