786 lines
24 KiB
C++
786 lines
24 KiB
C++
#include "AtSimInit.h"
|
|
#include "IPeripheralManager.h"
|
|
#include "Log.h"
|
|
#include "sf_opera_adapt_v2.h"
|
|
#include <string.h>
|
|
const char *AT_COMMAND_ATE = "ATE1\r";
|
|
// class NetworkATTaskV2 : public VNetworkTask
|
|
// {
|
|
// public:
|
|
// NetworkATTaskV2(const char *command, ResponseCode (AtSimInit::*response)(const char *, const unsigned int &),
|
|
// std::shared_ptr<VAtBasics> network)
|
|
// : mATCommand(command), mResponse(response), mNetwork(network)
|
|
// {
|
|
// }
|
|
// ~NetworkATTaskV2()
|
|
// {
|
|
// }
|
|
// const char *GetWriteBuf(void) override
|
|
// {
|
|
// return mATCommand;
|
|
// }
|
|
// unsigned int GetWriteBufLength(void) override
|
|
// {
|
|
// return strlen(mATCommand);
|
|
// }
|
|
// bool IsTaskBlock(void) override
|
|
// {
|
|
// return true;
|
|
// }
|
|
// unsigned int RetryTimes(void) override
|
|
// {
|
|
// return 200;
|
|
// }
|
|
// ResponseCode Response(const char *buf, const unsigned int &length) override
|
|
// {
|
|
// if (mResponse)
|
|
// {
|
|
// ResponseCode code = ((dynamic_cast<AtSimInit *>(mNetwork.get()))->*mResponse)(buf, length);
|
|
// return code;
|
|
// }
|
|
// return ResponseCode::RESPONSE_OK;
|
|
// }
|
|
|
|
// const char *mATCommand;
|
|
// ResponseCode (AtSimInit::*mResponse)(const char *, const unsigned int &);
|
|
// std::shared_ptr<VAtBasics> mNetwork;
|
|
// };
|
|
AtSimInit::AtSimInit()
|
|
{
|
|
mModuelV05 = 0;
|
|
memset(GsnSaved, 0, GSN_BUF_LENGTH);
|
|
memset(ModuleVersion, 0, SF_MODULE_VER_MAX_LEN);
|
|
memset(lastICCID, 0, ICCID_BUF_LENGTH);
|
|
mInitRuning = false;
|
|
}
|
|
void AtSimInit::UnInit(void)
|
|
{
|
|
LogInfo("AtSimInit::UnInit.\n");
|
|
mInitRuning = false;
|
|
if (mInitThread.joinable())
|
|
{
|
|
mInitThread.join();
|
|
}
|
|
}
|
|
RETURN_CODE AtSimInit::AtSimCardInit(void)
|
|
{
|
|
// TODO: 4G module has already connected ???
|
|
auto SimInitThreadStart = [](std::shared_ptr<VAtBasics> atCommand)
|
|
{
|
|
std::dynamic_pointer_cast<AtSimInit>(atCommand)->AtSimInitStart();
|
|
};
|
|
// std::thread simInit(SimInitThreadStart, SharedFromThis());
|
|
// simInit.detach();
|
|
if (mInitRuning)
|
|
{
|
|
LogWarning("AtSimCardInit runing.\n");
|
|
return VReturnCode::NewCode(VReturnCodeDefine::NOT_OK_UNDEFINE_REASON);
|
|
}
|
|
mInitRuning = true;
|
|
mInitThread = std::thread(SimInitThreadStart, SharedFromThis());
|
|
return VReturnCode::NewCode(VReturnCodeDefine::OK);
|
|
}
|
|
void AtSimInit::AtSimInitStart(void)
|
|
{
|
|
ATE_Handle();
|
|
}
|
|
bool AtSimInit::SimInitRetry(void)
|
|
{
|
|
if (!mInitRuning)
|
|
{
|
|
LogWarning("Stop Init.\n");
|
|
return false;
|
|
}
|
|
constexpr int SIM_INIT_CALL_RETRY = 200;
|
|
AtCallOnce();
|
|
if (GetAtCallTimes() <= SIM_INIT_CALL_RETRY)
|
|
{
|
|
LogInfo("Retry to call, call times = %d.\n", GetAtCallTimes());
|
|
return true;
|
|
}
|
|
// SetAtCallTimes();
|
|
LogError("Sim card init failed.\n"); // TODO:
|
|
return false;
|
|
}
|
|
void AtSimInit::ATE_Handle(void)
|
|
{
|
|
LogInfo("AT-Command:ATE1\n");
|
|
SetAtCallTimes(0);
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
std::shared_ptr<VNetworkTask> task = std::make_shared<AtTaskBasics_V2>(AT_COMMAND_ATE, response, RESPONSE_BUF_LENGTH);
|
|
ATE_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("AtSimInitStart. response = %s\n", response);
|
|
if (strstr(response, "OK"))
|
|
{
|
|
LogInfo("ATE_Handle response ok.\n");
|
|
AT_GSN_Handle();
|
|
return;
|
|
}
|
|
if (SimInitRetry())
|
|
{
|
|
goto ATE_RETRY;
|
|
}
|
|
}
|
|
const char *AT_GSN = "AT+GSN\r";
|
|
void AtSimInit::AT_GSN_Handle(void)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task = std::make_shared<AtTaskBasics_V2>(AT_GSN, response, RESPONSE_BUF_LENGTH);
|
|
AT_GSN_RETRY:
|
|
if (!mInitRuning)
|
|
{
|
|
LogWarning("Stop Init.\n");
|
|
return;
|
|
}
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
unsigned int length = std::dynamic_pointer_cast<AtTaskBasics_V2>(task)->ActualResponseLength();
|
|
LogInfo("AT_GSN_Handle. response = %s\n", response);
|
|
UINT16 index = 0;
|
|
SF_CHAR GsnNow[GSN_BUF_LENGTH] = {0};
|
|
if (response[0] != '\0')
|
|
{
|
|
for (index = 0; index < length; index++)
|
|
{
|
|
if ((response[index] == '8') && (response[index + 1] == '6'))
|
|
{
|
|
SF_CHAR tempImei[16] = {0};
|
|
UINT8 p = 0;
|
|
for (p = 0; p < IMEI_LEN; p++)
|
|
{
|
|
if ((response[p + index] >= '0') && (response[p + index] <= '9'))
|
|
tempImei[p] = response[p + index];
|
|
else
|
|
tempImei[p] = '\0';
|
|
}
|
|
tempImei[15] = '\0';
|
|
strcpy(GsnNow, tempImei);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
LogInfo("GsnNow = %s\n", GsnNow);
|
|
LogInfo("GsnSaved = %s\n", GsnSaved);
|
|
if ((GsnNow[0] != '\0') && (strncmp(GsnNow, GsnSaved, IMEI_LEN) == 0))
|
|
{
|
|
AtGetIMEI(GsnNow);
|
|
ATI_Handle();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
LogWarning("RESPONSE_FAILED_RETRY.\n");
|
|
strcpy(GsnSaved, GsnNow);
|
|
goto AT_GSN_RETRY;
|
|
}
|
|
if (SimInitRetry())
|
|
{
|
|
goto AT_GSN_RETRY;
|
|
}
|
|
}
|
|
const char *AT_ATI = "ATI\r";
|
|
void AtSimInit::ATI_Handle(void)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task = std::make_shared<AtTaskBasics_V2>(AT_ATI, response, RESPONSE_BUF_LENGTH);
|
|
ATI_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("ATI_Handle.buf = %s\n", response);
|
|
SF_CHAR *pTemp = nullptr;
|
|
SF_CHAR *p = nullptr;
|
|
if ((strstr(response, "OK") != nullptr) || (strstr(response, "ERROR") != nullptr))
|
|
{
|
|
pTemp = strstr(response, "Revision:");
|
|
if (pTemp != nullptr)
|
|
{
|
|
SF_CHAR modulVerStr[256] = {0};
|
|
strcpy(modulVerStr, pTemp + 10);
|
|
pTemp = strtok(modulVerStr, "OK");
|
|
p = strtok(pTemp, "\r\n");
|
|
if (strcasecmp(p, ModuleVersion) != 0)
|
|
{
|
|
strcpy(ModuleVersion, p);
|
|
}
|
|
}
|
|
if ((strstr(response, "AFAR05")))
|
|
{
|
|
SetModuleV05(1);
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
|
QFLST_1_Handle("at+qflst=\"../../usr/fota_ip_a/update_report.ur\"\r");
|
|
}
|
|
else if (strstr(response, "AFAR07"))
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
|
QFLST_1_Handle("at+qflst=\"../../data/fota_ip_a/update_report.ur\"\r");
|
|
}
|
|
else
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
QGMR_Handle();
|
|
}
|
|
return;
|
|
}
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
if (SimInitRetry())
|
|
{
|
|
goto ATI_RETRY;
|
|
}
|
|
}
|
|
const char *AT_QGMR = "AT+QGMR\r";
|
|
void AtSimInit::QGMR_Handle(void)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task = std::make_shared<AtTaskBasics_V2>(AT_QGMR, response, RESPONSE_BUF_LENGTH);
|
|
QGMR_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("QGMR_Handle.response = %s\n", response);
|
|
if (strstr(response, GPRS_MODULE_TYPE_EG91) != nullptr)
|
|
{
|
|
char subTemp[SF_MODULE_VER_MAX_LEN] = {0};
|
|
eg91_parse_module_version((SF_CHAR *)strstr(response, GPRS_MODULE_TYPE_EG91), subTemp);
|
|
AtGetModuleSubVersion(subTemp);
|
|
if (strstr(ModuleVersion, GPRS_MODULE_TYPE_EG91_V))
|
|
{
|
|
QNVFR_Handle();
|
|
}
|
|
else
|
|
{
|
|
QSIMSTAT_Handle();
|
|
}
|
|
return;
|
|
}
|
|
else if (strstr(response, GPRS_MODULE_TYPE_EG95) != nullptr)
|
|
{
|
|
char subTemp[SF_MODULE_VER_MAX_LEN] = {0};
|
|
eg91_parse_module_version((SF_CHAR *)strstr(response, GPRS_MODULE_TYPE_EG95), subTemp);
|
|
AtGetModuleSubVersion(subTemp);
|
|
if (strstr(ModuleVersion, GPRS_MODULE_TYPE_EG95_V))
|
|
{
|
|
QNVFR_Handle();
|
|
}
|
|
else
|
|
{
|
|
QSIMSTAT_Handle();
|
|
}
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (GetAtCallTimes() > 5)
|
|
{
|
|
if (strstr(ModuleVersion, GPRS_MODULE_TYPE_EG91_V))
|
|
{
|
|
QNVFR_Handle();
|
|
}
|
|
else if (strstr(ModuleVersion, GPRS_MODULE_TYPE_EG95_V))
|
|
{
|
|
QNVFR_Handle();
|
|
}
|
|
else
|
|
{
|
|
QSIMSTAT_Handle();
|
|
}
|
|
return;
|
|
}
|
|
if (SimInitRetry())
|
|
{
|
|
goto QGMR_RETRY;
|
|
}
|
|
}
|
|
}
|
|
const char *AT_QSIMSTAT = "AT+QSIMSTAT?\r";
|
|
void AtSimInit::QSIMSTAT_Handle(void)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task =
|
|
std::make_shared<AtTaskBasics_V2>(AT_QSIMSTAT, response, RESPONSE_BUF_LENGTH);
|
|
QSIMSTAT_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("QSIMSTAT_Handle. response=%s\n", response);
|
|
if (strstr(response, "+QSIMSTAT: 0,0"))
|
|
{
|
|
if (GetAtCallTimes() > 50)
|
|
{
|
|
LogError("SimCard not inserted.\n");
|
|
AtSimInitResult(SimInitResult::SIM_INIT_NOT_INSERTED);
|
|
return;
|
|
}
|
|
if (SimInitRetry())
|
|
{
|
|
LogWarning("QSIMSTAT_RETRY.\n");
|
|
goto QSIMSTAT_RETRY;
|
|
}
|
|
}
|
|
else if (strstr(response, "+QSIMSTAT: 0,1"))
|
|
{
|
|
LogInfo("SIM_INIT_QURCCFG.\n");
|
|
QURCCFG_Handle();
|
|
return;
|
|
}
|
|
else if (strstr(response, "+CPIN: NOT INSERTED"))
|
|
{
|
|
LogError("SimCard not inserted.\n");
|
|
AtSimInitResult(SimInitResult::SIM_INIT_NOT_INSERTED);
|
|
return;
|
|
}
|
|
if (SimInitRetry())
|
|
{
|
|
goto QSIMSTAT_RETRY;
|
|
}
|
|
}
|
|
void AtSimInit::AT_END_Handle(char *atCommand)
|
|
{
|
|
constexpr int AT_LENGTH = 1024;
|
|
SetAtCallTimes(0);
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
char at[AT_LENGTH] = {0};
|
|
memcpy(at, atCommand, strlen(atCommand));
|
|
std::shared_ptr<VNetworkTask> task =
|
|
std::make_shared<AtTaskBasics_V2>(atCommand, response, RESPONSE_BUF_LENGTH);
|
|
// AT_END_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("AT_END_Handle. response = %s\n", response);
|
|
if (strstr(response, "OK"))
|
|
{
|
|
LogInfo("Sim card init ok.\n");
|
|
AtSimInitResult(SimInitResult::SIM_INIT_OK);
|
|
return;
|
|
}
|
|
else if (strstr(response, "NOT"))
|
|
{
|
|
LogError("Sim card init failed, no sim card.\n");
|
|
AtSimInitResult(SimInitResult::SIM_INIT_NOT_INSERTED);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
LogWarning("What happened?\n");
|
|
if ((GetAtCallTimes() % 10) == 0)
|
|
{ // TODO: What happend? No need to handle response?
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
std::shared_ptr<VNetworkTask> task2 =
|
|
std::make_shared<AtTaskBasics_V2>("AT+CPIN?\r", response, RESPONSE_BUF_LENGTH); // TODO:
|
|
SendAtCommandTask(task2);
|
|
}
|
|
}
|
|
}
|
|
void AtSimInit::QNVFR_Handle(void)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task =
|
|
std::make_shared<AtTaskBasics_V2>("at+qnvfr=\"/nv/item_files/modem/uim/gstk/feature_bmsk\"\r", response, RESPONSE_BUF_LENGTH);
|
|
QNVFR_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("QNVFR_Handle.\n");
|
|
if (strstr(response, "+QNVFR: 11000000"))
|
|
{
|
|
QNVFW_Handle();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
AT_END_Handle((char *)"AT\r");
|
|
return;
|
|
}
|
|
if (SimInitRetry())
|
|
{
|
|
goto QNVFR_RETRY;
|
|
}
|
|
}
|
|
void AtSimInit::QNVFW_Handle(void)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task =
|
|
std::make_shared<AtTaskBasics_V2>("at+qnvfw=\"/nv/item_files/modem/uim/gstk/feature_bmsk\",01000000\r", response, RESPONSE_BUF_LENGTH);
|
|
QNVFW_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("QNVFW_Handle.\n");
|
|
if (strstr(response, "OK"))
|
|
{
|
|
AT_END_Handle((char *)"AT\r");
|
|
return;
|
|
}
|
|
if (SimInitRetry())
|
|
{
|
|
goto QNVFW_RETRY;
|
|
}
|
|
}
|
|
void AtSimInit::QFLST_1_Handle(const char *atCommand)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task = std::make_shared<AtTaskBasics_V2>(atCommand, response, RESPONSE_BUF_LENGTH);
|
|
QFLST_1_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("QFLST_1_Handle.\n");
|
|
if (strstr(response, "OK"))
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
QGMR_Handle();
|
|
return;
|
|
}
|
|
else if (strstr(response, "ERROR: 417"))
|
|
{
|
|
UINT8 modulev05 = GetModuleV05();
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
|
if (modulev05 == 1)
|
|
{
|
|
QFLST_2_Handle("at+qfopen=\"../../usr/fota_ip_a/update_report.ur\",1\r");
|
|
}
|
|
else
|
|
{
|
|
QFLST_2_Handle("at+qfopen=\"../../data/fota_ip_a/update_report.ur\",1\r");
|
|
}
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (GetAtCallTimes() > 10)
|
|
{
|
|
SetAtCallTimes(0);
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
QFLST_2_Handle("ATI\r");
|
|
return;
|
|
}
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
|
if (SimInitRetry())
|
|
{
|
|
goto QFLST_1_RETRY;
|
|
}
|
|
}
|
|
}
|
|
void AtSimInit::QFLST_2_Handle(const char *atCommand)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task = std::make_shared<AtTaskBasics_V2>(atCommand, response, RESPONSE_BUF_LENGTH);
|
|
QFLST_2_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("QFLST_2_Handle.\n");
|
|
if (strstr(response, "OK"))
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
QGMR_Handle();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
ATI_Handle();
|
|
return;
|
|
}
|
|
if (SimInitRetry())
|
|
{
|
|
goto QFLST_2_RETRY;
|
|
}
|
|
}
|
|
const char *AT_QURCCFG = "AT+QURCCFG=\"urcport\",\"usbat\"\r";
|
|
void AtSimInit::QURCCFG_Handle(void)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
std::shared_ptr<VNetworkTask> task = std::make_shared<AtTaskBasics_V2>(AT_QURCCFG, response, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("QSIMSTAT_Handle. response=%s\n", response); // TODO: ??
|
|
QCFG_1_Handle();
|
|
}
|
|
const char *AT_QCFG = "AT+QCFG=\"risignaltype\",\"physical\"\r";
|
|
void AtSimInit::QCFG_1_Handle(void)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task = std::make_shared<AtTaskBasics_V2>(AT_QCFG, response, RESPONSE_BUF_LENGTH);
|
|
QCFG_1_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("QCFG_1_Handle. response=%s\n", response);
|
|
if (strstr(response, "OK"))
|
|
{
|
|
QCFG_2_Handle();
|
|
return;
|
|
}
|
|
if (SimInitRetry())
|
|
{
|
|
goto QCFG_1_RETRY;
|
|
}
|
|
}
|
|
const char *AT_QCFG_2 = "AT+QCFG=\"urc/ri/other\",\"off\"\r";
|
|
void AtSimInit::QCFG_2_Handle(void)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task = std::make_shared<AtTaskBasics_V2>(AT_QCFG_2, response, RESPONSE_BUF_LENGTH);
|
|
QCFG_2_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("QCFG_2_Handle. response=%s\n", response);
|
|
if (strstr(response, "OK"))
|
|
{
|
|
QLWCFG_1_Handle();
|
|
return;
|
|
}
|
|
if (SimInitRetry())
|
|
{
|
|
goto QCFG_2_RETRY;
|
|
}
|
|
}
|
|
const char *AT_QLWCFG = "AT+QLWCFG=\"urc\",0\r";
|
|
void AtSimInit::QLWCFG_1_Handle(void)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task = std::make_shared<AtTaskBasics_V2>(AT_QLWCFG, response, RESPONSE_BUF_LENGTH);
|
|
QLWCFG_1_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("QLWCFG_1_Handle. response=%s\n", response);
|
|
if (strstr(response, "OK"))
|
|
{
|
|
QLWCFG_2_Handle();
|
|
return;
|
|
}
|
|
if (SimInitRetry())
|
|
{
|
|
goto QLWCFG_1_RETRY;
|
|
}
|
|
}
|
|
const char *AT_QLWCFG_2 = "AT+QLWCFG=\"startup\",0\r";
|
|
void AtSimInit::QLWCFG_2_Handle(void)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task = std::make_shared<AtTaskBasics_V2>(AT_QLWCFG_2, response, RESPONSE_BUF_LENGTH);
|
|
QLWCFG_2_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("QLWCFG_2_Handle. response=%s\n", response);
|
|
if (strstr(response, "OK"))
|
|
{
|
|
CPIN_Handle();
|
|
return;
|
|
}
|
|
if (SimInitRetry())
|
|
{
|
|
goto QLWCFG_2_RETRY;
|
|
}
|
|
}
|
|
const char *AT_CPIN = "AT+CPIN?\r";
|
|
void AtSimInit::CPIN_Handle(void)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task = std::make_shared<AtTaskBasics_V2>(AT_CPIN, response, RESPONSE_BUF_LENGTH);
|
|
CPIN_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("CPIN_Handle. response=%s\n", response);
|
|
if (strstr(response, "READY"))
|
|
{
|
|
QCCID_Handle();
|
|
return;
|
|
}
|
|
if (SimInitRetry())
|
|
{
|
|
goto CPIN_RETRY;
|
|
}
|
|
}
|
|
const char *AT_QCCID = "AT+QCCID\r";
|
|
void AtSimInit::QCCID_Handle(void)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task = std::make_shared<AtTaskBasics_V2>(AT_QCCID, response, RESPONSE_BUF_LENGTH);
|
|
QCCID_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("QCCID_Handle. response=%s\n", response);
|
|
SF_CHAR *pStr = nullptr;
|
|
SF_CHAR tempICCID[ICCID_BUF_LENGTH] = {0};
|
|
if ((strstr(response, "+QCCID: ") != nullptr))
|
|
{
|
|
pStr = strstr(response, "+QCCID: ");
|
|
memcpy(tempICCID, pStr + 8, 20);
|
|
if ((tempICCID[19] <= '9') && (tempICCID[19] >= '0'))
|
|
tempICCID[20] = '\0';
|
|
else
|
|
tempICCID[19] = '\0';
|
|
if (strncmp(lastICCID, tempICCID, 21) == 0)
|
|
{
|
|
LogInfo("ICCID=%s\n", tempICCID);
|
|
AtGetICCID(tempICCID);
|
|
CIMI_Handle();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
strcpy(lastICCID, tempICCID);
|
|
memset(tempICCID, '\0', sizeof(tempICCID));
|
|
goto QCCID_RETRY;
|
|
}
|
|
}
|
|
if (SimInitRetry())
|
|
{
|
|
goto QCCID_RETRY;
|
|
}
|
|
}
|
|
const char *AT_CIMI = "AT+CIMI\r";
|
|
void AtSimInit::CIMI_Handle(void)
|
|
{
|
|
char response[RESPONSE_BUF_LENGTH] = {0};
|
|
SetAtCallTimes(0);
|
|
std::shared_ptr<VNetworkTask> task = std::make_shared<AtTaskBasics_V2>(AT_CIMI, response, RESPONSE_BUF_LENGTH);
|
|
CIMI_RETRY:
|
|
memset(response, 0, RESPONSE_BUF_LENGTH);
|
|
SendAtCommandTask(task);
|
|
LogInfo("CIMI_Handle. response=%s\n", response);
|
|
SF_CHAR operationCode[OPERATION_CODE_LENGTH] = {0};
|
|
SF_CHAR *pTemp = nullptr;
|
|
SIM_INFO_S simInfo = {0};
|
|
pTemp = strstr(response, "AT+CIMI");
|
|
constexpr int SF_TTYUSB_RECV_MAX = 580;
|
|
SF_CHAR ttyData[SF_TTYUSB_RECV_MAX] = {0};
|
|
if (pTemp)
|
|
{
|
|
memcpy(operationCode, pTemp + 10, 5);
|
|
LogInfo("operationCode:%s\n", operationCode);
|
|
sprintf(simInfo.OperatorCode, "%s", operationCode);
|
|
sf_auto_operation_adaptation(simInfo.OperatorCode, &simInfo);
|
|
LogInfo("ApnGPRS:%s\n", simInfo.ApnGPRS);
|
|
if ((strstr(simInfo.ApnGPRS, APNGPRS_WUYUAN2)) || (strstr(simInfo.ApnGPRS, APNGPRS_WUYUAN))) // 20408 sifar kpn sim
|
|
{
|
|
AtGetSimType(SF_SIM_MEGA);
|
|
// 1. mega sim,set pdp 1 apn
|
|
eg91_module_Polling_Comparison_CIMI(operationCode); // mega sim,recorde sim operation code
|
|
sprintf(ttyData, "AT+CGDCONT=1,\"IPV4V6\",\"%s\"\r", simInfo.ApnGPRS);
|
|
AT_END_Handle(ttyData);
|
|
return;
|
|
}
|
|
else if (strstr(simInfo.ApnGPRS, APNGPRSTEMP))
|
|
{
|
|
AtGetSimType(SF_SIM_MEGA_IOT);
|
|
AT_END_Handle((char *)"AT+CGDCONT=1,\"IPV4V6\",\"\"\r");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
// AtSimInitResult(SimInitResult::SIM_INIT_NOT_SUPPORT_MOBILE_NETWORK);
|
|
AtSimInitResult(SimInitResult::SIM_INIT_OK);
|
|
return;
|
|
}
|
|
}
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
|
if (SimInitRetry())
|
|
{
|
|
goto CIMI_RETRY;
|
|
}
|
|
}
|
|
void AtSimInit::CGDCONT_Handle(void)
|
|
{
|
|
// LogInfo("CGDCONT_Handle. buf=%s\n", buf);
|
|
}
|
|
SINT32 AtSimInit::eg91_parse_module_version(SF_CHAR *pTemp, SF_CHAR *version)
|
|
{
|
|
SF_CHAR *pT1 = nullptr;
|
|
SF_CHAR *pT2 = nullptr;
|
|
SF_CHAR *pT3 = nullptr;
|
|
SF_CHAR *pT4 = nullptr;
|
|
|
|
pT1 = strstr(pTemp, "FAR");
|
|
pT2 = strstr(pTemp, "_");
|
|
pT3 = strstr(pTemp, "GAR");
|
|
pT4 = strstr(pTemp, "OCPU");
|
|
|
|
LogInfo("pTemp = %s\n", pTemp);
|
|
LogInfo("pT1 = %s\n", pT1);
|
|
LogInfo("pT2 = %s\n", pT2);
|
|
LogInfo("pT3 = %s\n", pT3);
|
|
|
|
if (pT1 != nullptr)
|
|
eg91_parse_module_version_detail(pTemp, pT1, pT2, pT4, version);
|
|
else if (pT3 != nullptr)
|
|
eg91_parse_module_version_detail(pTemp, pT3, pT2, pT4, version);
|
|
|
|
LogInfo("version:%s\n", version);
|
|
return SF_SUCCESS;
|
|
}
|
|
void AtSimInit::eg91_parse_module_version_detail(SF_CHAR *pTemp, SF_CHAR *pT1, SF_CHAR *pT2, SF_CHAR *pT4, SF_CHAR *version)
|
|
{
|
|
// FILE_HEADER *sim_info_t = sf_statistics_param_get();
|
|
const char *moduleVersion = GetModuleVersionParam();
|
|
SF_CHAR str0[5] = {0};
|
|
SF_CHAR str1[5] = {0};
|
|
SF_CHAR str2[5] = {0};
|
|
SF_CHAR str3[5] = {0};
|
|
SF_CHAR str4[256] = {0};
|
|
SF_CHAR str5[256] = {0};
|
|
SF_CHAR *pT5 = nullptr;
|
|
memcpy(str1, pTemp + 4, pT1 - pTemp - 4);
|
|
// printf("str1 = %s\n", str1);
|
|
memcpy(str2, pT1 + 3, 2);
|
|
// printf("str2 = %s\n", str2);
|
|
memcpy(str3, pT1 + 6, 2);
|
|
// printf("str3 = %s\n", str3);
|
|
|
|
if (strstr(moduleVersion, GPRS_MODULE_TYPE_EG91))
|
|
{
|
|
sprintf(str0, "%s", "91");
|
|
}
|
|
else if (strstr(moduleVersion, GPRS_MODULE_TYPE_EG95))
|
|
{
|
|
sprintf(str0, "%s", "95");
|
|
}
|
|
else
|
|
{
|
|
sprintf(str0, "%s", "UN");
|
|
}
|
|
|
|
if (pT2 != nullptr)
|
|
{
|
|
strcpy(str4, pT2 + 1);
|
|
// printf("str4 = %s\n", str4);
|
|
pT5 = strtok(str4, "\r\n");
|
|
|
|
if (pT5 != nullptr)
|
|
{
|
|
strcpy(str5, pT5);
|
|
// printf("str5 = %s\n",str5);
|
|
|
|
if (pT4 != nullptr)
|
|
sprintf(version, "S%sY%sY%sY%sY%sOS", str0, str1, str2, str3, str5);
|
|
else
|
|
sprintf(version, "S%sY%sY%sY%sY%sS", str0, str1, str2, str3, str5);
|
|
}
|
|
else
|
|
{
|
|
if (pT4 != nullptr)
|
|
sprintf(version, "S%sY%sY%sY%sOS", str0, str1, str2, str3);
|
|
else
|
|
sprintf(version, "S%sY%sY%sY%sS", str0, str1, str2, str3);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (pT4 != nullptr)
|
|
sprintf(version, "S%sY%sY%sY%sOS", str0, str1, str2, str3);
|
|
else
|
|
sprintf(version, "S%sY%sY%sY%sS", str0, str1, str2, str3);
|
|
}
|
|
|
|
LogInfo("module_QGver = %s\n", version);
|
|
return;
|
|
} |