Skip to content

Commit 7acb76a

Browse files
committed
[quectel][msom] re-enable 2G support for M404, fix for M524
1 parent 917ed35 commit 7acb76a

File tree

2 files changed

+64
-48
lines changed

2 files changed

+64
-48
lines changed

hal/network/ncp_client/quectel/quectel_ncp_client.cpp

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ int QuectelNcpClient::getCellularGlobalIdentity(CellularGlobalIdentity* cgi) {
661661
// Fill in LAC and Cell ID based on current RAT, prefer PSD and EPS
662662
// fallback to CSD
663663
CHECK_PARSER_OK(parser_.execCommand("AT+CEREG?"));
664-
if (isQuecCat1Device() || ncpId() == PLATFORM_NCP_QUECTEL_BG95_M5) {
664+
if (isQuec2g3gEnabled()) {
665665
CHECK_PARSER_OK(parser_.execCommand("AT+CGREG?"));
666666
CHECK_PARSER_OK(parser_.execCommand("AT+CREG?"));
667667
}
@@ -1065,6 +1065,17 @@ bool QuectelNcpClient::isQuecBG95xDevice() {
10651065
ncp_id == PLATFORM_NCP_QUECTEL_BG95_MF) ;
10661066
}
10671067

1068+
bool QuectelNcpClient::isQuec2g3gEnabled() {
1069+
// PLATFORM_NCP_QUECTEL_BG96 specifically not included to
1070+
// disable 2G support so that a 10W power supply is not required
1071+
int ncp_id = ncpId();
1072+
return (ncp_id == PLATFORM_NCP_QUECTEL_EG91_E ||
1073+
ncp_id == PLATFORM_NCP_QUECTEL_EG91_NA ||
1074+
ncp_id == PLATFORM_NCP_QUECTEL_EG91_EX ||
1075+
ncp_id == PLATFORM_NCP_QUECTEL_EG91_NAX ||
1076+
ncp_id == PLATFORM_NCP_QUECTEL_BG95_M5);
1077+
}
1078+
10681079
int QuectelNcpClient::getRuntimeBaudrate() {
10691080
auto runtimeBaudrate = QUECTEL_NCP_RUNTIME_SERIAL_BAUDRATE;
10701081
if (ncpId() == PLATFORM_NCP_QUECTEL_BG95_M5) {
@@ -1386,13 +1397,14 @@ int QuectelNcpClient::registerNet() {
13861397

13871398
resetRegistrationState();
13881399

1389-
if (isQuecCat1Device() || ncpId() == PLATFORM_NCP_QUECTEL_BG95_M5) {
1390-
// Register GPRS, LET, NB-IOT network
1400+
if (isQuec2g3gEnabled()) {
1401+
// Register GSM, GPRS network registration and location URCs
13911402
r = CHECK_PARSER(parser_.execCommand("AT+CREG=2"));
13921403
CHECK_TRUE(r == AtResponse::OK, SYSTEM_ERROR_UNKNOWN);
13931404
r = CHECK_PARSER(parser_.execCommand("AT+CGREG=2"));
13941405
CHECK_TRUE(r == AtResponse::OK, SYSTEM_ERROR_UNKNOWN);
13951406
}
1407+
// Register LTE, NB-IoT network registration and location URCs
13961408
r = CHECK_PARSER(parser_.execCommand("AT+CEREG=2"));
13971409
CHECK_TRUE(r == AtResponse::OK, SYSTEM_ERROR_UNKNOWN);
13981410

@@ -1427,47 +1439,41 @@ int QuectelNcpClient::registerNet() {
14271439
// CHECK_TRUE(r == AtResponse::OK, SYSTEM_ERROR_UNKNOWN);
14281440
}
14291441

1430-
if (isQuecCatM1Device()) {
1431-
if (ncpId() == PLATFORM_NCP_QUECTEL_BG96 || ncpId() == PLATFORM_NCP_QUECTEL_BG95_M5) {
1432-
// NOTE: BG96 supports 2G fallback which we disable explicitly so that a 10W power supply is not required
1433-
// Configure RATs to be searched
1434-
// Set to scan LTE only if not already set, take effect immediately
1435-
auto respNwMode = parser_.sendCommand("AT+QCFG=\"nwscanmode\"");
1436-
int nwScanMode = -1;
1437-
r = CHECK_PARSER(respNwMode.scanf("+QCFG: \"nwscanmode\",%d", &nwScanMode));
1438-
CHECK_TRUE(r == 1, SYSTEM_ERROR_UNKNOWN);
1439-
r = CHECK_PARSER(respNwMode.readResult());
1440-
CHECK_TRUE(r == AtResponse::OK, SYSTEM_ERROR_UNKNOWN);
1441-
#if PLATFORM_ID == PLATFORM_MSOM
1442-
// M404/BG95M5 should be LTEM only, ie scan mode 3
1443-
// M524/EG91EX should be AUTO (both LTEM and 2G), ie scan mode 0
1444-
int desiredNwScanMode = (ncpId() == PLATFORM_NCP_QUECTEL_BG95_M5) ? 3 : 0;
1442+
// nwscanmode: configure RATs to be searched
1443+
// only valid on BG96, BG95-M5 and EG91xxx
1444+
if (ncpId() == PLATFORM_NCP_QUECTEL_BG96 || ncpId() == PLATFORM_NCP_QUECTEL_BG95_M5 || isQuecCat1Device()) {
1445+
auto respNwMode = parser_.sendCommand("AT+QCFG=\"nwscanmode\"");
1446+
int nwScanMode = -1;
1447+
r = CHECK_PARSER(respNwMode.scanf("+QCFG: \"nwscanmode\",%d", &nwScanMode));
1448+
CHECK_TRUE(r == 1, SYSTEM_ERROR_UNKNOWN);
1449+
r = CHECK_PARSER(respNwMode.readResult());
1450+
CHECK_TRUE(r == AtResponse::OK, SYSTEM_ERROR_UNKNOWN);
14451451

1446-
if (nwScanMode != desiredNwScanMode) {
1447-
CHECK_PARSER(parser_.execCommand("AT+QCFG=\"nwscanmode\",%d,1", desiredNwScanMode));
1448-
}
1452+
int desiredNwScanMode = isQuec2g3gEnabled() ? 0 : 3; // 0: AUTO, 3: LTE-ONLY
1453+
if (nwScanMode != desiredNwScanMode) {
1454+
CHECK_PARSER(parser_.execCommand("AT+QCFG=\"nwscanmode\",%d,1", desiredNwScanMode));
1455+
}
1456+
}
14491457

1450-
if (ncpId() == PLATFORM_NCP_QUECTEL_BG95_M5) {
1451-
auto respNwScanSeq = parser_.sendCommand("AT+QCFG=\"nwscanseq\"");
1452-
int nwScanSeq = -1;
1453-
r = CHECK_PARSER(respNwScanSeq.scanf("+QCFG: \"nwscanseq\",%d", &nwScanSeq));
1454-
CHECK_TRUE(r == 1, SYSTEM_ERROR_UNKNOWN);
1455-
r = CHECK_PARSER(respNwScanSeq.readResult());
1456-
CHECK_TRUE(r == AtResponse::OK, SYSTEM_ERROR_UNKNOWN);
1457-
if (nwScanSeq != 20103) { // i.e. 020103
1458-
CHECK_PARSER(parser_.execCommand("AT+QCFG=\"nwscanseq\",020103,1")); // LTE 02, then GSM 01, then NBIOT 03
1459-
}
1460-
}
1461-
#else
1462-
if (nwScanMode != 3) {
1463-
CHECK_PARSER(parser_.execCommand("AT+QCFG=\"nwscanmode\",3,1"));
1458+
// nwscanseq: only setting RAT scan order for M404
1459+
#if PLATFORM_ID == PLATFORM_MSOM
1460+
if (ncpId() == PLATFORM_NCP_QUECTEL_BG95_M5) {
1461+
auto respNwScanSeq = parser_.sendCommand("AT+QCFG=\"nwscanseq\"");
1462+
int nwScanSeq = -1;
1463+
r = CHECK_PARSER(respNwScanSeq.scanf("+QCFG: \"nwscanseq\",%d", &nwScanSeq));
1464+
CHECK_TRUE(r == 1, SYSTEM_ERROR_UNKNOWN);
1465+
r = CHECK_PARSER(respNwScanSeq.readResult());
1466+
CHECK_TRUE(r == AtResponse::OK, SYSTEM_ERROR_UNKNOWN);
1467+
if (nwScanSeq != 20103) { // i.e. 020103
1468+
CHECK_PARSER(parser_.execCommand("AT+QCFG=\"nwscanseq\",020103,1")); // LTE 02, then GSM 01, then NBIOT 03
14641469
}
1465-
#endif
14661470
}
1471+
#endif // PLATFORM_ID == PLATFORM_MSOM
14671472

1473+
// iotopmode: configure network category to be searched
1474+
// Set to use LTE Cat-M1 ONLY (exclude NBIOT) if not already set, take effect immediately
1475+
if (isQuecCatM1Device()) {
14681476
if (isQuecCatNBxDevice()) {
1469-
// Configure Network Category to be searched
1470-
// Set to use LTE Cat-M1 ONLY (exclude NBIOT) if not already set, take effect immediately
14711477
auto respOpMode = parser_.sendCommand("AT+QCFG=\"iotopmode\"") ;
14721478

14731479
int iotOpMode = -1;
@@ -1481,11 +1487,12 @@ int QuectelNcpClient::registerNet() {
14811487
}
14821488
}
14831489
}
1490+
14841491
// Check GSM, GPRS, and LTE network registration status
14851492
CHECK_PARSER_OK(parser_.execCommand("AT+CEREG?"));
1486-
if (isQuecCat1Device() || ncpId() == PLATFORM_NCP_QUECTEL_BG95_M5) {
1487-
CHECK_PARSER_OK(parser_.execCommand("AT+CREG?"));
1493+
if (isQuec2g3gEnabled()) {
14881494
CHECK_PARSER_OK(parser_.execCommand("AT+CGREG?"));
1495+
CHECK_PARSER_OK(parser_.execCommand("AT+CREG?"));
14891496
}
14901497

14911498
regStartTime_ = millis();
@@ -1813,7 +1820,7 @@ int QuectelNcpClient::interveneRegistration() {
18131820
auto timeout = (registrationInterventions_ + 1) * REGISTRATION_INTERVENTION_TIMEOUT;
18141821

18151822
// Intervention to speed up registration or recover in case of failure
1816-
if (!isQuecCatM1Device()) {
1823+
if (isQuecCat1Device()) {
18171824
if (eps_.sticky() && eps_.duration() >= timeout) {
18181825
if (eps_.status() == CellularRegistrationStatus::NOT_REGISTERING && csd_.status() == eps_.status()) {
18191826
LOG(TRACE, "Sticky not registering state for %lu s, PLMN reselection", eps_.duration() / 1000);
@@ -1834,7 +1841,8 @@ int QuectelNcpClient::interveneRegistration() {
18341841
return 0;
18351842
}
18361843
}
1837-
1844+
}
1845+
if (isQuec2g3gEnabled()) {
18381846
if (csd_.sticky() && csd_.duration() >= timeout ) {
18391847
if (csd_.status() == CellularRegistrationStatus::DENIED && psd_.status() == csd_.status()) {
18401848
LOG(TRACE, "Sticky CSD and PSD denied state for %lu s, RF reset", csd_.duration() / 1000);
@@ -1847,7 +1855,6 @@ int QuectelNcpClient::interveneRegistration() {
18471855
return 0;
18481856
}
18491857
}
1850-
18511858
if (csd_.registered() && psd_.sticky() && psd_.duration() >= timeout) {
18521859
if (psd_.status() == CellularRegistrationStatus::NOT_REGISTERING && eps_.status() == psd_.status()) {
18531860
LOG(TRACE, "Sticky not registering PSD state for %lu s, force GPRS attach", psd_.duration() / 1000);
@@ -1864,15 +1871,21 @@ int QuectelNcpClient::interveneRegistration() {
18641871
}
18651872
}
18661873
}
1867-
} else {
1874+
}
1875+
if (isQuecCatM1Device()) {
18681876
if (eps_.sticky() && eps_.duration() >= timeout) {
18691877
if (eps_.status() == CellularRegistrationStatus::NOT_REGISTERING) {
18701878
LOG(TRACE, "Sticky not registering EPS state for %lu s, PLMN reselection", eps_.duration() / 1000);
18711879
eps_.reset();
18721880
registrationInterventions_++;
18731881
CHECK_PARSER(parser_.execCommand(QUECTEL_COPS_TIMEOUT, "AT+COPS=0,2"));
1874-
CHECK_PARSER(parser_.execCommand("AT+QCFG=\"nwscanmode\",3,1"));
1875-
CHECK_PARSER(parser_.execCommand("AT+QCFG=\"iotopmode\",0,1"));
1882+
if (ncpId() == PLATFORM_NCP_QUECTEL_BG96 || ncpId() == PLATFORM_NCP_QUECTEL_BG95_M5) {
1883+
int desiredNwScanMode = isQuec2g3gEnabled() ? 0 : 3; // 0: AUTO, 3: LTE-ONLY
1884+
CHECK_PARSER(parser_.execCommand("AT+QCFG=\"nwscanmode\",%d,1", desiredNwScanMode));
1885+
}
1886+
if (isQuecCatNBxDevice()) {
1887+
CHECK_PARSER(parser_.execCommand("AT+QCFG=\"iotopmode\",0,1"));
1888+
}
18761889
} else if (eps_.status() == CellularRegistrationStatus::DENIED) {
18771890
LOG(TRACE, "Sticky EPS denied state for %lu s, RF reset", eps_.duration() / 1000);
18781891
eps_.reset();
@@ -1882,6 +1895,7 @@ int QuectelNcpClient::interveneRegistration() {
18821895
}
18831896
}
18841897
}
1898+
18851899
return 0;
18861900
}
18871901

@@ -1916,9 +1930,9 @@ int QuectelNcpClient::processEventsImpl() {
19161930

19171931
// Check GSM, GPRS, and LTE network registration status
19181932
CHECK_PARSER_OK(parser_.execCommand("AT+CEREG?"));
1919-
if (isQuecCat1Device() || ncpId() == PLATFORM_NCP_QUECTEL_BG95_M5) {
1920-
CHECK_PARSER_OK(parser_.execCommand("AT+CREG?"));
1933+
if (isQuec2g3gEnabled()) {
19211934
CHECK_PARSER_OK(parser_.execCommand("AT+CGREG?"));
1935+
CHECK_PARSER_OK(parser_.execCommand("AT+CREG?"));
19221936
}
19231937

19241938
// Check the signal seen by the module while trying to register

hal/network/ncp_client/quectel/quectel_ncp_client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ class QuectelNcpClient: public CellularNcpClient {
153153
bool isQuecCatNBxDevice();
154154
/** Is this a Quectel BG95* device ? */
155155
bool isQuecBG95xDevice();
156+
/** Is this a Quectel device we want to enable 2G and/or 3G on ? */
157+
bool isQuec2g3gEnabled();
156158
int getRuntimeBaudrate();
157159
int modemInit() const;
158160
bool waitModemPowerState(bool onOff, system_tick_t timeout);

0 commit comments

Comments
 (0)