This commit is contained in:
cfif 2024-12-04 13:10:47 +03:00
commit b083744d7f
9 changed files with 870 additions and 0 deletions

13
GsmSocketTimeouts.h Normal file
View File

@ -0,0 +1,13 @@
//
// Created by cfif on 19.07.2024.
//
#ifndef SMART_COMPONENTS_TELEMATICA_GSMSOCKETTIMEOUTS_H
#define SMART_COMPONENTS_TELEMATICA_GSMSOCKETTIMEOUTS_H
#define defaultSocketTimeout 2000
#define defaultSocketOpenTimeout 4000
#define defaultSocketTransmiteTimeout 4000
#endif //SMART_COMPONENTS_TELEMATICA_GSMSOCKETTIMEOUTS_H

238
GsmWithGnss.c Normal file
View File

@ -0,0 +1,238 @@
//
// 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;
}
}
const char LOG_TASK_GSM_SOCKET[] = "GSM SOCKET";
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);
tString32 AdrServer;
AdrServer.length = 0;
SocketSocketGsm_Init(&env->socketGsm, &env->gsmAt, &AdrServer, 12345, &env->gsmAt.access);
env->socketGsm.logger = env->logger;
env->socketGsm.loggerTaskName = (char *) LOG_TASK_GSM_SOCKET;
}
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;
}

163
GsmWithGnss.h Normal file
View File

@ -0,0 +1,163 @@
//
// Created by xemon on 02.09.22.
//
#ifndef GNSSTELITLE910_GNSSTELITLE910_H
#define GNSSTELITLE910_GNSSTELITLE910_H
#include "NmeaACPParser.h"
#include "SerialPortIO.h"
#include "AtGsmTelitLe910.h"
#include "EraGlonassUveos.h"
#include "LoggerInterface.h"
#include "BaseTypes.h"
#include <AudioPlayerInterface.h>
#include <AudioRecorderInterface.h>
#include "ControllableSwitch.h"
#include "RtcIO.h"
#include "Nmea0183Parser.h"
#include "LoggerToSerialPort.h"
#include "SocketInterface.h"
#include "GsmSocketTimeouts.h"
#include "Gsm_SockInt.h"
#include "CmsisRtosThreadUtils.h"
typedef struct {
tAtCmd gsmAt;
tNavDataProvider navDataProvider;
tEraGlonassEcallProvider ecallProvider;
tEraGlonassSmsProvider smsProvider;
tLoggerInterface *logger;
tString32 *smsCenter;
tRtcIO *Rtc;
tAudioPlayerInterface audioPlayer;
tAudioRecorderInterface audioRecorder;
tControllableSwitch useInternalAntennaSwitch;
tControllableSwitch enableNetworkSwitch;
bool *enableGnssUpdate;
struct {
bool msdSuccess;
bool msdPull;
bool ring;
} urc;
struct {
uint32_t next;
uint16_t *dataRateHz;
bool success;
tNmeaRmc currentRmc;
tNmeaRmc prevRmc;
tNmeaAcp currentAcp;
} gnss;
struct {
uint8_t gsmRx[512];
uint8_t gsmTx[512];
} mem;
bool isBusy;
tLoggerToSerialPort *slog;
struct {
osMutexId_t rmcAccess;
// tNmeaGga currentGgaRmc;
tNmeaRmc currentRmc;
} gnssRmcGga;
// uint8_t bufLog[2048];
// char bufLogHexString[260];
tSocketGsm socketGsm;
tGsmSocketSlot slots[2];
bool isNav;
bool isDisconnect;
uint8_t codeResultOpen;
} tGsmWithGnss;
//Common
void GsmWithGnssInit(
tGsmWithGnss *env,
tSerialPortIO *gsmIo,
tString32 *smsCenter,
uint16_t *gnssDataRateHz,
tRtcIO *Rtc,
bool *enableGnssUpdate,
bool isBusy
);
bool GsmWithGnss_GetBusyState(tGsmWithGnss *env);
bool GsmWithGnssWaitStartup(tGsmWithGnss *env);
bool GsmWithGnss_InvalidateNetworkEnable(tGsmWithGnss *env, uint32_t currentState, bool targetState);
void GsmWithGnss_SetNetworkRegistration(tGsmWithGnss *env, bool value);
bool GsmWithGnss_WaitNetworkRegistration(tGsmWithGnss *env, uint16_t timeReg);
void GsmWithGnss_UseInternalAntenna(tGsmWithGnss *env, bool value);
//Gnss ops
AtCommandResult GsmWithGnssInitGnss(tGsmWithGnss *env);
void GsmWithGnss_GetNevData(tGsmWithGnss *env, uint32_t timeout);
void AtGsm_Gsnss_GetNMEA_Pack(tGsmWithGnss *env, uint32_t timeout);
void AtGsm_Gsnss_NavData_Processing(tGsmWithGnss *env);
AtCommandResult GsmWithGnss_GetCCID(tAtCmd *env, char *ccidString, size_t *acpStringLen);
AtCommandResult GsmWithGnss_GetCGSN(tAtCmd *env, char *acpString, size_t *acpStringLen);
AtCommandResult GsmWithGnss_StopRMCThread(tAtCmd *env);
AtCommandResult GsmWithGnss_StartRMCThread(tAtCmd *env);
AtCommandResult GsmWithGnss_SelectStandartNetwork(tAtCmd *env, uint8_t standatr);
AtCommandResult GsmWithGnss_ActivateRMCPort(tAtCmd *env);
void GsmWithGnssHoldStart(tGsmWithGnss *env, uint32_t timeOut);
bool GsmWithGnss_IsGnssReady(tGsmWithGnss *env);
//Audio ops
void GsmWithGnss_InitAudio(tGsmWithGnss *env);
//Ring ops
bool GsmWithGnss_IsRing(tGsmWithGnss *env);
//Ring reset
void GsmWithGnss_ResetRing(tGsmWithGnss *env);
bool GsmWithGnss_isOutCallActive(tGsmWithGnss *env);
bool GsmWithGnss_isInpCallActive(tGsmWithGnss *env);
void Gsm_WaitGsmBoot(tGsmWithGnss *env);
void AtGsm_Gsnss_NavData_Incorrect(tGsmWithGnss *env);
void AtGsm_Gsnss_GetLastActualNavData(tGsmWithGnss *env, EraGlonassUveosNavData *location, bool locSourse);
AtCommandResult GsmWithGnss_NetworkReconnect(tAtCmd *env, uint8_t cuontReg);
AtCommandResult GsmWithGnss_NetworkEnableInnaterups(tGsmWithGnss *env, uint8_t cuontReg, uint16_t timeOut);
void Gnss_GetFullNavData(tGsmWithGnss *env, tNmeaRmc *nmeaRmc);
#endif //GNSSTELITLE910_GNSSTELITLE910_H

View File

@ -0,0 +1,15 @@
//
// Created by xemon on 21.10.22.
//
#include "GsmWithGnss_Private.h"
void GsmWithGnss_InitAudio(tGsmWithGnss *env) {
AtGsmSetErrorLogLevel(&env->gsmAt, GSM_LOG_ERROR_VERBOSE);
AtGsmTelitLe910_SetSpeakerVolumeLevel(&env->gsmAt, 1000);
AtGsmTelitLe910_DviEnableMaster(&env->gsmAt);
AtGsmTelitLe910_DviToPcmMode(&env->gsmAt);
// at#adspc=0,0
// AtGsmTelitLe910_DviPcmClk(&env->gsmAt, AT_GSM_TELIT_910_DVI_CLOCK_1024_KHz, AT_GSM_TELIT_910_DVI_SAMPLE_RATE_16KHz);
AtGsmTelitLe910_DviPcmClk(&env->gsmAt, AT_GSM_TELIT_910_DVI_CLOCK_1024_KHz, AT_GSM_TELIT_910_DVI_SAMPLE_RATE_8KHz);
}

144
GsmWithGnss_Ecall.c Normal file
View File

@ -0,0 +1,144 @@
//
// 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;
}

198
GsmWithGnss_GnssOps.c Normal file
View File

@ -0,0 +1,198 @@
//
// Created by xemon on 02.09.22.
//
//#include <Log.h>
#include <memory.h>
#include "SerialPort.h"
#include "SystemDelayInterface.h"
#include "AsciiStringAssmeblingUtils.h"
#include "NmeaACPParser.h"
#include "GsmWithGnss.h"
#include "AtGsmTelitLe910.h"
#include "AtCmdCommonProtected.h"
#include "AtGsmSms_DeleteAll.h"
#include "Nmea0183Parser.h"
#include "Rtc.h"
#define LOGGER env->logger
#define LOG_SIGN "GSM&GNSSOPS"
time_t gnssTime;
bool fl_rtcIsUsed = false;
#define GWG_IER(FUNC) {A}
AtCommandResult GsmWithGnssInitGnss(tGsmWithGnss *env) {
AT_INOKR(AtGsmTelitLe910_GnssSwitchOnRestoreParam(&env->gsmAt))
SystemDelayMs(200);
AT_INOKR(AtGsmTelitLe910_Gnss_ClearNvramGnssBuf(&env->gsmAt));
SystemDelayMs(200);
AT_INOKR(AtGsmTelitLe910_Gnss_ClearStaticBufFix(&env->gsmAt));
SystemDelayMs(200);
// AT_INOKR(AtGsmTelitLe910_Gnss_AGPSup(&env->gsmAt,2));
// SystemDelayMs(1000);
AT_INOKR(AtGsmTelitLe910_Gnss_ReStartReceiver(&env->gsmAt, 1));
SystemDelayMs(200);
AT_INOKR(AtGsmTelitLe910_SIMCardDetect(&env->gsmAt));
SystemDelayMs(200);
// AT_INOKR(AtGsmTelitLe910_GnssEcallOnlyMode(&env->gsmAt,0));
// SystemDelayMs(200);
AT_INOKR(AtGsmSms_DeleteAll(&env->gsmAt));
SystemDelayMs(200);
GsmWithGnss_ActivateRMCPort(&env->gsmAt);
SystemDelayMs(200);
AT_INOKR(GsmWithGnss_SelectStandartNetwork(&env->gsmAt, 25));
SystemDelayMs(200);
return AT_OK;
}
void AtGsm_Gsnss_NavData_Incorrect(tGsmWithGnss *env) {
env->gnss.currentRmc.status = 'V';
}
void AtGsm_Gsnss_NavData_Processing(tGsmWithGnss *env) {
// Поиск строки RMC
// char Data[] = "$GPRMC,122118.00,A,5500.000013,N,03700.002305,E,0.0,0.0,180119,8.5,E,A,V*49";
// bNmea0183ParseRMC(Data + 7, sizeof(Data)- 7, &env->gnss.currentRmc);
// env->gnss.success = true;
if (bNmea0183IsRmcString(env->gsmAt.rxBuffer.data, env->gsmAt.rxBuffer.len)) {
if (bNmea0183IsValidString(env->gsmAt.rxBuffer.data, env->gsmAt.rxBuffer.len)) {
bNmea0183ParseRMC(env->gsmAt.rxBuffer.data + 7, env->gsmAt.rxBuffer.len - 7, &env->gnss.currentRmc);
bNmea0183ParseRMC(env->gsmAt.rxBuffer.data + 7, env->gsmAt.rxBuffer.len - 7, &env->gnssRmcGga.currentRmc);
env->gnss.success = true;
}
}
}
void Gnss_GetFullNavData(tGsmWithGnss *env, tNmeaRmc *nmeaRmc) {
if (osMutexAcquire(env->gnssRmcGga.rmcAccess, 2000) == osOK) {
memcpy(nmeaRmc, &env->gnssRmcGga.currentRmc, sizeof(tNmeaRmc));
osMutexRelease(env->gnssRmcGga.rmcAccess);
} else {
LoggerInfoStatic(LOGGER, LOG_SIGN, "Ошибка захвата доступа Gnss_GetFullNavData")
}
}
void GsmWithGnss_GetNevData(tGsmWithGnss *env, uint32_t timeout) {
GsmWithGnss_StartRMCThread(&env->gsmAt);
uint32_t endTimeout = SystemGetMs() + timeout;
env->gnss.currentRmc.time.second = 0;
while (endTimeout > SystemGetMs()) {
AtCmdProcessUnresolvedLines(&env->gsmAt);
if(env->gnss.currentRmc.time.second != 0){
GsmWithGnss_StopRMCThread(&env->gsmAt);
return;
}
SystemDelayMs(2);
}
GsmWithGnss_StopRMCThread(&env->gsmAt);
}
void AtGsm_Gsnss_GetNMEA_Pack(tGsmWithGnss *env, uint32_t timeout) {
env->gnss.currentAcp.status = 0;
char acpString[256];
size_t aspStringLen;
xAtGsmTelitLe910_Gnss_GetAcquiredPositionNMEA(&env->gsmAt, acpString, &aspStringLen, timeout);
if (bNmeaACPString(acpString, aspStringLen, &env->gnss.currentAcp)) {
if (bNmeaACPParse(acpString, aspStringLen, &env->gnss.currentAcp) && aspStringLen > 24) {
env->gnss.success = true;
}
}
}
char convertDecToMilliArcSec(double dec, int32_t *mArcs, double *gradus) {
int deg = 0, min = 0;
double sec = 0.0;
double _dec = dec;
deg = (int) (_dec / 100);
min = (int) (_dec) - (deg * 100);
sec = (double) (_dec - min - 100 * deg) * 60.0;
if (gradus != NULL) *gradus = deg + min / 60.0 + sec / 3600.0;
if (mArcs != NULL) *mArcs = (int) (deg * 3600 + min * 60) * 1000 + (int) (sec * 1000);
return 0;
}
void NmeaRMCLocationToLocationACP(tNmeaLocationAcp *nmea, EraGlonassUveosNavData *gnss) {
convertDecToMilliArcSec(nmea->latitude, &gnss->latitude, NULL);
convertDecToMilliArcSec(nmea->longitude, &gnss->longitude, NULL);
}
void NmeaRMCLocationToLocationRMC(tNmeaLocationRmc *nmea, EraGlonassUveosNavData *gnss) {
convertDecToMilliArcSec(nmea->latitude, &gnss->latitude, NULL);
convertDecToMilliArcSec(nmea->longitude, &gnss->longitude, NULL);
}
void GnssTaskGetTime(tGsmWithGnss *env, uint32_t *timestamp) {
*timestamp = iNmea0183TimestampFromRmc(&env->gnss.currentRmc);
}
void GnssSetRTC(tGsmWithGnss *env) {
if (env->gnss.currentRmc.time.second != 0) {
if (!fl_rtcIsUsed) {
GnssTaskGetTime(env, (uint32_t *) &gnssTime);
RtcSet(env->Rtc, &gnssTime);
fl_rtcIsUsed = true;
}
}
}
void AtGsm_Gsnss_GetLastActualNavData(tGsmWithGnss *env, EraGlonassUveosNavData *location, bool locSourse) {
if(locSourse == 1) {
if (env->gnss.currentRmc.status == 'A') {
env->gnss.prevRmc = env->gnss.currentRmc;
location->valid = 2;
} else {
if (env->gnss.prevRmc.status == 'A') {
env->gnss.currentRmc = env->gnss.prevRmc;
env->gnss.currentRmc.status = 'V';
location->valid = 1;
} else if (env->gnss.prevRmc.location.latitude < 1) {
env->gnss.currentRmc.status = 'V';
location->valid = 0;
}
}
} else {
if (env->gnss.currentAcp.status == 'A') {
location->valid = 1;
} else {
location->valid = 0;
}
}
}
void GnssGetNavData(tGsmWithGnss *env, EraGlonassUveosNavData *location, bool locSourse) {
GnssSetRTC(env);
AtGsm_Gsnss_GetLastActualNavData(env, location, locSourse);
if(locSourse == 1) {
NmeaRMCLocationToLocationRMC(&env->gnss.currentRmc.location, location);
location->direction = (uint16_t) env->gnss.currentRmc.headingAngle;
} else {
NmeaRMCLocationToLocationACP(&env->gnss.currentAcp.location, location);
location->direction = (uint16_t) env->gnss.currentAcp.course;
}
}

50
GsmWithGnss_Private.h Normal file
View File

@ -0,0 +1,50 @@
//
// Created by xemon on 11.12.22.
//
#ifndef UVEOS_ON_NATION_GSMWITHGNSS_PRIVATE_H
#define UVEOS_ON_NATION_GSMWITHGNSS_PRIVATE_H
#include "GsmWithGnss.h"
//Gnss ops
void GnssGetNavData(tGsmWithGnss *env, EraGlonassUveosNavData *location, bool locSourse);
void GnssTaskGetTime(tGsmWithGnss *env, uint32_t *timestamp);
//ecall
bool GsmWithGnss_Ecall(tGsmWithGnss *env,
uint8_t *msd,
size_t msdLength,
char *phoneNumber,
size_t phoneNumberLength,
eEcallActivationType activationType,
eEcallTestMode testMode,
bool blocRegNetwork
);
bool GsmWithGnss_SetNewMSD(tGsmWithGnss *env,
uint8_t *msd,
size_t msdLength
);
bool GsmWithGnss_isCallDialing(tGsmWithGnss *env);
bool GsmWithGnss_isMsdSent(tGsmWithGnss *env);
bool GsmWithGnss_isMsdReSent(tGsmWithGnss *env);
bool GsmWithGnss_HangUp(tGsmWithGnss *env);
//sms
bool GsmWithGnss_SendDataPduSms(tGsmWithGnss *env, char *phone, uint8_t phoneSize, uint8_t *data, uint16_t dataSize);
//ring
#endif //UVEOS_ON_NATION_GSMWITHGNSS_PRIVATE_H

17
GsmWithGnss_Sms.c Normal file
View File

@ -0,0 +1,17 @@
//
// Created by xemon on 28.11.22.
//
#include "GsmWithGnss_Private.h"
#include "AtGsmSms_Utils.h"
bool GsmWithGnss_SendDataPduSms(tGsmWithGnss *env, char *phone, uint8_t phoneSize, uint8_t *data, uint16_t dataSize) {
return AtGsmSms_UtilsSendPduData(
&env->gsmAt,
env->smsCenter->data, env->smsCenter->length,
phone, phoneSize,
data, dataSize
) == AT_OK;
}

32
modular.json Normal file
View File

@ -0,0 +1,32 @@
{
"dep": [
{
"type": "git",
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
"repo": "SystemDelayInterface"
},
{
"type": "git",
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
"repo": "AtGsmTelitLe910"
},
{
"type": "git",
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
"repo": "AtGsmSms_Utils"
},
{
"type": "git",
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
"repo": "ControllableSwitch"
}
],
"cmake": {
"inc_dirs": [
"./"
],
"srcs": [
"*.c"
]
}
}