383 lines
10 KiB
C
383 lines
10 KiB
C
//
|
|
// Created by xemon on 06.09.22.
|
|
//
|
|
|
|
#include "AtGsmTelitLe910.h"
|
|
#include "AtCmdCommonProtected.h"
|
|
#include "SystemDelayInterface.h"
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
|
|
AtCommandResult AtGsmTelitLe910_Gnss_ClearRxGnssBuf(tAtCmd *env) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "AT$GPSCLRX\r\n");
|
|
return AtCmdOkErrAnswer(env, 2000 * env->stdRxTimeout);
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_GnssSwitchOnRestoreParam(tAtCmd *env) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "AT$GPSRST\r\n");
|
|
return AtCmdOkErrAnswer(env, 2000 * env->stdRxTimeout);
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_GnssEcallOnlyMode(tAtCmd *env, bool mode) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
if(mode){
|
|
AtCmdSendStatic(env, "AT#ECONLY=1\r\n");
|
|
} else{
|
|
AtCmdSendStatic(env, "AT#ECONLY=0\r\n");
|
|
}
|
|
return AtCmdOkErrAnswer(env, 2000 * env->stdRxTimeout);
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_Gnss_ClearNvramGnssBuf(tAtCmd *env) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "AT$GPSNVRAM=15,0\r\n");
|
|
return AtCmdOkErrAnswer(env, 2000 * env->stdRxTimeout);
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_Gnss_ClearStaticBufFix(tAtCmd *env) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "AT$GPSACP\r\n");
|
|
return AtCmdOkErrAnswer(env, 2000 * env->stdRxTimeout);
|
|
}
|
|
|
|
AtCommandResult xAtGsmTelitLe910_Gnss_xClearBuf(tAtCmd *env, char value, uint8_t paramLen) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdTxAddStatic(env, "AT$GPSNVRAM=");
|
|
AtCmdTxAdd(env, &value, paramLen);
|
|
|
|
AtCmdTxSendLn(env);
|
|
return AtCmdOkErrAnswer(env, 5000 * env->stdRxTimeout);
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_Gnss_ReStartReceiver(tAtCmd *env, bool value) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdTxAddStatic(env, "AT$GPSP=");
|
|
AtCmdTxAddChar(env, value ? '1' : '0');
|
|
AtCmdTxSendLn(env);
|
|
|
|
return AtCmdOkErrAnswer(env, 5 * env->stdRxTimeout);
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_Gnss_AGPSup(tAtCmd *env, bool value) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdTxAddStatic(env, "AT$AGPSEN=0");
|
|
return AtCmdOkErrAnswer(env, 2000 * env->stdRxTimeout);
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_Gnss_ExternalLnaSupport(tAtCmd *env, eTelitLe910_ExternalLnaSupportMode value) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdTxAddStatic(env, "AT$GPSELNA=");
|
|
AtCmdTxAddChar(env, value);
|
|
AtCmdTxSendLn(env);
|
|
|
|
return AtCmdOkErrAnswer(env, 2 * env->stdRxTimeout);
|
|
}
|
|
|
|
AtCommandResult
|
|
xAtGsmTelitLe910_Gnss_GetAcquiredPositionRMC(tAtCmd *env, char *acpString, size_t *acpStringLen, uint32_t timeout) {
|
|
|
|
}
|
|
|
|
AtCommandResult
|
|
xAtGsmTelitLe910_Gnss_GetAcquiredPositionNMEA(tAtCmd *env, char *acpString, size_t *acpStringLen, uint32_t timeout) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "AT$GPSACP\r\n");
|
|
|
|
*acpStringLen = 0;
|
|
bool hasValue = false;
|
|
|
|
while (AtCmdReceiveNextLine(env, timeout) == AT_OK) {
|
|
|
|
if (AtCmdRxBeginWithStatic(env, "ERROR")) {
|
|
return AT_ERROR;
|
|
}
|
|
|
|
if (AtCmdRxBeginWithStatic(env, "OK")) {
|
|
return hasValue ? AT_OK : AT_ERROR;
|
|
}
|
|
|
|
if (AtCmdRxBeginWithStatic(env, "$GPSACP:")) {
|
|
*acpStringLen = env->rxBuffer.len;
|
|
memcpy(acpString, env->rxBuffer.data, *acpStringLen);
|
|
hasValue = true;
|
|
}
|
|
}
|
|
return AT_TIMEOUT;
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_Gnss_GetExternalLnaSupport(tAtCmd *env, eTelitLe910_ExternalLnaSupportMode *value) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "AT$GPSELNA?\r\n");
|
|
|
|
static const uint32_t timeout = 1000;
|
|
uint32_t endTimeout = SystemGetMs() + timeout;
|
|
bool hasValue = false;
|
|
|
|
while (AtCmdReceiveNextLine(env, endTimeout - SystemGetMs()) == AT_OK) {
|
|
|
|
if (AtCmdRxBeginWithStatic(env, "ERROR")) {
|
|
return AT_ERROR;
|
|
}
|
|
|
|
if (AtCmdRxBeginWithStatic(env, "OK")) {
|
|
return hasValue ? AT_OK : AT_ERROR;
|
|
}
|
|
|
|
if (AtCmdRxBeginWithStatic(env, "$GPSELNA: ")) {
|
|
*value = env->rxBuffer.data[sizeof("$GPSELNA: ") - 1];
|
|
hasValue = true;
|
|
}
|
|
|
|
AtCmdProcessUnresolvedLine(env);
|
|
|
|
}
|
|
return AT_TIMEOUT;
|
|
}
|
|
|
|
//deprecated
|
|
//#define GsmWithGnss_ActivateRMCPort AtGsmTelitLe910_Gnss_ActivateRMCPort
|
|
|
|
AtCommandResult AtGsmTelitLe910_Gnss_ActivateRMCPort(tAtCmd *env) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "AT&K0\r\n");
|
|
|
|
while (AtCmdReceiveNextLine(env, 500) == AT_OK) {
|
|
if (AtCmdWaitOk(env, 100, 500) == AT_OK) {
|
|
return AT_OK;
|
|
} else {
|
|
return AT_ERROR;
|
|
}
|
|
}
|
|
return AT_TIMEOUT;
|
|
}
|
|
|
|
AtCommandResult GsmWithGnss_ActivateRMCPort(tAtCmd *env) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "AT&K0\r\n");
|
|
|
|
while (AtCmdReceiveNextLine(env, 500) == AT_OK) {
|
|
if (AtCmdWaitOk(env, 100, 500) == AT_OK) {
|
|
return AT_OK;
|
|
} else {
|
|
return AT_ERROR;
|
|
}
|
|
}
|
|
return AT_TIMEOUT;
|
|
}
|
|
|
|
AtCommandResult GsmWithGnss_SelectStandartNetwork(tAtCmd *env, uint8_t standatr) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdTxAddStatic(env, "AT+WS46=");
|
|
AtCmdTxAddDecimalIntWithLimit(env, standatr, 3);
|
|
AtCmdTxSendLn(env);
|
|
|
|
return AtCmdOkErrAnswer(env, env->stdRxTimeout);
|
|
}
|
|
|
|
AtCommandResult GsmWithGnss_StartRMCThread2(tAtCmd *env) {
|
|
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "AT$GPSNMUN=1,0,0,0,0,1,0\r\n");
|
|
|
|
uint32_t timeout = 10000;
|
|
uint32_t endMs = SystemGetMs() + timeout;
|
|
uint32_t leftMs = timeout;
|
|
|
|
while ((AtCmdReceiveNextLine(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) {
|
|
leftMs = endMs - SystemGetMs();
|
|
|
|
if (AtCmdRxBeginWithStatic(env, "CONNECT")) {
|
|
AtCmdRxClear(env);
|
|
return AT_OK;
|
|
|
|
} else if (AtCmdRxBeginWithStatic(env, "NO CARRIER")) {
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
} else {
|
|
AtCmdProcessUnresolvedLine(env);
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
}
|
|
}
|
|
|
|
return AT_TIMEOUT;
|
|
}
|
|
|
|
AtCommandResult GsmWithGnss_StartRMCThread(tAtCmd *env) {
|
|
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "AT$GPSNMUN=3,0,0,0,0,1,0\r\n");
|
|
|
|
static const uint32_t timeout = 1000;
|
|
uint32_t endTimeout = SystemGetMs() + timeout;
|
|
AtCommandResult res;
|
|
while (AtCmdReceiveNextLine(env, endTimeout - SystemGetMs()) == AT_OK) {
|
|
if (AtCmdRxBeginWithStatic(env, "CONNECT")) {
|
|
res = AT_OK;
|
|
}
|
|
}
|
|
|
|
if (res != AT_OK) {
|
|
res = AT_TIMEOUT;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
AtCommandResult GsmWithGnss_StopRMCThread(tAtCmd *env) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "+++");
|
|
|
|
static const uint32_t timeout = 2000;
|
|
uint32_t endTimeout = SystemGetMs() + timeout;
|
|
AtCommandResult res;
|
|
while (AtCmdReceiveNextLine(env, endTimeout - SystemGetMs()) == AT_OK) {
|
|
if (AtCmdRxBeginWithStatic(env, "NO CARRIER")) {
|
|
res = AT_OK;
|
|
}
|
|
}
|
|
if (res != AT_OK) {
|
|
res = AT_TIMEOUT;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
AtCommandResult GsmWithGnss_GetCGSN(tAtCmd *env, char *acpString, size_t *acpStringLen) {
|
|
if (osMutexAcquire(env->access, 5000) == osOK) {
|
|
AtCmdPrepare(env);
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "AT#CGSN\r\n");
|
|
|
|
SystemDelayMs(2000);
|
|
while (AtCmdReceiveNextLine(env, 15000) == AT_OK) {
|
|
if (AtCmdRxBeginWithStatic(env, "#CGSN: ")) {
|
|
static const uint16_t prefixSize = sizeof("#CGSN: ") - 1;
|
|
*acpStringLen = env->rxBuffer.len - (prefixSize + 2);
|
|
memcpy(acpString, env->rxBuffer.data + prefixSize, *acpStringLen);
|
|
osMutexRelease(env->access);
|
|
return AT_OK;
|
|
}
|
|
if (AtCmdRxBeginWithStatic(env, "ERROR")) {
|
|
osMutexRelease(env->access);
|
|
return AT_ERROR;
|
|
}
|
|
}
|
|
osMutexRelease(env->access);
|
|
}
|
|
return AT_TIMEOUT;
|
|
}
|
|
|
|
AtCommandResult GsmWithGnss_GetCCID(tAtCmd *env, char *acpStr, size_t *acpStrLen) {
|
|
if (osMutexAcquire(env->access, 5000) == osOK) {
|
|
AtCmdPrepare(env);
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "AT#CCID\r\n");
|
|
|
|
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;
|
|
}
|
|
|
|
if (AtCmdRxBeginWithStatic(env, "ERROR")) {
|
|
osMutexRelease(env->access);
|
|
return AT_ERROR;
|
|
}
|
|
}
|
|
osMutexRelease(env->access);
|
|
}
|
|
return AT_TIMEOUT;
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_Gsm_RSSI(tAtCmd *env, char *rsi, uint8_t *len) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "AT+CSQ\r\n");
|
|
|
|
static const uint32_t timeout = 500;
|
|
uint32_t endTimeout = SystemGetMs() + timeout;
|
|
bool hasValue = false;
|
|
|
|
while (AtCmdReceiveNextLine(env, endTimeout - SystemGetMs()) == AT_OK) {
|
|
if (AtCmdRxBeginWithStatic(env, "ERROR")) {
|
|
return AT_ERROR;
|
|
}
|
|
|
|
if (AtCmdRxBeginWithStatic(env, "OK")) {
|
|
return hasValue ? AT_OK : AT_ERROR;
|
|
}
|
|
|
|
if (AtCmdRxBeginWithStatic(env, "+CSQ: ")) {
|
|
static const uint16_t prefixSize = sizeof("+CSQ: ") - 1;
|
|
*rsi = env->rxBuffer.data[sizeof("+CSQ: ") - 1];
|
|
*len = env->rxBuffer.len;
|
|
hasValue = true;
|
|
}
|
|
|
|
AtCmdProcessUnresolvedLine(env);
|
|
}
|
|
|
|
return AT_TIMEOUT;
|
|
}
|
|
|
|
AtCommandResult GsmWithGnss_setCodecConf(tAtCmd *env, tString32 codecConf) {
|
|
|
|
AtCmdPrepare(env);
|
|
AtCmdTxClear(env);
|
|
AtCmdSendStatic(env, "AT#I2CWR=2,3,20,2,15\r\n");
|
|
SystemDelayMs(500);
|
|
AtCmdSend(env, codecConf.data, codecConf.length);
|
|
SystemDelayMs(500);
|
|
AtCmdSendStatic(env, "\x1A");
|
|
return AT_OK;
|
|
|
|
// AtCmdPrepare(env);
|
|
//
|
|
// AtCmdTxClear(env);
|
|
// AtCmdSendStatic(env, "AT#I2CWR=2,3,20,2,15\r\n");
|
|
// SystemDelayMs(500);
|
|
// AtCmdSendStatic(env, "00109000040033060f20320000008a");
|
|
// SystemDelayMs(500);
|
|
// AtCmdSendStatic(env, "\x1A");
|
|
// return AT_OK;
|
|
|
|
} |