229 lines
6.6 KiB
C
229 lines
6.6 KiB
C
//
|
|
// Created by xemon on 24.10.22.
|
|
//
|
|
|
|
#include <AsciiStringAssmeblingUtils.h>
|
|
#include <AtCmdCommonProtected.h>
|
|
#include <string.h>
|
|
#include <SystemDelayInterface.h>
|
|
#include "AtGsmTelitLe910_Ecall.h"
|
|
|
|
|
|
|
|
AtCommandResult AtGsmTelitLe910_EcallSetUrc(tAtCmd *env, eGsmTelitEcallUrcLevel mode) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdTxAddStatic(env, "AT#ECALLURC=");
|
|
AtCmdTxAddChar(env, mode);
|
|
AtCmdTxSendLn(env);
|
|
|
|
return AtCmdOkErrAnswer(env, env->stdRxTimeout);
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_EcallSetTestNumber(tAtCmd *env, char *phoneNumber, size_t phoneNumberLength) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdTxAddStatic(env, "AT#TESTNUM=0,");
|
|
AtCmdTxAdd(env, phoneNumber, phoneNumberLength);
|
|
AtCmdTxSendLn(env);
|
|
|
|
return AtCmdOkErrAnswer(env, env->stdRxTimeout);
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_EcallSetModeBattle(tAtCmd *env) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdSendStatic(env, "AT#ECALL=1\r\n");
|
|
|
|
return AtCmdOkErrAnswer(env, env->stdRxTimeout);
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_SIMCardDetect(tAtCmd *env) {
|
|
AtCmdPrepare(env);
|
|
AtCmdRxClear(env);
|
|
AtCmdSendStatic(env, "AT#SIMDET=1\r\n");
|
|
uint32_t timeout = SystemGetMs() + 4000;
|
|
|
|
while ( (AtCmdReceiveNextLine(env, 500) == AT_OK) && (timeout > SystemGetMs()) ) {
|
|
if(AtCmdRxBeginWithStatic(env, "OK") == AT_OK){
|
|
AtCmdPrepare(env);
|
|
AtCmdRxClear(env);
|
|
SystemDelayMs(500);
|
|
AtCmdSendStatic(env, "AT#CIMI\r\n");
|
|
timeout = SystemGetMs() + 4000;
|
|
while ( (AtCmdReceiveNextLine(env, 500) == AT_OK) || (timeout > SystemGetMs()) ) {
|
|
if(AtCmdRxBeginWithStatic(env, "OK") == AT_OK){
|
|
SystemDelayMs(1000);
|
|
return AT_OK;
|
|
} else if(AtCmdRxBeginWithStatic(env, "+CME ERROR: SIM not inserted") == AT_OK){
|
|
AtCmdPrepare(env);
|
|
AtCmdRxClear(env);
|
|
SystemDelayMs(500);
|
|
AtCmdSendStatic(env, "AT#SIMDET=1\r\n");
|
|
AtCmdPrepare(env);
|
|
AtCmdRxClear(env);
|
|
SystemDelayMs(500);
|
|
AtCmdSendStatic(env, "AT#CIMI\r\n");
|
|
continue;
|
|
}
|
|
if(timeout < SystemGetMs()){
|
|
return AT_TIMEOUT;
|
|
}
|
|
}
|
|
if(timeout < SystemGetMs()){
|
|
return AT_TIMEOUT;
|
|
} else {
|
|
return AT_ERROR;
|
|
}
|
|
} else {
|
|
continue;
|
|
}
|
|
}
|
|
return AT_ERROR;
|
|
|
|
///===================================================
|
|
//
|
|
// AtCmdPrepare(env);
|
|
// AtCmdRxClear(env);
|
|
// AtCmdSendStatic(env, "AT#SIMDET=1\r\n");
|
|
//
|
|
// uint32_t timeout = SystemGetMs() + 4000;
|
|
//
|
|
// while ( (AtCmdReceiveNextLine(env, 500) == AT_OK) && (timeout > SystemGetMs()) ) {
|
|
// if (AtCmdRxBeginWithStatic(env, "")) {
|
|
// if (AtCmdRxBeginWithStatic(env, "OK")) {
|
|
// AtCmdPrepare(env);
|
|
// AtCmdRxClear(env);
|
|
// SystemDelayMs(500);
|
|
// AtCmdSendStatic(env, "AT#CIMI\r\n");
|
|
// timeout = SystemGetMs() + 4000;
|
|
//
|
|
// while ((AtCmdReceiveNextLine(env, 500) == AT_OK) && (timeout > SystemGetMs())) {
|
|
// if (AtCmdRxBeginWithStatic(env, "#CIMI: ")) {
|
|
// SystemDelayMs(1000);
|
|
// return AT_OK;
|
|
// } else if (AtCmdRxBeginWithStatic(env, "+CME ERROR: SIM not inserted")) {
|
|
// AtCmdPrepare(env);
|
|
// AtCmdRxClear(env);
|
|
// SystemDelayMs(500);
|
|
// AtCmdSendStatic(env, "AT#CIMI\r\n");
|
|
// continue;
|
|
// }
|
|
// }
|
|
// } else {
|
|
// AtCmdPrepare(env);
|
|
// AtCmdRxClear(env);
|
|
// SystemDelayMs(500);
|
|
// AtCmdSendStatic(env, "AT#SIMDET=1\r\n");
|
|
// continue;
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// return AT_ERROR;
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_SIMCardNoDetect(tAtCmd *env) {
|
|
AtCmdPrepare(env);
|
|
AtCmdRxClear(env);
|
|
AtCmdSendStatic(env, "AT#SIMDET=0\r\n");
|
|
AtCommandResult res = AtCmdOkErrAnswer(env, env->stdRxTimeout);
|
|
SystemDelayMs(500);
|
|
return res;
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_EcallWriteMsdToModem(tAtCmd *env, uint8_t *msd, size_t msdLength) {
|
|
|
|
//prepare msd data packet
|
|
char dataInModemFormat[281];
|
|
size_t dataInModemFormatLen = 0;
|
|
memset(dataInModemFormat, '0', 281);
|
|
vAsciiStringAddBytesAsHex(dataInModemFormat, &dataInModemFormatLen, msd, msdLength);
|
|
dataInModemFormat[280] = 0x1A;
|
|
|
|
//execute at
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdSendStatic(env, "AT#MSDSEND\r\n");
|
|
AtCmdWaitChar(env, 10000, '>');
|
|
|
|
AtCmdSend(env, (uint8_t *) dataInModemFormat, 281);
|
|
|
|
|
|
return AtCmdOkErrAnswer(env, env->stdRxTimeout);
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_EcallPushMsd(tAtCmd *env) {
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdSendStatic(env, "AT#MSDPUSH\r\n");
|
|
|
|
return AtCmdOkErrAnswer(env, 2 * env->stdRxTimeout);
|
|
}
|
|
|
|
|
|
AtCommandResult AtGsmTelitLe910_EcallMake(tAtCmd *env, eGsmEcallType value) {
|
|
|
|
AtCmdPrepare(env);
|
|
|
|
AtCmdTxClear(env);
|
|
AtCmdTxAddStatic(env, "AT+CECALL=");
|
|
AtCmdTxAddDecimalInt(env, value, 1);
|
|
AtCmdTxSendLn(env);
|
|
|
|
return AtCmdOkErrAnswer(env, 25 * env->stdRxTimeout);
|
|
|
|
}
|
|
|
|
|
|
//GsmCommandResult AtGsmTelitLe910_EcallMsdRead(tGsmAt *env) {
|
|
// vGsmClearRx(env);
|
|
// vSendAtStatic(env, "AT#MSDREAD\r");
|
|
// xGsmWaitAnswerLine(env, "#MSDREAD:", 20000);
|
|
// return xGsmOkErrAnswer(env, 1000);
|
|
//}
|
|
|
|
|
|
|
|
AtCommandResult AtGsmTelitLe910_SendEcall(
|
|
tAtCmd *env,
|
|
|
|
uint8_t *msd,
|
|
size_t msdLength,
|
|
|
|
char *phoneNumber,
|
|
size_t phoneNumberLength,
|
|
|
|
eGsmEcallType ecallType
|
|
) {
|
|
|
|
if (ecallType == GSM_ECALLTYPE_TEST) {
|
|
AT_INOKR(AtGsmTelitLe910_EcallSetTestNumber(env, phoneNumber, phoneNumberLength))
|
|
SystemDelayMs(100);
|
|
}
|
|
|
|
AT_INOKR(AtGsmTelitLe910_EcallSetModeBattle(env))
|
|
SystemDelayMs(100);
|
|
AT_INOKR(AtGsmTelitLe910_EcallWriteMsdToModem(env, msd, msdLength))
|
|
SystemDelayMs(100);
|
|
AT_INOKR(AtGsmTelitLe910_EcallPushMsd(env))
|
|
SystemDelayMs(100);
|
|
AT_INOKR(AtGsmTelitLe910_EcallMake(env, ecallType))
|
|
|
|
return AT_OK;
|
|
}
|
|
|
|
AtCommandResult AtGsmTelitLe910_ResetiingMsd(
|
|
tAtCmd *env,
|
|
uint8_t *msd,
|
|
size_t msdLength
|
|
) {
|
|
|
|
AT_INOKR(AtGsmTelitLe910_EcallWriteMsdToModem(env, msd, msdLength))
|
|
SystemDelayMs(100);
|
|
AT_INOKR(AtGsmTelitLe910_EcallPushMsd(env))
|
|
|
|
return AT_OK;
|
|
} |