UveosOnNation_VEGA_GsmWithG.../GsmWithGnss.c

227 lines
7.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Created by xemon on 21.10.22.
//
#include "GsmWithGnss_Private.h"
#include "AtGsm_GetTime.h"
#include "Rtc.h"
#include <AtCmdCommonProtected.h>
#include <AudioPlayerTelitLe910.h>
#include <AudioRecorderTelitLe910.h>
#include <SystemDelayInterface.h>
#define LOGGER env->logger
#define LOG_SIGN "GSM&GNSS"
bool isRtc = false;
void GsmWithGnss_Urc(tGsmWithGnss *env, tAtBuffer *buff) {
if (AtBufferBeginWithStatic(buff, "SRING: ")) {
if (osMutexAcquire(env->gsmAt.access, 2000) == osOK) {
SocketSocketGsm_UrcProcessor_SRING(&env->socketGsm, buff);
osMutexRelease(env->gsmAt.access);
}
return;
}
if (AtBufferBeginWithStatic(buff, "NO CARRIER")) {
if (osMutexAcquire(env->gsmAt.access, 2000) == osOK) {
SocketSocketGsm_UrcProcessor_NO_CARRIER(&env->socketGsm, buff);
osMutexRelease(env->gsmAt.access);
}
return;
}
if (AtBufferBeginWithStatic(buff, "#ECALLEV:2,0")) {
env->urc.msdSuccess = true;
} else if (AtBufferBeginWithStatic(buff, "RING")) {
env->urc.ring = true;
} else if (AtBufferBeginWithStatic(buff, "#ECALLEV:0")) {
env->urc.msdPull = true;
} else if (AtBufferBeginWithStatic(buff, "$GPRMC,")) {
if (*env->enableGnssUpdate == true) {
EraGlonassUveosNavData location;
AtGsm_Gsnss_NavData_Processing(env);
if (env->gnss.currentRmc.time.second != 0) {
if (isRtc == false) {
isRtc = true;
RtcSet(env->Rtc, (time_t *) &time);
}
}
AtGsm_Gsnss_GetLastActualNavData(env, &location, 1);
}
}
}
uint32_t GsmWithGnss_InvalidateGnssUserExternalAntenna(tGsmWithGnss *env, uint32_t currentState, uint32_t targetState) {
AtGsmTelitLe910_Gnss_ExternalLnaSupport(
&env->gsmAt,
targetState ? TELIT_LE910_EXTERNAL_LNA_NOT_SUPPORT
: TELIT_LE910_EXTERNAL_LNA_SUPPORT
);
return targetState;
}
bool GsmWithGnss_InvalidateNetworkEnable(tGsmWithGnss *env, uint32_t currentState, bool targetState) {
if (targetState) {
LoggerInfoStatic(LOGGER, LOG_SIGN, "Включаем регистрацию в сети")
AtGsm_OperatorSelectionAutomatic(&env->gsmAt);
return true;
} else {
LoggerInfoStatic(LOGGER, LOG_SIGN, "Отключаем регистрацию в сети")
AtGsm_OperatorSelectionDeregister(&env->gsmAt);
return false;
}
}
void GsmWithGnssInit(
tGsmWithGnss *env,
tSerialPortIO *gsmIo,
tString32 *smsCenter,
uint16_t *gnssDataRateHz,
tRtcIO *Rtc,
bool *enableGnssUpdate,
bool isBusy
) {
AtCmdInit(
&env->gsmAt, gsmIo,
env->mem.gsmTx, sizeof(env->mem.gsmTx),
env->mem.gsmRx, sizeof(env->mem.gsmRx),
2000, 2000
);
env->isBusy = isBusy;
env->enableGnssUpdate = enableGnssUpdate;
env->smsCenter = smsCenter;
env->gnss.dataRateHz = gnssDataRateHz;
env->Rtc = Rtc;
env->navDataProvider.env = env;
env->navDataProvider.getNavData = (void *) GnssGetNavData;
env->navDataProvider.getTime = (void *) GnssTaskGetTime;
env->ecallProvider = (tEraGlonassEcallProvider) {
.env = env,
.settingNewMsd = (setNewMsd) GsmWithGnss_SetNewMSD,
.ecall =(sendEcallCall) GsmWithGnss_Ecall,
.isDialing =(eraGlonassEcallProviderCall) GsmWithGnss_isCallDialing,
.isMsdSent =(eraGlonassEcallProviderCall) GsmWithGnss_isMsdSent,
.isMsdReSent =(eraGlonassEcallProviderCall) GsmWithGnss_isMsdReSent,
.isActive =(eraGlonassEcallProviderCall) GsmWithGnss_isOutCallActive,
.hangup =(eraGlonassEcallProviderCall) GsmWithGnss_HangUp,
.isNetworkState =(void *) GsmWithGnss_WaitNetworkRegistration,
.isNetworkReg =(void *) GsmWithGnss_InvalidateNetworkEnable
};
env->smsProvider.env = env;
env->smsProvider.sendDataPdu = (void *) GsmWithGnss_SendDataPduSms;
AtCmdSetUrcProcessor(&env->gsmAt, env, GsmWithGnss_Urc);
GsmWithGnss_ResetRing(env);
env->audioPlayer = AudioPlayerTelitLe910_GetInterface(&env->gsmAt);
env->audioRecorder = AudioRecordTelitLe910_GetInterface(&env->gsmAt);
ControllableSwitch_Init(&env->useInternalAntennaSwitch, env, GsmWithGnss_InvalidateGnssUserExternalAntenna);
ControllableSwitch_Init(&env->enableNetworkSwitch, env, GsmWithGnss_InvalidateNetworkEnable);
env->gnssRmcGga.rmcAccess = osMutexNew(NULL);
}
void GsmWithGnss_UseInternalAntenna(tGsmWithGnss *env, bool value) {
ControllableSwitch_Set(&env->useInternalAntennaSwitch, value);
}
void GsmWithGnss_SetNetworkRegistration(tGsmWithGnss *env, bool value) {
ControllableSwitch_Set(&env->enableNetworkSwitch, value);
}
bool GsmWithGnss_WaitNetworkRegistration(tGsmWithGnss *env, uint16_t timeReg) {
uint32_t timeEnd = SystemGetMs() + timeReg;
tAtGsm_NetworkRegistrationReportMode mode;
tAtGsm_NetworkRegistrationState state;
while (timeEnd > SystemGetMs()) {
if (AtGsm_NetworkRegistrationStatus(&env->gsmAt, &mode, &state)) {
if (
state == AT_NETWORK_REGISTRATION_STATE_REGISTERED_HOME ||
state == AT_NETWORK_REGISTRATION_STATE_REGISTERED_ROAMING
) {
return true;
}
}
SystemDelayMs(50);
}
return false;
}
void GsmWithGnss_SetNetworkRegistrationHard(tGsmWithGnss *env, bool value) {
ControllableSwitch_SetHard(&env->enableNetworkSwitch, value);
}
bool GsmWithGnssWaitStartup(tGsmWithGnss *env) {
return AtCmdWaitOk(&env->gsmAt, 1000, 35000) == AT_OK;
}
bool GsmWithGnss_IsGnssReady(tGsmWithGnss *env) {
return (env->gnss.currentRmc.status == 'A') &&
(env->gnss.currentRmc.location.longitude) &&
(env->gnss.currentRmc.location.latitude);
}
void GsmWithGnss_ResetRing(tGsmWithGnss *env) {
env->urc.ring = false;
}
bool GsmWithGnss_IsRing(tGsmWithGnss *env) {
AtCmdProcessUnresolvedLines(&env->gsmAt);
return env->urc.ring;
}
void Gsm_WaitGsmBoot(tGsmWithGnss *env) {
struct tm tmtime;
SystemDelayMs(6000);
AtGsm_GetTime(&env->gsmAt, &tmtime);
//RtcSetTM(env->Rtc, &tmtime);
uint32_t time = SystemGetMs() + 20000;
while (time > SystemGetMs()) {
if (GsmWithGnssInitGnss(env) == AT_OK) {
break;
}
}
GsmWithGnss_InitAudio(env);
}
AtCommandResult GsmWithGnss_NetworkReconnect(tAtCmd *env, uint8_t cuontReg) {
AtCommandResult res = AT_ERROR;
for (uint8_t i = 0; i < cuontReg; i++) {
res = AtGsm_OperatorSelectionAutomatic(env);
SystemDelayMs(200);
}
return res;
}
AtCommandResult GsmWithGnss_NetworkEnableInnaterups(tGsmWithGnss *env, uint8_t cuontReg, uint16_t timeOut) {
if (GsmWithGnss_NetworkReconnect(&env->gsmAt, cuontReg) == AT_OK) {
LoggerInfoStatic(LOGGER, LOG_SIGN, "Ждем сеть...");
if (GsmWithGnss_WaitNetworkRegistration(env, timeOut) == true) {
LoggerTraceStatic(LOGGER, LOG_SIGN, "Сеть найдена")
return AT_OK;
} else {
LoggerTraceStatic(LOGGER, LOG_SIGN, "Попытка регистрации в сети НЕ выполнена")
return AT_ERROR;
}
}
return AT_ERROR;
}