145 lines
4.5 KiB
C
145 lines
4.5 KiB
C
//
|
||
// Created by xemon on 28.11.22.
|
||
//
|
||
|
||
#include "GsmWithGnss_Private.h"
|
||
#include <SystemDelayInterface.h>
|
||
|
||
bool GsmWithGnss_GetCurrentCallGranted(tGsmWithGnss *env, tGsmCurrentCallsTable *callsTable) {
|
||
static const uint8_t tries_limit = 10;
|
||
uint8_t tries = tries_limit;
|
||
do {
|
||
bool gotGable = (AtGsmListOfCurrentCalls(&env->gsmAt, callsTable) == AT_OK);
|
||
if (gotGable) {
|
||
return true;
|
||
} else {
|
||
SystemDelayMs(200);
|
||
--tries;
|
||
}
|
||
} while (tries);
|
||
|
||
return false;
|
||
}
|
||
|
||
|
||
bool GsmWithGnss_SetNewMSD(tGsmWithGnss *env,
|
||
uint8_t *msd,
|
||
size_t msdLength
|
||
) {
|
||
AtGsmTelitLe910_EcallSetUrc(&env->gsmAt, GSM_TELIT_ECALL_URC_MODE_2);
|
||
return AtGsmTelitLe910_ResetiingMsd(&env->gsmAt, msd, msdLength) == AT_OK;
|
||
}
|
||
|
||
bool GsmWithGnss_Ecall(tGsmWithGnss *env,
|
||
uint8_t *msd,
|
||
size_t msdLength,
|
||
|
||
char *phoneNumber,
|
||
size_t phoneNumberLength,
|
||
|
||
eEcallActivationType activationType,
|
||
eEcallTestMode testMode,
|
||
bool blocRegNetwork
|
||
) {
|
||
if(blocRegNetwork == false) {
|
||
LoggerTraceStatic(LOGGER, LOG_SIGN, "Проверка наличия сети")
|
||
if (GsmWithGnss_WaitNetworkRegistration(env, 2000)) {
|
||
LoggerTraceStatic(LOGGER, LOG_SIGN, "Сеть присутствует, выполняется регистрация")
|
||
|
||
if (AtGsm_OperatorSelectionAutomatic(&env->gsmAt) == AT_OK) {
|
||
LoggerTraceStatic(LOGGER, LOG_SIGN, "Выполнена регистрация в сети")
|
||
} else {
|
||
LoggerTraceStatic(LOGGER, LOG_SIGN, "Регистрация в сети НЕ выполнена")
|
||
}
|
||
} else {
|
||
LoggerTraceStatic(LOGGER, LOG_SIGN, "Сеть или сим-чип отсутствует")
|
||
}
|
||
}
|
||
eGsmEcallType ecallType =
|
||
(testMode == TEST_CALL) ?
|
||
GSM_ECALLTYPE_TEST : (
|
||
(activationType == MANUAL_ACTIVATION) ?
|
||
GSM_ECALLTYPE_MANUAL :
|
||
GSM_ECALLTYPE_AUTOMATIC
|
||
);
|
||
|
||
env->urc.msdSuccess = false;
|
||
AtGsmTelitLe910_EcallSetUrc(&env->gsmAt, GSM_TELIT_ECALL_URC_MODE_2);
|
||
|
||
return AtGsmTelitLe910_SendEcall(&env->gsmAt, msd, msdLength, phoneNumber, phoneNumberLength, ecallType) == 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) {
|
||
AtCmdProcessUnresolvedLines(&env->gsmAt);
|
||
if(env->urc.msdPull){
|
||
env->urc.msdPull = false;
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
bool GsmWithGnss_isMsdSent(tGsmWithGnss *env) {
|
||
AtCmdProcessUnresolvedLines(&env->gsmAt);
|
||
return env->urc.msdSuccess;
|
||
}
|
||
|
||
bool GsmWithGnss_HangUp(tGsmWithGnss *env) {
|
||
env->urc.msdSuccess = false;
|
||
env->urc.msdPull = false;
|
||
return AtGsmHangUpCall(&env->gsmAt) == AT_OK;
|
||
}
|
||
|
||
|
||
|